Skip to content

Commit

Permalink
V0.24: Renamed Height to Zsize, Raise to Zoffset
Browse files Browse the repository at this point in the history
  • Loading branch information
jnweiger committed Sep 10, 2018
1 parent 9f12fbe commit 3787909
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 47 deletions.
14 changes: 8 additions & 6 deletions paths2openscad-de.inx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<param type="string" name="fname" gui-text="Ausgabedatei" xml:lang="de">{NAME}.scad</param>
<_param name="fname_help" type="description" xml:lang="de">Mit '{NAME}.scad' wird der Name vom svg übernommen.</_param>

<param type="float" precision="2" name="height" min="0" max="1000" gui-text="Höhe [mm]" xml:lang="de">5.0</param>
<param type="description" name="height_help" xml:lang="de">Vorgegebene Höhe der 3D-Extrusion (wenn keine Höhe im SVG-Objekt steht).</param>
<param type="float" precision="2" name="zsize" min="0" max="1000" gui-text="Höhe [mm]" xml:lang="de">5.0</param>
<param type="description" name="zsize_help" xml:lang="de">Vorgegebene Höhe der 3D-Extrusion (wenn keine Höhe im SVG-Objekt steht).</param>

<param type="boolean" name="parsedesc" gui-text="Beschreibung Auslesen" xml:lang="de">true</param>
<param type="description" name="parsedesc_help" xml:lang="de">Lese die extrudierte Höhe, Boden und Skalierung pro SVG-Objekt aus dessen Beschreibung oder ID. Siehe auch den Reiter Extrusion-Syntax.</param>
Expand Down Expand Up @@ -90,11 +90,13 @@ das Objekt "Antimaterie". D.h. es wird von allen normalen
Objekten weggeschnitten (subtrahiert).
</param>
<param type="description" name="extrusion_2" appearance="header" xml:lang="de">Syntax in der Objekteigenschaft Beschreibung</param>
<param xml:space="preserve" type="description" name="extrusion_3" xml:lang="de">Height: 10 mm oder Height: a12.3 mm
Höhe der linearen Extrusion des Objekts. Die Höhe zeigt
<param xml:space="preserve" type="description" name="extrusion_3" xml:lang="de">Zsize: 10 mm
Länge der linearen Extrusion des Objekts. Die Länge zeigt
nach oben, auch für "Antimaterie".

Raise: 4.5 mm
Antimatter: true

Zoffset: 4.5 mm
Hebt das Objekt an, um Balkone (oder Fenster) zu erzeugen.

Scale: 90 % oder Scale: 120,60 %
Expand Down Expand Up @@ -123,7 +125,7 @@ umgerechnet: 96 px = 1 inch = 25.4 mm.
(Vor inkscape 0.92 war der Standard 90 px pro inch,
Adobe Produkte verwenden oft 75 px pro inch)

v0.23
v0.24
Dan Newman (dan newman @ mtbaldy us)
Josef Skladanka (jskladan @ redhat com)
Juergen Weigert (juergen @ fabmail org)
Expand Down
26 changes: 14 additions & 12 deletions paths2openscad.inx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<param name="fname" type="string" _gui-text="Output file">{NAME}.scad</param>
<_param name="fname_help" type="description">Use '{NAME}.scad' here to use the name from svg.</_param>

<param name="height" type="float" min="0" max="1000" precision="2" _gui-text="Height [mm]">5.0</param>
<_param name="height_help" type="description">Default 3D extrude height (when no height is parsed from an svg object).</_param>
<param name="zsize" type="float" min="0" max="1000" precision="2" _gui-text="Z-Size [mm]">5.0</param>
<_param name="zsize_help" type="description">Default 3D extrude length (when no zsize is parsed from an svg object).</_param>

<param name="parsedesc" type="boolean" _gui-text="Description parsing">true</param>
<_param name="parsedesc_help" type="description">Read the extruded height, raise, scale per svg object from its description or ID. See the Extrusion Syntax tab for details.</_param>
<_param name="parsedesc_help" type="description">Read the extruded zsize, zoffset, scale per svg object from its description or ID. See the Extrusion Syntax tab for details.</_param>
<_param name="spacer" type="description"><!-- --></_param>

<param name="scadview" type="boolean" _gui-text="View in OpenSCAD">false</param>
Expand Down Expand Up @@ -83,27 +83,29 @@ Mac: /Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD</_param>
</page>

<page name="extrusion" _gui-text="Extrusion Syntax">
<_param name="extrusion_1" type="description" xml:space="preserve">The height and other parameters can be defined through an svg object's description label or id. The menu 'Object-&gt;Objects ...' shows an overview of all, the menu 'Object-&gt;Object Properties ...' (Shift-Ctrl-O) shows details of one selected object.
<_param name="extrusion_1" type="description" xml:space="preserve">The zsize and other parameters can be defined through an svg object's description label or id. The menu 'Object-&gt;Objects ...' shows an overview of all, the menu 'Object-&gt;Object Properties ...' (Shift-Ctrl-O) shows details of one selected object.

If an object's ID is in either name_XXX_mm or name_XXXmm
format, then XXX is translated into height in millimeters.
format, then XXX is translated into zsize in millimeters.
Use . or _ as separator for a decimal number.
Note that all whitespace or comma are saved as '_' in ID.

If the height is prefixed with a letter 'a', the
If the zsize is prefixed with a letter 'a', the
object is "anti-matter", it is cut away (subtracted)
from all normal objects.
</_param>
<_param name="extrusion_2" type="description" appearance="header">Syntax for the object property description</_param>
<_param name="extrusion_3" type="description" xml:space="preserve">Height: 10 mm or Height: a12.3 mm
Linear extrusion height of the object. Note that the
height always counts upwards, even for "anti-matter".
<_param name="extrusion_3" type="description" xml:space="preserve">Zsize: 10 mm
Linear extrusion length of the object. Note that the
zsize always counts upwards, even for "anti-matter".

Raise: 4.5 mm
Antimatter: true

Zoffset: 4.5 mm
Move an object upwards to create a balcony (or window).

Scale: 90 % or Scale: 120,60 %
Taper the object along its height. The bottom surface always
Taper the object along its zsize. The bottom surface always
is as drawn, but the top surface is scaled to this value.
If two values are given (separated by Komma), different scaling
applies along X- and Y-axis.
Expand All @@ -125,7 +127,7 @@ definition of 96 px = 1 inch = 25.4 mm.
(Before inkscape 0.92 the standard was 90 px per inch,
Adobe products often use 75 px per inch)

v0.23
v0.24
Dan Newman (dan newman @ mtbaldy us)
Josef Skladanka (jskladan @ redhat com)
Juergen Weigert (juergen @ fabmail org)
Expand Down
63 changes: 34 additions & 29 deletions paths2openscad.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# 0.12 parse svg width="400mm" correctly. Came out downscaled by 3...
#
# 2017-04-08, juergen@fabmail.org
# 0.13 allow letter 'a' prefix on height values for anti-matter.
# 0.13 allow letter 'a' prefix on zsize values for anti-matter.
# All anti-matter objects are subtracted from all normal objects.
# raise: Offset along Z axis, to make cut-outs and balconies.
# Refactored object_merge_extrusion_values() from convertPath().
Expand Down Expand Up @@ -53,7 +53,7 @@
# value for explicit Y scaling. Renamed the autoheight command line
# option to 'parsedesc' with default true. Renamed dict auto to
# extrusion. Rephrased all prose to refer to extrusion syntax rather
# than auto height.
# than auto zsize.
# 2017-06-18, juergen@fabmail.org
# 0.18 pep8 relaxed. all hard 80 cols line breaks removed.
# Refactored the commands into a separate tab in the inx.
Expand All @@ -76,6 +76,9 @@
# 0.23 fixed rect with x=0 not rendered.
# FIXME: should really use inksvg.py here too!
#
# 2018.09-09, juergen@fabmail.org
# 0.24 merged module feature, renamed Heigh,Raise to Zsize,Zoffset
#
# CAUTION: keep the version numnber in sync with paths2openscad.inx about page

# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -108,12 +111,14 @@

DEFAULT_WIDTH = 100
DEFAULT_HEIGHT = 100
# Parse all these as 56.7 mm height:
# Parse all these as 56.7 mm zsize:
# "path1234_56_7_mm", "pat1234____57.7mm", "path1234_57.7__mm"
RE_AUTO_HEIGHT_ID = re.compile(r".*?_+([aA]?\d+(?:[_\.]\d+)?)_*mm$")
RE_AUTO_HEIGHT_DESC = re.compile(r"^(?:ht|[Hh]eight):\s*([aA]?\d+(?:\.\d+)?) ?mm$", re.MULTILINE)
RE_AUTO_SCALE_DESC = re.compile(r"^(?:sc|[Ss]cale):\s*(\d+(?:\.\d+)?(?: ?, ?\d+(?:\.\d+)?)?) ?%$", re.MULTILINE)
RE_AUTO_RAISE_DESC = re.compile(r"^(?:[Rr]aise|[Oo]ffset):\s*(\d+(?:\.\d+)?) ?mm$", re.MULTILINE)
#
# the verbs Height and Raise are deprecated. Use Zsize and Zoffset instead.
RE_AUTO_ZSIZE_ID = re.compile(r".*?_+([aA]?\d+(?:[_\.]\d+)?)_*mm$")
RE_AUTO_ZSIZE_DESC = re.compile(r"^(?:[Hh]eight|[Zz]size):\s*([aA]?\d+(?:\.\d+)?) ?mm$", re.MULTILINE)
RE_AUTO_SCALE_DESC = re.compile(r"^(?:sc|[Ss]cale):\s*(\d+(?:\.\d+)?(?: ?, ?\d+(?:\.\d+)?)?) ?%$", re.MULTILINE)
RE_AUTO_ZOFFSET_DESC = re.compile(r"^(?:[Rr]aise|[Zz]offset):\s*(\d+(?:\.\d+)?) ?mm$", re.MULTILINE)
DESC_TAGS = ['desc', inkex.addNS('desc', 'svg')]

# CAUTION: keep these defaults in sync with paths2openscad.inx
Expand Down Expand Up @@ -382,8 +387,8 @@ def __init__(self):
help='Curve smoothing (less for more)')

self.OptionParser.add_option(
'--height', dest='height', type='string', default='5', action='store',
help='Height (mm)')
'--zsize', dest='zsize', type='string', default='5', action='store',
help='Z-size (mm)')

self.OptionParser.add_option(
'--min_line_width', dest='min_line_width', type='float', default=float(1), action='store',
Expand All @@ -403,7 +408,7 @@ def __init__(self):

self.OptionParser.add_option(
'--parsedesc', dest='parsedesc', type='string', default='true', action='store',
help='Parse height and other parameters from object descriptions')
help='Parse zsize and other parameters from object descriptions')

self.OptionParser.add_option(
'--scadview', dest='scadview', type='string', default='false', action='store',
Expand Down Expand Up @@ -548,7 +553,7 @@ def getDocProps(self):
# inkex.errormsg("switching to 96 dpi")

# BUGFIX https://github.com/fablabnbg/inkscape-paths2openscad/issues/1
# get height and width after dpi. This is needed for e.g. mm units.
# get zsize and width after dpi. This is needed for e.g. mm units.
self.docHeight = self.getLength('height', DEFAULT_HEIGHT)
self.docWidth = self.getLength('width', DEFAULT_WIDTH)

Expand Down Expand Up @@ -689,28 +694,28 @@ def object_merge_extrusion_values(extrusion, node):
# let the node override inherited values
rawid = node.get('id', '')
if rawid is not None:
height = RE_AUTO_HEIGHT_ID.findall(rawid)
if height:
extrusion['height'] = height[-1].replace("_", ".")
zsize = RE_AUTO_ZSIZE_ID.findall(rawid)
if zsize:
extrusion['zsize'] = zsize[-1].replace("_", ".")
# let description contents override id contents.
for tagname in DESC_TAGS:
desc_node = node.find("./%s" % tagname)
if desc_node is not None:
height = RE_AUTO_HEIGHT_DESC.findall(desc_node.text)
if height:
extrusion['height'] = height[-1]
zsize = RE_AUTO_ZSIZE_DESC.findall(desc_node.text)
if zsize:
extrusion['zsize'] = zsize[-1]
zscale = RE_AUTO_SCALE_DESC.findall(desc_node.text)
if zscale:
if ',' in zscale[-1]:
extrusion['scale'] = '[' + zscale[-1] + ']'
else:
extrusion['scale'] = zscale[-1]
zraise = RE_AUTO_RAISE_DESC.findall(desc_node.text)
if zraise:
extrusion['raise'] = zraise[-1]
if extrusion['height'][0] in ('a', 'A'):
zoffset = RE_AUTO_ZOFFSET_DESC.findall(desc_node.text)
if zoffset:
extrusion['zoffset'] = zoffset[-1]
if extrusion['zsize'][0] in ('a', 'A'):
extrusion['neg'] = True
extrusion['height'] = extrusion['height'][1:]
extrusion['zsize'] = extrusion['zsize'][1:]
# END object_merge_extrusion_values

path = self.paths[node]
Expand Down Expand Up @@ -822,14 +827,14 @@ def object_merge_extrusion_values(extrusion, node):
self.f.write(' scale([25.4/%g, -25.4/%g, 1]) union()\n {\n' % (self.dpi, self.dpi))

# And add the call to the call list
# Height is set by the overall module parameter
# unless an extrusion height is parsed from the description or ID.
extrusion = {'height': 'h', 'raise': '0', 'scale': 100.0, 'neg': False}
# Z-size is set by the overall module parameter
# unless an extrusion zsize is parsed from the description or ID.
extrusion = {'zsize': 'h', 'zoffset': '0', 'scale': 100.0, 'neg': False}
if self.options.parsedesc == 'true':
object_merge_extrusion_values(extrusion, node)

call_item = 'translate ([0,0,%s]) poly_%s(%s, min_line_mm(%s), %s);\n' % (
extrusion['raise'], id, extrusion['height'], stroke_width_mm, extrusion['scale'])
extrusion['zoffset'], id, extrusion['zsize'], stroke_width_mm, extrusion['scale'])

if extrusion['neg']:
self.call_list_neg.append(call_item)
Expand Down Expand Up @@ -1232,7 +1237,7 @@ def effect(self):
fudge = 0.1;
''')
# writeout users parameters
self.f.write('height = %s;\n' % (self.options.height))
self.f.write('zsize = %s;\n' % (self.options.zsize))
self.f.write('line_fn = %d;\n' % (self.options.line_fn))
self.f.write('min_line_width = %s;\n' % (self.options.min_line_width))
self.f.write('function min_line_mm(w) = max(min_line_width, w) * %g/25.4;\n\n' % self.dpi)
Expand All @@ -1259,9 +1264,9 @@ def effect(self):

# The module that calls all the other ones.
if self.options.stlmodule == 'true':
self.f.write('}\n\n//%s(height);\n' % (name))
self.f.write('}\n\n//%s(zsize);\n' % (name))
else:
self.f.write('}\n\n%s(height);\n' % (name))
self.f.write('}\n\n%s(zsize);\n' % (name))
self.f.close()

except IOError as e:
Expand Down

0 comments on commit 3787909

Please sign in to comment.