Sfoglia il codice sorgente

- Copper Thieving Tool - added units label for the pattern plated area
- Properties Tool - added a new parameter, the copper area which show the area of the copper features for the Gerber objects

Marius Stanciu 6 anni fa
parent
commit
efb82abac6
3 ha cambiato i file con 85 aggiunte e 36 eliminazioni
  1. 2 0
      README.md
  2. 19 12
      flatcamTools/ToolCopperThieving.py
  3. 64 24
      flatcamTools/ToolProperties.py

+ 2 - 0
README.md

@@ -12,6 +12,8 @@ CAD program, and create G-Code for Isolation routing.
 5.12.2019 
 
 - in NCC Tool, the new Geometry object that is created on copper clear now has the solid_geometry attribute where the geometry is stored not only in the obj.tools attribute
+- Copper Thieving Tool - added units label for the pattern plated area
+- Properties Tool - added a new parameter, the copper area which show the area of the copper features for the Gerber objects
 
 4.12.2019 
 

+ 19 - 12
flatcamTools/ToolCopperThieving.py

@@ -46,7 +46,7 @@ class ToolCopperThieving(FlatCAMTool):
         self.canvas = self.app.plotcanvas
 
         self.decimals = 4
-        self.units = ''
+        self.units = self.app.defaults['units']
 
         # ## Title
         title_label = QtWidgets.QLabel("%s" % self.toolName)
@@ -341,11 +341,12 @@ class ToolCopperThieving(FlatCAMTool):
         self.layout.addLayout(grid_lay_1)
         grid_lay_1.setColumnStretch(0, 0)
         grid_lay_1.setColumnStretch(1, 1)
+        grid_lay_1.setColumnStretch(2, 0)
 
         separator_line_1 = QtWidgets.QFrame()
         separator_line_1.setFrameShape(QtWidgets.QFrame.HLine)
         separator_line_1.setFrameShadow(QtWidgets.QFrame.Sunken)
-        grid_lay_1.addWidget(separator_line_1, 0, 0, 1, 2)
+        grid_lay_1.addWidget(separator_line_1, 0, 0, 1, 3)
 
         grid_lay_1.addWidget(QtWidgets.QLabel(''))
 
@@ -354,7 +355,7 @@ class ToolCopperThieving(FlatCAMTool):
             _("Parameters used for the robber bar.\n"
               "Robber bar = copper border to help in pattern hole plating.")
         )
-        grid_lay_1.addWidget(self.robber_bar_label, 1, 0, 1, 2)
+        grid_lay_1.addWidget(self.robber_bar_label, 1, 0, 1, 3)
 
         # ROBBER BAR MARGIN #
         self.rb_margin_label = QtWidgets.QLabel('%s:' % _("Margin"))
@@ -367,7 +368,7 @@ class ToolCopperThieving(FlatCAMTool):
         self.rb_margin_entry.setSingleStep(0.1)
 
         grid_lay_1.addWidget(self.rb_margin_label, 2, 0)
-        grid_lay_1.addWidget(self.rb_margin_entry, 2, 1)
+        grid_lay_1.addWidget(self.rb_margin_entry, 2, 1, 1, 2)
 
         # THICKNESS #
         self.rb_thickness_label = QtWidgets.QLabel('%s:' % _("Thickness"))
@@ -380,7 +381,7 @@ class ToolCopperThieving(FlatCAMTool):
         self.rb_thickness_entry.setSingleStep(0.1)
 
         grid_lay_1.addWidget(self.rb_thickness_label, 3, 0)
-        grid_lay_1.addWidget(self.rb_thickness_entry, 3, 1)
+        grid_lay_1.addWidget(self.rb_thickness_entry, 3, 1, 1, 2)
 
         # ## Insert Robber Bar
         self.rb_button = QtWidgets.QPushButton(_("Insert Robber Bar"))
@@ -396,18 +397,18 @@ class ToolCopperThieving(FlatCAMTool):
                             font-weight: bold;
                         }
                         """)
-        grid_lay_1.addWidget(self.rb_button, 4, 0, 1, 2)
+        grid_lay_1.addWidget(self.rb_button, 4, 0, 1, 3)
 
         separator_line_2 = QtWidgets.QFrame()
         separator_line_2.setFrameShape(QtWidgets.QFrame.HLine)
         separator_line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
-        grid_lay_1.addWidget(separator_line_2, 5, 0, 1, 2)
+        grid_lay_1.addWidget(separator_line_2, 5, 0, 1, 3)
 
         self.patern_mask_label = QtWidgets.QLabel('<b>%s</b>' % _('Pattern Plating Mask'))
         self.patern_mask_label.setToolTip(
             _("Generate a mask for pattern plating.")
         )
-        grid_lay_1.addWidget(self.patern_mask_label, 6, 0, 1, 2)
+        grid_lay_1.addWidget(self.patern_mask_label, 6, 0, 1, 3)
 
         self.sm_obj_label = QtWidgets.QLabel("%s:" % _("Select Soldermask object"))
         self.sm_obj_label.setToolTip(
@@ -421,8 +422,8 @@ class ToolCopperThieving(FlatCAMTool):
         self.sm_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
         self.sm_object_combo.setCurrentIndex(1)
 
-        grid_lay_1.addWidget(self.sm_obj_label, 7, 0, 1, 2)
-        grid_lay_1.addWidget(self.sm_object_combo, 8, 0, 1, 2)
+        grid_lay_1.addWidget(self.sm_obj_label, 7, 0, 1, 3)
+        grid_lay_1.addWidget(self.sm_object_combo, 8, 0, 1, 3)
 
         # Openings CLEARANCE #
         self.clearance_ppm_label = QtWidgets.QLabel('%s:' % _("Clearance"))
@@ -436,7 +437,7 @@ class ToolCopperThieving(FlatCAMTool):
         self.clearance_ppm_entry.setSingleStep(0.1)
 
         grid_lay_1.addWidget(self.clearance_ppm_label, 9, 0)
-        grid_lay_1.addWidget(self.clearance_ppm_entry, 9, 1)
+        grid_lay_1.addWidget(self.clearance_ppm_entry, 9, 1, 1, 2)
 
         # Plated area
         self.plated_area_label = QtWidgets.QLabel('%s:' % _("Plated area"))
@@ -451,8 +452,14 @@ class ToolCopperThieving(FlatCAMTool):
         self.plated_area_entry = FCEntry()
         self.plated_area_entry.setDisabled(True)
 
+        if self.units.upper() == 'MM':
+            self.units_area_label = QtWidgets.QLabel('%s<sup>2</sup>' % _("mm"))
+        else:
+            self.units_area_label = QtWidgets.QLabel('%s<sup>2</sup>' % _("in"))
+
         grid_lay_1.addWidget(self.plated_area_label, 10, 0)
         grid_lay_1.addWidget(self.plated_area_entry, 10, 1)
+        grid_lay_1.addWidget(self.units_area_label, 10, 2)
 
         # ## Pattern Plating Mask
         self.ppm_button = QtWidgets.QPushButton(_("Generate pattern plating mask"))
@@ -467,7 +474,7 @@ class ToolCopperThieving(FlatCAMTool):
                             font-weight: bold;
                         }
                         """)
-        grid_lay_1.addWidget(self.ppm_button, 11, 0, 1, 2)
+        grid_lay_1.addWidget(self.ppm_button, 11, 0, 1, 3)
 
         self.layout.addStretch()
 

+ 64 - 24
flatcamTools/ToolProperties.py

@@ -7,7 +7,6 @@
 
 from PyQt5 import QtGui, QtCore, QtWidgets
 from FlatCAMTool import FlatCAMTool
-from FlatCAMObj import FlatCAMCNCjob
 
 from shapely.geometry import MultiPolygon, Polygon
 from shapely.ops import cascaded_union
@@ -28,13 +27,15 @@ log = logging.getLogger('base')
 class Properties(FlatCAMTool):
     toolName = _("Properties")
 
-    calculations_finished = QtCore.pyqtSignal(float, float, float, float, object)
+    calculations_finished = QtCore.pyqtSignal(float, float, float, float, float, object)
 
     def __init__(self, app):
         FlatCAMTool.__init__(self, app)
 
         self.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored)
 
+        self.decimals = 4
+
         # this way I can hide/show the frame
         self.properties_frame = QtWidgets.QFrame()
         self.properties_frame.setContentsMargins(0, 0, 0, 0)
@@ -162,6 +163,7 @@ class Properties(FlatCAMTool):
             length = 0.0
             width = 0.0
             area = 0.0
+            copper_area = 0.0
 
             geo = obj_prop.solid_geometry
             if geo:
@@ -172,13 +174,22 @@ class Properties(FlatCAMTool):
                     length = abs(xmax - xmin)
                     width = abs(ymax - ymin)
                 except Exception as e:
-                    log.debug("PropertiesTool.addItems() --> %s" % str(e))
+                    log.debug("PropertiesTool.addItems() -> calculate dimensions --> %s" % str(e))
 
                 # calculate box area
                 if self.app.defaults['units'].lower() == 'mm':
                     area = (length * width) / 100
                 else:
                     area = length * width
+
+                if obj_prop.kind.lower() == 'gerber':
+                    # calculate copper area
+                    try:
+                        for geo_el in geo:
+                            copper_area += geo_el.area
+                    except TypeError:
+                        copper_area += geo.area
+                    copper_area /= 100
             else:
                 xmin = []
                 ymin = []
@@ -209,11 +220,28 @@ class Properties(FlatCAMTool):
                         area = (length * width) / 100
                     else:
                         area = length * width
+
+                    if obj_prop.kind.lower() == 'gerber':
+                        # calculate copper area
+
+                        # create a complete solid_geometry from the tools
+                        geo_tools = list()
+                        for tool_k in obj_prop.tools:
+                            if 'solid_geometry' in obj_prop.tools[tool_k]:
+                                for geo_el in obj_prop.tools[tool_k]['solid_geometry']:
+                                    geo_tools.append(geo_el)
+
+                        try:
+                            for geo_el in geo_tools:
+                                copper_area += geo_el.area
+                        except TypeError:
+                            copper_area += geo_tools.area
+                        copper_area /= 100
                 except Exception as e:
                     log.debug("Properties.addItems() --> %s" % str(e))
 
             area_chull = 0.0
-            if not isinstance(obj_prop, FlatCAMCNCjob):
+            if obj_prop.kind.lower() != 'cncjob':
                 # calculate and add convex hull area
                 if geo:
                     if isinstance(geo, MultiPolygon):
@@ -241,20 +269,12 @@ class Properties(FlatCAMTool):
             if self.app.defaults['units'].lower() == 'mm':
                 area_chull = area_chull / 100
 
-            self.calculations_finished.emit(area, length, width, area_chull, dims)
+            self.calculations_finished.emit(area, length, width, area_chull, copper_area, dims)
 
         self.app.worker_task.emit({'fcn': job_thread, 'params': [obj]})
 
-        self.addChild(units,
-                      ['FlatCAM units:',
-                       {
-                           'in': _('Inch'),
-                           'mm': _('Metric')
-                       }
-                       [str(self.app.defaults['units'].lower())]
-                       ],
-                      True
-                      )
+        f_unit = {'in': _('Inch'), 'mm': _('Metric')}[str(self.app.defaults['units'].lower())]
+        self.addChild(units, ['FlatCAM units:', f_unit], True)
 
         for option in obj.options:
             if option is 'name':
@@ -349,21 +369,41 @@ class Properties(FlatCAMTool):
         if column1 is not None:
             item.setText(1, str(title[1]))
 
-    def show_area_chull(self, area, length, width, chull_area, location):
+    def show_area_chull(self, area, length, width, chull_area, copper_area, location):
 
         # add dimensions
-        self.addChild(location, ['%s:' % _('Length'), '%.4f %s' % (
-            length, self.app.defaults['units'].lower())], True)
-        self.addChild(location, ['%s:' % _('Width'), '%.4f %s' % (
-            width, self.app.defaults['units'].lower())], True)
+        self.addChild(
+            location,
+            ['%s:' % _('Length'), '%.*f %s' % (self.decimals, length, self.app.defaults['units'].lower())],
+            True
+        )
+        self.addChild(
+            location,
+            ['%s:' % _('Width'), '%.*f %s' % (self.decimals, width, self.app.defaults['units'].lower())],
+            True
+        )
 
         # add box area
         if self.app.defaults['units'].lower() == 'mm':
-            self.addChild(location, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'cm2')], True)
-            self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (chull_area, 'cm2')], True)
+            self.addChild(location, ['%s:' % _('Box Area'), '%.*f %s' % (self.decimals, area, 'cm2')], True)
+            self.addChild(
+                location,
+                ['%s:' % _('Convex_Hull Area'), '%.*f %s' % (self.decimals, chull_area, 'cm2')],
+                True
+            )
 
         else:
-            self.addChild(location, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'in2')], True)
-            self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (chull_area, 'in2')], True)
+            self.addChild(location, ['%s:' % _('Box Area'), '%.*f %s' % (self.decimals, area, 'in2')], True)
+            self.addChild(
+                location,
+                ['%s:' % _('Convex_Hull Area'), '%.*f %s' % (self.decimals, chull_area, 'in2')],
+                True
+            )
+
+        # add copper area
+        if self.app.defaults['units'].lower() == 'mm':
+            self.addChild(location, ['%s:' % _('Copper Area'), '%.*f %s' % (self.decimals, copper_area, 'cm2')], True)
+        else:
+            self.addChild(location, ['%s:' % _('Copper Area'), '%.*f %s' % (self.decimals, copper_area, 'in2')], True)
 
 # end of file