From a15bb71f1e87e84dab32d2680409277d8fafd9b1 Mon Sep 17 00:00:00 2001
From: Alex Precosky <precosky@mac.com>
Date: Thu, 23 Apr 2009 21:36:34 -0700
Subject: [PATCH] Changed several actions to allow increment preferences to be used in the software.

When the (g)pcb-menu.res files were added to allow customization of keystrokes, the increment preferences in pcb no longer were used by keystrokes. Rather, increment values were set in the .res file.  To allow pcb to work as before this change, a new +pref and -pref set of values accepted in the relevant actions that take the 'delta' parameter have been added.  +pref means increment by the relevant preference, and -pref means decrement by the relevant preference.  The affected actions are:
 - SetValue (for grid and linesize changes only)
 - ChangeClearSize
 - ChangeSize
 - ChangeDrillSize
---
 src/action.c      |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/gpcb-menu.res |   26 +++++++--------
 2 files changed, 95 insertions(+), 17 deletions(-)

diff --git a/src/action.c b/src/action.c
index ab47e87..04fd67e 100644
--- a/src/action.c
+++ b/src/action.c
@@ -2091,6 +2091,10 @@ Changes the size of new text.
 
 @end table
 
+For Grid and LineSize, delta can also take on +pref or -pref, and the relevant size will change
+based on the grid_increment_mm/line_increment_mm or grid_increment_mil/line_increment_mil
+settings, depending on what the current grid units are
+
 %end-doc */
 
 static int
@@ -2100,11 +2104,17 @@ ActionSetValue (int argc, char **argv, int x, int y)
   char *val = ARG (1);
   char *units = ARG (2);
   Boolean r;			/* flag for 'relative' value */
+  Boolean pref=False;	  /* flag meaning 'preference' token was passed, so get value from prefs
+  						     for line or grid size changes */
+  
   float value;
   int err = 0;
 
   if (function && val)
     {
+       if( strncasecmp( val+1, "pref", 4) == 0 )
+         pref=True; /* applicable to line or grid size changes */
+    
       HideCrosshair (True);
       value = GetValue (val, units, &r);
       switch (GetFunctionID (function))
@@ -2122,6 +2132,15 @@ ActionSetValue (int argc, char **argv, int x, int y)
 		  || (value != (int) value && PCB->Grid != (int) PCB->Grid)
                   || PCB->Grid ==1)
                 {
+                  /* get the grid increment preference if the pref token was passed */
+           	      if( pref )
+	                {
+	                  value = Settings.grid_units_mm ? 
+	                    Settings.grid_increment_mm*MM_TO_COOR : Settings.grid_increment_mil*100;
+	                 if( val[0] == '-' ) value *= -1;
+	                 else if( val[0] != '+') value = 0;
+	                }     
+                
                   /* 
 		   * On the way down short against the minimum 
 		   * PCB drawing unit 
@@ -2144,6 +2163,13 @@ ActionSetValue (int argc, char **argv, int x, int y)
 
 	case F_LineSize:
 	case F_Line:
+	  if( pref )
+	    {
+	      value = Settings.grid_units_mm ? 
+	        Settings.line_increment_mm*MM_TO_COOR : Settings.line_increment_mil*100;
+	      if( val[0] == '-' ) value *= -1;
+	      else if( val[0] != '+') value = 0;
+	    }
 	  SetLineSize (r ? value : value + Settings.LineThickness);
 	  hid_action ("RouteStylesChanged");
 	  break;
@@ -3937,6 +3963,10 @@ changes the width and, indirectly, the length.  For texts and names,
 this changes the scaling factor.  For elements, this changes the width
 of the silk layer lines and arcs for this element.
 
+Delta can also take on +pref or -pref, and the relevant size will change
+based on the size_increment_mm or size_increment_mil settings, depending on
+what the current grid units are
+
 %end-doc */
 
 static int
@@ -3948,10 +3978,24 @@ ActionChangeSize (int argc, char **argv, int x, int y)
   Boolean r;			/* indicates if absolute size is given */
   float value;
 
+
   if (function && delta)
     {
-      value = GetValue (delta, units, &r);
+	  if( strncasecmp( delta+1, "pref", 4) == 0 )
+	    {
+	      value = Settings.grid_units_mm ? 
+	        Settings.size_increment_mm*MM_TO_COOR : Settings.size_increment_mil*100;
+	      r = False;
+          if( delta[0] == '-' )
+	       	  value *= -1;
+	       	else if( delta[0] != '+' )
+	       	  value = 0; /* safety net if pref token not preceeded by + or - */
+	    }
+	  else
+	    value = GetValue (delta, units, &r);    
+        
       HideCrosshair (True);
+       
       switch (GetFunctionID (function))
 	{
 	case F_Object:
@@ -4031,6 +4075,12 @@ static const char changedrillsize_help[] =
 
 /* %start-doc actions ChangeDrillSize
 
+Changes the drilling size of drill holes
+
+Delta can also take on +pref or -pref, and the relevant size will change
+based on the size_increment_mm or size_increment_mil settings, depending on
+what the current grid units are
+
 %end-doc */
 
 static int
@@ -4044,8 +4094,21 @@ ActionChange2ndSize (int argc, char **argv, int x, int y)
 
   if (function && delta)
     {
-      value = GetValue (delta, units, &r);
+	  if( strncasecmp( delta+1, "pref", 4) == 0 )
+	    {
+	      value = Settings.grid_units_mm ? 
+	        Settings.size_increment_mm*MM_TO_COOR : Settings.size_increment_mil*100;
+	      r = False;
+          if( delta[0] == '-' )
+	       	  value *= -1;
+	       	else if( delta[0] != '+' )
+	       	  value = 0; /* safety net if token other than +pref or -pref is passed */
+	    }
+	  else
+	    value = GetValue (delta, units, &r);    
+	    
       HideCrosshair (True);
+      
       switch (GetFunctionID (function))
 	{
 	case F_Object:
@@ -4100,6 +4163,10 @@ If the solder mask is currently showing, this action changes the
 solder mask clearance.  If the mask is not showing, this action
 changes the polygon clearance.
 
+delta can also take on +pref or -pref, and the relevant size will change
+based on the clear_increment_mm or clear_increment_mil settings, depending on
+what the current grid units are
+
 %end-doc */
 
 static int
@@ -4113,8 +4180,21 @@ ActionChangeClearSize (int argc, char **argv, int x, int y)
 
   if (function && delta)
     {
-      value = 2 * GetValue (delta, units, &r);
+      if( strncasecmp( delta+1, "pref", 4) == 0 )
+	    {
+	      value = Settings.grid_units_mm ? 
+	        2*Settings.clear_increment_mm*MM_TO_COOR : 2*Settings.clear_increment_mil*100;
+	      r = False;
+          if( delta[0] == '-' )
+	       	  value *= -1;
+	      else if( delta[0] != '+' )
+	       	value = 0; /* safety net if pref token not preceeded by + or - */
+	    }
+	  else
+        value = 2 * GetValue (delta, units, &r);
+      
       HideCrosshair (True);
+      
       switch (GetFunctionID (function))
 	{
 	case F_Object:
diff --git a/src/gpcb-menu.res b/src/gpcb-menu.res
index 6cde1f0..5ac3f4a 100644
--- a/src/gpcb-menu.res
+++ b/src/gpcb-menu.res
@@ -129,10 +129,8 @@ MainMenu =
     {"0.5 mm"  checked=gridsize,1969 SetUnits(mm) SetValue(Grid,1968.503937)}
     {"1 mm"    checked=gridsize,3937 SetUnits(mm) SetValue(Grid,3937.00787400)}
     -
-    {"Grid -5mil" SetValue(Grid,-5,mil) a={"Shift-G" "Shift<Key>g"}}
-    {"Grid +5mil" SetValue(Grid,+5,mil) a={"G" "<Key>g"}}
-    {"Grid -0.05mm" SetValue(Grid,-0.05,mm) a={"Shift-Ctrl-G" "Shift Ctrl<Key>g"}}
-    {"Grid +0.05mm" SetValue(Grid,+0.05,mm) a={"Ctrl-G" "Ctrl<Key>g"}}
+    {"Grid decrement" SetValue(Grid,-pref) a={"Shift-G" "Shift<Key>g"}}
+    {"Grid increment" SetValue(Grid,+pref) a={"G" "<Key>g"}}
    }
    {"Realign grid" GetXY(Click to set the grid origin) Display(ToggleGrid)}
    -
@@ -394,12 +392,12 @@ MainMenu =
     {"ChangeHole Object" a={"Ctrl-H" "Ctrl<Key>h"} ChangeHole(Object)}
     {"ChangeJoin Object" a={"J" "<Key>j"} ChangeJoin(Object)}
     {"ChangeJoin SelectedObject" a={"Shift-J" "Shift<Key>j"} ChangeJoin(SelectedObjects)}
-    {"Clear Object +2 mil" a={"K" "<Key>k"} ChangeClearSize(Object,+2,mil)}
-    {"Clear Object -2 mil" a={"Shift-K" "Shift<Key>k"} ChangeClearSize(Object,-2,mil)}
-    {"Clear Selected +2 mil" a={"Ctrl-K" "Ctrl<Key>k"} ChangeClearSize(SelectedObjects,+2,mil)}
-    {"Clear Selected -2 mil" a={"Shift-Ctrl-K" "Shift Ctrl<Key>k"} ChangeClearSize(SelectedObjects,-2,mil)}
-    {"Linesize +5 mil" a={"L" "<Key>l"} SetValue(LineSize,+5,mil)}
-    {"Linesize -5 mil" a={"Shift-L" "Shift<Key>l"} SetValue(LineSize,-5,mil)}
+    {"Clear Object increment" a={"K" "<Key>k"} ChangeClearSize(Object,+pref)}
+    {"Clear Object decrement" a={"Shift-K" "Shift<Key>k"} ChangeClearSize(Object,-pref)}
+    {"Clear Selected increment" a={"Ctrl-K" "Ctrl<Key>k"} ChangeClearSize(SelectedObjects,+pref)}
+    {"Clear Selected decrement" a={"Shift-Ctrl-K" "Shift Ctrl<Key>k"} ChangeClearSize(SelectedObjects,-pref)}
+    {"Linesize increment" a={"L" "<Key>l"} SetValue(LineSize,+pref)}
+    {"Linesize decrement" a={"Shift-L" "Shift<Key>l"} SetValue(LineSize,-pref)}
     {"MarkCrosshair" a={"Ctrl-M" "Ctrl<Key>m"} MarkCrosshair()}
     {"Select shortest rat" a={"Shift-N" "Shift<Key>n"} AddRats(Close)}
     {"AddRats to selected pins" a={"Shift-O" "Shift<Key>o"}
@@ -412,10 +410,10 @@ MainMenu =
     {"Polygon PreviousPoint" a={"P" "<Key>p"} Polygon(PreviousPoint)}
     {"Polygon Close" a={"Shift-P" "Shift<Key>p"} Polygon(Close)}
     {"ChangeSquare Object" a={"Q" "<Key>q"} ChangeSquare(ToggleObject)}
-    {"ChangeSize +5 mil" a={"S" "<Key>s"} ChangeSize(Object,+5,mil)}
-    {"ChangeSize -5 mil" a={"Shift-S" "Shift<Key>s"} ChangeSize(Object,-5,mil)}
-    {"ChangeDrill +5 mil" a={"Alt-S" "Alt<Key>s"} ChangeDrillSize(Object,+5,mil)}
-    {"ChangeDrill -5 mil" a={"Alt-Shift-S" "Alt Shift<Key>s"} ChangeDrillSize(Object,-5,mil)}
+    {"ChangeSize increment" a={"S" "<Key>s"} ChangeSize(Object,+pref)}
+    {"ChangeSize decrement" a={"Shift-S" "Shift<Key>s"} ChangeSize(Object,-pref)}
+    {"ChangeDrill increment" a={"Alt-S" "Alt<Key>s"} ChangeDrillSize(Object,+pref)}
+    {"ChangeDrill decrement" a={"Alt-Shift-S" "Alt Shift<Key>s"} ChangeDrillSize(Object,-pref)}
     {"TextScale +10 mil" a={"T" "<Key>t"} SetValue(TextScale,+10,mil)}
     {"TextScale -10 mil" a={"Shift-T" "Shift<Key>t"} SetValue(TextScale,-10,mil)}
     {"ViaSize +5 mil" a={"Shift-V" "Shift<Key>v"} SetValue(ViaSize,+5,mil)}
-- 
1.5.2.1

