Преглед изворни кода

- the main issue was the modules that I imported. It was the FlatCAMObj.py
modules which it was not what it was needed. I changed the imports to
camlib.py, remade the functions in camlib.py and now the Flip, Rotate
and Skew work over all the objects of FlatCAM (Gerber, Geometry created
by the FC, Geometry created by the objects, Excellon, CNCJob)

Marius Stanciu пре 7 година
родитељ
комит
14477f4db4
2 измењених фајлова са 68 додато и 20 уклоњено
  1. 4 4
      ToolTransform.py
  2. 64 16
      camlib.py

+ 4 - 4
ToolTransform.py

@@ -2,7 +2,7 @@ from PyQt4 import QtGui, QtCore
 from PyQt4 import Qt
 from GUIElements import FCEntry, FCButton
 from FlatCAMTool import FlatCAMTool
-from FlatCAMObj import FlatCAMGerber, FlatCAMExcellon, FlatCAMGeometry
+from camlib import *
 
 
 class ToolTransform(FlatCAMTool):
@@ -224,7 +224,7 @@ class ToolTransform(FlatCAMTool):
                 self.app.inform.emit('Object was rotated ...')
             except Exception as e:
                 self.app.inform.emit("[ERROR] Due of %s, rotation movement was not executed." % str(e))
-                return
+                raise
 
     def on_flip(self, axis):
         obj_list = self.app.collection.get_selected()
@@ -276,7 +276,7 @@ class ToolTransform(FlatCAMTool):
 
             except Exception as e:
                 self.app.inform.emit("[ERROR] Due of %s, Flip action was not executed.")
-                return
+                raise
 
     def on_skew(self, axis, num):
         obj_list = self.app.collection.get_selected()
@@ -314,6 +314,6 @@ class ToolTransform(FlatCAMTool):
                 self.app.inform.emit('Object was skewed on %s axis ...' % str(axis))
             except Exception as e:
                 self.app.inform.emit("[ERROR] Due of %s, Skew action was not executed." % str(e))
-                return
+                raise
 
 # end of file

+ 64 - 16
camlib.py

@@ -1039,7 +1039,6 @@ class Geometry(object):
 
         px, py = point
         xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
-
         def mirror_geom(obj):
             if type(obj) is list:
                 new_obj = []
@@ -1065,31 +1064,60 @@ class Geometry(object):
         See shapely manual for more information:
         http://toblerity.org/shapely/manual.html#affine-transformations
         """
-        if angle_y is None:
-            angle_y = 0.0
+
         if angle_x is None:
-            angle_x = 0.0
+            angle_x = 0
+        if angle_y is None:
+            angle_y = 0
         if point is None:
-            self.solid_geometry = affinity.skew(self.solid_geometry, angle_x, angle_y,
-                                            origin=(0, 0))
+            point = (0,0)
         else:
             px, py = point
-            self.solid_geometry = affinity.skew(self.solid_geometry, angle_x, angle_y,
-                                                origin=(px, py))
+
+        def skew_geom(obj):
+            if type(obj) is list:
+                new_obj = []
+                for g in obj:
+                    new_obj.append(skew_geom(g))
+                return new_obj
+            else:
+                return affinity.skew(obj, angle_x, angle_y,
+                              origin=(px, py))
+
+        self.solid_geometry = skew_geom(self.solid_geometry)
         return
 
     def rotate(self, angle, point=None):
         """
-        Rotate an object by a given angle around given coords (point)
-        :param angle:
-        :param point:
-        :return:
+        Rotate an object by an angle (in degrees) around the provided coordinates.
+
+        Parameters
+        ----------
+        The angle of rotation are specified in degrees (default). Positive angles are
+        counter-clockwise and negative are clockwise rotations.
+
+        The point of origin can be a keyword 'center' for the bounding box
+        center (default), 'centroid' for the geometry's centroid, a Point object
+        or a coordinate tuple (x0, y0).
+
+        See shapely manual for more information:
+        http://toblerity.org/shapely/manual.html#affine-transformations
         """
-        if point is None:
-            self.solid_geometry = affinity.rotate(self.solid_geometry, angle, origin='center')
-        else:
+        if point is not None:
             px, py = point
-            self.solid_geometry = affinity.rotate(self.solid_geometry, angle, origin=(px, py))
+        else:
+            px, py = (0,0)
+
+        def rotate_geom(obj):
+            if type(obj) is list:
+                new_obj = []
+                for g in obj:
+                    new_obj.append(rotate_geom(g))
+                return new_obj
+            else:
+                return affinity.rotate(obj, angle, origin=(px, py))
+
+        self.solid_geometry = rotate_geom(self.solid_geometry)
         return
 
 class ApertureMacro:
@@ -3677,6 +3705,26 @@ class CNCjob(Geometry):
 
         self.create_geometry()
 
+    def mirror(self, axis, point=None):
+        """
+        Mirror the geometrys of an object around the coordinates of the 'point'
+        :param axis: X or Y
+        :param point: tupple of coordinates
+        :return:
+        """
+        if point is None:
+            return
+        else:
+            px, py = point
+
+        xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
+
+        for g in self.gcode_parsed:
+            g['geom'] = affinity.scale(g['geom'], xscale, yscale, origin=(px, py))
+
+        self.create_geometry()
+        return
+
     def export_svg(self, scale_factor=0.00):
         """
         Exports the CNC Job as a SVG Element