def process_rotate_extrude(obj): myrev = doc.addObject("Part::Revolution", "RotateExtrude") myrev.Source = obj myrev.Axis = (0.00, 1.00, 0.00) myrev.Base = (0.00, 0.00, 0.00) myrev.Angle = 360.00 myrev.Placement = FreeCAD.Placement(FreeCAD.Vector(), FreeCAD.Rotation(0, 0, 90)) obj.ViewObject.hide() newobj = doc.addObject("Part::FeaturePython", 'RefineRotateExtrude') RefineShape(newobj, myrev) if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(newobj.ViewObject) else: newobj.ViewObject.Proxy = 0 myrev.ViewObject.hide() return (newobj)
def process_linear_extrude(obj, h): mylinear = doc.addObject("Part::Extrusion", "LinearExtrude") mylinear.Base = obj mylinear.Dir = (0, 0, h) mylinear.Placement = FreeCAD.Placement() try: mylinear.Solid = True except: a = 1 # Any old null statement obj.ViewObject.hide() newobj = doc.addObject("Part::FeaturePython", 'RefineLinearExtrude') RefineShape(newobj, mylinear) if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(newobj.ViewObject) else: newobj.ViewObject.Proxy = 0 mylinear.ViewObject.hide() return (newobj)
def process_linear_extrude(obj, h): #if gui: from OpenSCADFeatures import RefineShape newobj = doc.addObject("Part::FeaturePython", 'RefineLinearExtrude') RefineShape(newobj, obj) #mylinear) if gui: if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(newobj.ViewObject) else: newobj.ViewObject.Proxy = 0 obj.ViewObject.hide() #mylinear.ViewObject.hide() mylinear = doc.addObject("Part::Extrusion", "LinearExtrude") mylinear.Base = newobj #obj mylinear.Dir = (0, 0, h) mylinear.Placement = FreeCAD.Placement() # V17 change to False mylinear.Solid = True mylinear.Solid = False if gui: newobj.ViewObject.hide() return (mylinear)
def p_cylinder_action(p): 'cylinder_action : cylinder LPAREN keywordargument_list RPAREN SEMICOL' print "Cylinder" tocenter = p[3]['center'] h = float(p[3]['h']) r1 = float(p[3]['r1']) r2 = float(p[3]['r2']) n = int(p[3]['$fn']) print p[3] if (r1 == r2): print "Make Cylinder" fnmax = FreeCAD.ParamGet(\ "User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetInt('useMaxFN') if n < 3 or fnmax != 0 and n >= fnmax: mycyl = doc.addObject("Part::Cylinder", p[1]) mycyl.Height = h mycyl.Radius = r1 else: print "Make Prism" mycyl = doc.addObject("Part::Extrusion", "prism") mycyl.Dir = (0, 0, h) try: import Draft mycyl.Base = Draft.makePolygon(n, r1) except: # If Draft can't import (probably due to lack of Pivy on Mac and # Linux builds of FreeCAD), this is a fallback. # or old level of FreeCAD print "Draft makePolygon Failed, falling back on manual polygon" mycyl.Base = myPolygon(n, r1) else: pass if gui: mycyl.Base.ViewObject.hide() # mycyl.Solid = True else: print "Make Cone" mycyl = doc.addObject("Part::Cone", p[1]) mycyl.Height = h mycyl.Radius1 = r1 mycyl.Radius2 = r2 print "Center = ", center if tocenter == 'true': center(mycyl, 0, 0, h) if False: # Does not fix problemfile or beltTighener although later is closer newobj = doc.addObject("Part::FeaturePython", 'RefineCylinder') RefineShape(newobj, mycyl) if gui: if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(newobj.ViewObject) else: newobj.ViewObject.Proxy = 0 mycyl.ViewObject.hide() p[0] = [newobj] else: p[0] = [mycyl] print "End Cylinder"
def p_multmatrix_action(p): 'multmatrix_action : multmatrix LPAREN matrix RPAREN OBRACE block_list EBRACE' print "MultMatrix" transform_matrix = FreeCAD.Matrix() print "Multmatrix" print p[3] transform_matrix.A11 = round(float(p[3][0][0]), 12) transform_matrix.A12 = round(float(p[3][0][1]), 12) transform_matrix.A13 = round(float(p[3][0][2]), 12) transform_matrix.A14 = round(float(p[3][0][3]), 12) transform_matrix.A21 = round(float(p[3][1][0]), 12) transform_matrix.A22 = round(float(p[3][1][1]), 12) transform_matrix.A23 = round(float(p[3][1][2]), 12) transform_matrix.A24 = round(float(p[3][1][3]), 12) transform_matrix.A31 = round(float(p[3][2][0]), 12) transform_matrix.A32 = round(float(p[3][2][1]), 12) transform_matrix.A33 = round(float(p[3][2][2]), 12) transform_matrix.A34 = round(float(p[3][2][3]), 12) print transform_matrix print "Apply Multmatrix" # If more than one object on the stack for multmatrix fuse first if (len(p[6]) > 1): part = fuse(p[6], "Matrix Union") else: part = p[6][0] # part = new_part.transformGeometry(transform_matrix) # part = new_part.copy() # part.transformShape(transform_matrix) if (isspecialorthogonaldeterminant(fcsubmatrix(transform_matrix))): print "Orthogonal" part.Placement = FreeCAD.Placement(transform_matrix).multiply( part.Placement) new_part = part elif FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useMultmatrixFeature'): from OpenSCADFeatures import MatrixTransform new_part = doc.addObject("Part::FeaturePython", 'Matrix Deformation') MatrixTransform(new_part, transform_matrix, part) if gui: if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(new_part.ViewObject) else: new_part.ViewObject.Proxy = 0 part.ViewObject.hide() else: print "Transform Geometry" # Need to recompute to stop transformGeometry causing a crash doc.recompute() new_part = doc.addObject("Part::Feature", "Matrix Deformation") # new_part.Shape = part.Base.Shape.transformGeometry(transform_matrix) new_part.Shape = part.Shape.transformGeometry(transform_matrix) if gui: part.ViewObject.hide() if False: # Does not fix problemfile or beltTighener although later is closer newobj = doc.addObject("Part::FeaturePython", 'RefineMultMatrix') RefineShape(newobj, new_part) if gui: newobj.ViewObject.Proxy = 0 new_part.ViewObject.hide() p[0] = [newobj] else: p[0] = [new_part] print "Multmatrix applied"
def p_cylinder_action(p): 'cylinder_action : cylinder LPAREN keywordargument_list RPAREN SEMICOL' if printverbose: print("Cylinder") tocenter = p[3]['center'] h = float(p[3]['h']) r1 = float(p[3]['r1']) r2 = float(p[3]['r2']) #n = int(p[3]['$fn']) #n = int(round(float(p[3]['$fn']))) n = num(p[3]['$fn']) fnmax = FreeCAD.ParamGet(\ "User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetInt('useMaxFN') if fnmax == 0: fnmax = 16 if printverbose: print(p[3]) if h > 0: if (r1 == r2 and r1 > 0): if printverbose: print("Make Cylinder") if n < 3 or fnmax != 0 and n > fnmax: mycyl = doc.addObject("Part::Cylinder", p[1]) mycyl.Height = h mycyl.Radius = r1 else: if printverbose: print("Make Prism") if False: #user Draft Polygon mycyl = doc.addObject("Part::Extrusion", "prism") mycyl.Dir = (0, 0, h) try: import Draft mycyl.Base = Draft.makePolygon(n, r1, face=True) except: # If Draft can't import (probably due to lack of Pivy on Mac and # Linux builds of FreeCAD), this is a fallback. # or old level of FreeCAD if printverbose: print( "Draft makePolygon Failed, falling back on manual polygon" ) mycyl.Base = myPolygon(n, r1) # mycyl.Solid = True else: pass if gui: mycyl.Base.ViewObject.hide() else: #Use Part::Prism primitive mycyl = doc.addObject("Part::Prism", "prism") mycyl.Polygon = n mycyl.Circumradius = r1 mycyl.Height = h elif (r1 != r2): if n < 3 or fnmax != 0 and n > fnmax: if printverbose: print("Make Cone") mycyl = doc.addObject("Part::Cone", p[1]) mycyl.Height = h mycyl.Radius1 = r1 mycyl.Radius2 = r2 else: if printverbose: print("Make Frustum") mycyl = doc.addObject("Part::FeaturePython", 'frustum') from OpenSCADFeatures import Frustum Frustum(mycyl, r1, r2, n, h) if gui: if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(mycyl.ViewObject) else: mycyl.ViewObject.Proxy = 0 else: # r1 == r2 == 0 FreeCAD.Console.PrintWarning('cylinder with radius zero\n') mycyl = doc.addObject("Part::Feature", "emptycyl") mycyl.Shape = Part.Compound([]) else: # h == 0 FreeCAD.Console.PrintWarning('cylinder with height <= zero\n') mycyl = doc.addObject("Part::Feature", "emptycyl") mycyl.Shape = Part.Compound([]) if printverbose: print("Center = ", tocenter) if tocenter == 'true': center(mycyl, 0, 0, h) if False: # Does not fix problemfile or beltTighener although later is closer newobj = doc.addObject("Part::FeaturePython", 'RefineCylinder') RefineShape(newobj, mycyl) if gui: if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(newobj.ViewObject) else: newobj.ViewObject.Proxy = 0 mycyl.ViewObject.hide() p[0] = [newobj] else: p[0] = [mycyl] if printverbose: print("End Cylinder")
def p_multmatrix_action(p): 'multmatrix_action : multmatrix LPAREN matrix RPAREN OBRACE block_list EBRACE' from OpenSCADUtils import isspecialorthogonalpython, \ fcsubmatrix, roundrotation, isrotoinversionpython, \ decomposerotoinversion from OpenSCADFeatures import RefineShape if printverbose: print("MultMatrix") transform_matrix = FreeCAD.Matrix() if printverbose: print("Multmatrix") if printverbose: print(p[3]) m1l = sum(p[3], []) if any('x' in me for me in m1l): #hexfloats m1l = [float.fromhex(me) for me in m1l] matrixisrounded = False elif max((len(me) for me in m1l)) >= 14: #might have double precision m1l = [float(me) for me in m1l] # assume precise output m1l = [(0 if (abs(me) < 1e-15) else me) for me in m1l] matrixisrounded = False else: #trucanted numbers m1l = [round(float(me), 12) for me in m1l] #round matrixisrounded = True transform_matrix = FreeCAD.Matrix(*tuple(m1l)) if printverbose: print(transform_matrix) if printverbose: print("Apply Multmatrix") # If more than one object on the stack for multmatrix fuse first if p[6] == None: print(p) print(dir(p)) if (len(p[6]) == 0): part = placeholder('group', [], '{}') elif (len(p[6]) > 1): part = fuse(p[6], "Matrix Union") else: part = p[6][0] if (isspecialorthogonalpython(fcsubmatrix(transform_matrix))): if printverbose: print("special orthogonal") if matrixisrounded: if printverbose: print("rotation rounded") plm = FreeCAD.Placement(transform_matrix) plm = FreeCAD.Placement(plm.Base, roundrotation(plm.Rotation)) part.Placement = plm.multiply(part.Placement) else: part.Placement=FreeCAD.Placement(transform_matrix).multiply(\ part.Placement) new_part = part elif isrotoinversionpython(fcsubmatrix(transform_matrix)): if printverbose: print("orthogonal and inversion") cmat, axisvec = decomposerotoinversion(transform_matrix) new_part = doc.addObject("Part::Mirroring", 'mirr_%s' % part.Name) new_part.Source = part new_part.Normal = axisvec if matrixisrounded: if printverbose: print("rotation rounded") plm = FreeCAD.Placement(cmat) new_part.Placement = FreeCAD.Placement(plm.Base, roundrotation(plm.Rotation)) else: new_part.Placement = FreeCAD.Placement(cmat) new_part.Label = "mirrored %s" % part.Label if gui: part.ViewObject.hide() elif FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useMultmatrixFeature'): from OpenSCADFeatures import MatrixTransform new_part = doc.addObject("Part::FeaturePython", 'Matrix Deformation') MatrixTransform(new_part, transform_matrix, part) if gui: if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('useViewProviderTree'): from OpenSCADFeatures import ViewProviderTree ViewProviderTree(new_part.ViewObject) else: new_part.ViewObject.Proxy = 0 part.ViewObject.hide() else: if printverbose: print("Transform Geometry") # Need to recompute to stop transformGeometry causing a crash doc.recompute() new_part = doc.addObject("Part::Feature", "Matrix Deformation") # new_part.Shape = part.Base.Shape.transformGeometry(transform_matrix) new_part.Shape = part.Shape.transformGeometry(transform_matrix) if gui: part.ViewObject.hide() if False: # Does not fix problemfile or beltTighener although later is closer newobj = doc.addObject("Part::FeaturePython", 'RefineMultMatrix') RefineShape(newobj, new_part) if gui: newobj.ViewObject.Proxy = 0 new_part.ViewObject.hide() p[0] = [newobj] else: p[0] = [new_part] if printverbose: print("Multmatrix applied")