Commits

Ed Blake committed 95f462b

Added translate argument to primitives.
Fixed a few new bugs.

Comments (0)

Files changed (3)

 
 Implement lookup table function, this will be especiallly useful
     for creating animations.
-Add fn, fa, fs controls for individual primatives.
 
 ############################## Ed ###############################
 
 See the License for the specific language governing permissions and
 limitations under the License.
 """
-from utility import TAB_WIDTH
+from utility import TAB_WIDTH, val_to_str
 
 class SCAD_Prog(object):
     """Wrapper for Openscad program."""
 class SCAD_Object(object):
     """Scad object wrapper base class."""
 
-    def __init__(self, center=True, mod='', comment='', fa=None, fs=None, fn=None):
+    def __init__(self, center=True, mod='', comment='',
+                 fa=None, fs=None, fn=None, translate=None):
         self.type = None    # ?
         self.center = center# Centered or positive quadrent
         self.cmp = False    # Is compound
         self.fa = fa
         self.fs = fs
         self.fn = fn
+        # Integrated transform
+        self.translate = translate
 
     def facets(self):
         """Return any facet arguments that are set."""
         comment = ''
         if self.comment:
             comment = tab_str + '// ' + self.comment + '\n'
-        return '{0}{1}{2}{3}'.format(comment, tab_str, mod_str,
+        rtn_str = '{0}{1}{2}'.format(tab_str, mod_str,
                                self.cmd_str(tab_level=tab_level))
+        if self.translate:
+            translate = tab_str + "translate(" + val_to_str(self.translate)
+            rtn_str = translate + ") {\n" + ' '*TAB_WIDTH + rtn_str + "\n}"
+        return comment + rtn_str
 
     def write(self, filename, fn=None):
         outfile = open(filename,'w')
             try:
                 rtn_str = '%s%s\n'%(rtn_str,obj.__str__(tab_level=tab_level+1))
             except: # Assume obj is str, otherwise it is converted...
-                rtn_str = "{0}{1}\n".format(rtn_str, (" "*(TAB_WIDTH*tab_level+1))+obj)
+                rtn_str = "{0}{1}\n".format(rtn_str, (" "*(TAB_WIDTH*tab_level+1))+str(obj))
         rtn_str = '%s%s}'%(rtn_str,tab_str,)
 
         return rtn_str

py2scad/transforms.py

         """Outputs the module signature."""
         return 'module {0}({1})'.format(self.name, ', '.join(arg for arg in self.args))
 
-    def __call__(self, *args):
+    def __call__(self, mod='', *args):
         """Returns a string calling this module with provided arguments."""
+        if not mod in '*!#%'.split(): # mod can eat he first arg
+            args = (mod,) + args
+            mod = ''
         if len(args) > len(self.args):
             raise TypeError("{0}() takes exactly {1} argument(s) ({2} given)".format(self.name, len(self.args), len(args)))
-        return "{0}({1});".format(self.name,
+        return "{0}{1}({2});".format(mod, self.name,
                 ', '.join(utility.val_to_str(arg) for arg in args))
 
 # 3D transformations ---------------------------------------------------------