Changeset 5525


Ignore:
Timestamp:
08/22/09 17:58:58 (4 years ago)
Author:
werner
Message:

Made life in mil-land a little less painful.

  • .fpd file format: new directive "unit" to set the default unit
  • new selection was too aggressive - make it only rearrange settings if we also fail the second vector search
  • gui_draw_pad_text: calculation of height vs. width lost too much precision, causing pad text to be rotated arbitrarily
  • drag_new_vec: display distance in mil if unit is mil
  • end_new_raw_vec: store distance in mil if unit is mil
  • gridify: use a 10 mil grid if unit is mil
  • ps_hline: corrected gsave/grestore mismatch
  • Makefile: made "all" a prerequisite of "install"
  • Postscript output now mentions the default unit (if set)
  • ps_package: height and width were swapped, oopsie !
Location:
trunk/eda/fped
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/eda/fped/Makefile

    r5487 r5525  
    119119# ----- Install / uninstall --------------------------------------------------- 
    120120 
    121 install: 
     121install:        all 
    122122                install -m 755 fped $(PREFIX)/bin/ 
    123123 
  • trunk/eda/fped/README

    r5519 r5525  
    9191... 
    9292package name 
     93unit 
    9394objects 
    9495... 
     
    125126 
    126127All values used as dimensions must be either mm or mil. 
     128 
     129The default unit can be set with one of the following directives: 
     130 
     131unit mm 
     132unit mil 
     133unit auto 
     134 
     135When saving a footprint definition, the default unit is set to the 
     136unit set in the GUI. 
    127137 
    128138 
  • trunk/eda/fped/dump.c

    r5490 r5525  
    1818#include "unparse.h" 
    1919#include "obj.h" 
     20#include "gui_status.h" 
    2021#include "dump.h" 
    2122 
     
    492493 
    493494 
     495static void dump_unit(FILE *file) 
     496{ 
     497        switch (curr_unit) { 
     498        case curr_unit_mm: 
     499                fprintf(file, "unit mm\n"); 
     500                break; 
     501        case curr_unit_mil: 
     502                fprintf(file, "unit mil\n"); 
     503                break; 
     504        case curr_unit_auto: 
     505                fprintf(file, "unit auto\n"); 
     506                break; 
     507        default: 
     508                abort(); 
     509        } 
     510} 
     511 
     512 
    494513int dump(FILE *file) 
    495514{ 
     
    502521                if (!frame->name) { 
    503522                        fprintf(file, "package \"%s\"\n", pkg_name); 
     523                        dump_unit(file); 
    504524                        dump_frame(file, frame, ""); 
    505525                } else { 
  • trunk/eda/fped/fpd.l

    r5478 r5525  
    119119<INITIAL>"measy"                { BEGIN(NOKEYWORD); 
    120120                                  return TOK_MEASY; } 
     121<INITIAL>"unit"                 { BEGIN(NOKEYWORD); 
     122                                  return TOK_UNIT; } 
    121123 
    122124<INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0; 
  • trunk/eda/fped/fpd.y

    r5478 r5525  
    2020#include "obj.h" 
    2121#include "meas.h" 
     22#include "gui_status.h" 
    2223#include "fpd.h" 
    2324 
     
    157158%token          TOK_SET TOK_LOOP TOK_PACKAGE TOK_FRAME TOK_TABLE TOK_VEC 
    158159%token          TOK_PAD TOK_RPAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC 
    159 %token          TOK_MEAS TOK_MEASX TOK_MEASY 
     160%token          TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT 
    160161%token          TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED 
    161162 
     
    207208 
    208209fpd: 
    209         | frame_defs part_name frame_items 
     210        | frame_defs part_name opt_unit frame_items 
    210211        ; 
    211212 
     
    225226                                } 
    226227                        pkg_name = $2; 
     228                } 
     229        ; 
     230 
     231opt_unit: 
     232        | TOK_UNIT ID 
     233                { 
     234                        if (!strcmp($2, "mm")) 
     235                                curr_unit = curr_unit_mm; 
     236                        else if (!strcmp($2, "mil")) 
     237                                curr_unit = curr_unit_mil; 
     238                        else if (!strcmp($2, "auto")) 
     239                                curr_unit = curr_unit_auto; 
     240                        else { 
     241                                yyerrorf("unrecognized unit \"%s\"", $2); 
     242                                YYABORT; 
     243                        } 
    227244                } 
    228245        ; 
  • trunk/eda/fped/gui_inst.c

    r5484 r5525  
    242242        struct coord c; 
    243243        unit_type h, w; 
    244  
     244        int rot; 
     245 
     246        w = self->bbox.max.x-self->bbox.min.x; 
     247        h = self->bbox.max.y-self->bbox.min.y; 
     248        rot = w/1.1 < h; 
    245249        gc = gc_ptext[get_mode(self)]; 
    246250        sort_coord(&min, &max); 
     
    248252        h = max.y-min.y; 
    249253        w = max.x-min.x; 
    250         render_text(DA, gc, c.x/2, c.y/2, w <= h*1.1 ? 0 : 90, 
     254        render_text(DA, gc, c.x/2, c.y/2, rot ? 0 : 90, 
    251255            self->u.pad.name, PAD_FONT, 0.5, 0.5, 
    252256            w-2*PAD_BORDER, h-2*PAD_BORDER); 
  • trunk/eda/fped/gui_status.c

    r5461 r5525  
    737737 
    738738 
     739static void show_curr_unit(void) 
     740{ 
     741        switch (curr_unit) { 
     742        case curr_unit_mm: 
     743                status_set_unit("mm"); 
     744                break; 
     745        case curr_unit_mil: 
     746                status_set_unit("mil"); 
     747                break; 
     748        case curr_unit_auto: 
     749                status_set_unit("auto"); 
     750                break; 
     751        default: 
     752                abort(); 
     753        } 
     754} 
     755 
     756 
    739757static gboolean unit_button_press_event(GtkWidget *widget, 
    740758    GdkEventButton *event, gpointer data) 
     
    743761        case 1: 
    744762                curr_unit = (curr_unit+1) % curr_unit_n; 
    745                 switch (curr_unit) { 
    746                 case curr_unit_mm: 
    747                         status_set_unit("mm"); 
    748                         break; 
    749                 case curr_unit_mil: 
    750                         status_set_unit("mil"); 
    751                         break; 
    752                 case curr_unit_auto: 
    753                         status_set_unit("auto"); 
    754                         break; 
    755                 default: 
    756                         abort(); 
    757                 } 
     763                show_curr_unit(); 
    758764                break; 
    759765        } 
     
    860866 
    861867        label_in_box_bg(status_unit, COLOR_UNIT_SELECTOR); 
    862         status_set_unit("mm"); 
     868        show_curr_unit(); 
    863869        g_signal_connect(G_OBJECT(box_of_label(status_unit)), 
    864870            "button_press_event", G_CALLBACK(unit_button_press_event), NULL); 
  • trunk/eda/fped/gui_tool.c

    r5524 r5525  
    216216{ 
    217217        struct coord new; 
    218         unit_type unit = mm_to_units(0.1); 
    219  
     218        unit_type unit; 
     219 
     220        switch (curr_unit) { 
     221        case curr_unit_mm: 
     222        case curr_unit_auto: 
     223                unit = mm_to_units(0.1); 
     224                break; 
     225        case curr_unit_mil: 
     226                unit = mil_to_units(10); 
     227                break; 
     228        default: 
     229                abort(); 
     230        } 
    220231        new.x = pos.x-((pos.x-base.x) % unit); 
    221232        new.y = pos.y-((pos.y-base.y) % unit); 
     
    239250        status_set_type_x("dX ="); 
    240251        status_set_type_y("dX ="); 
    241         status_set_x("%lg mm", units_to_mm(to.x-pos.x)); 
    242         status_set_y("%lg mm", units_to_mm(to.y-pos.y)); 
     252        /* @@@ use status_set_xy */ 
     253        switch (curr_unit) { 
     254        case curr_unit_mm: 
     255        case curr_unit_auto: 
     256                status_set_x("%lg mm", units_to_mm(to.x-pos.x)); 
     257                status_set_y("%lg mm", units_to_mm(to.y-pos.y)); 
     258                break; 
     259        case curr_unit_mil: 
     260                status_set_x("%lg mil", units_to_mil(to.x-pos.x)); 
     261                status_set_y("%lg mil", units_to_mil(to.y-pos.y)); 
     262                break; 
     263        default: 
     264                abort(); 
     265        } 
    243266        pos = translate(pos); 
    244267        to = translate(to); 
     
    271294        pos = inst_get_point(from); 
    272295        to = gridify(pos, to); 
    273         vec->x = new_num(make_mm(units_to_mm(to.x-pos.x))); 
    274         vec->y = new_num(make_mm(units_to_mm(to.y-pos.y))); 
     296        switch (curr_unit) { 
     297        case curr_unit_mm: 
     298        case curr_unit_auto: 
     299                vec->x = new_num(make_mm(units_to_mm(to.x-pos.x))); 
     300                vec->y = new_num(make_mm(units_to_mm(to.y-pos.y))); 
     301                break; 
     302        case curr_unit_mil: 
     303                vec->x = new_num(make_mil(units_to_mil(to.x-pos.x))); 
     304                vec->y = new_num(make_mil(units_to_mil(to.y-pos.y))); 
     305                break; 
     306        default: 
     307                abort(); 
     308        } 
    275309        return 1; 
    276310} 
  • trunk/eda/fped/inst.c

    r5523 r5525  
    209209                        goto selected; 
    210210        } 
     211 
     212        /* give vectors a second chance */ 
     213 
     214        if (show_stuff) { 
     215                FOR_ALL_INSTS(i, ip_vec, inst) { 
     216                        if (!inst->active) 
     217                                continue; 
     218                        if (!inst_connected(inst)) 
     219                                continue; 
     220                        dist = gui_dist_vec_fallback(inst, pos, draw_ctx.scale); 
     221                        if (dist >= 0 && (!selected_inst || best_dist > dist)) { 
     222                                selected_inst = inst; 
     223                                best_dist = dist; 
     224                        } 
     225                } 
     226         
     227                if (selected_inst) 
     228                        goto selected; 
     229        } 
     230 
    211231        if (any_same_frame) { 
    212232                if (activate_item(any_same_frame)) 
     
    221241        } 
    222242 
    223         if (!show_stuff) 
    224                 return 0; 
    225  
    226         /* give vectors a second chance */ 
    227  
    228         FOR_ALL_INSTS(i, ip_vec, inst) { 
    229                 if (!inst->active) 
    230                         continue; 
    231                 if (!inst_connected(inst)) 
    232                         continue; 
    233                 dist = gui_dist_vec_fallback(inst, pos, draw_ctx.scale); 
    234                 if (dist >= 0 && (!selected_inst || best_dist > dist)) { 
    235                         selected_inst = inst; 
    236                         best_dist = dist; 
    237                 } 
    238         } 
    239          
    240         if (!selected_inst) 
    241                 return 0; 
     243        return 0; 
    242244 
    243245selected: 
  • trunk/eda/fped/postscript.c

    r5522 r5525  
    5353#define PS_DIVIDER_BORDER       mm_to_units(2) 
    5454#define PS_DIVIDER_WIDTH        mm_to_units(0.5) 
     55 
     56#define PS_MISC_TEXT_HEIGHT     mm_to_units(3) 
    5557 
    5658#define PS_DOT_DIST             mm_to_units(0.03) 
     
    455457        fprintf(file, "gsave %d setlinewidth\n", PS_DIVIDER_WIDTH); 
    456458        fprintf(file, "    %d %d moveto\n", -PAGE_HALF_WIDTH, y); 
    457         fprintf(file, "    %d 0 rlineto stroke gsave\n", PAGE_HALF_WIDTH*2); 
     459        fprintf(file, "    %d 0 rlineto stroke grestore\n", PAGE_HALF_WIDTH*2); 
    458460} 
    459461 
     
    489491 
    490492 
     493static void ps_unit(FILE *file, 
     494    unit_type x, unit_type y, unit_type w, unit_type h) 
     495{ 
     496        const char *s; 
     497 
     498        switch (curr_unit) { 
     499        case curr_unit_mm: 
     500                s = "Dimensions in mm"; 
     501                break; 
     502        case curr_unit_mil: 
     503                s = "Dimensions in mil"; 
     504                break; 
     505        case curr_unit_auto: 
     506                return; 
     507        default: 
     508                abort(); 
     509        } 
     510 
     511        fprintf(file, "gsave %d %d moveto\n", x, y); 
     512        fprintf(file, "    /Helvetica findfont dup\n"); 
     513        fprintf(file, "    (%s) %d %d\n", s, w, h); 
     514        fprintf(file, "    4 copy 1000 maxfont maxfont scalefont setfont\n"); 
     515        fprintf(file, "    (%s) show grestore\n", s); 
     516} 
     517 
     518 
    491519static void ps_package(FILE *file, const struct pkg *pkg, int page) 
    492520{ 
     
    505533 
    506534        bbox = inst_get_bbox(); 
    507         w = 2*(-bbox.min.y > bbox.max.y ? -bbox.min.y : bbox.max.y); 
    508         h = 2*(-bbox.min.x > bbox.max.x ? -bbox.min.x : bbox.max.x); 
     535        w = 2*(-bbox.min.x > bbox.max.x ? -bbox.min.x : bbox.max.x); 
     536        h = 2*(-bbox.min.y > bbox.max.y ? -bbox.min.y : bbox.max.y); 
    509537 
    510538        /* 
     
    575603        fprintf(file, "grestore\n"); 
    576604 
     605        ps_unit(file, -PAGE_HALF_WIDTH, PS_DIVIDER_BORDER, PAGE_HALF_WIDTH, 
     606            PS_MISC_TEXT_HEIGHT); 
    577607        ps_hline(file, 0); 
    578608 
Note: See TracChangeset for help on using the changeset viewer.