refactored and rename modify path start node
This commit is contained in:
parent
275d8d657d
commit
90fd706551
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<name>Modify Path Start Node</name>
|
<name>Move Path Node</name>
|
||||||
<id>fablabchemnitz.de.modify_path_start</id>
|
<id>fablabchemnitz.de.move_path_node</id>
|
||||||
<param name="tab" type="notebook">
|
<param name="tab" type="notebook">
|
||||||
<page name="tab_settings" gui-text="Modify Path Start Node">
|
<page name="tab_settings" gui-text="Modify Path Start Node">
|
||||||
<param name="closed_only" type="bool" gui-text="Handle closed paths only" gui-description="If disabled we also apply on open (sub)paths. Warning: This REMOVES segments!">true</param>
|
<param name="closed_only" type="bool" gui-text="Handle closed paths only" gui-description="If disabled we also apply on open (sub)paths. Warning: This REMOVES segments!">true</param>
|
||||||
<param name="movenode" type="int" min="-99999" max="99999" gui-text="Move starting node n nodes further">0</param>
|
<param name="movenode" type="int" min="-99999" max="99999" gui-text="Move node n nodes further">0</param>
|
||||||
<param name="visualize_result" type="bool" gui-text="Visualize first two nodes" gui-description="If enabled first two nodes get a number and a dot">false</param>
|
<param name="visualize_result" type="bool" gui-text="Visualize first two nodes" gui-description="If enabled first two nodes get a number and a dot">false</param>
|
||||||
<param name="fontsize" type="string" gui-text="Font size:">10px</param>
|
<param name="fontsize" type="string" gui-text="Font size:">10px</param>
|
||||||
<param name="dotsize" type="string" gui-text="Dot size:">10px</param>
|
<param name="dotsize" type="string" gui-text="Dot size:">10px</param>
|
||||||
@ -15,12 +15,12 @@
|
|||||||
<label>Use extension "Chain Paths" to make closed paths out of segments.</label>
|
<label>Use extension "Chain Paths" to make closed paths out of segments.</label>
|
||||||
</page>
|
</page>
|
||||||
<page name="tab_about" gui-text="About">
|
<page name="tab_about" gui-text="About">
|
||||||
<label appearance="header">Modify Path Start Node</label>
|
<label appearance="header">Move Path Node</label>
|
||||||
<label>Extension to change starting node of a path and visualize it by dots and numbers</label>
|
<label>Extension to change starting / end node of a path and visualize it by dots and numbers. You can also use this extension as a trimmer for open paths.</label>
|
||||||
<label>2021 / written by Mario Voigt (Stadtfabrikanten e.V. / FabLab Chemnitz)</label>
|
<label>2021 / written by Mario Voigt (Stadtfabrikanten e.V. / FabLab Chemnitz)</label>
|
||||||
<spacer/>
|
<spacer/>
|
||||||
<label appearance="header">Online Documentation</label>
|
<label appearance="header">Online Documentation</label>
|
||||||
<label appearance="url">https://y.stadtfabrikanten.org/modifypathstartnode</label>
|
<label appearance="url">https://y.stadtfabrikanten.org/movepathnode</label>
|
||||||
<spacer/>
|
<spacer/>
|
||||||
<label appearance="header">Contributing</label>
|
<label appearance="header">Contributing</label>
|
||||||
<label appearance="url">https://gitea.fablabchemnitz.de/MarioVoigt/mightyscape-1.X</label>
|
<label appearance="url">https://gitea.fablabchemnitz.de/MarioVoigt/mightyscape-1.X</label>
|
||||||
@ -50,6 +50,6 @@
|
|||||||
</effects-menu>
|
</effects-menu>
|
||||||
</effect>
|
</effect>
|
||||||
<script>
|
<script>
|
||||||
<command location="inx" interpreter="python">modify_path_start.py</command>
|
<command location="inx" interpreter="python">move_path_node.py</command>
|
||||||
</script>
|
</script>
|
||||||
</inkscape-extension>
|
</inkscape-extension>
|
@ -1,22 +1,18 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
Author: Mario Voigt / FabLab Chemnitz
|
Author: Mario Voigt / FabLab Chemnitz
|
||||||
Mail: mario.voigt@stadtfabrikanten.org
|
Mail: mario.voigt@stadtfabrikanten.org
|
||||||
Date: 19.05.2021
|
Date: 19.05.2021
|
||||||
Last patch: 19.05.2021
|
Last patch: 19.05.2021
|
||||||
License: GNU GPL v3
|
License: GNU GPL v3
|
||||||
|
|
||||||
ToDo:
|
|
||||||
link for usage: plotting/laser cutting, path unwinding plugin > startpunkt für anwicklung
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import inkex
|
import inkex
|
||||||
from inkex import Circle, TextElement, Path, PathElement, CubicSuperPath
|
from inkex import Circle, TextElement, Path, PathElement, CubicSuperPath
|
||||||
|
|
||||||
class ModifyStartDirection(inkex.EffectExtension):
|
class MovePathNode(inkex.EffectExtension):
|
||||||
|
|
||||||
def modify(self, element):
|
def modify(self, element):
|
||||||
raw = element.path.to_arrays()
|
raw = element.path.to_arrays()
|
||||||
@ -27,7 +23,10 @@ class ModifyStartDirection(inkex.EffectExtension):
|
|||||||
prev = i
|
prev = i
|
||||||
subpaths.append(raw[prev:])
|
subpaths.append(raw[prev:])
|
||||||
if self.options.debug is True:
|
if self.options.debug is True:
|
||||||
self.msg("Element {} has {} subpath(s)".format(element.get('id'), len(subpaths)))
|
if len(subpaths) == 0:
|
||||||
|
self.msg("{} has no subpaths").format(element.get('id'))
|
||||||
|
else:
|
||||||
|
self.msg("{} has {} subpath(s)".format(element.get('id'), len(subpaths)))
|
||||||
|
|
||||||
subpathNr = 0
|
subpathNr = 0
|
||||||
for path in subpaths:
|
for path in subpaths:
|
||||||
@ -43,9 +42,13 @@ class ModifyStartDirection(inkex.EffectExtension):
|
|||||||
|
|
||||||
if self.options.debug is True:
|
if self.options.debug is True:
|
||||||
self.msg("pathIsClosed = " + str(pathIsClosed))
|
self.msg("pathIsClosed = " + str(pathIsClosed))
|
||||||
|
self.msg("nodes = " + str(len(path)))
|
||||||
|
|
||||||
if self.options.closed_only is True and pathIsClosed is False:
|
if self.options.closed_only is True and pathIsClosed is False:
|
||||||
self.msg("Path {}/subpath {} is not closed!".format(element.get('id'), subpathNr))
|
if len(subpaths) == 0:
|
||||||
|
self.msg("{}/subpath {} is not closed! Skipping ...".format(element.get('id'), subpathNr))
|
||||||
|
else:
|
||||||
|
self.msg("{} is not closed! Skipping ...".format(element.get('id')))
|
||||||
continue #skip this open path
|
continue #skip this open path
|
||||||
|
|
||||||
if path[-1][0] == 'Z': #replace Z with another L command (which moves to the coordinates of the first M command in path) to have better overview
|
if path[-1][0] == 'Z': #replace Z with another L command (which moves to the coordinates of the first M command in path) to have better overview
|
||||||
@ -53,32 +56,32 @@ class ModifyStartDirection(inkex.EffectExtension):
|
|||||||
path[-1][1] = path[0][1]
|
path[-1][1] = path[0][1]
|
||||||
|
|
||||||
#adjust if entered move number is higher than actual node count. We handle as infinite looping
|
#adjust if entered move number is higher than actual node count. We handle as infinite looping
|
||||||
moves = self.options.movenode % len(path)
|
moves = (self.options.movenode - 1) % len(path)
|
||||||
if pathIsClosed is True: #if closed start and end collapse and "duplicate"
|
if pathIsClosed is True: #if closed start and end collapse and "duplicate"
|
||||||
moves = self.options.movenode % (len(path) - 1)
|
moves = (self.options.movenode - 1) % (len(path) - 1)
|
||||||
|
if self.options.movenode == 0: #special handling for 0 is required
|
||||||
|
moves = 0
|
||||||
|
|
||||||
if self.options.debug is True:
|
if self.options.debug is True:
|
||||||
|
self.msg("moves to perform = " + str(moves))
|
||||||
self.msg("root path:")
|
self.msg("root path:")
|
||||||
self.msg(path)
|
self.msg(path)
|
||||||
self.msg("-"*25)
|
self.msg("-"*25)
|
||||||
|
|
||||||
if self.options.debug is True:
|
|
||||||
self.msg("moves = " + str(moves))
|
|
||||||
|
|
||||||
for i in range(moves):
|
for i in range(moves):
|
||||||
if len(path) > 2: #the path needs at least more than two nodes
|
if len(path) > 2: #the path needs at least more than two segments
|
||||||
#we move the first node to the end of the list
|
|
||||||
|
#we move the first segment to the end of the list
|
||||||
move = path[0]
|
move = path[0]
|
||||||
del path[0]
|
del path[0]
|
||||||
path.append(move)
|
path.append(move)
|
||||||
|
oldseg = copy.deepcopy(path[0]) #if we assign like "oldseg = path[0]", it will get overwritten. So we need copy
|
||||||
|
|
||||||
if self.options.debug is True:
|
if self.options.debug is True:
|
||||||
self.msg("moved path:")
|
self.msg("moved path (move no. {}):".format(i+1))
|
||||||
self.msg(path)
|
self.msg(path)
|
||||||
self.msg("-"*25)
|
self.msg("-"*25)
|
||||||
|
|
||||||
oldseg = copy.deepcopy(path[0]) #if we assign like "oldseg = path[0]", it will get overwritten. So we need copy
|
|
||||||
|
|
||||||
#Now we messed the integrity of the path. It does not begin with 'M' now. But we need an 'M'.
|
#Now we messed the integrity of the path. It does not begin with 'M' now. But we need an 'M'.
|
||||||
#It now either starts with L or C. H, V, Z cannot occure here.
|
#It now either starts with L or C. H, V, Z cannot occure here.
|
||||||
if path[0][0] == 'C': #and path[-1][0] == 'M':
|
if path[0][0] == 'C': #and path[-1][0] == 'M':
|
||||||
@ -108,8 +111,8 @@ class ModifyStartDirection(inkex.EffectExtension):
|
|||||||
self.msg("-"*25)
|
self.msg("-"*25)
|
||||||
|
|
||||||
newSubpaths[subpathNr - 1] = path
|
newSubpaths[subpathNr - 1] = path
|
||||||
#else:
|
else:
|
||||||
# inkex.utils.debug("More moves entered than possible to apply")
|
inkex.utils.debug("More moves entered than possible to apply")
|
||||||
|
|
||||||
composedPath = inkex.Path()
|
composedPath = inkex.Path()
|
||||||
for newSubpath in newSubpaths:
|
for newSubpath in newSubpaths:
|
||||||
@ -173,4 +176,4 @@ class ModifyStartDirection(inkex.EffectExtension):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ModifyStartDirection().run()
|
MovePathNode().run()
|
Reference in New Issue
Block a user