From 1c464b313d1cf42ccdfcd9c8e3ea9694cf4f40e2 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Thu, 20 Aug 2020 02:41:10 +0200 Subject: [PATCH] Updated migrate groups --- extensions/fablabchemnitz_drawdirections.inx | 14 ++++++ extensions/fablabchemnitz_drawdirections.py | 32 +++++++++++++ extensions/fablabchemnitz_migrategroups.inx | 14 +++++- extensions/fablabchemnitz_migrategroups.py | 50 ++++++++++++++++---- 4 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 extensions/fablabchemnitz_drawdirections.inx create mode 100644 extensions/fablabchemnitz_drawdirections.py diff --git a/extensions/fablabchemnitz_drawdirections.inx b/extensions/fablabchemnitz_drawdirections.inx new file mode 100644 index 00000000..9dc03427 --- /dev/null +++ b/extensions/fablabchemnitz_drawdirections.inx @@ -0,0 +1,14 @@ + + + Draw Directions + fablabchemnitz.de.directions + + path + + + + + + diff --git a/extensions/fablabchemnitz_drawdirections.py b/extensions/fablabchemnitz_drawdirections.py new file mode 100644 index 00000000..610bf66e --- /dev/null +++ b/extensions/fablabchemnitz_drawdirections.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import inkex +from inkex.paths import Path +from inkex import Circle + +# Draws red points at the path's beginning and blue point at the path's end + +class StartEndPoints(inkex.Effect): + + def __init__(self): + inkex.Effect.__init__(self) + self.arg_parser.add_argument("--dotsize", type=int, default=10, help="Dot size (px) for self-intersecting points") + + def effect(self): + dot_group = node.getparent().add(inkex.Group()) + + for node in self.svg.selection.values(): + + points = list(node.path.end_points) + start = points[0] + end = points[len(points) - 1] + + style = inkex.Style({'stroke': 'none', 'fill': '#FF0000'}) + startCircle = dot_group.add(Circle(cx=str(start[0]), cy=str(start[1]), r=str(self.svg.unittouu(str(self.options.dotsize/2) + "px")))) + startCircle.style = style + + style = inkex.Style({'stroke': 'none', 'fill': '#0000FF'}) + endCircle = dot_group.add(Circle(cx=str(end[0]), cy=str(end[1]), r=str(self.svg.unittouu(str(self.options.dotsize/2) + "px")))) + endCircle.style = style + +StartEndPoints().run() \ No newline at end of file diff --git a/extensions/fablabchemnitz_migrategroups.inx b/extensions/fablabchemnitz_migrategroups.inx index 318ac287..9743b4f6 100644 --- a/extensions/fablabchemnitz_migrategroups.inx +++ b/extensions/fablabchemnitz_migrategroups.inx @@ -2,7 +2,19 @@ Migrate Groups fablabchemnitz.de.migrategroups - + + + true + true + true + true + true + true + true + true + true + true + path diff --git a/extensions/fablabchemnitz_migrategroups.py b/extensions/fablabchemnitz_migrategroups.py index cc5e57f4..9a52175c 100644 --- a/extensions/fablabchemnitz_migrategroups.py +++ b/extensions/fablabchemnitz_migrategroups.py @@ -17,18 +17,46 @@ class MigrateGroups(inkex.Effect): allPaths = [] allGroups = [] - + allNonMigrates = [] + def __init__(self): inkex.Effect.__init__(self) + self.arg_parser.add_argument("--rect", type=inkex.Boolean, default=True, help="rect") + self.arg_parser.add_argument("--circle", type=inkex.Boolean, default=True, help="circle") + self.arg_parser.add_argument("--ellipse", type=inkex.Boolean, default=True, help="ellipse") + self.arg_parser.add_argument("--line", type=inkex.Boolean, default=True, help="line") + self.arg_parser.add_argument("--polyline", type=inkex.Boolean, default=True, help="polyline") + self.arg_parser.add_argument("--polygon", type=inkex.Boolean, default=True, help="polygon") + self.arg_parser.add_argument("--path", type=inkex.Boolean, default=True, help="path") + self.arg_parser.add_argument("--image", type=inkex.Boolean, default=True, help="image") + self.arg_parser.add_argument("--text", type=inkex.Boolean, default=True, help="text") + self.arg_parser.add_argument("--tspan", type=inkex.Boolean, default=True, help="tspan") def effect(self): + namespace = [] + namespace.append("{http://www.w3.org/2000/svg}rect") if self.options.rect else "" + namespace.append("{http://www.w3.org/2000/svg}circle") if self.options.circle else "" + namespace.append("{http://www.w3.org/2000/svg}ellipse") if self.options.ellipse else "" + namespace.append("{http://www.w3.org/2000/svg}line") if self.options.line else "" + namespace.append("{http://www.w3.org/2000/svg}polyline") if self.options.polyline else "" + namespace.append("{http://www.w3.org/2000/svg}polygon") if self.options.polygon else "" + namespace.append("{http://www.w3.org/2000/svg}path") if self.options.path else "" + namespace.append("{http://www.w3.org/2000/svg}image") if self.options.image else "" + namespace.append("{http://www.w3.org/2000/svg}text") if self.options.text else "" + namespace.append("{http://www.w3.org/2000/svg}tspan") if self.options.tspan else "" + #get all paths and groups from selection. Remove all groups from the selection and form a new single group of it def parseNodes(self, node): - if node.tag == inkex.addNS('path','svg'): + if node.tag in namespace: if node not in self.allPaths: self.allPaths.append(node) + else: + if node.tag != inkex.addNS('g','svg'): + self.allNonMigrates.append(node) if node.tag == inkex.addNS('g','svg'): + if node not in self.allGroups: + self.allGroups.append(node) groups = node.getchildren() if groups is not None: for group in groups: @@ -38,28 +66,34 @@ class MigrateGroups(inkex.Effect): for id, item in self.svg.selected.items(): parseNodes(self, item) - + if len(self.allPaths) > 0: #make a new group at root level - TODO: respect the position where the first selected object is in XML tree and put it there instead (or make this optional) newGroup = self.document.getroot().add(inkex.Group()) - + #copy all paths into the new group for path in self.allPaths: newGroup.add(path.copy()) #then remove all the old stuff path.getparent().remove(path) - + #now remove all the obsolete groups if len(self.allGroups) > 0: for group in self.allGroups: if group.getparent() is not None: group.getparent().remove(group) - + #remove the selected, now empty group (if it's the case) - if len(self.svg.selected) > 0: + if len(self.svg.selected) > 0 and len(self.allPaths) > 0: if self.svg.selected[0].tag == inkex.addNS('g','svg'): - self.svg.selected[0].getparent().remove(self.svg.selected[0]) + if self.svg.selected[0].getparent() is not None: + self.svg.selected[0].getparent().remove(self.svg.selected[0]) + if len(self.allNonMigrates) > 0: + self.msg("You are going to remove " + str(len(self.allNonMigrates)) + " nodes while migrating:") + for i in self.allNonMigrates: + self.msg(i.get('id')) + #TODO: make newGroup selected now. How ? MigrateGroups().run() \ No newline at end of file