2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal#!/usr/bin/env python
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal'''
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalCopyright (C) 2007
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalThis program is free software; you can redistribute it and/or modify
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalit under the terms of the GNU General Public License as published by
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalthe Free Software Foundation; either version 2 of the License, or
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal(at your option) any later version.
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalThis program is distributed in the hope that it will be useful,
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalbut WITHOUT ANY WARRANTY; without even the implied warranty of
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalGNU General Public License for more details.
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalYou should have received a copy of the GNU General Public License
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalalong with this program; if not, write to the Free Software
107e00c8104649437b9520d0ba298dba659e7cd7JazzyNicoFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal'''
789b5bcf61bdd8067c5b6f69bf6d2f76e8e70177apenner# local library
789b5bcf61bdd8067c5b6f69bf6d2f76e8e70177apennerimport inkex
789b5bcf61bdd8067c5b6f69bf6d2f76e8e70177apennerimport simplepath
789b5bcf61bdd8067c5b6f69bf6d2f76e8e70177apennerimport simpletransform
789b5bcf61bdd8067c5b6f69bf6d2f76e8e70177apennerimport cubicsuperpath
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
789b5bcf61bdd8067c5b6f69bf6d2f76e8e70177apennerinkex.localize()
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmalclass Extrude(inkex.Effect):
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal def __init__(self):
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal inkex.Effect.__init__(self)
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal opts = [('-m', '--mode', 'string', 'mode', 'Lines',
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal 'Join paths with lines or polygons'),
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal ]
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal for o in opts:
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal self.OptionParser.add_option(o[0], o[1], action="store", type=o[2],
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal dest=o[3], default=o[4], help=o[5])
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal def effect(self):
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal paths = []
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal for id, node in self.selected.iteritems():
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal if node.tag == '{http://www.w3.org/2000/svg}path':
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal paths.append(node)
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner if len(paths) < 2:
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner inkex.errormsg(_('Need at least 2 paths selected'))
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal return
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal pts = [cubicsuperpath.parsePath(paths[i].get('d'))
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for i in range(len(paths))]
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for i in range(len(paths)):
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal if 'transform' in paths[i].keys():
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal trans = paths[i].get('transform')
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal trans = simpletransform.parseTransform(trans)
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal simpletransform.applyTransformToPath(trans, pts[i])
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for n1 in range(0, len(paths)):
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for n2 in range(n1 + 1, len(paths)):
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner verts = []
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for i in range(0, min(map(len, pts))):
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner comp = []
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for j in range(0, min(len(pts[n1][i]), len(pts[n2][i]))):
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner comp.append([pts[n1][i][j][1][-2:], pts[n2][i][j][1][-2:]])
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner verts.append(comp)
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner if self.options.mode.lower() == 'lines':
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal line = []
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for comp in verts:
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for n,v in enumerate(comp):
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('M', v[0])]
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('L', v[1])]
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner paths[0].xpath('..')[0].append(ele)
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal ele.set('d', simplepath.formatPath(line))
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner ele.set('style', 'fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;')
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner elif self.options.mode.lower() == 'polygons':
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner g = inkex.etree.Element('{http://www.w3.org/2000/svg}g')
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner g.set('style', 'fill:#000000;stroke:#000000;fill-opacity:0.3;stroke-width:2;stroke-opacity:0.6;')
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner paths[0].xpath('..')[0].append(g)
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for comp in verts:
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner for n,v in enumerate(comp):
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner nn = n+1
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner if nn == len(comp): nn = 0
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line = []
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('M', comp[n][0])]
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('L', comp[n][1])]
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('L', comp[nn][1])]
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('L', comp[nn][0])]
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner line += [('L', comp[n][0])]
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner g.append(ele)
3107bbf34c689fba7ed6fd8c7a7be933e489d5a2apenner ele.set('d', simplepath.formatPath(line))
2a8da5bd8f757b218f0a9e9826a7afea16e7a773ishmal
83aaf46c9feab529aeb9add871c05c3d1177afccaurium
83aaf46c9feab529aeb9add871c05c3d1177afccauriumif __name__ == '__main__': #pragma: no cover
83aaf46c9feab529aeb9add871c05c3d1177afccaurium e = Extrude()
83aaf46c9feab529aeb9add871c05c3d1177afccaurium e.affect()