Skip to content

Commit ecc8f97

Browse files
author
Jürgen Weigert
committed
chamfer option added, and module chamfer_sphere() to the scad file.
Added a header with version number and date and source file to the scad file.
1 parent 523a27d commit ecc8f97

File tree

4 files changed

+88
-23
lines changed

4 files changed

+88
-23
lines changed

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ NAME = $(notdir $(CURDIR))
66
PYTHON_VERSION = 2.7.8
77
VIRTUALENV_VERSION = 1.11.6
88

9+
910
.PHONY: all
1011
all: test
1112

13+
include make-includes/python.mk
14+
include make-includes/variables.mk
15+
1216
#
1317
# pep8 seems to disallow visually aligned code in a tabular way.
1418
# Therefore we ignored these pep8 errors:
@@ -21,7 +25,7 @@ all: test
2125
.PHONY: test
2226
test: virtualenv
2327
. virtualenv/bin/activate && \
24-
pip install --requirement python-test-requirements.txt && \
28+
pip2 install --requirement python-test-requirements.txt && \
2529
$(MAKE) METHOD=git PEP8_OPTIONS='--max-line-length=140 --ignore=E127,E221,E241,E272' python-pep8
2630

2731
.PHONY: clean
@@ -57,6 +61,3 @@ install:
5761
install -m 755 -t $(DEST) *.py
5862
install -m 644 -t $(DEST) *.inx
5963

60-
61-
include make-includes/python.mk
62-
include make-includes/variables.mk

paths2openscad-de.inx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,29 @@
2727
<param type="boolean" name="stlpost" gui-text="STL Nachbearbeitung" xml:lang="de">false</param>
2828
<param type="description" name="stlpost_help" xml:lang="de">Starte beispielsweise einen 'slicer' nach der STL-Konvertierung. Siehe auch den Reiter Kommandos.</param>
2929

30-
<param name="stlmodule" type="boolean" _gui-text="Erzeuge ein Modul">false</param>
31-
<_param name="stlmodule_help" type="description">Rendern Sie das Objekt nicht in der Scad-Datei, erstellen Sie eine für den Import geeignete Datei.</_param>
32-
<param type="description" name="spacer"><!-- --></param>
30+
<param name="stlmodule" type="boolean" _gui-text="Erzeuge nur ein Modul">false</param>
3331
</page>
3432

3533
<page name="tuning" gui-text="Feinheiten" xml:lang="de">
3634
<param type="float" name="smoothness" min="0.0001" max="5" gui-text="Glättung" xml:lang="de">0.2</param>
3735
<param type="description" name="smoothness_help" xml:lang="de">Wird verwendet, wenn Kurven dargestellt werden. Kleinere Werte sind glatter. Bereich: 0.0001 bis 5</param>
36+
<param type="description" name="spacer"><!-- --></param>
37+
<param type="float" name="chamfer" min="0.0" gui-text="Radius (Verrundung) hinzufügen [mm]" xml:lang="de">0</param>
38+
<param name="chamfer_fn" type="optiongroup" appearance="minimal" _gui-text="Genauigkeit der Verrundung ($fn)">
39+
<option value="4">4: Rough (fast)</option>
40+
<option value="12">12: Medium (slow)</option>
41+
<option value="16">16: Fine (slower)</option>
42+
<option value="32">32: Perfect (slowest)</option>
43+
</param>
3844
<param type="description" name="outline_header" appearance="header" xml:lang="de">Umrisslinien-Modus</param>
39-
<param type="description" name="outline_help" xml:lang="de">Objekte werden nach einer von zwei Methoden in 3D extrudiert: Normal oder Umrisslinien-Modus. Normalerweise werden gefüllte Flächen von geschlossenen Objekten extrudiert, die Dicke der Randlinie wird dabei nicht hinzugerechnet. Offene Linienzüge oder Objekte ohne Füllung werden im Umrisslinien-Modus extrudiert. Die Anweisung 'Scale: XX %' wird im Umrisslinien-Modus nicht beachtet.</param>
45+
<param type="description" name="outline_help" xml:lang="de">Objekte werden nach einer von zwei Methoden in 3D extrudiert: Normal oder Umrisslinien-Modus. Normalerweise werden gefüllte Flächen extrudiert, die Dicke der Randlinie wird dabei nicht hinzugerechnet. Objekte ohne Füllung werden im Umrisslinien-Modus extrudiert. Die Anweisung 'Scale: XX %' wird im Umrisslinien-Modus nicht beachtet.</param>
4046
<param type="float" name="min_line_width" min="0.1" max="10" gui-text="Minimale Linienbreite [mm]" xml:lang="de">1.0</param>
4147
<param type="float" name="line_width_scale_perc" min="1" max="10000" gui-text="Skaliere Linienbreite [%]" xml:lang="de">100.0</param>
4248
<param type="optiongroup" name="line_fn" appearance="minimal" gui-text="Genauigkeit der Linienbreite ($fn)" xml:lang="de">
43-
<option value="4" xml:lang="de">Grob (schnell)</option>
44-
<option value="8" xml:lang="de">Mittel (langsam)</option>
45-
<option value="16" xml:lang="de">Fein (sehr langsam)</option>
49+
<option value="4" xml:lang="de">4: Grob (schnell)</option>
50+
<option value="8" xml:lang="de">8: Mittel (langsam)</option>
51+
<option value="16" xml:lang="de">16: Fein (langsamer)</option>
52+
<option value="32" xml:lang="de">32: Perfekt (sehr langsam)</option>
4653
</param>
4754
<param type="boolean" name="force_line" gui-text="Umrisslinien-Modus immer verwenden; Füllungen werden ignoriert" xml:lang="de">False</param>
4855
<param type="description" name="spacer"><!-- --></param>

paths2openscad.inx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,35 @@
2727
<param name="stlpost" type="boolean" _gui-text="STL postprocessing">false</param>
2828
<_param name="stlpost_help" type="description">Start e.g. a slicer after converting to STL. See the Commands tab for details.</_param>
2929

30-
<param name="stlmodule" type="boolean" _gui-text="Only create module">false</param>
31-
<_param name="stlmodule_help" type="description">Do not render the object in the scad file, create file suitable for import.</_param>
30+
<param name="stlmodule" type="boolean" _gui-text="Only create a module">false</param>
3231
<_param name="spacer" type="description"><!-- --></_param>
3332
</page>
3433

3534
<page name="tuning" _gui-text="Tuning">
36-
<param name="smoothness" type="float" min="0.0001" max="5" _gui-text="Smoothing">0.2</param>
35+
<param name="smoothness" type="float" min="0.0001" max="5" precision="4" _gui-text="Smoothing">0.2</param>
3736
<_param name="smoothness_help" type="description">Used when rendering curves. Smaller values are smoother. Range: 0.0001 to 5
3837
</_param>
38+
<param type="float" name="chamfer" min="0.0" gui-text="Add chamfer radius [mm]" xml:lang="de">0</param>
39+
<param name="chamfer_fn" type="optiongroup" appearance="minimal" _gui-text="Chamfer präzision ($fn)">
40+
<option value="4">4: Rough (fast)</option>
41+
<option value="12">12: Medium (slow)</option>
42+
<option value="16">16: Fine (slower)</option>
43+
<option value="32">32: Perfekt (slowest)</option>
44+
</param>
3945
<_param name="outline_header" type="description" appearance="header">Outline Mode</_param>
40-
<_param name="outline_help" type="description">Objects are extruded into 3D either in normal mode, or in outline mode. Normally the filled surface of a closed object is extruded without adding any line width. Lines that are not a closed loop and objects with no fill are rendered in outline mode.
46+
<_param name="outline_help" type="description">Objects are extruded into 3D either in normal mode, or in outline mode. Normally filled areas are extruded, ignoring the line width. Objects with no fill are rendered in outline mode.
4147

4248
Note: the 'Scale: XX %' instruction has no effect in outline mode.</_param>
4349
<param name="min_line_width" type="float" min="0.1" max="10" _gui-text="Minimum line width [mm]">1.0</param>
4450
<param type="float" name="line_width_scale_perc" min="1" max="10000" gui-text="Scale line width [%]">100.0</param>
51+
4552
<param name="line_fn" type="optiongroup" appearance="minimal" _gui-text="Line width precision ($fn)">
46-
<option value="4">Rough (fast)</option>
47-
<option value="8">Medium (slow)</option>
48-
<option value="16">Fine (very slow)</option>
53+
<option value="4">4: Rough (fast)</option>
54+
<option value="8">8: Medium (slow)</option>
55+
<option value="16">16: Fine (slower)</option>
56+
<option value="32">32: Perfekt (slowest)</option>
4957
</param>
58+
5059
<param name="force_line" type="boolean" _gui-text="Force outline mode, ignore fill">False</param>
5160
<_param name="spacer" type="description"><!-- --></_param>
5261
</page>

paths2openscad.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
# 0.25 Allow Depth,Offset instead of Zsize,Zoffset
8484
# Simplify the syntax description page.
8585
# Added parameter line_width_scale.
86+
# Added parameter chamfer, and module chamfer_sphere for doing minkowski
8687
#
8788
# CAUTION: keep the version number in sync with paths2openscad.inx about page
8889

@@ -110,10 +111,12 @@
110111
import cspsubdiv
111112
import bezmisc
112113
import re
114+
import time
113115
import string
114116
import tempfile
115117
import gettext
116118

119+
VERSION = '0.25'; # CAUTION: Keep in sync with all *.inx files
117120
DEFAULT_WIDTH = 100
118121
DEFAULT_HEIGHT = 100
119122
# Parse all these as 56.7 mm zsize:
@@ -391,6 +394,14 @@ def __init__(self):
391394
'--smoothness', dest='smoothness', type='float', default=float(0.2), action='store',
392395
help='Curve smoothing (less for more)')
393396

397+
self.OptionParser.add_option(
398+
'--chamfer', dest='chamfer', type='float', default=float(1.), action='store',
399+
help='Add a chamfer radius, displacing all object walls outwards [mm]')
400+
401+
self.OptionParser.add_option(
402+
'--chamfer_fn', dest='chamfer_fn', type='int', default=int(4), action='store',
403+
help='Chamfer precision ($fn when generating the minkowski sphere)')
404+
394405
self.OptionParser.add_option(
395406
'--depth', '--zsize', dest='zsize', type='string', default='5', action='store',
396407
help='Depth (Z-size) [mm]')
@@ -552,6 +563,7 @@ def getDocProps(self):
552563
'''
553564
inkscape:version="0.91 r"
554565
inkscape:version="0.92.0 ..."
566+
inkscape:version="0.92.4 (unknown)"
555567
See also https://github.com/fablabnbg/paths2openscad/issues/1
556568
'''
557569
# inkex.errormsg("inkscape:version="+inkscape_version)
@@ -565,6 +577,7 @@ def getDocProps(self):
565577
# get zsize and width after dpi. This is needed for e.g. mm units.
566578
self.docHeight = self.getLength('height', DEFAULT_HEIGHT)
567579
self.docWidth = self.getLength('width', DEFAULT_WIDTH)
580+
self.inkscape_version = re.sub(" *\(unknown\) *", "", inkscape_version)
568581

569582
if (self.docHeight is None) or (self.docWidth is None):
570583
return False
@@ -1228,6 +1241,10 @@ def effect(self):
12281241
if '/' != os.sep:
12291242
scad_fname = scad_fname.replace('/', os.sep)
12301243
self.f = open(scad_fname, 'w')
1244+
1245+
self.f.write('// Generated by inkscape %s + inkscape-paths2openscad %s\n' % (self.inkscape_version, VERSION))
1246+
self.f.write('// %s from "%s.svg"\n' % (time.ctime(), self.basename))
1247+
12311248
# for use in options.fname basename is derived from the sodipodi_docname by
12321249
# stripping the svg extension - or if there is no sodipodi_docname basename is 'inkscape'.
12331250
# for use in scadviewcmd, scad2stlcmd and stlpostcmd basename is rederived from
@@ -1245,9 +1262,14 @@ def effect(self):
12451262
// keep the resulting .stl file manifold.
12461263
fudge = 0.1;
12471264
''')
1265+
if self.options.chamfer < 0.001: self.options.chamfer = None
1266+
12481267
# writeout users parameters
12491268
self.f.write('zsize = %s;\n' % (self.options.zsize))
12501269
self.f.write('line_fn = %d;\n' % (self.options.line_fn))
1270+
if self.options.chamfer:
1271+
self.f.write('chamfer = %s;\n' % (self.options.chamfer))
1272+
self.f.write('chamfer_fn = %d;\n' % (self.options.chamfer_fn))
12511273
self.f.write('min_line_width = %s;\n' % (self.options.min_line_width))
12521274
self.f.write('line_width_scale = %s;\n' % (self.options.line_width_scale_perc * 0.01))
12531275
self.f.write('function min_line_mm(w) = max(min_line_width, w * line_width_scale) * %g/25.4;\n\n' % self.dpi)
@@ -1256,21 +1278,47 @@ def effect(self):
12561278
self.f.write('\n')
12571279
self.convertPath(key)
12581280

1281+
if self.options.chamfer:
1282+
self.f.write('''
1283+
module chamfer_sphere(rad=chamfer, res=chamfer_fn)
1284+
{
1285+
if(res <= 4)
1286+
{
1287+
// octaeder: 3 sided faces = 8
1288+
polyhedron(
1289+
points = [ [.0, .0, rad], [.0, .0, -rad], [ rad, .0, .0], [-rad, .0, .0], [.0, rad, .0], [.0, -rad, .0] ],
1290+
faces = [ [4, 2, 0], [3, 4, 0], [5, 3, 0], [2, 5, 0], [5, 2, 1], [3, 5, 1], [4, 3, 1], [2 , 4, 1] ]);
1291+
}
1292+
else
1293+
{
1294+
sphere(r=rad, center=true, $fn=res);
1295+
}
1296+
}
1297+
''')
1298+
12591299
# Come up with a name for the module based on the file name.
12601300
name = os.path.splitext(os.path.basename(self.options.fname))[0]
12611301
# Remove all punctuation except underscore.
12621302
name = re.sub('[' + string.punctuation.replace('_', '') + ']', '', name)
12631303

12641304
self.f.write('\nmodule %s(h)\n{\n' % name)
1305+
mi = ''
1306+
if self.options.chamfer:
1307+
mi = ' '
1308+
self.f.write(' minkowski()\n {\n')
1309+
12651310

12661311
# Now output the list of modules to call
1267-
self.f.write(' difference()\n {\n union()\n {\n')
1312+
self.f.write('%s difference()\n%s {\n%s union()\n%s {\n' % (mi,mi,mi,mi))
12681313
for call in self.call_list:
1269-
self.f.write(' ' + call)
1270-
self.f.write(' }\n union()\n {\n')
1314+
self.f.write('%s %s' % (mi,call))
1315+
self.f.write('%s }\n%s union()\n%s {\n' % (mi,mi,mi))
12711316
for call in self.call_list_neg:
1272-
self.f.write(' ' + call)
1273-
self.f.write(' }\n }\n')
1317+
self.f.write('%s %s' % (mi,call))
1318+
self.f.write('%s }\n%s }\n' % (mi,mi))
1319+
if self.options.chamfer:
1320+
self.f.write(' chamfer_sphere();\n }\n')
1321+
12741322

12751323
# The module that calls all the other ones.
12761324
if self.options.stlmodule == 'true':

0 commit comments

Comments
 (0)