Index: trunk/src/board.h =================================================================== --- trunk/src/board.h (revision 34927) +++ trunk/src/board.h (revision 34928) @@ -80,6 +80,7 @@ pcb_fontkit_t fontkit; pcb_layer_stack_t LayerGroups; vtroutestyle_t RouteStyle; + int route_style_last; /* last selected route style; GUI: check this first for match with the "pen" when deciding which route style is active; fixes the bug with multiple matching route styles */ pcb_netlist_t netlist[PCB_NUM_NETLISTS]; /* htsp_t netlist_subc[PCB_NUM_NETLISTS]; hierarchic netlists */ pcb_ratspatch_line_t *NetlistPatches, *NetlistPatchLast; Index: trunk/src/gui_act.c =================================================================== --- trunk/src/gui_act.c (revision 34927) +++ trunk/src/gui_act.c (revision 34928) @@ -565,7 +565,7 @@ switch(*cmd) { case '\0': do_select:; - pcb_use_route_style(rts); + pcb_use_route_style_idx(PCB, number - 1); break; case 'd': /* del */ res->type = FGW_INT; @@ -665,7 +665,7 @@ static void set_same_(rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name) { int known; - known = pcb_route_style_lookup_strict(&PCB->RouteStyle, Thick, textt, texts, fid, Clearance, via_proto, Name); + known = pcb_route_style_lookup_strict(&PCB->RouteStyle, PCB->route_style_last, Thick, textt, texts, fid, Clearance, via_proto, Name); if (known < 0) { /* unknown style, set properties */ if (Thick != -1) { rnd_conf_set_design("design/line_thickness", "%$mS", Thick); } @@ -677,7 +677,7 @@ PCB->pen_attr = NULL; } else - pcb_use_route_style_idx(&PCB->RouteStyle, known); + pcb_use_route_style_idx(PCB, known); } static fgw_error_t pcb_act_SetSame(fgw_arg_t *res, int argc, fgw_arg_t *argv) Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (revision 34927) +++ trunk/src/plug_io.c (revision 34928) @@ -670,7 +670,7 @@ extern fgw_error_t pcb_act_GetStyle(fgw_arg_t *res, int argc, fgw_arg_t *argv); fgw_arg_t res, argv; if (RND_ACT_CALL_C(&PCB->hidlib, pcb_act_GetStyle, &res, 1, &argv) < 0) - pcb_use_route_style_idx(&PCB->RouteStyle, 0); + pcb_use_route_style_idx(PCB, 0); } if ((how == 0) || (revert)) Index: trunk/src/route_style.c =================================================================== --- trunk/src/route_style.c (revision 34927) +++ trunk/src/route_style.c (revision 34928) @@ -42,7 +42,7 @@ static const char rst_cookie[] = "core route style"; -void pcb_use_route_style(pcb_route_style_t * rst) +void pcb_use_route_style_(pcb_route_style_t * rst) { rnd_conf_set_design("design/line_thickness", "%$mS", rst->Thick); rnd_conf_set_design("design/text_scale", "%d", rst->texts <= 0 ? 100 : rst->texts); @@ -55,11 +55,11 @@ PCB->pen_attr = &rst->attr; } -int pcb_use_route_style_idx(vtroutestyle_t *styles, int idx) +int pcb_use_route_style_idx_(vtroutestyle_t *styles, int idx) { if ((idx < 0) || (idx >= vtroutestyle_len(styles))) return -1; - pcb_use_route_style(styles->array+idx); + pcb_use_route_style_(styles->array+idx); return 0; } @@ -89,22 +89,34 @@ #undef cmpi0 #undef cmps -int pcb_route_style_lookup(vtroutestyle_t *styles, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name) +int pcb_route_style_lookup(vtroutestyle_t *styles, int hint, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name) { - int n; - for (n = 0; n < vtroutestyle_len(styles); n++) + int n, len = vtroutestyle_len(styles); + + if ((hint >= 0) && (hint array[hint], 0, Thick, textt, texts, fid, Clearance, via_proto, Name)) + return hint; + + for (n = 0; n < len; n++) if (pcb_route_style_match_(&styles->array[n], 0, Thick, textt, texts, fid, Clearance, via_proto, Name)) return n; + return -1; } -int pcb_route_style_lookup_strict(vtroutestyle_t *styles, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name) +int pcb_route_style_lookup_strict(vtroutestyle_t *styles, int hint, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name) { - int n; + int n, len = vtroutestyle_len(styles); + + if ((hint >= 0) && (hint array[hint], 1, Thick, textt, texts, fid, Clearance, via_proto, Name)) + return hint; + for (n = 0; n < vtroutestyle_len(styles); n++) if (pcb_route_style_match_(&styles->array[n], 1, Thick, textt, texts, fid, Clearance, via_proto, Name)) return n; + return -1; } Index: trunk/src/route_style.h =================================================================== --- trunk/src/route_style.h (revision 34927) +++ trunk/src/route_style.h (revision 34928) @@ -29,20 +29,33 @@ #include "vtroutestyle.h" -/* Set design configuration (the pen we draw with) to a given route style */ -void pcb_use_route_style(pcb_route_style_t *rst); +/* Set design configuration (the pen we draw with) to a given route style + (Do not call directly, use the macro below) */ +void pcb_use_route_style_(pcb_route_style_t *rst); /* Same as pcb_use_route_style() but uses one of the styles in a vector; - returns -1 if idx is out of bounds, 0 on success. */ -int pcb_use_route_style_idx(vtroutestyle_t *styles, int idx); + returns -1 if idx is out of bounds, 0 on success. + (Do not call directly, use the macro below) */ +int pcb_use_route_style_idx_(vtroutestyle_t *styles, int idx); +/* Macros for the same thing: these also set the last selected route style idx + in the pcb struct which is necessary because multiple route styles can + have the same parameters so looking at the parameters only it is not possible + to decide which one was last selected */ +#define pcb_use_route_style_idx(pcb, idx) \ + do { \ + if (pcb_use_route_style_idx_(&pcb->RouteStyle, idx) == 0) \ + pcb->route_style_last = idx; \ + } while(0) + /* Compare supplied parameters to each style in the vector and return the index of the first matching style. All non-(-1) parameters need to match to accept a style. Return -1 on no match. The strict version returns match only if the route style did set all values explicitly and not matching "wildcard" from - the style's side */ -int pcb_route_style_lookup(vtroutestyle_t *styles, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name); -int pcb_route_style_lookup_strict(vtroutestyle_t *styles, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name); + the style's side. If hint >= 0, check that index first, out-of-order; this + is useful for finding the last selected route style over the first match */ +int pcb_route_style_lookup(vtroutestyle_t *styles, int hint, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name); +int pcb_route_style_lookup_strict(vtroutestyle_t *styles, int hint, rnd_coord_t Thick, rnd_coord_t textt, int texts, pcb_font_id_t fid, rnd_coord_t Clearance, rnd_cardinal_t via_proto, char *Name); /* Return 1 if rst matches the style in supplied args. Same matching rules as in pcb_route_style_lookup(). */ @@ -53,7 +66,7 @@ int pcb_get_style_size(int funcid, rnd_coord_t * out, int type, int size_id); #define PCB_LOOKUP_ROUTE_STYLE_PEN_(pcb, how) \ - pcb_route_style_ ## how(&pcb->RouteStyle,\ + pcb_route_style_ ## how(&pcb->RouteStyle, pcb->route_style_last, \ conf_core.design.line_thickness, \ conf_core.design.text_thickness, \ conf_core.design.text_scale, \ Index: trunk/src_plugins/lib_hid_pcbui/routest.c =================================================================== --- trunk/src_plugins/lib_hid_pcbui/routest.c (revision 34927) +++ trunk/src_plugins/lib_hid_pcbui/routest.c (revision 34928) @@ -166,7 +166,7 @@ } if (ridx < 0) return; - pcb_use_route_style(&(PCB->RouteStyle.array[ridx])); + pcb_use_route_style_idx(PCB, ridx); rst_force_update_chk_and_dlg(); } @@ -180,7 +180,7 @@ static void rst_new_cb(void *hid_ctx, void *caller_data, rnd_hid_attribute_t *attr) { int target = pcb_route_style_new(PCB, "new style", 1); - pcb_use_route_style(&(PCB->RouteStyle.array[target])); + pcb_use_route_style_idx(PCB, target); pcb_dlg_rstdlg(target); } Index: trunk/src_plugins/lib_hid_pcbui/routest_dlg.c =================================================================== --- trunk/src_plugins/lib_hid_pcbui/routest_dlg.c (revision 34927) +++ trunk/src_plugins/lib_hid_pcbui/routest_dlg.c (revision 34928) @@ -118,7 +118,7 @@ static void rst_updated(pcb_route_style_t *rst) { if (rst != NULL) - pcb_use_route_style(rst); + pcb_use_route_style_(rst); rnd_event(&PCB->hidlib, PCB_EVENT_ROUTE_STYLES_CHANGED, NULL); pcb_board_set_changed_flag(PCB, 1); } @@ -222,7 +222,7 @@ } /* something got modified - re-select the current route style so "pen" is updated */ - pcb_use_route_style(&(PCB->RouteStyle.array[rstdlg_ctx.curr])); + pcb_use_route_style_idx(PCB, rstdlg_ctx.curr); } static int rst_edit_attr(char **key, char **val)