diff -r 63b6f80e09ef -r a01a3fd32073 cylindertransport.py --- a/cylindertransport.py Mon Apr 03 09:10:41 2017 +0200 +++ b/cylindertransport.py Mon Apr 03 19:40:06 2017 +0200 @@ -8,7 +8,8 @@ from PIL import Image, ImageDraw, ImageFont import argparse, sys from data import CYLINDER, PIPES -from config import FONTBASE +from stl import OPENSCAD_MODULES, precompile_all_stl +from config import FONTBASE, SCALE3D def offset(r_1, r_2): """ @@ -30,38 +31,14 @@ self.scad = { "tmpl": """// Color support only in compile mode (F5) // cylindertransport.py OpenSCAD script -module tank(x, r, h) { - color("SteelBlue") render() { //rotate([90,0,0]) { - translate([x, r, r]) { - sphere(r = r); // bottom - cylinder(h = h-2*r, r = r); - } - translate([x, r, h-r]) { - sphere(r = r); // top - cylinder(h = r*1.4, r = r*0.25); - } - } -} - -module spacer(x, r, rcyl, h) { - color("DarkGrey") render() { //rotate([90,0,0]) { - translate([x, r, rcyl]) { - difference() { - cylinder(h = h-2*rcyl, r = r); - cylinder(h = h-2*rcyl, r = r*0.8); - } - } - } -} $fn = 10; -""", +""" + OPENSCAD_MODULES, "spacer": "", "cylinder": "" } self.circles = [] self.spacings = [] self.margin = 20 - self.scale3d = 0.1 def calc_min(self, r_1, r_2): """ @@ -100,8 +77,8 @@ posx = self.margin + r_2 # start offset x self._circle(posx, r_2, label, 0.5) self.scad["spacer"] += "spacer(%f, %f, %f, %f);\n" % ( - posx * self.scale3d, r_2 * self.scale3d, r_3 * self.scale3d, - CYLINDER[self.cylinders[0]][1] * self.scale3d) + posx * SCALE3D, r_2 * SCALE3D, r_3 * SCALE3D, + CYLINDER[self.cylinders[0]][1] * SCALE3D) posx += offset(r_2, r_3) for i in range(0, len(self.cylinders) - 1): @@ -111,23 +88,23 @@ # draw cylinder self._circle(posx, r_1, "Tank " + self.cylinders[i]) self.scad["cylinder"] += "tank(%f, %f, %f);\n" % ( - posx * self.scale3d, r_1 * self.scale3d, - CYLINDER[self.cylinders[i]][1] * self.scale3d) + posx * SCALE3D, r_1 * SCALE3D, + CYLINDER[self.cylinders[i]][1] * SCALE3D) sx1 = posx + r_1 posx += offset(r_1, r_2) # draw right spacer self._circle(posx, r_2, label, 0.5) self.scad["spacer"] += "spacer(%f, %f, %f, %f);\n" % ( - posx * self.scale3d, r_2 * self.scale3d, r_1 * self.scale3d, - CYLINDER[self.cylinders[i]][1] * self.scale3d) + posx * SCALE3D, r_2 * SCALE3D, r_1 * SCALE3D, + CYLINDER[self.cylinders[i]][1] * SCALE3D) posx += offset(r_2, r_3) sx2 = posx - r_3 if i == (len(self.cylinders) - 2): # draw last bottle self._circle(posx, r_3, "Tank " + self.cylinders[i + 1]) self.scad["cylinder"] += "tank(%f, %f, %f);\n" % ( - posx * self.scale3d, r_3 * self.scale3d, - CYLINDER[self.cylinders[i + 1]][1] * self.scale3d) + posx * SCALE3D, r_3 * SCALE3D, + CYLINDER[self.cylinders[i + 1]][1] * SCALE3D) posx += offset(r_2, r_3) self.spacings.append([sx1, sx2]) @@ -135,8 +112,8 @@ # last bottle spacer pipe self._circle(posx, r_2, label, 0.5) self.scad["spacer"] += "spacer(%f, %f, %f, %f);\n" % ( - posx * self.scale3d, r_2 * self.scale3d, r_3 * self.scale3d, - CYLINDER[self.cylinders[-1]][1] * self.scale3d) + posx * SCALE3D, r_2 * SCALE3D, r_3 * SCALE3D, + CYLINDER[self.cylinders[-1]][1] * SCALE3D) return int(posx + r_2 + self.margin) def centertext(self, draw, posx, posy, txt, size): @@ -189,9 +166,15 @@ parser.add_argument('--scad', dest='scad', \ type=str, default="", metavar='filename', \ help='Write OpenSCAD script file') + parser.add_argument('--precompile', dest='precompile', \ + default=False, action='store_true', \ + help='Precompile STL objects for 3D View') options = parser.parse_args() + if options.precompile: + precompile_all_stl() + for test in options.cylinders: if not test in CYLINDER.keys(): print "Cylinder type '%s' is unknown" % test