From a4b597cfc269fa84fee77e529ad0a428cbd450ed Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Mon, 25 Sep 2023 23:23:08 +0200 Subject: [PATCH] add Alt-c command for copy object and create nets to connected terminals --- doc/xschem_man/commands.html | 25 ++++++++++++++++--------- src/actions.c | 19 +++++++++++++++++-- src/callback.c | 17 +++++++++++++++-- src/keys.help | 17 +++++++++++------ src/move.c | 26 ++++++++++++++++++++++---- src/xschem.h | 3 ++- 6 files changed, 83 insertions(+), 24 deletions(-) diff --git a/doc/xschem_man/commands.html b/doc/xschem_man/commands.html index e472b684..bba3718e 100644 --- a/doc/xschem_man/commands.html +++ b/doc/xschem_man/commands.html @@ -38,6 +38,7 @@ p{padding: 15px 30px 10px;} This list is available in XSCHEM in the Help menu

+
                         XSCHEM MOUSE BINDINGS
 ----------------------------------------------------------------------
 LeftButton              Clear selection and select a graphic object 
@@ -51,13 +52,16 @@ ctrl + LeftButton       if an 'url' or 'tclcommand' property is defined on
                         tclcommand
 
 LeftButton drag         Select objects by area, clearing previous selection
-
-shift + LeftButton drag Select objects by area, without clearing 
-                        previous selection
+                        "[shift] left button drag" and "[shift] ctrl-left
+                        button drag" commands are swapped if enable_stretch
+                        is set.
 
 Ctrl + LeftButton drag  Select objects by area to perform a 
                         subsequent   'stretch'  move operation
 
+shift + LeftButton drag Select objects by area, without clearing 
+                        previous selection
+
 Shift +                 Select objects by area without unselecting
 Ctrl + LeftButton drag  to perform a subsequent   'stretch'  move operation
 
@@ -69,10 +73,11 @@ Ctrl + Right Button     Select all connected wires/labels/pins, stopping at
 Alt + RightButton       Cut wire at mouse position (creates 2 adjacent wires)
                         aligns the cut point to current snap setting.
 
-Alt + Shift + RightButton 
+Alt + Shift + RightButton
                         Cut wire at mouse position (creates 2 adjacent wires)
                         does not align cut point to current snap setting.
 
+
 Mouse Wheel             Zoom in / out
 
 MidButton drag          Pan viewable area
@@ -129,7 +134,8 @@ shift       'A'         Toggle show netlist
 Shift       'B'         Edit/add header/license metadata to the schematic/symbol file.
 ctrl        'b'         Toggle show text in symbol
 alt         'b'         Toggle show symbol details / only bounding boxes
--           'c'         Copy selected obj. 
+-           'c'         Copy selected objects, 'c' and 'alt-c' commands are swapped if enable_stretch is set
+Alt         'c'         Copy selected objects, insert wires when separating touching instance pins/wires
 ctrl        'c'         Save to clipboard
 shift       'C'         Start arc placement
 shift+ctrl  'C'         Start circle placement
@@ -173,9 +179,10 @@ alt+shift   'l'         add lab_wire.sym to schematic
 alt         'l'         add lab_pin.sym to schematic
 ctrl+shift  'o'         Load most recent schematic
 ctrl        'o'         Load schematic
--           'm'         Move selected objects
+-           'm'         Move selected objects. 'm' and 'ctrl-m' commands are swapped if enable_stretch is set
 ctrl        'm'         Move selected objects, stretching wires attached to them
-shift       'M'         Move selected objects, insert wire when separating touching instance pins/wires
+Alt         'm'         Move selected objects, insert wires when separating touching instance pins/wires
+shift       'M'         Move selected objects, insert wires when separating touching instance pins/wires
                         Stretch wires that land on selected instance pins.
 shift       'N'         Top level only netlist
 -           'n'         Hierarchical Netlist
@@ -195,9 +202,9 @@ ctrl        'q'         Exit XSCHEM
 alt         'r'         Rotate objects around their anchor points
 shift       'R'         Rotate
 -           'r'         Start rect
-            's'         run simulation (asks confirmation)
 shift       'S'         Change element order
 ctrl+shift  'S'         Save  as schematic
+            's'         run simulation (asks confirmation)
 ctrl        's'         Save schematic
 alt         's'         Reload current schematic from disk
 ctrl+alt    's'         Save-as symbol
@@ -219,7 +226,7 @@ shift       'X'         Highlight discrepancies between object ports and attache
 shift       'Z'         Zoom in
 ctrl        'z'         Zoom out
 -           '?'         Help
--           '&'         Join / break / collapse wires
+-           '&         Join / break / collapse wires
 shift       '*'         Postscript/pdf print
 ctr+shift   '*'         Xpm/png print
 alt+shift   '*'         Svg print
diff --git a/src/actions.c b/src/actions.c
index ef4a537b..603204cb 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -963,8 +963,23 @@ void enable_layers(void)
   }
 }
 
-/* Add wires when moving instances or wires */
-short connect_by_kissing(void)
+
+/* not used... */
+void clear_partial_selected_wires(void)
+{
+  int j;
+  rebuild_selected_array();
+  for(j=0; j < xctx->lastsel; ++j) if(xctx->sel_array[j].type == WIRE) {
+    int wire = xctx->sel_array[j].n;
+    select_wire(wire, 0, 1);
+  }
+  rebuild_selected_array();
+}
+
+
+/* Add wires when moving instances or wires
+ * action: 1 to select, 0 to unselect */
+short connect_by_kissing(int action)
 {
   xSymbol *symbol;
   int npin, i, j;
diff --git a/src/callback.c b/src/callback.c
index 540f76c9..6438e928 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -2233,7 +2233,8 @@ int draw_xhair = tclgetboolvar("draw_crosshair");
     move_objects(START,0,0,0);
     break;
    }
-   if(key=='M' && state==ShiftMask && !(xctx->ui_state & (STARTMOVE | STARTCOPY))) /* move selection */
+   if(((key == 'M' && state == ShiftMask) || (key == 'm' && EQUAL_MODMASK)) &&
+     !(xctx->ui_state & (STARTMOVE | STARTCOPY))) /* move selection */
    {
     xctx->mx_double_save=xctx->mousex_snap;
     xctx->my_double_save=xctx->mousey_snap;
@@ -2242,7 +2243,8 @@ int draw_xhair = tclgetboolvar("draw_crosshair");
     move_objects(START,0,0,0);
     break;
    }
-   if(key=='m' && state==ControlMask && !(xctx->ui_state & (STARTMOVE | STARTCOPY))) /* move selection */
+   if(key=='m' && (state==ControlMask) &&
+       !(xctx->ui_state & (STARTMOVE | STARTCOPY))) /* move selection */
    {        
     xctx->mx_double_save=xctx->mousex_snap;
     xctx->my_double_save=xctx->mousey_snap;
@@ -2252,6 +2254,17 @@ int draw_xhair = tclgetboolvar("draw_crosshair");
     break;
    }    
 
+   if(key=='c' && EQUAL_MODMASK &&           /* duplicate selection */
+     !(xctx->ui_state & (STARTMOVE | STARTCOPY)))
+   {
+    if(xctx->semaphore >= 2) break;
+    tclsetintvar("connect_by_kissing", 2); /* 2 will be used to reset var to 0 at end of move */
+    xctx->mx_double_save=xctx->mousex_snap;
+    xctx->my_double_save=xctx->mousey_snap;
+    copy_objects(START);
+    break;
+   }
+
    if(key=='c' && state==0 &&           /* duplicate selection */
      !(xctx->ui_state & (STARTMOVE | STARTCOPY)))
    {
diff --git a/src/keys.help b/src/keys.help
index 3cdee72b..6f6823cc 100644
--- a/src/keys.help
+++ b/src/keys.help
@@ -11,13 +11,16 @@ ctrl + LeftButton       if an 'url' or 'tclcommand' property is defined on
                         tclcommand
 
 LeftButton drag         Select objects by area, clearing previous selection
-
-shift + LeftButton drag Select objects by area, without clearing 
-                        previous selection
+                        "[shift] left button drag" and "[shift] ctrl-left
+                        button drag" commands are swapped if enable_stretch
+                        is set.
 
 Ctrl + LeftButton drag  Select objects by area to perform a 
                         subsequent   'stretch'  move operation
 
+shift + LeftButton drag Select objects by area, without clearing 
+                        previous selection
+
 Shift +                 Select objects by area without unselecting
 Ctrl + LeftButton drag  to perform a subsequent   'stretch'  move operation
 
@@ -90,7 +93,8 @@ shift       'A'         Toggle show netlist
 Shift       'B'         Edit/add header/license metadata to the schematic/symbol file.
 ctrl        'b'         Toggle show text in symbol
 alt         'b'         Toggle show symbol details / only bounding boxes
--           'c'         Copy selected obj. 
+-           'c'         Copy selected objects, 'c' and 'alt-c' commands are swapped if enable_stretch is set
+Alt         'c'         Copy selected objects, insert wires when separating touching instance pins/wires
 ctrl        'c'         Save to clipboard
 shift       'C'         Start arc placement
 shift+ctrl  'C'         Start circle placement
@@ -134,9 +138,10 @@ alt+shift   'l'         add lab_wire.sym to schematic
 alt         'l'         add lab_pin.sym to schematic
 ctrl+shift  'o'         Load most recent schematic
 ctrl        'o'         Load schematic
--           'm'         Move selected objects
+-           'm'         Move selected objects. 'm' and 'ctrl-m' commands are swapped if enable_stretch is set
 ctrl        'm'         Move selected objects, stretching wires attached to them
-shift       'M'         Move selected objects, insert wire when separating touching instance pins/wires
+Alt         'm'         Move selected objects, insert wires when separating touching instance pins/wires
+shift       'M'         Move selected objects, insert wires when separating touching instance pins/wires
                         Stretch wires that land on selected instance pins.
 shift       'N'         Top level only netlist
 -           'n'         Hierarchical Netlist
diff --git a/src/move.c b/src/move.c
index 1a7f2f7c..aed3c16e 100644
--- a/src/move.c
+++ b/src/move.c
@@ -658,6 +658,9 @@ void copy_objects(int what)
    xctx->rotatelocal=0;
    dbg(1, "copy_objects(): START copy\n");
    rebuild_selected_array();
+   if(tclgetintvar("connect_by_kissing") == 2) xctx->kissing = connect_by_kissing(1);
+   else xctx->kissing = 0;
+
    save_selection(1);
    xctx->deltax = xctx->deltay = 0.0;
    xctx->movelastsel = xctx->lastsel;
@@ -669,6 +672,12 @@ void copy_objects(int what)
   {
    char *str = NULL; /* 20161122 overflow safe */
    draw_selection(xctx->gctiled,0);
+
+   if(xctx->kissing) {
+     pop_undo(0, 0);
+     if(tclgetintvar("connect_by_kissing") == 2) tclsetintvar("connect_by_kissing", 0);
+   }
+
    #if defined(FIX_BROKEN_TILED_FILL) || !defined(__unix__) 
    MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0], xctx->xrect[0].x, xctx->xrect[0].y,
        xctx->xrect[0].width, xctx->xrect[0].height, xctx->xrect[0].x, xctx->xrect[0].y);
@@ -708,12 +717,21 @@ void copy_objects(int what)
   {
     int l, firstw, firsti;
     int floaters = there_are_floaters();
+
+
+    if(tclgetintvar("connect_by_kissing") == 2) {
+      tclsetintvar("connect_by_kissing", 0);
+    }
+
     if(!floaters) bbox(START, 0.0 , 0.0 , 0.0 , 0.0);
     newpropcnt=0;
-    xctx->push_undo();
-    
-    firstw = firsti = 1;
 
+    if( !xctx->kissing ) {
+      dbg(1, "copy_objects(): push undo state\n");
+      xctx->push_undo();
+    }
+
+    firstw = firsti = 1;
     draw_selection(xctx->gctiled,0);
     update_symbol_bboxes(0, 0);
     /* build list before copying and recalculating prepare_netlist_structs() */
@@ -1088,7 +1106,7 @@ void move_objects(int what, int merge, double dx, double dy)
   xctx->deltax = xctx->deltay = 0.0;
   rebuild_selected_array();
   /* if connect_by_kissing==2 it was set in callback.c ('M' command) */
-  if(tclgetintvar("connect_by_kissing")) xctx->kissing = connect_by_kissing();
+  if(tclgetintvar("connect_by_kissing")) xctx->kissing = connect_by_kissing(1);
   else xctx->kissing = 0;
   xctx->movelastsel = xctx->lastsel;
   if(xctx->lastsel==1 && xctx->sel_array[0].type==ARC &&
diff --git a/src/xschem.h b/src/xschem.h
index 43d0c10f..d23a4ffd 100644
--- a/src/xschem.h
+++ b/src/xschem.h
@@ -1354,7 +1354,8 @@ extern int place_symbol(int pos, const char *symbol_name, double x, double y, sh
                          const char *inst_props, int draw_sym, int first_call, int to_push_undo);
 extern void place_net_label(int type);
 extern void attach_labels_to_inst(int interactive);
-extern short connect_by_kissing(void);
+extern void clear_partial_selected_wires(void);
+extern short connect_by_kissing(int action); /* action: 1 to select, 0 to unselect */
 extern void delete_files(void);
 extern int sym_vs_sch_pins(void);
 extern char *get_generator_command(const char *str);