From de4c51b480ed1efa309fdcf967623e2b1ee96012 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 28 Oct 2021 20:11:06 +0300 Subject: [PATCH] - fixed error that did not allowed printing from the TextEditor - added an error message when the File -> Print to PDF functionality is not working due of missing a root element in the SVG step --- CHANGELOG.md | 2 ++ appEditors/AppTextEditor.py | 2 +- app_Main.py | 12 +++++++++--- camlib.py | 20 ++++++++++++++++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40aed027..3e695556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ CHANGELOG for FlatCAM beta 28.10.2021 - cleaned the geometry generated by flattening by removing the empty geometry; fixed issue #539 on jpcgt's bitbucket account +- fixed error that did not allowed printing from the TextEditor +- added an error message when the File -> Print to PDF functionality is not working due of missing a root element in the SVG step 27.10.2021 diff --git a/appEditors/AppTextEditor.py b/appEditors/AppTextEditor.py index 5d8ebaa9..e466c7ca 100644 --- a/appEditors/AppTextEditor.py +++ b/appEditors/AppTextEditor.py @@ -176,7 +176,7 @@ class AppTextEditor(QtWidgets.QWidget): def handlePrint(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec() == QtWidgets.QDialog.DialogCode.Accepted: - self.code_editor.document().print_(dialog.printer()) + self.code_editor.document().print(dialog.printer()) def handlePreview(self): dialog = QtPrintSupport.QPrintPreviewDialog() diff --git a/app_Main.py b/app_Main.py index 977010a4..885a2b98 100644 --- a/app_Main.py +++ b/app_Main.py @@ -10420,8 +10420,7 @@ class MenuFileHandlers(QtCore.QObject): exported_svg = [] for obj in obj_selection: - svg_obj = obj.export_svg(scale_stroke_factor=0.0, scale_factor_x=None, scale_factor_y=None, - skew_factor_x=None, skew_factor_y=None, mirror=None) + svg_obj = obj.export_svg(scale_stroke_factor=0.0) if obj.kind.lower() == 'gerber' or obj.kind.lower() == 'excellon': color = obj.fill_color[:-2] @@ -10433,7 +10432,14 @@ class MenuFileHandlers(QtCore.QObject): # We don't need stroke-width # We set opacity to maximum # We set the colour to WHITE - root = ET.fromstring(svg_obj) + + try: + root = ET.fromstring(svg_obj) + except Exception as e: + self.log.debug("MenuFileHandlers.save_pdf() -> Missing root node -> %s" % str(e)) + self.app.inform.emit("[ERROR_NOTCL] %s" % _("Failed.")) + return + for child in root: child.set('fill', str(color)) child.set('opacity', str(transparency_level)) diff --git a/camlib.py b/camlib.py index cb9ac65f..9e4fa40a 100644 --- a/camlib.py +++ b/camlib.py @@ -7613,15 +7613,27 @@ class CNCjob(Geometry): gcode += self.doformat(p.lift_code, x=first_x, y=first_y) # Stop cutting return gcode - def export_svg(self, scale_stroke_factor=0.00): + def export_svg(self, scale_stroke_factor=0.00, + scale_factor_x=None, scale_factor_y=None, + skew_factor_x=None, skew_factor_y=None, + skew_reference='center', scale_reference='center', mirror_reference='center', + mirror=None): + """ Exports the CNC Job as a SVG Element - :param scale_stroke_factor: A factor to scale the SVG geometry - :type scale_stroke_factor: float + :param scale_stroke_factor: A factor to scale the SVG geometry element outline + :param scale_factor_x: x factor for scale + :param scale_factor_y: y factor for scale + :param skew_factor_x: x factor for skew + :param skew_factor_y: y factor for skew + :param skew_reference: The reference point for skewing (str, tuple) + :param scale_reference: The reference point for scaling (str, tuple) + :param mirror_reference: The reference point for mirroring (str, tuple) + :param mirror: Bool, if to mirror or not :return: SVG Element string - :rtype: str """ + # scale_factor is a multiplication factor for the SVG stroke-width used within shapely's svg export # If not specified then try and use the tool diameter # This way what is on screen will match what is outputed for the svg