Browse Source

- fixed issue in Film Tool where some parameters names in calls of method export_positive() were not matching the actual parameters name
- finished the Extract Drills Tool
- fixed a small issue in the DoubleSided Tool

Marius Stanciu 6 years ago
parent
commit
c16ecfe0c3
5 changed files with 103 additions and 53 deletions
  1. 12 5
      FlatCAMApp.py
  2. 3 0
      README.md
  3. 4 3
      flatcamTools/ToolDblSided.py
  4. 66 32
      flatcamTools/ToolExtractDrills.py
  5. 18 13
      flatcamTools/ToolFilm.py

+ 12 - 5
FlatCAMApp.py

@@ -10389,7 +10389,8 @@ class App(QtCore.QObject):
         self.report_usage("export_svg()")
         self.report_usage("export_svg()")
 
 
         if filename is None:
         if filename is None:
-            filename = self.defaults["global_last_save_folder"]
+            filename = self.defaults["global_last_save_folder"] if self.defaults["global_last_save_folder"] \
+                                                                   is not None else self.defaults["global_last_folder"]
 
 
         self.log.debug("export_svg()")
         self.log.debug("export_svg()")
 
 
@@ -10457,7 +10458,8 @@ class App(QtCore.QObject):
         self.report_usage("save source file()")
         self.report_usage("save source file()")
 
 
         if filename is None:
         if filename is None:
-            filename = self.defaults["global_last_save_folder"]
+            filename = self.defaults["global_last_save_folder"] if self.defaults["global_last_save_folder"] \
+                                                                   is not None else self.defaults["global_last_folder"]
 
 
         self.log.debug("save source file()")
         self.log.debug("save source file()")
 
 
@@ -10500,7 +10502,10 @@ class App(QtCore.QObject):
         self.report_usage("export_excellon()")
         self.report_usage("export_excellon()")
 
 
         if filename is None:
         if filename is None:
-            filename = self.defaults["global_last_save_folder"] + '/' + 'exported_excellon'
+            if self.defaults["global_last_save_folder"]:
+                filename = self.defaults["global_last_save_folder"] + '/' + 'exported_excellon'
+            else:
+                filename = self.defaults["global_last_folder"] + '/' + 'exported_excellon'
 
 
         self.log.debug("export_excellon()")
         self.log.debug("export_excellon()")
 
 
@@ -10656,7 +10661,8 @@ class App(QtCore.QObject):
         self.report_usage("export_gerber()")
         self.report_usage("export_gerber()")
 
 
         if filename is None:
         if filename is None:
-            filename = self.defaults["global_last_save_folder"]
+            filename = self.defaults["global_last_save_folder"] if self.defaults["global_last_save_folder"] \
+                                                                   is not None else self.defaults["global_last_folder"]
 
 
         self.log.debug("export_gerber()")
         self.log.debug("export_gerber()")
 
 
@@ -10792,7 +10798,8 @@ class App(QtCore.QObject):
         self.report_usage("export_dxf()")
         self.report_usage("export_dxf()")
 
 
         if filename is None:
         if filename is None:
-            filename = self.defaults["global_last_save_folder"]
+            filename = self.defaults["global_last_save_folder"] if self.defaults["global_last_save_folder"] \
+                                                                   is not None else self.defaults["global_last_folder"]
 
 
         self.log.debug("export_dxf()")
         self.log.debug("export_dxf()")
 
 

+ 3 - 0
README.md

@@ -13,6 +13,9 @@ CAD program, and create G-Code for Isolation routing.
 
 
 - working on a new tool: Extract Drills Tool who will create a Excellon object out of the apertures of a Gerber object
 - working on a new tool: Extract Drills Tool who will create a Excellon object out of the apertures of a Gerber object
 - finished the GUI in the Extract Drills Tool
 - finished the GUI in the Extract Drills Tool
+- fixed issue in Film Tool where some parameters names in calls of method export_positive() were not matching the actual parameters name
+- finished the Extract Drills Tool
+- fixed a small issue in the DoubleSided Tool
 
 
 8.01.2019
 8.01.2019
 
 

+ 4 - 3
flatcamTools/ToolDblSided.py

@@ -533,16 +533,17 @@ class DblSidedTool(FlatCAMTool):
                                                           "Add them and retry."))
                                                           "Add them and retry."))
             return
             return
 
 
-        drills = []
+        drills = list()
 
 
         for hole in holes:
         for hole in holes:
             point = Point(hole)
             point = Point(hole)
             point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
             point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
             drills.append({"point": point, "tool": "1"})
             drills.append({"point": point, "tool": "1"})
             drills.append({"point": point_mirror, "tool": "1"})
             drills.append({"point": point_mirror, "tool": "1"})
-            if 'solid_geometry' not in tools:
-                tools["1"]['solid_geometry'] = []
+            if 'solid_geometry' not in tools["1"]:
+                tools["1"]['solid_geometry'] = list()
             else:
             else:
+                tools["1"]['solid_geometry'].append(point)
                 tools["1"]['solid_geometry'].append(point_mirror)
                 tools["1"]['solid_geometry'].append(point_mirror)
 
 
         def obj_init(obj_inst, app_inst):
         def obj_init(obj_inst, app_inst):

+ 66 - 32
flatcamTools/ToolExtractDrills.py

@@ -150,11 +150,8 @@ class ToolExtractDrills(FlatCAMTool):
         self.e_drills_button.clicked.connect(self.on_extract_drills_click)
         self.e_drills_button.clicked.connect(self.on_extract_drills_click)
         self.reset_button.clicked.connect(self.set_tool_ui)
         self.reset_button.clicked.connect(self.set_tool_ui)
 
 
-        self.tools = list()
-        self.drills = dict()
-
     def install(self, icon=None, separator=None, **kwargs):
     def install(self, icon=None, separator=None, **kwargs):
-        FlatCAMTool.install(self, icon, separator, shortcut='ALT+E', **kwargs)
+        FlatCAMTool.install(self, icon, separator, shortcut='ALT+I', **kwargs)
 
 
     def run(self, toggle=True):
     def run(self, toggle=True):
         self.app.report_usage("Extract Drills()")
         self.app.report_usage("Extract Drills()")
@@ -192,6 +189,12 @@ class ToolExtractDrills(FlatCAMTool):
         self.ring_entry.set_value(float(self.app.defaults["tools_edrills_hole_ring"]))
         self.ring_entry.set_value(float(self.app.defaults["tools_edrills_hole_ring"]))
 
 
     def on_extract_drills_click(self):
     def on_extract_drills_click(self):
+
+        drill_dia = self.dia_entry.get_value()
+        ring_val = self.ring_entry.get_value()
+        drills = list()
+        tools = dict()
+
         selection_index = self.gerber_object_combo.currentIndex()
         selection_index = self.gerber_object_combo.currentIndex()
         model_index = self.app.collection.index(selection_index, 0, self.gerber_object_combo.rootModelIndex())
         model_index = self.app.collection.index(selection_index, 0, self.gerber_object_combo.rootModelIndex())
 
 
@@ -201,34 +204,65 @@ class ToolExtractDrills(FlatCAMTool):
             self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
             self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
             return
             return
 
 
-        # axis = self.mirror_axis.get_value()
-        # mode = self.axis_location.get_value()
-        #
-        # if mode == "point":
-        #     try:
-        #         px, py = self.point_entry.get_value()
-        #     except TypeError:
-        #         self.app.inform.emit('[WARNING_NOTCL] %s' % _("'Point' coordinates missing. "
-        #                                                       "Using Origin (0, 0) as mirroring reference."))
-        #         px, py = (0, 0)
-        #
-        # else:
-        #     selection_index_box = self.box_combo.currentIndex()
-        #     model_index_box = self.app.collection.index(selection_index_box, 0, self.box_combo.rootModelIndex())
-        #     try:
-        #         bb_obj = model_index_box.internalPointer().obj
-        #     except Exception as e:
-        #         self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
-        #         return
-        #
-        #     xmin, ymin, xmax, ymax = bb_obj.bounds()
-        #     px = 0.5 * (xmin + xmax)
-        #     py = 0.5 * (ymin + ymax)
-        #
-        # fcobj.mirror(axis, [px, py])
-        # self.app.object_changed.emit(fcobj)
-        # fcobj.plot()
-        self.app.inform.emit('[success] Gerber %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
+        outname = fcobj.options['name'].rpartition('.')[0]
+
+        mode = self.hole_size_radio.get_value()
+
+        if mode == 'fixed':
+            tools = {"1": {"C": drill_dia}}
+            for apid, apid_value in fcobj.apertures.items():
+                for geo_el in apid_value['geometry']:
+                    if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
+                        drills.append({"point": geo_el['follow'], "tool": "1"})
+                        if 'solid_geometry' not in tools["1"]:
+                            tools["1"]['solid_geometry'] = list()
+                        else:
+                            tools["1"]['solid_geometry'].append(geo_el['follow'])
+        else:
+            for apid, apid_value in fcobj.apertures.items():
+                ap_type = apid_value['type']
+
+                dia = float(apid_value['size']) - (2 * ring_val)
+                if ap_type == 'R' or ap_type == 'O':
+                    width = float(apid_value['width'])
+                    height = float(apid_value['height'])
+                    if width >= height:
+                        dia = float(apid_value['height']) - (2 * ring_val)
+                    else:
+                        dia = float(apid_value['width']) - (2 * ring_val)
+
+                tool_in_drills = False
+                for tool, tool_val in tools.items():
+                    if abs(float('%.*f' % (self.decimals, tool_val["C"])) - dia) < (10 ** -self.decimals):
+                        tool_in_drills = tool
+
+                if tool_in_drills is False:
+                    if tools:
+                        new_tool = max([int(t) for t in tools]) + 1
+                        tool_in_drills = str(new_tool)
+                    else:
+                        tool_in_drills = "1"
+
+                for geo_el in apid_value['geometry']:
+                    if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
+                        if tool_in_drills not in tools:
+                            tools[tool_in_drills] = {"C": dia}
+
+                        drills.append({"point": geo_el['follow'], "tool": tool_in_drills})
+
+                        if 'solid_geometry' not in tools[tool_in_drills]:
+                            tools[tool_in_drills]['solid_geometry'] = list()
+                        else:
+                            tools[tool_in_drills]['solid_geometry'].append(geo_el['follow'])
+
+        def obj_init(obj_inst, app_inst):
+            obj_inst.tools = tools
+            obj_inst.drills = drills
+            obj_inst.create_geometry()
+            obj_inst.source_file = self.app.export_excellon(obj_name=outname, local_use=obj_inst, filename=None,
+                                                            use_thread=False)
+
+        self.app.new_object("excellon", outname, obj_init)
 
 
     def on_hole_size_toggle(self, val):
     def on_hole_size_toggle(self, val):
         if val == "fixed":
         if val == "fixed":

+ 18 - 13
flatcamTools/ToolFilm.py

@@ -752,7 +752,7 @@ class Film(FlatCAMTool):
                                  skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y,
                                  skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y,
                                  skew_reference=skew_reference,
                                  skew_reference=skew_reference,
                                  mirror=mirror,
                                  mirror=mirror,
-                                 pagesize=pagesize, orientation=orientation, color=color, opacity=1.0,
+                                 pagesize_val=pagesize, orientation_val=orientation, color_val=color, opacity_val=1.0,
                                  ftype=ftype
                                  ftype=ftype
                                  )
                                  )
 
 
@@ -1080,23 +1080,28 @@ class Film(FlatCAMTool):
                         skew_factor_x=None, skew_factor_y=None, skew_reference='center',
                         skew_factor_x=None, skew_factor_y=None, skew_reference='center',
                         mirror=None,  orientation_val='p', pagesize_val='A4', color_val='black', opacity_val=1.0,
                         mirror=None,  orientation_val='p', pagesize_val='A4', color_val='black', opacity_val=1.0,
                         use_thread=True, ftype='svg'):
                         use_thread=True, ftype='svg'):
+
         """
         """
         Exports a Geometry Object to an SVG file in positive black.
         Exports a Geometry Object to an SVG file in positive black.
 
 
-        :param obj_name: the name of the FlatCAM object to be saved as SVG
-        :param box_name: the name of the FlatCAM object to be used as delimitation of the content to be saved
-        :param filename: Path to the SVG file to save to.
+        :param obj_name:            the name of the FlatCAM object to be saved
+        :param box_name:            the name of the FlatCAM object to be used as delimitation of the content to be saved
+        :param filename:            Path to the file to save to.
         :param scale_stroke_factor: factor by which to change/scale the thickness of the features
         :param scale_stroke_factor: factor by which to change/scale the thickness of the features
-        :param scale_factor_x: factor to scale the svg geometry on the X axis
-        :param scale_factor_y: factor to scale the svg geometry on the Y axis
-        :param skew_factor_x: factor to skew the svg geometry on the X axis
-        :param skew_factor_y: factor to skew the svg geometry on the Y axis
-        :param skew_reference: reference to use for skew. Can be 'bottomleft', 'bottomright', 'topleft', 'topright' and
-        those are the 4 points of the bounding box of the geometry to be skewed.
-        :param mirror: can be 'x' or 'y' or 'both'. Axis on which to mirror the svg geometry
+        :param scale_factor_x:      factor to scale the geometry on the X axis
+        :param scale_factor_y:      factor to scale the geometry on the Y axis
+        :param skew_factor_x:       factor to skew the geometry on the X axis
+        :param skew_factor_y:       factor to skew the geometry on the Y axis
+        :param skew_reference:      reference to use for skew. Can be 'bottomleft', 'bottomright', 'topleft',
+        'topright' and those are the 4 points of the bounding box of the geometry to be skewed.
+        :param mirror:              can be 'x' or 'y' or 'both'. Axis on which to mirror the svg geometry
+        :param orientation_val:
+        :param pagesize_val:
+        :param color_val:
+        :param opacity_val:
+        :param use_thread:          if to be run in a separate thread; boolean
+        :param ftype:               the type of file for saving the film: 'svg', 'png' or 'pdf'
 
 
-        :param use_thread: if to be run in a separate thread; boolean
-        :param ftype: the type of file for saving the film: 'svg', 'png' or 'pdf'
         :return:
         :return:
         """
         """
         self.app.report_usage("export_positive()")
         self.app.report_usage("export_positive()")