From 523457b4709b2eb86cbcb129f57b36e0130422bd Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Thu, 28 Oct 2021 03:42:25 +0200 Subject: [PATCH] several bugfixes --- .../epilog_dashboard_bbox_adjust.py | 16 +++++--- .../export_selection_as.py | 7 +++- .../fablabchemnitz/paperfold/paperfold.py | 40 +++++++++++++++++-- extensions/fablabchemnitz/plycutter/plycutter | 1 + 4 files changed, 54 insertions(+), 10 deletions(-) create mode 160000 extensions/fablabchemnitz/plycutter/plycutter diff --git a/extensions/fablabchemnitz/epilog_dashboard_bbox_adjust/epilog_dashboard_bbox_adjust.py b/extensions/fablabchemnitz/epilog_dashboard_bbox_adjust/epilog_dashboard_bbox_adjust.py index dab007d6..5765a170 100644 --- a/extensions/fablabchemnitz/epilog_dashboard_bbox_adjust/epilog_dashboard_bbox_adjust.py +++ b/extensions/fablabchemnitz/epilog_dashboard_bbox_adjust/epilog_dashboard_bbox_adjust.py @@ -77,9 +77,12 @@ class EpilogDashboardBboxAdjust(inkex.EffectExtension): The rectangle attributes are set in px. They ignore the real units from namedview. Strange fact: ellipses, spirals and other primitives work flawlessly. ''' - if isinstance (element, inkex.Rectangle): + if isinstance (element, inkex.Rectangle) or \ + isinstance (element, inkex.Circle) or \ + isinstance (element, inkex.Ellipse): bbox += element.bounding_box() * scale_factor - elif isinstance (element, inkex.TextElement): + elif isinstance (element, inkex.TextElement) or \ + isinstance (element, inkex.Tspan): if self.options.skip_errors is False: self.msg("Text elements are not supported!") return @@ -91,9 +94,12 @@ class EpilogDashboardBboxAdjust(inkex.EffectExtension): #for element in self.svg.root.getchildren(): for element in self.document.getroot().iter("*"): if isinstance (element, inkex.ShapeElement) and element.tag != inkex.addNS('use','svg') and element.get('inkscape:groupmode') != 'layer': #bbox fails for svg:use elements and layers: - if isinstance (element, inkex.Rectangle): - bbox += element.bounding_box() * scale_factor - elif isinstance (element, inkex.TextElement): + if isinstance (element, inkex.Rectangle) or \ + isinstance (element, inkex.Circle) or \ + isinstance (element, inkex.Ellipse): + bbox += element.bounding_box() * scale_factor + elif isinstance (element, inkex.TextElement) or \ + isinstance (element, inkex.Tspan): if self.options.skip_errors is False: self.msg("Text elements are not supported!") return diff --git a/extensions/fablabchemnitz/export_selection_as/export_selection_as.py b/extensions/fablabchemnitz/export_selection_as/export_selection_as.py index d95947f8..048105d8 100644 --- a/extensions/fablabchemnitz/export_selection_as/export_selection_as.py +++ b/extensions/fablabchemnitz/export_selection_as/export_selection_as.py @@ -112,9 +112,12 @@ class ExportObject(inkex.EffectExtension): The rectangle attributes are set in px. They ignore the real units from namedview. Strange fact: ellipses, spirals and other primitives work flawlessly. ''' - if isinstance (element, inkex.Rectangle): + if isinstance (element, inkex.Rectangle) or \ + isinstance (element, inkex.Circle) or \ + isinstance (element, inkex.Ellipse): bbox += element.bounding_box(transform) * scale_factor - elif isinstance (element, inkex.TextElement): + elif isinstance (element, inkex.TextElement) or \ + isinstance (element, inkex.Tspan): if self.options.skip_errors is False: self.msg("Text elements are not supported!") return diff --git a/extensions/fablabchemnitz/paperfold/paperfold.py b/extensions/fablabchemnitz/paperfold/paperfold.py index 5b285f6d..bc2ed183 100644 --- a/extensions/fablabchemnitz/paperfold/paperfold.py +++ b/extensions/fablabchemnitz/paperfold/paperfold.py @@ -52,6 +52,15 @@ class Paperfold(inkex.EffectExtension): minAngle = 0 angleRange = 0 + def getElementChildren(self, element, elements = None): + if elements == None: + elements = [] + if element.tag != inkex.addNS('g','svg'): + elements.append(element) + for child in element.getchildren(): + self.getElementChildren(child, elements) + return elements + # Compute the third point of a triangle when two points and all edge lengths are given def getThirdPoint(self, v0, v1, l01, l12, l20): v2rotx = (l01 ** 2 + l20 ** 2 - l12 ** 2) / (2 * l01) @@ -952,12 +961,37 @@ class Paperfold(inkex.EffectExtension): paperfoldPageGroup = self.writeSVG(unfoldedComponents[i], maxSize, randomColorSet) #translate the groups next to each other to remove overlappings if i != 0: - previous_bbox = paperfoldMainGroup[i-1].bounding_box() - this_bbox = paperfoldPageGroup.bounding_box() + #previous_bbox = paperfoldMainGroup[i-1].bounding_box() + #as TextElement, Tspan and Circle cause wrong BBox calculation, we have to make it more complex + previous_bbox = inkex.BoundingBox() + for child in self.getElementChildren(paperfoldMainGroup[i-1]): + if not isinstance (child, inkex.TextElement) and \ + not isinstance (child, inkex.Tspan) and \ + not isinstance (child, inkex.Circle): + transform = inkex.Transform() + parent = child.getparent() + if parent is not None and isinstance(parent, inkex.ShapeElement): + transform = parent.composed_transform() + previous_bbox += child.bounding_box(transform) + + #this_bbox = paperfoldPageGroup.bounding_box() + this_bbox = inkex.BoundingBox() + for child in self.getElementChildren(paperfoldPageGroup): + #as TextElement, Tspan and Circle cause wrong BBox calculation, we have to make it more complex + if not isinstance (child, inkex.TextElement) and \ + not isinstance (child, inkex.Tspan) and \ + not isinstance (child, inkex.Circle): + transform = inkex.Transform() + parent = child.getparent() + if parent is not None and isinstance(parent, inkex.ShapeElement): + transform = parent.composed_transform() + this_bbox += child.bounding_box(transform) + + #self.msg(previous_bbox) + #self.msg(this_bbox) paperfoldPageGroup.set("transform", "translate({:0.6f}, 0.0)".format(previous_bbox.left + previous_bbox.width - this_bbox.left + xSpacing)) paperfoldMainGroup.append(paperfoldPageGroup) - #apply scale factor translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]] paperfoldMainGroup.transform = Transform(translation_matrix) * paperfoldMainGroup.transform diff --git a/extensions/fablabchemnitz/plycutter/plycutter b/extensions/fablabchemnitz/plycutter/plycutter new file mode 160000 index 00000000..92b545ed --- /dev/null +++ b/extensions/fablabchemnitz/plycutter/plycutter @@ -0,0 +1 @@ +Subproject commit 92b545edd5f12d2e88e0b440e498fac55f0046e2