Procházet zdrojové kódy

Merged in marius_stanciu/flatcam_mpl/Fix_for_Flip_Rotate_Skew_pull_request (pull request #113)

Fixed the Flip/Rotate/Skew previous pull_request
Marius Stanciu před 7 roky
rodič
revize
46454c293a
2 změnil soubory, kde provedl 68 přidání a 20 odebrání
  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 PyQt4 import Qt
 from GUIElements import FCEntry, FCButton
 from GUIElements import FCEntry, FCButton
 from FlatCAMTool import FlatCAMTool
 from FlatCAMTool import FlatCAMTool
-from FlatCAMObj import FlatCAMGerber, FlatCAMExcellon, FlatCAMGeometry
+from camlib import *
 
 
 
 
 class ToolTransform(FlatCAMTool):
 class ToolTransform(FlatCAMTool):
@@ -224,7 +224,7 @@ class ToolTransform(FlatCAMTool):
                 self.app.inform.emit('Object was rotated ...')
                 self.app.inform.emit('Object was rotated ...')
             except Exception as e:
             except Exception as e:
                 self.app.inform.emit("[ERROR] Due of %s, rotation movement was not executed." % str(e))
                 self.app.inform.emit("[ERROR] Due of %s, rotation movement was not executed." % str(e))
-                return
+                raise
 
 
     def on_flip(self, axis):
     def on_flip(self, axis):
         obj_list = self.app.collection.get_selected()
         obj_list = self.app.collection.get_selected()
@@ -276,7 +276,7 @@ class ToolTransform(FlatCAMTool):
 
 
             except Exception as e:
             except Exception as e:
                 self.app.inform.emit("[ERROR] Due of %s, Flip action was not executed.")
                 self.app.inform.emit("[ERROR] Due of %s, Flip action was not executed.")
-                return
+                raise
 
 
     def on_skew(self, axis, num):
     def on_skew(self, axis, num):
         obj_list = self.app.collection.get_selected()
         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))
                 self.app.inform.emit('Object was skewed on %s axis ...' % str(axis))
             except Exception as e:
             except Exception as e:
                 self.app.inform.emit("[ERROR] Due of %s, Skew action was not executed." % str(e))
                 self.app.inform.emit("[ERROR] Due of %s, Skew action was not executed." % str(e))
-                return
+                raise
 
 
 # end of file
 # end of file

+ 64 - 16
camlib.py

@@ -1039,7 +1039,6 @@ class Geometry(object):
 
 
         px, py = point
         px, py = point
         xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
         xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
-
         def mirror_geom(obj):
         def mirror_geom(obj):
             if type(obj) is list:
             if type(obj) is list:
                 new_obj = []
                 new_obj = []
@@ -1065,31 +1064,60 @@ class Geometry(object):
         See shapely manual for more information:
         See shapely manual for more information:
         http://toblerity.org/shapely/manual.html#affine-transformations
         http://toblerity.org/shapely/manual.html#affine-transformations
         """
         """
-        if angle_y is None:
-            angle_y = 0.0
+
         if angle_x is None:
         if angle_x is None:
-            angle_x = 0.0
+            angle_x = 0
+        if angle_y is None:
+            angle_y = 0
         if point is None:
         if point is None:
-            self.solid_geometry = affinity.skew(self.solid_geometry, angle_x, angle_y,
-                                            origin=(0, 0))
+            point = (0,0)
         else:
         else:
             px, py = point
             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
         return
 
 
     def rotate(self, angle, point=None):
     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
             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
         return
 
 
 class ApertureMacro:
 class ApertureMacro:
@@ -3677,6 +3705,26 @@ class CNCjob(Geometry):
 
 
         self.create_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):
     def export_svg(self, scale_factor=0.00):
         """
         """
         Exports the CNC Job as a SVG Element
         Exports the CNC Job as a SVG Element