Commit 2b371589 authored by Alvin Penner's avatar Alvin Penner Committed by Alvin Penner

extensions. Extrude. allow selection of multiple objects (Bug 1055155)

Fixed bugs:
  - https://launchpad.net/bugs/1055155

(bzr r11734)
parent 20a8f057
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Extrude</_name>
<id>org.greygreen.inkscape.effects.extrude</id>
<_name>Extrude</_name>
<id>org.greygreen.inkscape.effects.extrude</id>
<dependency type="executable" location="extensions">extrude.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<param name="mode" type="enum" _gui-text="Mode:">
<_item>Lines</_item>
<_item>Polygons</_item>
</param>
<effect>
<param name="mode" type="enum" _gui-text="Mode:">
<_item value="Lines">Lines</_item>
<_item value="Polygons">Polygons</_item>
</param>
<effect>
<object-type>path</object-type>
<effects-menu>
<submenu _name="Generate from Path"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">extrude.py</command>
</script>
<effects-menu>
<submenu _name="Generate from Path"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">extrude.py</command>
</script>
</inkscape-extension>
......@@ -16,10 +16,10 @@ 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
'''
import sys, os
sys.path.append(os.path.dirname(sys.argv[0])) #?
import inkex, simplepath, simpletransform, sys, cubicsuperpath
import inkex, simplepath, simpletransform, cubicsuperpath
import gettext
_ = gettext.gettext
class Extrude(inkex.Effect):
def __init__(self):
......@@ -36,56 +36,55 @@ class Extrude(inkex.Effect):
for id, node in self.selected.iteritems():
if node.tag == '{http://www.w3.org/2000/svg}path':
paths.append(node)
if len(paths) == 2:
break
else:
sys.stderr.write('Need 2 paths selected\n')
if len(paths) < 2:
inkex.errormsg(_('Need at least 2 paths selected'))
return
pts = [cubicsuperpath.parsePath(paths[i].get('d'))
for i in (0,1)]
for i in range(len(paths))]
for i in (0,1):
for i in range(len(paths)):
if 'transform' in paths[i].keys():
trans = paths[i].get('transform')
trans = simpletransform.parseTransform(trans)
simpletransform.applyTransformToPath(trans, pts[i])
verts = []
for i in range(0, min(map(len, pts))):
comp = []
for j in range(0, min(len(pts[0][i]), len(pts[1][i]))):
comp.append([pts[0][i][j][1][-2:], pts[1][i][j][1][-2:]])
verts.append(comp)
for n1 in range(0, len(paths)):
for n2 in range(n1 + 1, len(paths)):
verts = []
for i in range(0, min(map(len, pts))):
comp = []
for j in range(0, min(len(pts[n1][i]), len(pts[n2][i]))):
comp.append([pts[n1][i][j][1][-2:], pts[n2][i][j][1][-2:]])
verts.append(comp)
if self.options.mode.lower() == 'lines':
line = []
for comp in verts:
for n,v in enumerate(comp):
line += [('M', v[0])]
line += [('L', v[1])]
ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
paths[0].xpath('..')[0].append(ele)
ele.set('d', simplepath.formatPath(line))
ele.set('style', 'fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;')
elif self.options.mode.lower() == 'polygons':
g = inkex.etree.Element('{http://www.w3.org/2000/svg}g')
g.set('style', 'fill:#000000;stroke:#000000;fill-opacity:0.3;stroke-width:2;stroke-opacity:0.6;')
paths[0].xpath('..')[0].append(g)
for comp in verts:
for n,v in enumerate(comp):
nn = n+1
if nn == len(comp): nn = 0
if self.options.mode.lower() == 'lines':
line = []
line += [('M', comp[n][0])]
line += [('L', comp[n][1])]
line += [('L', comp[nn][1])]
line += [('L', comp[nn][0])]
line += [('L', comp[n][0])]
for comp in verts:
for n,v in enumerate(comp):
line += [('M', v[0])]
line += [('L', v[1])]
ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
g.append(ele)
paths[0].xpath('..')[0].append(ele)
ele.set('d', simplepath.formatPath(line))
ele.set('style', 'fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;')
elif self.options.mode.lower() == 'polygons':
g = inkex.etree.Element('{http://www.w3.org/2000/svg}g')
g.set('style', 'fill:#000000;stroke:#000000;fill-opacity:0.3;stroke-width:2;stroke-opacity:0.6;')
paths[0].xpath('..')[0].append(g)
for comp in verts:
for n,v in enumerate(comp):
nn = n+1
if nn == len(comp): nn = 0
line = []
line += [('M', comp[n][0])]
line += [('L', comp[n][1])]
line += [('L', comp[nn][1])]
line += [('L', comp[nn][0])]
line += [('L', comp[n][0])]
ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
g.append(ele)
ele.set('d', simplepath.formatPath(line))
if __name__ == '__main__': #pragma: no cover
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment