This commit is contained in:
2021-07-23 02:36:56 +02:00
commit 4d622c5291
4878 changed files with 1849508 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Netting</name>
<id>fablabchemnitz.de.netting</id>
<param name="tab" type="notebook">
<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="node_shifting" type="int" min="-1000" max="1000" gui-text="Node shifting" gui-description="Does not apply for 'all with all' type.">0</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/FabLab_Chemnitz/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>
<object-type>path</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Shape/Pattern from existing Path(s)"/>
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">netting.py</command>
</script>
</inkscape-extension>

View File

@@ -0,0 +1,106 @@
#!/usr/bin/env python3
'''
netting.py
Sunabe kazumichi 2010/3/4
http://dp48069596.lolipop.jp/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
this program nets in the line.
'''
import random
import math
import inkex
import cubicsuperpath
from lxml import etree
from inkex.paths import Path, CubicSuperPath
class Netting(inkex.EffectExtension):
def add_arguments(self, pars):
pars.add_argument("--tab")
pars.add_argument("--netting_type", default="allwithall", help="Netting type")
pars.add_argument("--node_shifting", type=int, default=0, help="Does not apply for 'all with all' type.")
pars.add_argument("--stroke_width", type=float, default=1.0, help="stroke width")
def effect(self):
#static
style = {'stroke-width': str(self.options.stroke_width) +'px', 'stroke': '#000000', 'fill': 'none'}
old_segments = []
new_segments = []
#get complete path data from all selected paths
for element in self.svg.selected.filter(inkex.PathElement).values():
d = element.get('d')
p = CubicSuperPath(Path(d))
for subpath in p:
for i, csp in enumerate(subpath):
old_segments.append("%f,%f" % (csp[1][0], csp[1][1]))
if self.options.netting_type == "allwithall":
allnet_group = inkex.Group(id="g" + element.get('id'))
pathsCollection = []
self.svg.get_current_layer().append(allnet_group)
for segment1 in range(0, len(old_segments)):
for segment2 in range(1, len(old_segments)):
if old_segments[segment1] != old_segments[segment2]:
pathVariant1 = Path('M' + old_segments[segment1] + ' L' + old_segments[segment2])
pathVariant2 = Path('M' + old_segments[segment2] + ' L' + old_segments[segment1]) #the reversed one
if pathVariant1 not in pathsCollection and pathVariant2 not in pathsCollection:
pathsCollection.append(pathVariant1)
for p in pathsCollection:
allnet_path = inkex.PathElement()
allnet_path.style = style
allnet_path.path = p
allnet_group.append(allnet_path)
elif self.options.netting_type == "alternatingly":
#build up the net path between the path points alternatingly
first = True
while len(old_segments) > 0:
if first is True:
new_segments.append('M')
first = False
else:
new_segments.append('L')
new_segments.append(old_segments.pop(0))
if len(old_segments) > 0:
new_segments.append('L')
new_segments.append(old_segments.pop())
shift = self.options.node_shifting
if shift < 0:
counter = -1
else:
counter = +1
for i in range(0, self.options.node_shifting, counter):
for i in range(4):
shifting = new_segments[0]
if new_segments[0] == 'M':
shifting = 'L' #overwrite possible 'M' with 'L'
del new_segments[0]
new_segments.append(shifting)
new_segments[0] = 'M' #let's begin the path with 'M' again
#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__':
Netting().run()