X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fgeometry-1.5.0%2Fio%2F%40svg%2FparsePath.py;fp=octave_packages%2Fgeometry-1.5.0%2Fio%2F%40svg%2FparsePath.py;h=ffa9f551553ba569986e5e595b64bcd689af5e6c;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/geometry-1.5.0/io/@svg/parsePath.py b/octave_packages/geometry-1.5.0/io/@svg/parsePath.py new file mode 100644 index 0000000..ffa9f55 --- /dev/null +++ b/octave_packages/geometry-1.5.0/io/@svg/parsePath.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +## Copyright (c) 2012 Juan Pablo Carbajal +## +## 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 3 of the License, or +## 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, see . + +import inkex, simplepath +import sys +#import getopt + +def parsePaths (filen=None): + + svg = inkex.Effect () + svg.parse (filen) + + paths = svg.document.xpath ('//svg:path', namespaces=inkex.NSS) + for path in paths: + D = simplepath.parsePath (path.attrib['d']) + cmdlst = []; + parlst = []; + for cmd,params in D: + cmdlst.append(cmd) + parlst.append(params) + + print 'svgpath = struct("cmd","{0}","data",{{{1}}});' \ + .format(''.join(cmdlst),str(parlst).replace('[[','[').replace(']]',']')) + + print 'svgpathid = "{0}"; $'.format(path.attrib['id']) + + + +# ---------------------------- + +if __name__=="__main__": + ''' + try: + optlist,args = getopt.getopt(sys.argv[1:],"thdp") + except getopt.GetoptError: + usage() + sys.exit(2) + + doHelp = 0 + c = Context() + c.doPrint = 1 + for opt in optlist: + if opt[0] == "-d": c.debug = 1 + if opt[0] == "-p": c.plot = 1 + if opt[0] == "-t": c.triangulate = 1 + if opt[0] == "-h": doHelp = 1 + + if not doHelp: + pts = [] + fp = sys.stdin + if len(args) > 0: + fp = open(args[0],'r') + for line in fp: + fld = line.split() + x = float(fld[0]) + y = float(fld[1]) + pts.append(Site(x,y)) + if len(args) > 0: fp.close() + + if doHelp or len(pts) == 0: + usage() + sys.exit(2) + ''' + svg = sys.argv[1] + parsePaths(svg)