- 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)
This commit is contained in:
Marius Stanciu 2018-06-06 04:08:50 +03:00
parent 958313a360
commit 14477f4db4
2 changed files with 68 additions and 20 deletions

View File

@ -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

View File

@ -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, point = (0,0)
origin=(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) Rotate an object by an angle (in degrees) around the provided coordinates.
:param angle:
:param point: Parameters
:return: ----------
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: if point is not None:
self.solid_geometry = affinity.rotate(self.solid_geometry, angle, origin='center')
else:
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