From c16ecfe0c3de7eb8855da06bf43cc923100604db Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 11 Jan 2020 00:52:06 +0200 Subject: [PATCH] - 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 --- FlatCAMApp.py | 17 ++++-- README.md | 3 + flatcamTools/ToolDblSided.py | 7 ++- flatcamTools/ToolExtractDrills.py | 98 +++++++++++++++++++++---------- flatcamTools/ToolFilm.py | 31 ++++++---- 5 files changed, 103 insertions(+), 53 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 3815287c..d80e3ec5 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -10389,7 +10389,8 @@ class App(QtCore.QObject): self.report_usage("export_svg()") 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()") @@ -10457,7 +10458,8 @@ class App(QtCore.QObject): self.report_usage("save source file()") 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()") @@ -10500,7 +10502,10 @@ class App(QtCore.QObject): self.report_usage("export_excellon()") 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()") @@ -10656,7 +10661,8 @@ class App(QtCore.QObject): self.report_usage("export_gerber()") 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()") @@ -10792,7 +10798,8 @@ class App(QtCore.QObject): self.report_usage("export_dxf()") 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()") diff --git a/README.md b/README.md index 9093667b..3cc30ba8 100644 --- a/README.md +++ b/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 - 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 diff --git a/flatcamTools/ToolDblSided.py b/flatcamTools/ToolDblSided.py index 3308c159..0b00fc6e 100644 --- a/flatcamTools/ToolDblSided.py +++ b/flatcamTools/ToolDblSided.py @@ -533,16 +533,17 @@ class DblSidedTool(FlatCAMTool): "Add them and retry.")) return - drills = [] + drills = list() for hole in holes: point = Point(hole) point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py)) drills.append({"point": point, "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: + tools["1"]['solid_geometry'].append(point) tools["1"]['solid_geometry'].append(point_mirror) def obj_init(obj_inst, app_inst): diff --git a/flatcamTools/ToolExtractDrills.py b/flatcamTools/ToolExtractDrills.py index 7f47ab3e..5d2a604e 100644 --- a/flatcamTools/ToolExtractDrills.py +++ b/flatcamTools/ToolExtractDrills.py @@ -150,11 +150,8 @@ class ToolExtractDrills(FlatCAMTool): self.e_drills_button.clicked.connect(self.on_extract_drills_click) self.reset_button.clicked.connect(self.set_tool_ui) - self.tools = list() - self.drills = dict() - 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): 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"])) 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() 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 ...")) 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): if val == "fixed": diff --git a/flatcamTools/ToolFilm.py b/flatcamTools/ToolFilm.py index ead110b1..a3542e29 100644 --- a/flatcamTools/ToolFilm.py +++ b/flatcamTools/ToolFilm.py @@ -752,7 +752,7 @@ class Film(FlatCAMTool): skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y, skew_reference=skew_reference, 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 ) @@ -1080,23 +1080,28 @@ class Film(FlatCAMTool): 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, use_thread=True, ftype='svg'): + """ 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_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: """ self.app.report_usage("export_positive()")