From d66d914cc3920e68123c13cd1857d7b1852f919c Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 22 Apr 2019 20:33:03 +0300 Subject: [PATCH] - PDF Import tool: fixed bugs when drag & dropping PDF files on canvas the files geometry previously opened was added to the new one. Also scaling issues. Solved. --- README.md | 2 ++ flatcamTools/ToolPDF.py | 34 ++++++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 61394e8c..f1991ec7 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ CAD program, and create G-Code for Isolation routing. - PDF's can be drag & dropped on the GUI to be loaded - PDF import tool: added support for save/restore Graphics stack. Only for scale and offset transformations and for the linewidth. This is the final fix for Microsoft PDF printer who saves in PDF format 1.7 - PDF Import tool: added support for PDF files that embed multiple Gerber layers (top, bottom, outline, silkscreen etc). Each will be opened in it's own Gerber file. The requirement is that each one is drawn in a different color +- PDF Import tool: fixed bugs when drag & dropping PDF files on canvas the files geometry previously opened was added to the new one. Also scaling issues. Solved. + 21.04.2019 diff --git a/flatcamTools/ToolPDF.py b/flatcamTools/ToolPDF.py index 99f7de2d..e790b98b 100644 --- a/flatcamTools/ToolPDF.py +++ b/flatcamTools/ToolPDF.py @@ -102,7 +102,7 @@ class ToolPDF(FlatCAMTool): self.gs['transform'] = [] self.gs['line_width'] = [] # each element is a float - self.geo_buffer = [] + self.obj_dict = dict() self.pdf_parsed = '' # conversion factor to INCH @@ -111,18 +111,6 @@ class ToolPDF(FlatCAMTool): def run(self, toggle=True): self.app.report_usage("ToolPDF()") - # init variables for reuse - self.geo_buffer = [] - self.pdf_parsed = '' - - # the UNITS in PDF files are points and here we set the factor to convert them to real units (either MM or INCH) - if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM': - # 1 inch = 72 points => 1 point = 1 / 72 = 0.01388888888 inch = 0.01388888888 inch * 25.4 = 0.35277777778 mm - self.point_to_unit_factor = 0.35277777778 - else: - # 1 inch = 72 points => 1 point = 1 / 72 = 0.01388888888 inch - self.point_to_unit_factor = 0.01388888888 - self.set_tool_ui() self.on_open_pdf_click() @@ -161,6 +149,16 @@ class ToolPDF(FlatCAMTool): def open_pdf(self, filename): new_name = filename.split('/')[-1].split('\\')[-1] + self.obj_dict.clear() + self.pdf_parsed = '' + + # the UNITS in PDF files are points and here we set the factor to convert them to real units (either MM or INCH) + if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM': + # 1 inch = 72 points => 1 point = 1 / 72 = 0.01388888888 inch = 0.01388888888 inch * 25.4 = 0.35277777778 mm + self.point_to_unit_factor = 25.4 / 72 + else: + # 1 inch = 72 points => 1 point = 1 / 72 = 0.01388888888 inch + self.point_to_unit_factor = 1 / 72 with self.app.proc_container.new(_("Parsing PDF file ...")): with open(filename, "rb") as f: @@ -176,14 +174,14 @@ class ToolPDF(FlatCAMTool): except Exception as e: log.debug("ToolPDF.open_pdf().obj_init() --> %s" % str(e)) - obj_dict = self.parse_pdf(pdf_content=self.pdf_parsed) + self.obj_dict = self.parse_pdf(pdf_content=self.pdf_parsed) - for k in obj_dict: - ap_dict = obj_dict[k] + for k in self.obj_dict: + ap_dict = deepcopy(self.obj_dict[k]) if ap_dict: def obj_init(grb_obj, app_obj): - grb_obj.apertures = deepcopy(ap_dict) + grb_obj.apertures = ap_dict poly_buff = [] for ap in grb_obj.apertures: @@ -273,7 +271,7 @@ class ToolPDF(FlatCAMTool): else: object_dict[object_nr] = deepcopy(apertures_dict) object_nr += 1 - object_dict[object_nr] = {} + object_dict[object_nr] = dict() apertures_dict.clear() old_color = copy(color)