- 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.

This commit is contained in:
Marius Stanciu
2019-04-22 20:33:03 +03:00
parent 8f1a0c1fdc
commit d66d914cc3
2 changed files with 18 additions and 18 deletions

View File

@@ -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

View File

@@ -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)