Updated migrate groups

This commit is contained in:
Mario Voigt 2020-08-20 02:41:10 +02:00
parent 783c6b874d
commit 1c464b313d
4 changed files with 101 additions and 9 deletions

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Draw Directions</name>
<id>fablabchemnitz.de.directions</id>
<effect>
<object-type>path</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz Dev" />
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">fablabchemnitz_drawdirections.py</command>
</script>
</inkscape-extension>

View File

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

View File

@ -2,7 +2,19 @@
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Migrate Groups</name>
<id>fablabchemnitz.de.migrategroups</id>
<effect needs-live-preview="false">
<label>What elements to migrate?</label>
<label>Unchecked item types will be deleted!</label>
<param name="rect" type="bool" gui-text="rect">true</param>
<param name="circle" type="bool" gui-text="circle">true</param>
<param name="ellipse" type="bool" gui-text="ellipse">true</param>
<param name="line" type="bool" gui-text="line">true</param>
<param name="polyline" type="bool" gui-text="polyline">true</param>
<param name="polygon" type="bool" gui-text="polygon">true</param>
<param name="path" type="bool" gui-text="path">true</param>
<param name="image" type="bool" gui-text="image">true</param>
<param name="text" type="bool" gui-text="text">true</param>
<param name="tspan" type="bool" gui-text="tspan">true</param>
<effect needs-live-preview="true">
<object-type>path</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">

View File

@ -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:
@ -57,9 +85,15 @@ class MigrateGroups(inkex.Effect):
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'):
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()