enhance netting extension
This commit is contained in:
parent
c95724719b
commit
16ef1c7627
@ -2,8 +2,41 @@
|
|||||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
<name>Netting</name>
|
<name>Netting</name>
|
||||||
<id>fablabchemnitz.de.netting</id>
|
<id>fablabchemnitz.de.netting</id>
|
||||||
<label>This effect net in the a path alternately.</label>
|
<param name="tab" type="notebook">
|
||||||
<param name="s_width" type="float" gui-text="Stroke Width, px">1.0</param>
|
<page name="tab_settings" gui-text="Settings">
|
||||||
|
<param name="netting_type" type="optiongroup" appearance="combo" gui-text="Netting type">
|
||||||
|
<option value="alternatingly">alternatingly</option>
|
||||||
|
<option value="allwithall">all with all</option>
|
||||||
|
</param>
|
||||||
|
<param name="stroke_width" type="float" precision="3" min="0.001" gui-text="Stroke Width (px)">1.000</param>
|
||||||
|
</page>
|
||||||
|
<page name="tab_about" gui-text="About">
|
||||||
|
<label appearance="header">Netting</label>
|
||||||
|
<label>This effect (alternatingly) nets in the selected paths. Based on the work of Sunabe Kazumichi.</label>
|
||||||
|
<label>2019 - 2021 / written by Mario Voigt (Stadtfabrikanten e.V. / FabLab Chemnitz)</label>
|
||||||
|
<spacer/>
|
||||||
|
<label appearance="header">Online Documentation</label>
|
||||||
|
<label appearance="url">https://y.stadtfabrikanten.org/netting</label>
|
||||||
|
<spacer/>
|
||||||
|
<label appearance="header">Contributing</label>
|
||||||
|
<label appearance="url">https://gitea.fablabchemnitz.de/MarioVoigt/mightyscape-1.X</label>
|
||||||
|
<label appearance="url">mailto:mario.voigt@stadtfabrikanten.org</label>
|
||||||
|
<spacer/>
|
||||||
|
<label appearance="header">MightyScape Extension Collection</label>
|
||||||
|
<label>This piece of software is part of the MightyScape for Inkscape Extension Collection and is licensed under GNU GPL v3</label>
|
||||||
|
<label appearance="url">https://y.stadtfabrikanten.org/mightyscape-overview</label>
|
||||||
|
</page>
|
||||||
|
<page name="tab_donate" gui-text="Donate">
|
||||||
|
<label appearance="header">Coffee + Pizza</label>
|
||||||
|
<label>We are the Stadtfabrikanten, running the FabLab Chemnitz since 2016. A FabLab is an open workshop that gives people access to machines and digital tools like 3D printers, laser cutters and CNC milling machines.</label>
|
||||||
|
<spacer/>
|
||||||
|
<label>You like our work and want to support us? You can donate to our non-profit organization by different ways:</label>
|
||||||
|
<label appearance="url">https://y.stadtfabrikanten.org/donate</label>
|
||||||
|
<spacer/>
|
||||||
|
<label>Thanks for using our extension and helping us!</label>
|
||||||
|
<image>../000_about_fablabchemnitz.svg</image>
|
||||||
|
</page>
|
||||||
|
</param>
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>path</object-type>
|
<object-type>path</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -31,30 +31,46 @@ from inkex.paths import Path, CubicSuperPath
|
|||||||
class Netting(inkex.EffectExtension):
|
class Netting(inkex.EffectExtension):
|
||||||
|
|
||||||
def add_arguments(self, pars):
|
def add_arguments(self, pars):
|
||||||
pars.add_argument("--s_width", type=float, default=1.0, help="stroke width")
|
pars.add_argument("--tab")
|
||||||
pars.add_argument("--title")
|
pars.add_argument("--netting_type", default="allwithall", help="Netting type")
|
||||||
|
pars.add_argument("--stroke_width", type=float, default=1.0, help="stroke width")
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
path_strings = []
|
#static
|
||||||
net_strings= ["M"]
|
style = {'stroke-width': str(self.options.stroke_width) +'px', 'stroke': '#000000', 'fill': 'none'}
|
||||||
my_path = etree.Element(inkex.addNS('path','svg'))
|
old_segments = []
|
||||||
s = {'stroke-width': self.options.s_width, 'stroke': '#000000', 'fill': 'none' }
|
new_segments = ["M"] #begin with blank M
|
||||||
my_path.set('style', str(inkex.Style(s)))
|
|
||||||
for id, node in self.svg.selected.items():
|
#get complete path data from all selected paths
|
||||||
if node.tag == inkex.addNS('path','svg'):
|
for element in self.svg.selected.filter(inkex.PathElement).values():
|
||||||
d = node.get('d')
|
d = element.get('d')
|
||||||
p = CubicSuperPath(Path(d))
|
p = CubicSuperPath(Path(d))
|
||||||
for subpath in p:
|
for subpath in p:
|
||||||
for i, csp in enumerate(subpath):
|
for i, csp in enumerate(subpath):
|
||||||
path_strings.append("%f,%f" % ( csp[1][0], csp[1][1]))
|
old_segments.append("%f,%f" % (csp[1][0], csp[1][1]))
|
||||||
node.set('d',str(Path(p)))
|
|
||||||
|
if self.options.netting_type == "allwithall":
|
||||||
while len(path_strings)>0 :
|
allnet_group = inkex.Group(id="g" + element.get('id'))
|
||||||
net_strings.append(path_strings.pop(0))
|
self.svg.get_current_layer().append(allnet_group)
|
||||||
if len(path_strings)>0 :
|
for segment1 in range(0, len(old_segments)):
|
||||||
net_strings.append(path_strings.pop())
|
for segment2 in range(1, len(old_segments)):
|
||||||
my_path.set('d', " ".join(net_strings))
|
allnet_path = inkex.PathElement()
|
||||||
self.svg.get_current_layer().append( my_path )
|
allnet_path.style = style
|
||||||
|
allnet_path.path = Path('M' + old_segments[segment1] + ' L' + old_segments[segment2])
|
||||||
|
allnet_group.append(allnet_path)
|
||||||
|
|
||||||
|
elif self.options.netting_type == "alternatingly":
|
||||||
|
#build up the net path between the path points alternatingly
|
||||||
|
while len(old_segments) > 0:
|
||||||
|
new_segments.append(old_segments.pop(0))
|
||||||
|
if len(old_segments) > 0:
|
||||||
|
new_segments.append(old_segments.pop())
|
||||||
|
|
||||||
|
#create the path and add it to the current layer
|
||||||
|
net_path = inkex.PathElement()
|
||||||
|
net_path.style = style
|
||||||
|
net_path.path = Path(" ".join(new_segments))
|
||||||
|
self.svg.get_current_layer().append(net_path)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Netting().run()
|
Netting().run()
|
Reference in New Issue
Block a user