From 82fa7efd181f4b66791aaf4760492b62f186d4ef Mon Sep 17 00:00:00 2001 From: leyghisbb Date: Sun, 30 Aug 2020 11:23:15 +0200 Subject: [PATCH] no message --- .../fablabchemnitz_lasercut_sequence.py | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/extensions/fablabchemnitz_lasercut_sequence.py b/extensions/fablabchemnitz_lasercut_sequence.py index f6a8573a..6734349b 100644 --- a/extensions/fablabchemnitz_lasercut_sequence.py +++ b/extensions/fablabchemnitz_lasercut_sequence.py @@ -1,47 +1,41 @@ #!/usr/bin/env python3 -# We will use the inkex module with the predefined Effect base class. import inkex import measure -import re from inkex.paths import Path from inkex import paths -# The simplestyle module provides functions for style parsing. -from simplestyle import * - def getArea(path): - return abs(measure.csparea(paths.CubicSuperPath(path + "z"))) + return abs(measure.csparea(paths.CubicSuperPath(path + "z"))) class LaserSort(inkex.Effect): - def __init__(self): - inkex.Effect.__init__(self) - - def effect(self): - elements = self.document.xpath('//svg:path',namespaces=inkex.NSS) - for el in elements: - oldpathstring = el.attrib['d'] - nodes = Path(oldpathstring).to_arrays() - currentSection = [] - sections = [currentSection] - for node in nodes: - command = node.pop(0) - currentSection.append(command + ' ' + ' '.join(list(map(lambda c: ','.join(map(str, c)), node)))) - if command.lower() == 'z': - currentSection = [] - sections.append(currentSection) - - sections = list(map(lambda n: ' '.join(n), filter(lambda n: len(n) > 0, sections))) + def __init__(self): + inkex.Effect.__init__(self) + + def effect(self): + elements = self.document.xpath('//svg:path',namespaces=inkex.NSS) + for el in elements: + oldpathstring = el.attrib['d'] + nodes = Path(oldpathstring).to_arrays() + currentSection = [] + sections = [currentSection] + for node in nodes: + command = node.pop(0) + currentSection.append(command + ' ' + ' '.join(list(map(lambda c: ','.join(map(str, c)), node)))) + if command.lower() == 'z': + currentSection = [] + sections.append(currentSection) + + sections = list(map(lambda n: ' '.join(n), filter(lambda n: len(n) > 0, sections))) - if (sections[-1][-2].lower() != 'z'): - nonClosedSection = ' ' + sections.pop() - else: - nonClosedSection = '' - - sections = filter(lambda s: s[0].lower() != 'z', sections) - sections = sorted(sections, key=getArea) - newpathstring = "z ".join(sections) + nonClosedSection - el.set('d', newpathstring) - -# Create effect instance and apply it. -LaserSort().run() \ No newline at end of file + if (sections[-1][-2].lower() != 'z'): + nonClosedSection = ' ' + sections.pop() + else: + nonClosedSection = '' + + sections = filter(lambda s: s[0].lower() != 'z', sections) + sections = sorted(sections, key=getArea) + newpathstring = "z ".join(sections) + nonClosedSection + el.set('d', newpathstring) + +LaserSort().run()