Commits

Ed Blake committed 4800516

Added preiliminary support for per-object facet settings.
$f? commands seem not to effect operators (translate, scale, etc.)?

Comments (0)

Files changed (2)

 class SCAD_Object(object):
     """Scad object wrapper base class."""
 
-    def __init__(self, center=True, mod='', comment=''):
+    def __init__(self, center=True, mod='', comment='', fa=None, fs=None, fn=None):
         self.type = None    # ?
         self.center = center# Centered or positive quadrent
         self.cmp = False    # Is compound
         self.mod = mod      # Rendering modifier (*,%,#,!)
         self.comment = comment  # A comment to add to the output file
+        # Per object facet settings
+        self.fa = fa
+        self.fs = fs
+        self.fn = fn
+
+    def facets(self):
+        """Return any facet arguments that are set."""
+        facets = ''
+        if self.fa:
+            facets += ", $fa={0}".format(self.fa)
+        if self.fs:
+            facets += ", $fs={0}".format(self.fs)
+        if self.fn:
+            facets += ", $fn={0}".format(self.fn)
+        return facets
 
     def center_str(self):
         return str(self.center).lower()

py2scad/primitives.py

         self.size = size
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         size_str = utility.val_to_str(self.size)
         center_str = self.center_str()
-        return 'cube(size=%s,center=%s);'%(size_str, center_str)
+        return 'cube(size={0}, center={1}{2});'.format(size_str,
+                                                       center_str,
+                                                       facets)
 
 class Sphere(base.SCAD_Object):
 
         self.r = r
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         r_str = utility.val_to_str(self.r)
         center_str = self.center_str()
-        return 'sphere(r=%s,center=%s);'%(r_str, center_str)
+        return 'sphere(r={0}, center={1}{2});'.format(r_str,
+                                                      center_str,
+                                                      facets)
 
 class Cylinder(base.SCAD_Object):
 
         self.r2 = r2
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         center_str = self.center_str()
         h_str = utility.val_to_str(self.h)
         r1_str = utility.val_to_str(self.r1)
             return 'cylinder(h={0},r1={1},r2={2},center={3});'.format(h_str,
                                                                       r1_str,
                                                                       r2_str,
-                                                                      center_str)
+                                                                      center_str,
+                                                                      facets)
         # When Cylinder is constant radius the argument is just called 'r'
-        return 'cylinder(h=%s,r=%s,center=%s);'%(h_str, r1_str, center_str)
+        return 'cylinder(h={0},r={1},center={2}{3});'.format(h_str,
+                                                             r1_str,
+                                                             center_str,
+                                                             facets)
 
 class Polyhedron(base.SCAD_Object):
 
         self.faces = faces
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         tab_str0 = ' '*utility.TAB_WIDTH*tab_level
         tab_str1 = ' '*utility.TAB_WIDTH*(tab_level+1)
         rtn_str = 'polyhedron(\n'
             p_str = utility.val_to_str(p,tab_level=tab_level+2)
             rtn_str = '%s%s,\n'%(rtn_str,p_str)
         rtn_str = '%s%s]\n'%(rtn_str,tab_str1,)
+        rtn_str += facets
         rtn_str = '%s%s);\n'%(rtn_str,tab_str0)
         return rtn_str
 
         self.convexity = convexity
 
     def cmd_str(self,tab_level=0):
-        return 'import_stl("{0.filename}",convexity={0.convexity:d});'.format(self)
+        facets = self.facets() # Retreve object facet information
+        return 'import_stl("{0.filename}",convexity={0.convexity:d}{1});'.format(self, facets)
 
 # 2D primatives ---------------------------------------------------------------
 
         self.r = r
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         r_str = utility.val_to_str(self.r)
-        rtn_str = 'circle(r={0});'.format(r_str)
+        rtn_str = 'circle(r={0}{1});'.format(r_str, facets)
         return rtn_str
 
 class Square(base.SCAD_Object):
         self.size = size
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         size_str = utility.val_to_str(self.size)
         center_str = self.center_str()
-        return 'square(size=%s,center=%s);'%(size_str,center_str)
+        return 'square(size={0}, center={1}{2});'.format(size_str,
+                                                        center_str,
+                                                        facets)
 
 class Polygon(base.SCAD_Object):
 
         self.paths = paths
 
     def cmd_str(self,tab_level=0):
+        facets = self.facets() # Retreve object facet information
         tab_str0 = ' '*utility.TAB_WIDTH*tab_level
         tab_str1 = ' '*utility.TAB_WIDTH*(tab_level+1)
         rtn_str = 'polygon(\n'
             p_str = utility.val_to_str(p,tab_level=tab_level+2)
             rtn_str = '%s%s,\n'%(rtn_str,p_str)
         rtn_str = '%s%s]\n'%(rtn_str,tab_str1,)
+        rtn_str += facets
         rtn_str = '%s%s);\n'%(rtn_str,tab_str0)
         return rtn_str
 
     v.bar = [10, 2, 4]
     v.baz = "strings aren't usefull yet!"
     print("{0.foo}, {0.bar}, {0.baz}".format(v))
-    print(v.cmd_str())
+    print(v)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.