From 8231cd65db342bc86ca79f544b40cc36f69e6ffa Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 9 Nov 2023 15:12:56 +0100 Subject: [PATCH] set_first_sel(): returns first selected element (if any) --- src/editprop.c | 21 ++------------------- src/select.c | 32 +++++++++++++++++++++++++++++--- src/xschem.h | 2 +- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/editprop.c b/src/editprop.c index 5846c587..716a3d82 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -1760,25 +1760,8 @@ void edit_property(int x) tclsetvar("preserve_unchanged_attrs", "0"); } - /* retrieve first selected element (if still selected)... */ - if(xctx->first_sel.n >=0 && xctx->first_sel.type == ELEMENT && - xctx->inst[xctx->first_sel.n].sel == SELECTED) { - type = ELEMENT; - for(j=0; j < xctx->lastsel; j++) { - if(xctx->sel_array[j].type == ELEMENT && xctx->sel_array[j].n == xctx->first_sel.n) { - break; - } - } - /* ... otherwise get first from sel_array[] list */ - } else { - type = xctx->sel_array[0].type; - for(j=0; j < xctx->lastsel; j++) { - if(xctx->sel_array[j].type == ELEMENT) { - type = ELEMENT; - break; - } - } - } + j = set_first_sel(0, -2, 0); + type = xctx->sel_array[j].type; switch(type) { diff --git a/src/select.c b/src/select.c index 09e35ec1..f0555a28 100644 --- a/src/select.c +++ b/src/select.c @@ -725,17 +725,43 @@ void bbox(int what,double x1,double y1, double x2, double y2) } } -void set_first_sel(unsigned short type, int n, unsigned int col) +/* n = -1 : clear first selected info + * n = -2 : return first selected element if still selected, or get first from + * selected list. Id no elements selected return first selected item (j = 0) + * n >= 0 : store indicated element as first selected + */ +int set_first_sel(unsigned short type, int n, unsigned int col) { - if(n == -1) { /* reset first_sel */ + if(n == -2) { + int j; + /* retrieve first selected element (if still selected)... */ + if(xctx->first_sel.n >=0 && xctx->first_sel.type == ELEMENT && + xctx->inst[xctx->first_sel.n].sel == SELECTED) { + for(j=0; j < xctx->lastsel; j++) { + if(xctx->sel_array[j].type == ELEMENT && xctx->sel_array[j].n == xctx->first_sel.n) { + break; + } + } + /* ... otherwise get first from sel_array[] list */ + } else { + for(j=0; j < xctx->lastsel; j++) { + if(xctx->sel_array[j].type == ELEMENT) { + break; + } + } + } + if(j >= xctx->lastsel) j = 0; + return j; + } else if(n == -1) { /* reset first_sel */ xctx->first_sel.type = 0; xctx->first_sel.n = -1; xctx->first_sel.col = 0; - }else if(xctx->first_sel.n == -1) { + } else if(xctx->first_sel.n == -1) { xctx->first_sel.type = type; xctx->first_sel.n = n; xctx->first_sel.col = col; } + return 0; } void unselect_all(int dr) diff --git a/src/xschem.h b/src/xschem.h index 2b2f0a1e..ed227dfe 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1331,7 +1331,7 @@ extern int text_bbox_nocairo(const char * str,double xscale, double yscale, extern Selected select_object(double mx,double my, unsigned short sel_mode, int override_lock); /* return type 20160503 */ -extern void set_first_sel(unsigned short type, int n, unsigned int col); +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);