From 01989bba0cb9ed08d6053ee7eb71bd9a4d0842b7 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sun, 26 Jan 2025 00:26:56 +0100 Subject: [PATCH] fix issue with previous fix, add enable_stretch parameter to select_inside() and select_rect() --- src/actions.c | 6 +++--- src/callback.c | 41 ++++++++++++++--------------------------- src/findnet.c | 6 +++--- src/font.c | 2 +- src/scheduler.c | 2 +- src/select.c | 28 +++++++++++++--------------- src/xschem.h | 4 ++-- 7 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/actions.c b/src/actions.c index 60ee1174..b80f9f9a 100644 --- a/src/actions.c +++ b/src/actions.c @@ -3879,7 +3879,7 @@ void fix_restore_rect(double x1, double y1, double x2, double y2) /* 20150927 select=1: select objects, select=0: unselect objects */ -void select_rect(int what, int select) +void select_rect(int stretch, int what, int select) { int incremental_select = tclgetboolvar("incremental_select"); int sel_touch = tclgetboolvar("select_touch"); @@ -3901,7 +3901,7 @@ void select_rect(int what, int select) draw_selection(xctx->gc[SELLAYER], 0); if(!xctx->nl_sel || (incremental_select && xctx->nl_dir == 0)) - select_inside(xctx->nl_xx1, xctx->nl_yy1, xctx->nl_xx2, xctx->nl_yy2, xctx->nl_sel); + select_inside(stretch, xctx->nl_xx1, xctx->nl_yy1, xctx->nl_xx2, xctx->nl_yy2, xctx->nl_sel); else if(incremental_select && xctx->nl_dir == 1 && sel_touch) select_touch(xctx->nl_xx1, xctx->nl_yy1, xctx->nl_xx2, xctx->nl_yy2, xctx->nl_sel); xctx->nl_xx1=xctx->nl_xr;xctx->nl_xx2=xctx->nl_xr2;xctx->nl_yy1=xctx->nl_yr;xctx->nl_yy2=xctx->nl_yr2; @@ -3935,7 +3935,7 @@ void select_rect(int what, int select) drawtemprect(xctx->gctiled, NOW, xctx->nl_xr,xctx->nl_yr,xctx->nl_xr2,xctx->nl_yr2); if(!sel_touch || xctx->nl_dir == 0) - select_inside(xctx->nl_xr,xctx->nl_yr,xctx->nl_xr2,xctx->nl_yr2, xctx->nl_sel); + select_inside(stretch, xctx->nl_xr,xctx->nl_yr,xctx->nl_xr2,xctx->nl_yr2, xctx->nl_sel); else select_touch(xctx->nl_xr,xctx->nl_yr,xctx->nl_xr2,xctx->nl_yr2, xctx->nl_sel); diff --git a/src/callback.c b/src/callback.c index 498d9a95..ed168623 100644 --- a/src/callback.c +++ b/src/callback.c @@ -2251,6 +2251,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, #else XKeyboardState kbdstate; #endif +int enable_stretch = tclgetboolvar("enable_stretch"); int draw_xhair = tclgetboolvar("draw_crosshair"); int crosshair_size = tclgetintvar("crosshair_size"); int infix_interface = tclgetboolvar("infix_interface"); @@ -2462,12 +2463,12 @@ int rstate; /* (reduced state, without ShiftMask) */ if( (state & Button1Mask) && SET_MODMASK) { if(mx >= xctx->mx_save) xctx->nl_dir = 0; else xctx->nl_dir = 1; - select_rect(RUBBER,0); + select_rect(enable_stretch, RUBBER,0); /* select by area : determine direction */ } else if(state & Button1Mask) { if(mx >= xctx->mx_save) xctx->nl_dir = 0; else xctx->nl_dir = 1; - select_rect(RUBBER,1); + select_rect(enable_stretch, RUBBER,1); } } if(xctx->ui_state & STARTMOVE) { @@ -2492,7 +2493,7 @@ int rstate; /* (reduced state, without ShiftMask) */ xctx->mouse_moved = 1; if(!xctx->drag_elements) { if( !(xctx->ui_state & STARTSELECT)) { - select_rect(START,1); + select_rect(enable_stretch, START,1); xctx->onetime=1; } if(abs(mx-xctx->mx_save) > 8 || @@ -2511,7 +2512,7 @@ int rstate; /* (reduced state, without ShiftMask) */ !(xctx->ui_state & STARTPAN) && !xctx->shape_point_selected && !(xctx->ui_state & (PLACE_SYMBOL | PLACE_TEXT))) { /* unselect area */ if( !(xctx->ui_state & STARTSELECT)) { - select_rect(START,0); + select_rect(enable_stretch, START,0); } } /* Select by area. Shift pressed */ @@ -2520,7 +2521,7 @@ int rstate; /* (reduced state, without ShiftMask) */ !xctx->drag_elements && !(xctx->ui_state & STARTPAN) ) { if(mx != xctx->mx_save || my != xctx->my_save) { if( !(xctx->ui_state & STARTSELECT)) { - select_rect(START,1); + select_rect(enable_stretch, START,1); } if(abs(mx-xctx->mx_save) > 8 || abs(my-xctx->my_save) > 8 ) { /* set reasonable threshold before unsel */ @@ -3148,16 +3149,8 @@ int rstate; /* (reduced state, without ShiftMask) */ } if(key=='y' && rstate == 0) /* toggle stretching */ { - int en_s; - en_s = tclgetboolvar("enable_stretch"); - en_s = !en_s; - - if(en_s) { - tclsetvar("enable_stretch","1"); - } - else { - tclsetvar("enable_stretch","0"); - } + enable_stretch = !enable_stretch; + tclsetboolvar("enable_stretch", enable_stretch); break; } if(key=='x' && EQUAL_MODMASK) /* toggle draw crosshair at mouse pos */ @@ -3671,8 +3664,7 @@ int rstate; /* (reduced state, without ShiftMask) */ waves_callback(event, mx, my, key, button, aux, state); break; } - if(tclgetboolvar("enable_stretch")) - select_attached_nets(); /* stretch nets that land on selected instance pins */ + if(enable_stretch) select_attached_nets(); /* stretch nets that land on selected instance pins */ if(infix_interface) { xctx->mx_double_save=xctx->mousex_snap; xctx->my_double_save=xctx->mousey_snap; @@ -3707,8 +3699,7 @@ int rstate; /* (reduced state, without ShiftMask) */ waves_callback(event, mx, my, key, button, aux, state); break; } - if(!tclgetboolvar("enable_stretch")) - select_attached_nets(); /* stretch nets that land on selected instance pins */ + if(!enable_stretch) select_attached_nets(); /* stretch nets that land on selected instance pins */ if(infix_interface) { xctx->mx_double_save=xctx->mousex_snap; xctx->my_double_save=xctx->mousey_snap; @@ -3724,8 +3715,7 @@ int rstate; /* (reduced state, without ShiftMask) */ if(key=='M' && state == (ControlMask | ShiftMask) && !(xctx->ui_state & (STARTMOVE | STARTCOPY))) { - if(!tclgetboolvar("enable_stretch")) - select_attached_nets(); /* stretch nets that land on selected instance pins */ + if(enable_stretch) select_attached_nets(); /* stretch nets that land on selected instance pins */ xctx->connect_by_kissing = 2; /* 2 will be used to reset var to 0 at end of move */ if(infix_interface) { xctx->mx_double_save=xctx->mousex_snap; @@ -4187,7 +4177,7 @@ int rstate; /* (reduced state, without ShiftMask) */ /* xctx->push_undo(); */ xctx->drag_elements = 1; - if( (state & ControlMask) && !(state & ShiftMask) && !tclgetboolvar("enable_stretch")) { + if( (state & ControlMask) && !(state & ShiftMask) && !enable_stretch) { select_attached_nets(); /* stretch nets that land on selected instance pins */ } if(state == (ShiftMask | ControlMask) ) { @@ -4286,14 +4276,11 @@ int rstate; /* (reduced state, without ShiftMask) */ if(xctx->semaphore >= 2) break; if(xctx->ui_state & STARTSELECT) { if(state & ControlMask) { - int es = tclgetboolvar("enable_stretch"); - tclsetboolvar("enable_stretch", !es); - select_rect(END,-1); - tclsetboolvar("enable_stretch", es); + select_rect(!enable_stretch, END,-1); } else { /* Button1 release: end of rectangle select */ if(!(state & (Button4Mask|Button5Mask) ) ) { - select_rect(END,-1); + select_rect(enable_stretch, END,-1); } } rebuild_selected_array(); diff --git a/src/findnet.c b/src/findnet.c index 8f7cda41..e5641f6a 100644 --- a/src/findnet.c +++ b/src/findnet.c @@ -378,14 +378,14 @@ static void find_closest_box(double mx ,double my, int override_lock) int i, c, r=-1, col = 0; /* correction for very small boxes */ - double min = MINOR(xctx->rect[c][i].x2 - xctx->rect[c][i].x1, - xctx->rect[c][i].y2 - xctx->rect[c][i].y1); - ds = (ds * 8 <= min ) ? ds : min / 8; for(c=0;cenable_layer[c]) continue; for(i=0;irects[c]; ++i) { + double min = MINOR(xctx->rect[c][i].x2 - xctx->rect[c][i].x1, + xctx->rect[c][i].y2 - xctx->rect[c][i].y1); + ds = (xctx->cadhalfdotsize * 8 <= min ) ? xctx->cadhalfdotsize : min / 8; if( POINTINSIDE(mx, my, xctx->rect[c][i].x1 - ds, xctx->rect[c][i].y1 - ds, xctx->rect[c][i].x2 + ds, xctx->rect[c][i].y2 + ds) ) { diff --git a/src/font.c b/src/font.c index 372f8b5a..299bbda2 100644 --- a/src/font.c +++ b/src/font.c @@ -35,7 +35,7 @@ void compile_font(void) for(code=0;code<127;code++) { unselect_all(1); - select_inside(code*FONTOFFSET-1,-FONTHEIGHT-1, + select_inside(0, code*FONTOFFSET-1,-FONTHEIGHT-1, code*FONTOFFSET+FONTWIDTH+1,FONTWHITESPACE + FONTDESCENT+1, 1); rebuild_selected_array(); character[code] = my_calloc(_ALLOC_ID_, xctx->lastsel*4+1, sizeof(double)); diff --git a/src/scheduler.c b/src/scheduler.c index f4534fa7..22322d33 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -5018,7 +5018,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg y1 = atof(argv[3]); x2 = atof(argv[4]); y2 = atof(argv[5]); - select_inside(x1, y1, x2, y2, sel); + select_inside(tclgetboolvar("enable_stretch"), x1, y1, x2, y2, sel); Tcl_ResetResult(interp); } diff --git a/src/select.c b/src/select.c index 485c9ee3..ca5105d2 100644 --- a/src/select.c +++ b/src/select.c @@ -1298,20 +1298,18 @@ void select_attached_nets(void) rebuild_selected_array(); } -void select_inside(double x1,double y1, double x2, double y2, int sel) /*added unselect (sel param) */ +void select_inside(int stretch, double x1,double y1, double x2, double y2, int sel) { int c,i, tmpint; double x, y, r, a, b, xa, ya, xb, yb; /* arc */ double xx1,yy1,xx2,yy2, dtmp; xRect tmp; - int en_s; int select_rot = 0, select_flip = 0; #if HAS_CAIRO==1 int customfont; #endif char *estr = NULL; - en_s = tclgetboolvar("enable_stretch"); for(i=0;iwires; ++i) { if(sel) { @@ -1320,12 +1318,12 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /*added u xctx->ui_state |= SELECTION; /* set xctx->ui_state to SELECTION also if unselecting by area ???? */ select_wire(i, SELECTED, 1); } - else if(en_s && POINTINSIDE(xctx->wire[i].x1,xctx->wire[i].y1, x1,y1,x2,y2) ) + else if(stretch && POINTINSIDE(xctx->wire[i].x1,xctx->wire[i].y1, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; select_wire(i, SELECTED1, 1); } - else if(en_s && POINTINSIDE(xctx->wire[i].x2,xctx->wire[i].y2, x1,y1,x2,y2) ) + else if(stretch && POINTINSIDE(xctx->wire[i].x2,xctx->wire[i].y2, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; select_wire(i, SELECTED2, 1); @@ -1412,7 +1410,7 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /*added u select_polygon(c, i, SELECTED, 1); } else if(selected_points) { /* for polygon, SELECTED1 means partial sel */ - if(sel && en_s) select_polygon(c, i, SELECTED1,1); + if(sel && stretch) select_polygon(c, i, SELECTED1,1); } } @@ -1425,12 +1423,12 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /*added u xctx->ui_state |= SELECTION; select_line(c,i,SELECTED,1); } - else if(en_s && POINTINSIDE(xctx->line[c][i].x1,xctx->line[c][i].y1, x1,y1,x2,y2) ) + else if(stretch && POINTINSIDE(xctx->line[c][i].x1,xctx->line[c][i].y1, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; /* set xctx->ui_state to SELECTION also if unselecting by area ???? */ select_line(c, i,SELECTED1,1); } - else if(en_s && POINTINSIDE(xctx->line[c][i].x2,xctx->line[c][i].y2, x1,y1,x2,y2) ) + else if(stretch && POINTINSIDE(xctx->line[c][i].x2,xctx->line[c][i].y2, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; select_line(c, i,SELECTED2,1); @@ -1458,17 +1456,17 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /*added u xctx->ui_state |= SELECTION; /* set xctx->ui_state to SELECTION also if unselecting by area ???? */ sel? select_arc(c, i, SELECTED,1): select_arc(c, i, 0,1); } - else if( sel && en_s && POINTINSIDE(x, y, x1, y1, x2, y2) ) + else if( sel && stretch && POINTINSIDE(x, y, x1, y1, x2, y2) ) { xctx->ui_state |= SELECTION; /* set xctx->ui_state to SELECTION also if unselecting by area ???? */ select_arc(c, i,SELECTED1,1); } - else if( sel && en_s && POINTINSIDE(xb, yb, x1, y1, x2, y2) ) + else if( sel && stretch && POINTINSIDE(xb, yb, x1, y1, x2, y2) ) { xctx->ui_state |= SELECTION; /* set xctx->ui_state to SELECTION also if unselecting by area ???? */ select_arc(c, i,SELECTED3,1); } - else if( sel && en_s && POINTINSIDE(xa, ya, x1, y1, x2, y2) ) + else if( sel && stretch && POINTINSIDE(xa, ya, x1, y1, x2, y2) ) { xctx->ui_state |= SELECTION; /* set xctx->ui_state to SELECTION also if unselecting by area ???? */ select_arc(c, i,SELECTED2,1); @@ -1490,22 +1488,22 @@ void select_inside(double x1,double y1, double x2, double y2, int sel) /*added u } } else if(c != GRIDLAYER || !(xctx->rect[c][i].flags & 2048)){ /* no stretch on unscaled images */ - if( sel && en_s && POINTINSIDE(xctx->rect[c][i].x1,xctx->rect[c][i].y1, x1,y1,x2,y2) ) + if( sel && stretch && POINTINSIDE(xctx->rect[c][i].x1,xctx->rect[c][i].y1, x1,y1,x2,y2) ) { /*20070302 added stretch select */ xctx->ui_state |= SELECTION; select_box(c, i,SELECTED1,1, 0); } - if( sel && en_s && POINTINSIDE(xctx->rect[c][i].x2,xctx->rect[c][i].y1, x1,y1,x2,y2) ) + if( sel && stretch && POINTINSIDE(xctx->rect[c][i].x2,xctx->rect[c][i].y1, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; select_box(c, i,SELECTED2,1, 0); } - if( sel && en_s && POINTINSIDE(xctx->rect[c][i].x1,xctx->rect[c][i].y2, x1,y1,x2,y2) ) + if( sel && stretch && POINTINSIDE(xctx->rect[c][i].x1,xctx->rect[c][i].y2, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; select_box(c, i,SELECTED3,1, 0); } - if( sel && en_s && POINTINSIDE(xctx->rect[c][i].x2,xctx->rect[c][i].y2, x1,y1,x2,y2) ) + if( sel && stretch && POINTINSIDE(xctx->rect[c][i].x2,xctx->rect[c][i].y2, x1,y1,x2,y2) ) { xctx->ui_state |= SELECTION; select_box(c, i,SELECTED4,1, 0); diff --git a/src/xschem.h b/src/xschem.h index 68eefe8e..be4edd09 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1382,7 +1382,7 @@ extern Selected select_object(double mx,double my, unsigned short sel_mode, extern int set_first_sel(unsigned short type, int n, unsigned int col); extern void unselect_all(int dr); extern void select_attached_nets(void); -extern void select_inside(double x1,double y1, double x2, double y2, int sel); +extern void select_inside(int stretch, double x1,double y1, double x2, double y2, int sel); extern void select_touch(double x1,double y1, double x2, double y2, int sel); /* Select all nets that are dangling, ie not attached to any non pin/port/probe components */ extern int select_dangling_nets(void); @@ -1545,7 +1545,7 @@ extern void pan(int what, int mx, int my); extern void zoom_rectangle(int what); extern void zoom_box(double x1, double y1, double x2, double y2, double factor); extern void save_restore_zoom(int save, Zoom_info *zi); -extern void select_rect(int what, int select); +extern void select_rect(int stretch, int what, int select); extern void new_rect(int what, double mousex_snap, double mousey_snap); extern void new_polygon(int what, double mousex_snap, double mousey_snap); extern void compile_font(void);