make svg2fcstd compatible with FreeCAD 0.21
This commit is contained in:
parent
b2275717c5
commit
bbf9d0cbf7
@ -64,13 +64,12 @@ import sys
|
|||||||
import math
|
import math
|
||||||
sys_platform = sys.platform.lower()
|
sys_platform = sys.platform.lower()
|
||||||
if sys_platform.startswith('win'):
|
if sys_platform.startswith('win'):
|
||||||
sys.path.append('C:\Program Files\Inkscape\share\extensions')
|
sys.path.append('C:\\Program Files\\Inkscape\\share\\extensions')
|
||||||
elif sys_platform.startswith('darwin'):
|
elif sys_platform.startswith('darwin'):
|
||||||
sys.path.append('~/.config/inkscape/extensions')
|
sys.path.append('~/.config/inkscape/extensions')
|
||||||
else: # Linux
|
else: # Linux
|
||||||
sys.path.append('/usr/share/inkscape/extensions/')
|
sys.path.append('/usr/share/inkscape/extensions/')
|
||||||
sys.path.append('/usr/lib64/freecad-daily/lib64/') # prefer daily over normal.
|
sys.path.append('/usr/lib/freecad-python3/lib/')
|
||||||
sys.path.append('/usr/lib64/freecad/lib64/')
|
|
||||||
|
|
||||||
verbose=-1 # -1=quiet, 0=normal, 1=babble
|
verbose=-1 # -1=quiet, 0=normal, 1=babble
|
||||||
epsilon = 0.00001
|
epsilon = 0.00001
|
||||||
@ -89,7 +88,6 @@ if verbose <= 0:
|
|||||||
os.dup2(99,1) # back in cansas.
|
os.dup2(99,1) # back in cansas.
|
||||||
|
|
||||||
import Part, Sketcher # causes SEGV if Base is not yet imported from FreeCAD
|
import Part, Sketcher # causes SEGV if Base is not yet imported from FreeCAD
|
||||||
import ProfileLib.RegularPolygon as Poly
|
|
||||||
import gettext
|
import gettext
|
||||||
import re
|
import re
|
||||||
import inkex
|
import inkex
|
||||||
@ -325,7 +323,7 @@ class InkSvg():
|
|||||||
selectors = []
|
selectors = []
|
||||||
classes = node.get('class', '') # classes == None can happen here.
|
classes = node.get('class', '') # classes == None can happen here.
|
||||||
if classes is not None and classes != '':
|
if classes is not None and classes != '':
|
||||||
selectors = ["."+cls for cls in re.split('[\s,]+', classes)]
|
selectors = ["."+cls for cls in re.split(r'[\s,]+', classes)]
|
||||||
selectors += [node.tag+sel for sel in selectors]
|
selectors += [node.tag+sel for sel in selectors]
|
||||||
node_id = node.get('id', '')
|
node_id = node.get('id', '')
|
||||||
if node_id is not None and node_id != '':
|
if node_id is not None and node_id != '':
|
||||||
@ -474,19 +472,19 @@ class InkSvg():
|
|||||||
Represent css cdata as a hash in css_dict.
|
Represent css cdata as a hash in css_dict.
|
||||||
Implements what is seen on: http://www.blooberry.com/indexdot/css/examples/cssembedded.htm
|
Implements what is seen on: http://www.blooberry.com/indexdot/css/examples/cssembedded.htm
|
||||||
"""
|
"""
|
||||||
text=re.sub('^\s*(<!--)?\s*', '', text)
|
text=re.sub(r'^\s*(<!--)?\s*', '', text)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
(keys, rest) = text.split('{', 1)
|
(keys, rest) = text.split('{', 1)
|
||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
keys = re.sub('/\*.*?\*/', ' ', keys) # replace comments with whitespace
|
keys = re.sub(r'/\*.*?\*/', ' ', keys) # replace comments with whitespace
|
||||||
keys = re.split('[\s,]+', keys) # convert to list
|
keys = re.split(r'[\s,]+', keys) # convert to list
|
||||||
while '' in keys:
|
while '' in keys:
|
||||||
keys.remove('') # remove empty elements (at start or end)
|
keys.remove('') # remove empty elements (at start or end)
|
||||||
(val,text) = rest.split('}', 1)
|
(val,text) = rest.split('}', 1)
|
||||||
val = re.sub('/\*.*?\*/', '', val) # replace comments nothing in values
|
val = re.sub(r'/\*.*?\*/', '', val) # replace comments nothing in values
|
||||||
val = re.sub('\s+', ' ', val).strip() # normalize whitespace
|
val = re.sub(r'\s+', ' ', val).strip() # normalize whitespace
|
||||||
for k in keys:
|
for k in keys:
|
||||||
if not k in self.css_dict:
|
if not k in self.css_dict:
|
||||||
self.css_dict[k] = val
|
self.css_dict[k] = val
|
||||||
@ -1130,7 +1128,7 @@ class InkSvg():
|
|||||||
return self.docTransform
|
return self.docTransform
|
||||||
|
|
||||||
parser = OptionParser(usage="\n %prog [options] SVGFILE [OUTFILE]\n\nTry --help for details.")
|
parser = OptionParser(usage="\n %prog [options] SVGFILE [OUTFILE]\n\nTry --help for details.")
|
||||||
parser.add_option("-o", "--outfile", dest="outfile", help="write fcstd to OUTPUT. Default: stdout (unless it is a tty)", metavar="OUTPUT")
|
parser.add_option("-o", "--outfile", dest="outfile", help="write FCStd to OUTPUT. Default: stdout (unless it is a tty)", metavar="OUTPUT")
|
||||||
parser.add_option("-i", "--id", "--ids", dest="ids", action="append", type="string", default=[], help="Select svg object(s) by id attribute. Use multiple times or combine with comma. Default: root object, aka all")
|
parser.add_option("-i", "--id", "--ids", dest="ids", action="append", type="string", default=[], help="Select svg object(s) by id attribute. Use multiple times or combine with comma. Default: root object, aka all")
|
||||||
parser.add_option("--tab", dest="tab", type="string")
|
parser.add_option("--tab", dest="tab", type="string")
|
||||||
parser.add_option("--selected-nodes", dest="selected_nodes", action="append", type="string", default=[], help="id:subpath:position of selected nodes, if any") # TODO: check if inkscape is really passing us these
|
parser.add_option("--selected-nodes", dest="selected_nodes", action="append", type="string", default=[], help="id:subpath:position of selected nodes, if any") # TODO: check if inkscape is really passing us these
|
||||||
@ -1159,9 +1157,9 @@ else:
|
|||||||
if options.outfile:
|
if options.outfile:
|
||||||
fcstdfile = options.outfile
|
fcstdfile = options.outfile
|
||||||
else:
|
else:
|
||||||
fcstdfile = re.sub('\.svg$', '.fcstd', svgfile, re.I)
|
fcstdfile = re.sub(r'\.svg$', '.FCStd', svgfile, re.I)
|
||||||
docname = re.sub('\.fcstd$', '', fcstdfile, re.I)
|
docname = re.sub(r'\.fcstd$', '', fcstdfile, re.I)
|
||||||
docname = re.sub('^.*/', '', docname)
|
docname = re.sub(r'^.*/', '', docname)
|
||||||
|
|
||||||
if not options.outfile:
|
if not options.outfile:
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
@ -1871,7 +1869,7 @@ if verbose >= 0:
|
|||||||
|
|
||||||
if not options.outfile:
|
if not options.outfile:
|
||||||
import tempfile
|
import tempfile
|
||||||
fcstdfile = tempfile.mktemp(prefix=docname, suffix='.fcstd')
|
fcstdfile = tempfile.mktemp(prefix=docname, suffix='.FCStd')
|
||||||
|
|
||||||
fcdoc.saveAs(fcstdfile)
|
fcdoc.saveAs(fcstdfile)
|
||||||
## Add GuiDocument.xml to the zip archive of fcstdfile
|
## Add GuiDocument.xml to the zip archive of fcstdfile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user