Marius Stanciu 6 лет назад
Родитель
Сommit
5dd0ff7e14
2 измененных файлов с 41 добавлено и 54 удалено
  1. 1 0
      README.md
  2. 40 54
      flatcamTools/ToolTransform.py

+ 1 - 0
README.md

@@ -12,6 +12,7 @@ CAD program, and create G-Code for Isolation routing.
 10.05.2019
 10.05.2019
 
 
 - made sure that only units toggle done in Edit -> Preferences will toggle the data in Preferences. THe menu entry Edit -> Toggle Units and the shortcut key 'Q' will change only the display units in the app
 - made sure that only units toggle done in Edit -> Preferences will toggle the data in Preferences. THe menu entry Edit -> Toggle Units and the shortcut key 'Q' will change only the display units in the app
+- optimized Transform tool
 
 
 8.05.2019
 8.05.2019
 
 

+ 40 - 54
flatcamTools/ToolTransform.py

@@ -658,19 +658,18 @@ class ToolTransform(FlatCAMTool):
 
 
                     self.app.progress.emit(20)
                     self.app.progress.emit(20)
 
 
+                    px = 0.5 * (xminimal + xmaximal)
+                    py = 0.5 * (yminimal + ymaximal)
                     for sel_obj in obj_list:
                     for sel_obj in obj_list:
-                        px = 0.5 * (xminimal + xmaximal)
-                        py = 0.5 * (yminimal + ymaximal)
                         if isinstance(sel_obj, FlatCAMCNCjob):
                         if isinstance(sel_obj, FlatCAMCNCjob):
                             self.app.inform.emit(_("CNCJob objects can't be rotated."))
                             self.app.inform.emit(_("CNCJob objects can't be rotated."))
                         else:
                         else:
                             sel_obj.rotate(-num, point=(px, py))
                             sel_obj.rotate(-num, point=(px, py))
-                            sel_obj.plot()
                             self.app.object_changed.emit(sel_obj)
                             self.app.object_changed.emit(sel_obj)
 
 
                         # add information to the object that it was changed and how much
                         # add information to the object that it was changed and how much
                         sel_obj.options['rotate'] = num
                         sel_obj.options['rotate'] = num
-
+                        sel_obj.plot()
                     self.app.inform.emit(_('[success] Rotate done ...'))
                     self.app.inform.emit(_('[success] Rotate done ...'))
                     self.app.progress.emit(100)
                     self.app.progress.emit(100)
 
 
@@ -719,31 +718,30 @@ class ToolTransform(FlatCAMTool):
                     self.app.progress.emit(20)
                     self.app.progress.emit(20)
 
 
                     # execute mirroring
                     # execute mirroring
-                    for obj in obj_list:
-                        if isinstance(obj, FlatCAMCNCjob):
+                    for sel_obj in obj_list:
+                        if isinstance(sel_obj, FlatCAMCNCjob):
                             self.app.inform.emit(_("CNCJob objects can't be mirrored/flipped."))
                             self.app.inform.emit(_("CNCJob objects can't be mirrored/flipped."))
                         else:
                         else:
                             if axis is 'X':
                             if axis is 'X':
-                                obj.mirror('X', (px, py))
+                                sel_obj.mirror('X', (px, py))
                                 # add information to the object that it was changed and how much
                                 # add information to the object that it was changed and how much
                                 # the axis is reversed because of the reference
                                 # the axis is reversed because of the reference
-                                if 'mirror_y' in obj.options:
-                                    obj.options['mirror_y'] = not obj.options['mirror_y']
+                                if 'mirror_y' in sel_obj.options:
+                                    sel_obj.options['mirror_y'] = not sel_obj.options['mirror_y']
                                 else:
                                 else:
-                                    obj.options['mirror_y'] = True
-                                obj.plot()
+                                    sel_obj.options['mirror_y'] = True
                                 self.app.inform.emit(_('[success] Flip on the Y axis done ...'))
                                 self.app.inform.emit(_('[success] Flip on the Y axis done ...'))
                             elif axis is 'Y':
                             elif axis is 'Y':
-                                obj.mirror('Y', (px, py))
+                                sel_obj.mirror('Y', (px, py))
                                 # add information to the object that it was changed and how much
                                 # add information to the object that it was changed and how much
                                 # the axis is reversed because of the reference
                                 # the axis is reversed because of the reference
-                                if 'mirror_x' in obj.options:
-                                    obj.options['mirror_x'] = not obj.options['mirror_x']
+                                if 'mirror_x' in sel_obj.options:
+                                    sel_obj.options['mirror_x'] = not sel_obj.options['mirror_x']
                                 else:
                                 else:
-                                    obj.options['mirror_x'] = True
-                                obj.plot()
+                                    sel_obj.options['mirror_x'] = True
                                 self.app.inform.emit(_('[success] Flip on the X axis done ...'))
                                 self.app.inform.emit(_('[success] Flip on the X axis done ...'))
-                            self.app.object_changed.emit(obj)
+                            self.app.object_changed.emit(sel_obj)
+                        sel_obj.plot()
                     self.app.progress.emit(100)
                     self.app.progress.emit(100)
 
 
                 except Exception as e:
                 except Exception as e:
@@ -776,20 +774,20 @@ class ToolTransform(FlatCAMTool):
 
 
                     self.app.progress.emit(20)
                     self.app.progress.emit(20)
 
 
-                    for obj in obj_list:
-                        if isinstance(obj, FlatCAMCNCjob):
+                    for sel_obj in obj_list:
+                        if isinstance(sel_obj, FlatCAMCNCjob):
                             self.app.inform.emit(_("CNCJob objects can't be skewed."))
                             self.app.inform.emit(_("CNCJob objects can't be skewed."))
                         else:
                         else:
                             if axis is 'X':
                             if axis is 'X':
-                                obj.skew(num, 0, point=(xminimal, yminimal))
+                                sel_obj.skew(num, 0, point=(xminimal, yminimal))
                                 # add information to the object that it was changed and how much
                                 # add information to the object that it was changed and how much
-                                obj.options['skew_x'] = num
+                                sel_obj.options['skew_x'] = num
                             elif axis is 'Y':
                             elif axis is 'Y':
-                                obj.skew(0, num, point=(xminimal, yminimal))
+                                sel_obj.skew(0, num, point=(xminimal, yminimal))
                                 # add information to the object that it was changed and how much
                                 # add information to the object that it was changed and how much
-                                obj.options['skew_y'] = num
-                            obj.plot()
-                            self.app.object_changed.emit(obj)
+                                sel_obj.options['skew_y'] = num
+                            self.app.object_changed.emit(sel_obj)
+                        sel_obj.plot()
                     self.app.inform.emit(_('[success] Skew on the %s axis done ...') % str(axis))
                     self.app.inform.emit(_('[success] Skew on the %s axis done ...') % str(axis))
                     self.app.progress.emit(100)
                     self.app.progress.emit(100)
 
 
@@ -836,16 +834,17 @@ class ToolTransform(FlatCAMTool):
                         px = 0
                         px = 0
                         py = 0
                         py = 0
 
 
-                    for obj in obj_list:
-                        if isinstance(obj, FlatCAMCNCjob):
+                    for sel_obj in obj_list:
+                        if isinstance(sel_obj, FlatCAMCNCjob):
                             self.app.inform.emit(_("CNCJob objects can't be scaled."))
                             self.app.inform.emit(_("CNCJob objects can't be scaled."))
                         else:
                         else:
-                            obj.scale(xfactor, yfactor, point=(px, py))
+                            sel_obj.scale(xfactor, yfactor, point=(px, py))
                             # add information to the object that it was changed and how much
                             # add information to the object that it was changed and how much
-                            obj.options['scale_x'] = xfactor
-                            obj.options['scale_y'] = yfactor
-                            obj.plot()
-                            self.app.object_changed.emit(obj)
+                            sel_obj.options['scale_x'] = xfactor
+                            sel_obj.options['scale_y'] = yfactor
+                            self.app.object_changed.emit(sel_obj)
+                        sel_obj.plot()
+
                     self.app.inform.emit(_('[success] Scale on the %s axis done ...') % str(axis))
                     self.app.inform.emit(_('[success] Scale on the %s axis done ...') % str(axis))
                     self.app.progress.emit(100)
                     self.app.progress.emit(100)
                 except Exception as e:
                 except Exception as e:
@@ -854,8 +853,6 @@ class ToolTransform(FlatCAMTool):
 
 
     def on_offset(self, axis, num):
     def on_offset(self, axis, num):
         obj_list = self.app.collection.get_selected()
         obj_list = self.app.collection.get_selected()
-        xminlist = []
-        yminlist = []
 
 
         if not obj_list:
         if not obj_list:
             self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to offset!"))
             self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to offset!"))
@@ -863,34 +860,23 @@ class ToolTransform(FlatCAMTool):
         else:
         else:
             with self.app.proc_container.new(_("Applying Offset")):
             with self.app.proc_container.new(_("Applying Offset")):
                 try:
                 try:
-                    # first get a bounding box to fit all
-                    for obj in obj_list:
-                        if isinstance(obj, FlatCAMCNCjob):
-                            pass
-                        else:
-                            xmin, ymin, xmax, ymax = obj.bounds()
-                            xminlist.append(xmin)
-                            yminlist.append(ymin)
-
-                    # get the minimum x,y and maximum x,y for all objects selected
-                    xminimal = min(xminlist)
-                    yminimal = min(yminlist)
                     self.app.progress.emit(20)
                     self.app.progress.emit(20)
 
 
-                    for obj in obj_list:
-                        if isinstance(obj, FlatCAMCNCjob):
+                    for sel_obj in obj_list:
+                        if isinstance(sel_obj, FlatCAMCNCjob):
                             self.app.inform.emit(_("CNCJob objects can't be offseted."))
                             self.app.inform.emit(_("CNCJob objects can't be offseted."))
                         else:
                         else:
                             if axis is 'X':
                             if axis is 'X':
-                                obj.offset((num, 0))
+                                sel_obj.offset((num, 0))
                                 # add information to the object that it was changed and how much
                                 # add information to the object that it was changed and how much
-                                obj.options['offset_x'] = num
+                                sel_obj.options['offset_x'] = num
                             elif axis is 'Y':
                             elif axis is 'Y':
-                                obj.offset((0, num))
+                                sel_obj.offset((0, num))
                                 # add information to the object that it was changed and how much
                                 # add information to the object that it was changed and how much
-                                obj.options['offset_y'] = num
-                            obj.plot()
-                            self.app.object_changed.emit(obj)
+                                sel_obj.options['offset_y'] = num
+                            self.app.object_changed.emit(sel_obj)
+                        sel_obj.plot()
+
                     self.app.inform.emit(_('[success] Offset on the %s axis done ...') % str(axis))
                     self.app.inform.emit(_('[success] Offset on the %s axis done ...') % str(axis))
                     self.app.progress.emit(100)
                     self.app.progress.emit(100)