Просмотр исходного кода

Specify distance from axis instead of box in mirror shell command.

Juan Pablo Caram 10 лет назад
Родитель
Сommit
33146af784
1 измененных файлов с 41 добавлено и 22 удалено
  1. 41 22
      FlatCAMApp.py

+ 41 - 22
FlatCAMApp.py

@@ -2043,42 +2043,60 @@ class App(QtCore.QObject):
         def mirror(name, *args):
         def mirror(name, *args):
             a, kwa = h(*args)
             a, kwa = h(*args)
             types = {'box': str,
             types = {'box': str,
-                     'axis': str}
+                     'axis': str,
+                     'dist': float}
 
 
             for key in kwa:
             for key in kwa:
                 if key not in types:
                 if key not in types:
                     return 'Unknown parameter: %s' % key
                     return 'Unknown parameter: %s' % key
                 kwa[key] = types[key](kwa[key])
                 kwa[key] = types[key](kwa[key])
 
 
+            # Get source object.
             try:
             try:
                 obj = self.collection.get_by_name(str(name))
                 obj = self.collection.get_by_name(str(name))
             except:
             except:
                 return "Could not retrieve object: %s" % name
                 return "Could not retrieve object: %s" % name
 
 
-            try:
-                box = self.collection.get_by_name(kwa['box'])
-            except:
-                return "Could not retrieve object box: %s" % kwa['box']
-
             if obj is None:
             if obj is None:
                 return "Object not found: %s" % name
                 return "Object not found: %s" % name
 
 
-            if box is None:
-                return "Object box not found: %s" % kwa['box']
-
             if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMExcellon):
             if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMExcellon):
                 return "ERROR: Only Gerber and Excellon objects can be mirrored."
                 return "ERROR: Only Gerber and Excellon objects can be mirrored."
 
 
-            try:
-                xmin, ymin, xmax, ymax = box.bounds()
-                px = 0.5 * (xmin + xmax)
-                py = 0.5 * (ymin + ymax)
-            
-                obj.mirror(kwa['axis'], [px, py])
-                obj.plot()
+            # Box
+            if 'box' in kwa:
+                try:
+                    box = self.collection.get_by_name(kwa['box'])
+                except:
+                    return "Could not retrieve object box: %s" % kwa['box']
 
 
-            except Exception, e:
-                return "Operation failed: %s" % str(e)
+                if box is None:
+                    return "Object box not found: %s" % kwa['box']
+
+                try:
+                    xmin, ymin, xmax, ymax = box.bounds()
+                    px = 0.5 * (xmin + xmax)
+                    py = 0.5 * (ymin + ymax)
+
+                    obj.mirror(kwa['axis'], [px, py])
+                    obj.plot()
+
+                except Exception, e:
+                    return "Operation failed: %s" % str(e)
+
+            elif 'dist' in kwa:
+                try:
+                    dist = float(kwa['dist'])
+                except KeyError:
+                    dist = 0.0
+                except ValueError:
+                    return "Invalid distance: %s" % kwa['dist']
+
+                try:
+                    obj.mirror(kwa['axis'], [dist, dist])
+                    obj.plot()
+                except Exception, e:
+                    return "Operation failed: %s" % str(e)
 
 
             return 'Ok'
             return 'Ok'
 
 
@@ -2581,7 +2599,7 @@ class App(QtCore.QObject):
             },
             },
             'cutout': {
             'cutout': {
                 'fcn': cutout,
                 'fcn': cutout,
-                'help': "Creates cutout board.\n" +
+                'help': "Creates board cutout.\n" +
                         "> cutout <name> [-dia <3.0 (float)>] [-margin <0.0 (float)>] [-gapsize <0.5 (float)>] [-gaps <lr (4|tb|lr)>]\n" +
                         "> cutout <name> [-dia <3.0 (float)>] [-margin <0.0 (float)>] [-gapsize <0.5 (float)>] [-gaps <lr (4|tb|lr)>]\n" +
                         "   name: Name of the object\n" +
                         "   name: Name of the object\n" +
                         "   dia: Tool diameter\n" +
                         "   dia: Tool diameter\n" +
@@ -2591,11 +2609,12 @@ class App(QtCore.QObject):
             },
             },
             'mirror': {
             'mirror': {
                 'fcn': mirror,
                 'fcn': mirror,
-                'help': "Mirror board.\n" +
-                        "> mirror <nameMirroredObject> -box <nameOfBox> [-axis <X|Y>]\n" +
+                'help': "Mirror a layer.\n" +
+                        "> mirror <name> { -box <nameOfBox> | -axis <X|Y> [-dist <number>] }\n" +
                         "   name: Name of the object (Gerber or Excellon) to mirror\n" +
                         "   name: Name of the object (Gerber or Excellon) to mirror\n" +
                         "   box: Name of object which act as box (cutout for example)\n" +
                         "   box: Name of object which act as box (cutout for example)\n" +
-                        "   axis: Axis mirror over X or Y"
+                        "   axis: Mirror axis parallel to the X or Y axis.\n" +
+                        "   dist: Distance of the mirror axis to the X or Y axis."
             },
             },
             'exteriors': {
             'exteriors': {
                 'fcn': exteriors,
                 'fcn': exteriors,