Procházet zdrojové kódy

- optimized the Gerber mark shapes display
- fixed a color format bug in Tool Move for 3D engine
- made sure that when the Tool Move is used on a Gerber file with mark shapes active, those mark shapes are deleted before the actual move

Marius Stanciu před 6 roky
rodič
revize
ae7fec6dd1
4 změnil soubory, kde provedl 46 přidání a 46 odebrání
  1. 38 45
      FlatCAMObj.py
  2. 3 0
      README.md
  3. 1 0
      flatcamGUI/PlotCanvasLegacy.py
  4. 4 1
      flatcamTools/ToolMove.py

+ 38 - 45
FlatCAMObj.py

@@ -635,15 +635,6 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
         else:
             self.ui.create_buffer_button.hide()
 
-        # add the shapes storage for marking apertures
-        if self.app.is_legacy is False:
-            for ap_code in self.apertures:
-                self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=2)
-        else:
-            for ap_code in self.apertures:
-                self.mark_shapes[ap_code] = ShapeCollectionLegacy(obj=self, app=self.app,
-                                                                  name=self.options['name'] + str(ap_code))
-
         # set initial state of the aperture table and associated widgets
         self.on_aperture_table_visibility_change()
 
@@ -737,29 +728,6 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
 
             self.apertures_row += 1
 
-        # for ap_code in sorted_macros:
-        #     ap_code = str(ap_code)
-        #
-        #     ap_id_item = QtWidgets.QTableWidgetItem('%d' % int(self.apertures_row + 1))
-        #     ap_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        #     self.ui.apertures_table.setItem(self.apertures_row, 0, ap_id_item)  # Tool name/id
-        #
-        #     ap_code_item = QtWidgets.QTableWidgetItem(ap_code)
-        #
-        #     ap_type_item = QtWidgets.QTableWidgetItem('AM')
-        #     ap_type_item.setFlags(QtCore.Qt.ItemIsEnabled)
-        #
-        #     mark_item = FCCheckBox()
-        #     mark_item.setLayoutDirection(QtCore.Qt.RightToLeft)
-        #     # if self.ui.aperture_table_visibility_cb.isChecked():
-        #     #     mark_item.setChecked(True)
-        #
-        #     self.ui.apertures_table.setItem(self.apertures_row, 1, ap_code_item)  # Aperture Code
-        #     self.ui.apertures_table.setItem(self.apertures_row, 2, ap_type_item)  # Aperture Type
-        #     self.ui.apertures_table.setCellWidget(self.apertures_row, 5, mark_item)
-        #
-        #     self.apertures_row += 1
-
         self.ui.apertures_table.selectColumn(0)
         self.ui.apertures_table.resizeColumnsToContents()
         self.ui.apertures_table.resizeRowsToContents()
@@ -799,8 +767,16 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
 
     def ui_connect(self):
         for row in range(self.ui.apertures_table.rowCount()):
+            try:
+                self.ui.apertures_table.cellWidget(row, 5).clicked.disconnect(self.on_mark_cb_click_table)
+            except (TypeError, AttributeError):
+                pass
             self.ui.apertures_table.cellWidget(row, 5).clicked.connect(self.on_mark_cb_click_table)
 
+        try:
+            self.ui.mark_all_cb.clicked.disconnect(self.on_mark_all_click)
+        except (TypeError, AttributeError):
+            pass
         self.ui.mark_all_cb.clicked.connect(self.on_mark_all_click)
 
     def ui_disconnect(self):
@@ -1280,6 +1256,15 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
 
     def on_aperture_table_visibility_change(self):
         if self.ui.aperture_table_visibility_cb.isChecked():
+            # add the shapes storage for marking apertures
+            if self.app.is_legacy is False:
+                for ap_code in self.apertures:
+                    self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=2)
+            else:
+                for ap_code in self.apertures:
+                    self.mark_shapes[ap_code] = ShapeCollectionLegacy(obj=self, app=self.app,
+                                                                      name=self.options['name'] + str(ap_code))
+
             self.ui.apertures_table.setVisible(True)
             for ap in self.mark_shapes:
                 self.mark_shapes[ap].enabled = True
@@ -1292,12 +1277,16 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
             self.ui.mark_all_cb.setVisible(False)
 
             # on hide disable all mark plots
-            for row in range(self.ui.apertures_table.rowCount()):
-                self.ui.apertures_table.cellWidget(row, 5).set_value(False)
-            self.clear_plot_apertures()
+            try:
+                for row in range(self.ui.apertures_table.rowCount()):
+                    self.ui.apertures_table.cellWidget(row, 5).set_value(False)
+                self.clear_plot_apertures()
 
-            for ap in self.mark_shapes:
-                self.mark_shapes[ap].enabled = False
+                for ap in list(self.mark_shapes.keys()):
+                    # self.mark_shapes[ap].enabled = False
+                    del self.mark_shapes[ap]
+            except Exception as e:
+                log.debug(" FlatCAMGerber.on_aperture_visibility_changed() --> %s" % str(e))
 
     def convert_units(self, units):
         """
@@ -1426,8 +1415,8 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
 
         # Does all the required setup and returns False
         # if the 'ptint' option is set to False.
-        if not FlatCAMObj.plot(self):
-            return
+        # if not FlatCAMObj.plot(self):
+        #     return
 
         # for marking apertures, line color and fill color are the same
         if 'color' in kwargs:
@@ -1469,7 +1458,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
                 except (ObjectDeleted, AttributeError):
                     self.clear_plot_apertures()
                 except Exception as e:
-                    print(str(e))
+                    log.debug("FlatCAMGerber.plot_aperture() --> %s" % str(e))
 
             if run_thread:
                 self.app.worker_task.emit({'fcn': job_thread, 'params': [self]})
@@ -1482,11 +1471,14 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
         :param aperture: string; aperture for which to clear the mark shapes
         :return:
         """
-        if aperture == 'all':
-            for apid in self.apertures:
-                self.mark_shapes[apid].clear(update=True)
-        else:
-            self.mark_shapes[aperture].clear(update=True)
+        try:
+            if aperture == 'all':
+                for apid in list(self.apertures.keys()):
+                    self.mark_shapes[apid].clear(update=True)
+            else:
+                self.mark_shapes[aperture].clear(update=True)
+        except Exception as e:
+            log.debug("FlatCAMGerber.clear_plot_apertures() --> %s" % str(e))
 
     def clear_mark_all(self):
         self.ui.mark_all_cb.set_value(False)
@@ -1563,6 +1555,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
             self.app.ui.grid_snap_btn.trigger()
         else:
             self.clear_plot_apertures()
+            self.marked_rows[:] = []
 
         self.ui_connect()
 

+ 3 - 0
README.md

@@ -20,6 +20,9 @@ CAD program, and create G-Code for Isolation routing.
 - added the new keywords to the default keywords list
 - fixed the FullScreen option not working for the 3D graphic engine (due bug of Qt5 when OpenGL window is fullscreen) by creating a sort of fullscreen
 - added a final fix that allow full coverage of the screen in FullScreen in Windows and still the menus are working
+- optimized the Gerber mark shapes display
+- fixed a color format bug in Tool Move for 3D engine
+- made sure that when the Tool Move is used on a Gerber file with mark shapes active, those mark shapes are deleted before the actual move
 
 22.09.2019
 

+ 1 - 0
flatcamGUI/PlotCanvasLegacy.py

@@ -418,6 +418,7 @@ class PlotCanvasLegacy(QtCore.QObject):
 
         xmin, xmax = self.axes.get_xlim()
         ymin, ymax = self.axes.get_ylim()
+
         width = xmax - xmin
         height = ymax - ymin
 

+ 4 - 1
flatcamTools/ToolMove.py

@@ -153,6 +153,9 @@ class ToolMove(FlatCAMTool):
                                     return "fail"
 
                                 for sel_obj in obj_list:
+                                    # if the Gerber mark shapes are enabled they need to be disabled before move
+                                    if isinstance(sel_obj, FlatCAMGerber):
+                                        sel_obj.ui.aperture_table_visibility_cb.setChecked(False)
 
                                     # offset solid_geometry
                                     sel_obj.offset((dx, dy))
@@ -312,7 +315,7 @@ class ToolMove(FlatCAMTool):
         # face = Color('blue')
         # face.alpha = 0.2
 
-        face = '#0000FFAF' + str(hex(int(0.2 * 255)))[2:]
+        face = '#0000FF' + str(hex(int(0.2 * 255)))[2:]
         outline = '#0000FFAF'
 
         self.sel_shapes.add(proc_shape, color=outline, face_color=face, update=True, layer=0, tolerance=None)