python: OpenSCAD: *.py: Fix python3 syntax

This commit is contained in:
Priit Laes 2016-03-12 13:09:42 +02:00 committed by looooo
parent 34a3039577
commit 159dbe2cb8
9 changed files with 200 additions and 200 deletions

View File

@ -95,7 +95,7 @@ class Overlappingfaces():
if faceidx not in dict1:
return curdepth+1
else:
#print dict1[faceidx],[(finddepth(dict1,childface,curdepth)) for childface in dict1[faceidx]]
#print(dict1[faceidx],[(finddepth(dict1,childface,curdepth)) for childface in dict1[faceidx]])
return max([(Overlappingfaces.finddepth(dict1,childface,curdepth+1)) for childface in dict1[faceidx]])
def findrootdepth(self):
@ -139,7 +139,7 @@ class Overlappingfaces():
def printtree(isinsidedict,facenum):
def printtreechild(isinsidedict,facenum,parent):
children=Overlappingfaces.directchildren(isinsidedict,parent)
print 'parent %d directchild %s' % (parent,children)
print('parent %d directchild %s' % (parent,children))
if children:
subdict=isinsidedict.copy()
del subdict[parent]
@ -206,22 +206,22 @@ class Overlappingfaces():
isinsidedict=self.isinsidedict.copy()
finishedwith=[]
while not all([Overlappingfaces.hasnoparentstatic(isinsidedict,fi) for fi in range(len(faces))]):
#print [(Overlappingfaces.hasnoparentstatic(isinsidedict,fi),\
#Overlappingfaces.directchildren(isinsidedict,fi)) for fi in range(len(faces))]
#print([(Overlappingfaces.hasnoparentstatic(isinsidedict,fi),\
#Overlappingfaces.directchildren(isinsidedict,fi)) for fi in range(len(faces))])
for fi in range(len(faces))[::-1]:
directchildren = Overlappingfaces.directchildren(isinsidedict,fi)
if not directchildren:
continue
elif len(directchildren) == 1:
faces[fi]=faces[fi].cut(faces[directchildren[0]])
#print fi,'-' ,directchildren[0], faces[fi],faces[directchildren[0]]
#print(fi,'-' ,directchildren[0], faces[fi],faces[directchildren[0]])
removefaces(directchildren)
else:
toolface=fusefaces([faces[tfi] for tfi in directchildren])
faces[fi]=faces[fi].cut(toolface)
#print fi, '- ()', directchildren, [faces[tfi] for tfi in directchildren]
#print(fi, '- ()', directchildren, [faces[tfi] for tfi in directchildren])
removefaces(directchildren)
#print fi,directchildren
#print(fi,directchildren)
faces =[face for index,face in enumerate(faces) if index not in finishedwith]
# return faces
return fusefaces(faces)
@ -269,7 +269,7 @@ def findConnectedEdges(edgelist,eps=1e-6,debug=False):
#we are finished for this edge
debuglist.append(newedge)
retlist.append([item[0] for item in newedge]) #strip off direction
#print debuglist
#print(debuglist)
if debug:
return retlist,debuglist
else:
@ -319,7 +319,7 @@ def edgestowires(edgelist,eps=0.001):
maxd,mind,outerd = endpointdistancedebuglist(debug)
assert(maxd <= eps*2) # Assume the input to be broken
if maxd < eps*2 and maxd > 0.000001: #OCC wont like it if maxd > 0.02:
print 'endpointdistance max:%f min:%f, ends:%f' %(maxd,mind,outerd)
print('endpointdistance max:%f min:%f, ends:%f' %(maxd,mind,outerd))
if True:
tobeclosed = outerd < eps*2
@ -424,7 +424,7 @@ def superWireReverse(debuglist,closed=False):
from draftlibs.fcgeo import findMidpoint #workaround for Version 0.12
import Part
#edges = sortEdges(edgeslist)
print debuglist
print(debuglist)
newedges = []
for i in range(len(debuglist)):
curr = debuglist[i]
@ -442,7 +442,7 @@ def superWireReverse(debuglist,closed=False):
nexte = None
else:
nexte = debuglist[i+1]
print i,prev,curr,nexte
print(i,prev,curr,nexte)
if prev:
if curr[0].Vertexes[-1*(not curr[1])].Point == \
prev[0].Vertexes[-1*prev[1]].Point:
@ -462,16 +462,16 @@ def superWireReverse(debuglist,closed=False):
else:
p2 = curr[0].Vertexes[-1*(curr[1])].Point
if isinstance(curr[0].Curve,(Part.LineSegment, Part.Line)):
print "line",p1,p2
print("line",p1,p2)
newedges.append(Part.LineSegment(p1,p2).toShape())
elif isinstance(curr[0].Curve,Part.Circle):
p3 = findMidpoint(curr[0])
print "arc",p1,p3,p2
print("arc",p1,p3,p2)
newedges.append(Part.Arc(p1,p3,p2).toShape())
else:
print "Cannot superWire edges that are not lines or arcs"
print("Cannot superWire edges that are not lines or arcs")
return None
print newedges
print(newedges)
return Part.Wire(newedges)
def importDXFface(filename,layer=None,doc=None):
@ -489,7 +489,7 @@ def importDXFface(filename,layer=None,doc=None):
groupobj=[go for go in layers if (not layer) or go.Label == layer]
edges=[]
if not groupobj:
raise ValueError, 'import of layer %s failed' % layer
raise ValueError('import of layer %s failed' % layer)
for shapeobj in groupobj[0].Group:
edges.extend(shapeobj.Shape.Edges)
faces = edgestofaces(edges)

View File

@ -308,7 +308,7 @@ class AddSCADTask:
except OSError:
pass
except OpenSCADUtils.OpenSCADError, e:
except OpenSCADUtils.OpenSCADError as e:
FreeCAD.Console.PrintError(e.value)
class OpenSCADMeshBooleanWidget(QtGui.QWidget):

View File

@ -396,7 +396,7 @@ class Twist:
pipeshell.setSpineSupport(spine)
pipeshell.add(wire)
pipeshell.setAuxiliarySpine(auxspine,True,False)
print pipeshell.getStatus()
print(pipeshell.getStatus())
assert(pipeshell.isReady())
#fp.Shape=pipeshell.makeSolid()
pipeshell.build()

View File

@ -44,7 +44,7 @@ except AttributeError:
try:
import FreeCAD
BaseError = FreeCAD.Base.FreeCADError
except ImportError,AttributeError:
except (ImportError, AttributeError):
BaseError = RuntimeError
class OpenSCADError(BaseError):

View File

@ -95,40 +95,40 @@ def shape2polyhedron(shape):
def process_object(csg,ob):
print "Placement"
print "Pos : "+str(ob.Placement.Base)
print "axis : "+str(ob.Placement.Rotation.Axis)
print "angle : "+str(ob.Placement.Rotation.Angle)
print("Placement")
print("Pos : "+str(ob.Placement.Base))
print("axis : "+str(ob.Placement.Rotation.Axis))
print("angle : "+str(ob.Placement.Rotation.Angle))
if ob.TypeId == "Part::Sphere" :
print "Sphere Radius : "+str(ob.Radius)
print("Sphere Radius : "+str(ob.Radius))
check_multmatrix(csg,ob,0,0,0)
csg.write("sphere($fn = 0, "+fafs+", r = "+str(ob.Radius)+");\n")
elif ob.TypeId == "Part::Box" :
print "cube : ("+ str(ob.Length)+","+str(ob.Width)+","+str(ob.Height)+")"
print("cube : ("+ str(ob.Length)+","+str(ob.Width)+","+str(ob.Height)+")")
mm = check_multmatrix(csg,ob,-ob.Length/2,-ob.Width/2,-ob.Height/2)
csg.write("cube (size = ["+str(ob.Length.Value)+", "+str(ob.Width.Value)+", "+str(ob.Height.Value)+"], center = "+center(mm)+");\n")
if mm == 1 : csg.write("}\n")
elif ob.TypeId == "Part::Cylinder" :
print "cylinder : Height "+str(ob.Height)+ " Radius "+str(ob.Radius)
print("cylinder : Height "+str(ob.Height)+ " Radius "+str(ob.Radius))
mm = check_multmatrix(csg,ob,0,0,-ob.Height/2)
csg.write("cylinder($fn = 0, "+fafs+", h = "+str(ob.Height.Value)+ ", r1 = "+str(ob.Radius.Value)+\
", r2 = " + str(ob.Radius.Value) + ", center = "+center(mm)+");\n")
if mm == 1 : csg.write("}\n")
elif ob.TypeId == "Part::Cone" :
print "cone : Height "+str(ob.Height)+ " Radius1 "+str(ob.Radius1)+" Radius2 "+str(ob.Radius2)
print("cone : Height "+str(ob.Height)+ " Radius1 "+str(ob.Radius1)+" Radius2 "+str(ob.Radius2))
mm = check_multmatrix(csg,ob,0,0,-ob.Height/2)
csg.write("cylinder($fn = 0, "+fafs+", h = "+str(ob.Height.Value)+ ", r1 = "+str(ob.Radius1.Value)+\
", r2 = "+str(ob.Radius2.Value)+", center = "+center(mm)+");\n")
if mm == 1 : csg.write("}\n")
elif ob.TypeId == "Part::Torus" :
print "Torus"
print ob.Radius1
print ob.Radius2
print("Torus")
print(ob.Radius1)
print(ob.Radius2)
if ob.Angle3 == 360.00 :
mm = check_multmatrix(csg,ob,0,0,0)
csg.write("rotate_extrude("+convexity+", $fn = 0, "+fafs+")\n")
@ -155,9 +155,9 @@ def process_object(csg,ob):
if mm == 1: csg.write("}\n")
elif ob.TypeId == "Part::Extrusion" :
print "Extrusion"
print ob.Base
print ob.Base.Name
print("Extrusion")
print(ob.Base)
print(ob.Base.Name)
if ob.Base.isDerivedFrom('Part::Part2DObjectPython') and \
hasattr(ob.Base,'Proxy') and hasattr(ob.Base.Proxy,'TypeId'):
ptype=ob.Base.Proxy.TypeId
@ -165,9 +165,9 @@ def process_object(csg,ob):
f = str(ob.Base.FacesNumber)
r = str(ob.Base.Radius)
h = str(ob.Dir[2])
print "Faces : " + f
print "Radius : " + r
print "Height : " + h
print("Faces : " + f)
print("Radius : " + r)
print("Height : " + h)
mm = check_multmatrix(csg,ob,0,0,-float(h)/2)
csg.write("cylinder($fn = "+f+", "+fafs+", h = "+h+", r1 = "+r+\
", r2 = "+r+", center = "+center(mm)+");\n")
@ -176,16 +176,16 @@ def process_object(csg,ob):
elif ptype == "Circle" :
r = str(ob.Base.Radius)
h = str(ob.Dir[2])
print "Radius : " + r
print "Height : " + h
print("Radius : " + r)
print("Height : " + h)
mm = check_multmatrix(csg,ob,0,0,-float(h)/2)
csg.write("cylinder($fn = 0, "+fafs+", h = "+h+", r1 = "+r+\
", r2 = "+r+", center = "+center(mm)+");\n")
if mm == 1: csg.write("}\n")
elif ptype == "Wire" :
print "Wire extrusion"
print ob.Base
print("Wire extrusion")
print(ob.Base)
mm = check_multmatrix(csg,ob,0,0,0)
csg.write("linear_extrude(height = "+str(ob.Dir[2])+", center = "+center(mm)+", "+convexity+", twist = 0, slices = 2, $fn = 0, "+fafs+")\n{\n")
csg.write(vertexs2polygon(ob.Base.Shape.Vertexes))
@ -202,42 +202,42 @@ def process_object(csg,ob):
pass #There should be a fallback solution
elif ob.TypeId == "Part::Cut" :
print "Cut"
print("Cut")
csg.write("difference() {\n")
process_object(csg,ob.Base)
process_object(csg,ob.Tool)
csg.write("}\n")
elif ob.TypeId == "Part::Fuse" :
print "union"
print("union")
csg.write("union() {\n")
process_object(csg,ob.Base)
process_object(csg,ob.Tool)
csg.write("}\n")
elif ob.TypeId == "Part::Common" :
print "intersection"
print("intersection")
csg.write("intersection() {\n")
process_object(csg,ob.Base)
process_object(csg,ob.Tool)
csg.write("}\n")
elif ob.TypeId == "Part::MultiFuse" :
print "Multi Fuse / union"
print("Multi Fuse / union")
csg.write("union() {\n")
for subobj in ob.Shapes:
process_object(csg,subobj)
csg.write("}\n")
elif ob.TypeId == "Part::MultiCommon" :
print "Multi Common / intersection"
print("Multi Common / intersection")
csg.write("intersection() {\n")
for subobj in ob.Shapes:
process_object(csg,subobj)
csg.write("}\n")
elif ob.isDerivedFrom('Part::Feature') :
print "Part::Feature"
print("Part::Feature")
mm = check_multmatrix(csg,ob,0,0,0)
csg.write('%s\n' % shape2polyhedron(ob.Shape))
if mm == 1 : csg.write("}\n")
@ -246,21 +246,21 @@ def export(exportList,filename):
"called when freecad exports a file"
# process Objects
print "\nStart Export 0.1d\n"
print "Open Output File"
print("\nStart Export 0.1d\n")
print("Open Output File")
csg = pythonopen(filename,'w')
print "Write Inital Output"
print("Write Inital Output")
# Not sure if comments as per scad are allowed in csg file
csg.write("// CSG file generated from FreeCAD %s\n" % \
'.'.join(FreeCAD.Version()[0:3]))
#write initial group statements - not sure if required
csg.write("group() {\n group(){\n")
for ob in exportList:
print ob
print "Name : "+ob.Name
print "Type : "+ob.TypeId
print "Shape : "
print ob.Shape
print(ob)
print("Name : "+ob.Name)
print("Type : "+ob.TypeId)
print("Shape : ")
print(ob.Shape)
process_object(csg,ob)
# write closing group braces

View File

@ -38,7 +38,7 @@ if FreeCAD.GuiUp:
import FreeCADGui
gui = True
else:
if printverbose: print "FreeCAD Gui not present."
if printverbose: print("FreeCAD Gui not present.")
gui = False
@ -122,31 +122,31 @@ def insert(filename,docname):
def processcsg(filename):
global doc
if printverbose: print 'ImportCSG Version 0.6a'
if printverbose: print ('ImportCSG Version 0.6a')
# Build the lexer
if printverbose: print 'Start Lex'
if printverbose: print('Start Lex')
lex.lex(module=tokrules)
if printverbose: print 'End Lex'
if printverbose: print('End Lex')
# Build the parser
if printverbose: print 'Load Parser'
if printverbose: print('Load Parser')
# No debug out otherwise Linux has protection exception
parser = yacc.yacc(debug=0)
if printverbose: print 'Parser Loaded'
if printverbose: print('Parser Loaded')
# Give the lexer some input
#f=open('test.scad', 'r')
f = pythonopen(filename, 'r')
#lexer.input(f.read())
if printverbose: print 'Start Parser'
if printverbose: print('Start Parser')
# Swap statements to enable Parser debugging
#result = parser.parse(f.read(),debug=1)
result = parser.parse(f.read())
f.close()
if printverbose:
print 'End Parser'
print result
print('End Parser')
print(result)
FreeCAD.Console.PrintMessage('End processing CSG file\n')
doc.recompute()
@ -157,23 +157,23 @@ def p_block_list_(p):
| statementwithmod
| block_list statementwithmod
'''
if printverbose: print "Block List"
if printverbose: print p[1]
if printverbose: print("Block List")
if printverbose: print(p[1])
if(len(p) > 2) :
if printverbose: print p[2]
if printverbose: print(p[2])
p[0] = p[1] + p[2]
else :
p[0] = p[1]
if printverbose: print "End Block List"
if printverbose: print("End Block List")
def p_render_action(p):
'render_action : render LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE'
if printverbose: print "Render (ignored)"
if printverbose: print("Render (ignored)")
p[0] = p[6]
def p_group_action1(p):
'group_action1 : group LPAREN RPAREN OBRACE block_list EBRACE'
if printverbose: print "Group"
if printverbose: print("Group")
# Test if need for implicit fuse
if (len(p[5]) > 1) :
p[0] = [fuse(p[5],"Group")]
@ -182,7 +182,7 @@ def p_group_action1(p):
def p_group_action2(p) :
'group_action2 : group LPAREN RPAREN SEMICOL'
if printverbose: print "Group2"
if printverbose: print("Group2")
p[0] = []
def p_boolean(p) :
@ -249,7 +249,7 @@ def p_part(p):
def p_2d_point(p):
'2d_point : OSQUARE NUMBER COMMA NUMBER ESQUARE'
global points_list
if printverbose: print "2d Point"
if printverbose: print("2d Point")
p[0] = [float(p[2]),float(p[4])]
def p_points_list_2d(p):
@ -260,21 +260,21 @@ def p_points_list_2d(p):
'''
if p[2] == ',' :
if printverbose:
print "Start List"
print p[1]
print("Start List")
print(p[1])
p[0] = [p[1]]
else :
if printverbose:
print p[1]
print p[2]
print(p[1])
print(p[2])
p[1].append(p[2])
p[0] = p[1]
if printverbose: print p[0]
if printverbose: print(p[0])
def p_3d_point(p):
'3d_point : OSQUARE NUMBER COMMA NUMBER COMMA NUMBER ESQUARE'
global points_list
if printverbose: print "3d point"
if printverbose: print("3d point")
p[0] = [p[2],p[4],p[6]]
def p_points_list_3d(p):
@ -284,15 +284,15 @@ def p_points_list_3d(p):
| points_list_3d 3d_point
'''
if p[2] == ',' :
if printverbose: print "Start List"
if printverbose: print p[1]
if printverbose: print("Start List")
if printverbose: print(p[1])
p[0] = [p[1]]
else :
if printverbose: print p[1]
if printverbose: print p[2]
if printverbose: print(p[1])
if printverbose: print(p[2])
p[1].append(p[2])
p[0] = p[1]
if printverbose: print p[0]
if printverbose: print(p[0])
def p_path_points(p):
'''
@ -300,24 +300,24 @@ def p_path_points(p):
| path_points NUMBER COMMA
| path_points NUMBER
'''
if printverbose: print "Path point"
if printverbose: print("Path point")
if p[2] == ',' :
if printverbose: print 'Start list'
if printverbose: print p[1]
if printverbose: print('Start list')
if printverbose: print(p[1])
p[0] = [int(p[1])]
else :
if printverbose: print p[1]
if printverbose: print len(p[1])
if printverbose: print p[2]
if printverbose: print(p[1])
if printverbose: print(len(p[1]))
if printverbose: print(p[2])
p[1].append(int(p[2]))
p[0] = p[1]
if printverbose: print p[0]
if printverbose: print(p[0])
def p_path_list(p):
'path_list : OSQUARE path_points ESQUARE'
if printverbose: print 'Path List '
if printverbose: print p[2]
if printverbose: print('Path List ')
if printverbose: print(p[2])
p[0] = p[2]
def p_path_set(p) :
@ -325,14 +325,14 @@ def p_path_set(p) :
path_set : path_list
| path_set COMMA path_list
'''
if printverbose: print 'Path Set'
if printverbose: print len(p)
if printverbose: print('Path Set')
if printverbose: print(len(p))
if len(p) == 2 :
p[0] = [p[1]]
else :
p[1].append(p[3])
p[0] = p[1]
if printverbose: print p[0]
if printverbose: print(p[0])
def p_operation(p):
'''
@ -422,7 +422,7 @@ def p_not_supported(p):
def p_size_vector(p):
'size_vector : OSQUARE NUMBER COMMA NUMBER COMMA NUMBER ESQUARE'
if printverbose: print "size vector"
if printverbose: print("size vector")
p[0] = [p[2],p[4],p[6]]
def p_keywordargument(p):
@ -435,7 +435,7 @@ def p_keywordargument(p):
| ID EQ stripped_string
'''
p[0] = (p[1],p[3])
if printverbose: print p[0]
if printverbose: print(p[0])
def p_keywordargument_list(p):
'''
@ -451,7 +451,7 @@ def p_keywordargument_list(p):
def p_color_action(p):
'color_action : color LPAREN vector RPAREN OBRACE block_list EBRACE'
import math
if printverbose: print "Color"
if printverbose: print("Color")
color = tuple([float(f) for f in p[3][:3]]) #RGB
transp = 100 - int(math.floor(100*float(p[3][3]))) #Alpha
if gui:
@ -462,27 +462,27 @@ def p_color_action(p):
# Error rule for syntax errors
def p_error(p):
if printverbose: print "Syntax error in input!"
if printverbose: print p
if printverbose: print("Syntax error in input!")
if printverbose: print(p)
def fuse(lst,name):
global doc
if printverbose: print "Fuse"
if printverbose: print lst
if printverbose: print("Fuse")
if printverbose: print(lst)
if len(lst) == 0:
myfuse = placeholder('group',[],'{}')
elif len(lst) == 1:
return lst[0]
# Is this Multi Fuse
elif len(lst) > 2:
if printverbose: print "Multi Fuse"
if printverbose: print("Multi Fuse")
myfuse = doc.addObject('Part::MultiFuse',name)
myfuse.Shapes = lst
if gui:
for subobj in myfuse.Shapes:
subobj.ViewObject.hide()
else:
if printverbose: print "Single Fuse"
if printverbose: print("Single Fuse")
myfuse = doc.addObject('Part::Fuse',name)
myfuse.Base = lst[0]
myfuse.Tool = lst[1]
@ -493,18 +493,18 @@ def fuse(lst,name):
def p_union_action(p):
'union_action : union LPAREN RPAREN OBRACE block_list EBRACE'
if printverbose: print "union"
if printverbose: print("union")
newpart = fuse(p[5],p[1])
if printverbose: print "Push Union Result"
if printverbose: print("Push Union Result")
p[0] = [newpart]
if printverbose: print "End Union"
if printverbose: print("End Union")
def p_difference_action(p):
'difference_action : difference LPAREN RPAREN OBRACE block_list EBRACE'
if printverbose: print "difference"
if printverbose: print len(p[5])
if printverbose: print p[5]
if printverbose: print("difference")
if printverbose: print(len(p[5]))
if printverbose: print(p[5])
if (len(p[5]) == 0 ): #nochild
mycut = placeholder('group',[],'{}')
elif (len(p[5]) == 1 ): #single object
@ -515,31 +515,31 @@ def p_difference_action(p):
mycut.Base = p[5][0]
# Can only Cut two objects do we need to fuse extras
if (len(p[5]) > 2 ):
if printverbose: print "Need to Fuse Extra First"
if printverbose: print("Need to Fuse Extra First")
mycut.Tool = fuse(p[5][1:],'union')
else :
mycut.Tool = p[5][1]
if gui:
mycut.Base.ViewObject.hide()
mycut.Tool.ViewObject.hide()
if printverbose: print "Push Resulting Cut"
if printverbose: print("Push Resulting Cut")
p[0] = [mycut]
if printverbose: print "End Cut"
if printverbose: print("End Cut")
def p_intersection_action(p):
'intersection_action : intersection LPAREN RPAREN OBRACE block_list EBRACE'
if printverbose: print "intersection"
if printverbose: print("intersection")
# Is this Multi Common
if (len(p[5]) > 2):
if printverbose: print "Multi Common"
if printverbose: print("Multi Common")
mycommon = doc.addObject('Part::MultiCommon',p[1])
mycommon.Shapes = p[5]
if gui:
for subobj in mycommon.Shapes:
subobj.ViewObject.hide()
elif (len(p[5]) == 2):
if printverbose: print "Single Common"
if printverbose: print("Single Common")
mycommon = doc.addObject('Part::Common',p[1])
mycommon.Base = p[5][0]
mycommon.Tool = p[5][1]
@ -551,7 +551,7 @@ def p_intersection_action(p):
else : # 1 child
mycommon = placeholder('group',[],'{}')
p[0] = [mycommon]
if printverbose: print "End Intersection"
if printverbose: print("End Intersection")
def process_rotate_extrude(obj):
newobj=doc.addObject("Part::FeaturePython",'RefineRotateExtrude')
@ -576,21 +576,21 @@ def process_rotate_extrude(obj):
def p_rotate_extrude_action(p):
'rotate_extrude_action : rotate_extrude LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE'
if printverbose: print "Rotate Extrude"
if printverbose: print("Rotate Extrude")
if (len(p[6]) > 1) :
part = fuse(p[6],"Rotate Extrude Union")
else :
part = p[6][0]
p[0] = [process_rotate_extrude(part)]
if printverbose: print "End Rotate Extrude"
if printverbose: print("End Rotate Extrude")
def p_rotate_extrude_file(p):
'rotate_extrude_file : rotate_extrude LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Rotate Extrude File"
if printverbose: print("Rotate Extrude File")
filen,ext =p[3]['file'] .rsplit('.',1)
obj = process_import_file(filen,ext,p[3]['layer'])
p[0] = [process_rotate_extrude(obj)]
if printverbose: print "End Rotate Extrude File"
if printverbose: print("End Rotate Extrude File")
def process_linear_extrude(obj,h) :
#if gui:
@ -631,9 +631,9 @@ def process_linear_extrude_with_twist(base,height,twist) :
def p_linear_extrude_with_twist(p):
'linear_extrude_with_twist : linear_extrude LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE'
if printverbose: print "Linear Extrude With Twist"
if printverbose: print("Linear Extrude With Twist")
h = float(p[3]['height'])
if printverbose: print "Twist : ",p[3]
if printverbose: print("Twist : ",p[3])
if 'twist' in p[3]:
t = float(p[3]['twist'])
else:
@ -649,33 +649,33 @@ def p_linear_extrude_with_twist(p):
if p[3]['center']=='true' :
center(newobj,0,0,h)
p[0] = [newobj]
if printverbose: print "End Linear Extrude with twist"
if printverbose: print("End Linear Extrude with twist")
def p_import_file1(p):
'import_file1 : import LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Import File"
if printverbose: print("Import File")
filen,ext =p[3]['file'].rsplit('.',1)
p[0] = [process_import_file(filen,ext,p[3]['layer'])]
if printverbose: print "End Import File"
if printverbose: print("End Import File")
def p_surface_action(p):
'surface_action : surface LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Surface"
if printverbose: print("Surface")
obj = doc.addObject("Part::Feature",'surface')
obj.Shape,xoff,yoff=makeSurfaceVolume(p[3]['file'])
if p[3]['center']=='true' :
center(obj,xoff,yoff,0.0)
p[0] = [obj]
if printverbose: print "End surface"
if printverbose: print("End surface")
def process_import_file(fname,ext,layer):
if printverbose: print "Importing : "+fname+"."+ext+" Layer : "+layer
if printverbose: print("Importing : "+fname+"."+ext+" Layer : "+layer)
if ext.lower() in reverseimporttypes()['Mesh']:
obj=process_mesh_file(fname,ext)
elif ext.lower() == 'dxf' :
obj=processDXF(fname,layer)
else:
raise ValueError, "Unsupported file extension %s" % ext
raise ValueError("Unsupported file extension %s" % ext)
return(obj)
def process_mesh_file(fname,ext):
@ -729,33 +729,33 @@ def processDXF(fname,layer):
global doc
global pathName
from OpenSCAD2Dgeom import importDXFface
if printverbose: print "Process DXF file"
if printverbose: print "File Name : "+fname
if printverbose: print "Layer : "+layer
if printverbose: print "PathName : "+pathName
if printverbose: print("Process DXF file")
if printverbose: print("File Name : "+fname)
if printverbose: print("Layer : "+layer)
if printverbose: print("PathName : "+pathName)
dxfname = fname+'.dxf'
filename = os.path.join(pathName,dxfname)
shortname = os.path.split(fname)[1]
if printverbose: print "DXF Full path : "+filename
if printverbose: print("DXF Full path : "+filename)
face = importDXFface(filename,layer,doc)
obj=doc.addObject('Part::Feature','dxf_%s_%s' % (shortname,layer or "all"))
obj.Shape=face
if printverbose: print "DXF Diagnostics"
if printverbose: print obj.Shape.ShapeType
if printverbose: print "Closed : "+str(obj.Shape.isClosed())
if printverbose: print obj.Shape.check()
if printverbose: print [w.isClosed() for w in obj.Shape.Wires]
if printverbose: print("DXF Diagnostics")
if printverbose: print(obj.Shape.ShapeType)
if printverbose: print("Closed : "+str(obj.Shape.isClosed()))
if printverbose: print(obj.Shape.check())
if printverbose: print([w.isClosed() for w in obj.Shape.Wires])
return(obj)
def processSTL(fname):
if printverbose: print "Process STL file"
if printverbose: print("Process STL file")
def p_multmatrix_action(p):
'multmatrix_action : multmatrix LPAREN matrix RPAREN OBRACE block_list EBRACE'
if printverbose: print "MultMatrix"
if printverbose: print("MultMatrix")
transform_matrix = FreeCAD.Matrix()
if printverbose: print "Multmatrix"
if printverbose: print p[3]
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]
@ -768,8 +768,8 @@ def p_multmatrix_action(p):
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 printverbose: print(transform_matrix)
if printverbose: print("Apply Multmatrix")
# If more than one object on the stack for multmatrix fuse first
if (len(p[6]) == 0) :
part = placeholder('group',[],'{}')
@ -778,9 +778,9 @@ def p_multmatrix_action(p):
else :
part = p[6][0]
if (isspecialorthogonalpython(fcsubmatrix(transform_matrix))) :
if printverbose: print "special orthogonal"
if printverbose: print("special orthogonal")
if matrixisrounded:
if printverbose: print "rotation rounded"
if printverbose: print("rotation rounded")
plm=FreeCAD.Placement(transform_matrix)
plm=FreeCAD.Placement(plm.Base,roundrotation(plm.Rotation))
part.Placement=plm.multiply(part.Placement)
@ -789,13 +789,13 @@ def p_multmatrix_action(p):
part.Placement)
new_part = part
elif isrotoinversionpython(fcsubmatrix(transform_matrix)):
if printverbose: print "orthogonal and inversion"
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"
if printverbose: print("rotation rounded")
plm=FreeCAD.Placement(cmat)
new_part.Placement=FreeCAD.Placement(plm.Base,roundrotation(plm.Rotation))
else:
@ -817,7 +817,7 @@ def p_multmatrix_action(p):
new_part.ViewObject.Proxy = 0
part.ViewObject.hide()
else :
if printverbose: print "Transform Geometry"
if printverbose: print("Transform Geometry")
# Need to recompute to stop transformGeometry causing a crash
doc.recompute()
new_part = doc.addObject("Part::Feature","Matrix Deformation")
@ -835,16 +835,16 @@ def p_multmatrix_action(p):
p[0] = [newobj]
else :
p[0] = [new_part]
if printverbose: print "Multmatrix applied"
if printverbose: print("Multmatrix applied")
def p_matrix(p):
'matrix : OSQUARE vector COMMA vector COMMA vector COMMA vector ESQUARE'
if printverbose: print "Matrix"
if printverbose: print("Matrix")
p[0] = [p[2],p[4],p[6],p[8]]
def p_vector(p):
'vector : OSQUARE NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER ESQUARE'
if printverbose: print "Vector"
if printverbose: print("Vector")
p[0] = [p[2],p[4],p[6],p[8]]
def center(obj,x,y,z):
@ -854,18 +854,18 @@ def center(obj,x,y,z):
def p_sphere_action(p):
'sphere_action : sphere LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Sphere : ",p[3]
if printverbose: print("Sphere : ",p[3])
r = float(p[3]['r'])
mysphere = doc.addObject("Part::Sphere",p[1])
mysphere.Radius = r
if printverbose: print "Push Sphere"
if printverbose: print("Push Sphere")
p[0] = [mysphere]
if printverbose: print "End Sphere"
if printverbose: print("End Sphere")
def myPolygon(n,r1):
# Adapted from Draft::_Polygon
import math
if printverbose: print "My Polygon"
if printverbose: print("My Polygon")
angle = math.pi*2/n
nodes = [FreeCAD.Vector(r1,0,0)]
for i in range(n-1) :
@ -880,7 +880,7 @@ def myPolygon(n,r1):
def p_cylinder_action(p):
'cylinder_action : cylinder LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Cylinder"
if printverbose: print("Cylinder")
tocenter = p[3]['center']
h = float(p[3]['h'])
r1 = float(p[3]['r1'])
@ -889,16 +889,16 @@ def p_cylinder_action(p):
fnmax = FreeCAD.ParamGet(\
"User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
GetInt('useMaxFN')
if printverbose: print p[3]
if printverbose: print(p[3])
if h > 0:
if ( r1 == r2 and r1 > 0):
if printverbose: print "Make Cylinder"
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 printverbose: print("Make Prism")
if False: #user Draft Polygon
mycyl=doc.addObject("Part::Extrusion","prism")
mycyl.Dir = (0,0,h)
@ -909,7 +909,7 @@ def p_cylinder_action(p):
# 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"
if printverbose: print("Draft makePolygon Failed, falling back on manual polygon")
mycyl.Base = myPolygon(n,r1)
# mycyl.Solid = True
@ -925,13 +925,13 @@ def p_cylinder_action(p):
elif (r1 != r2):
if n < 3 or fnmax != 0 and n > fnmax:
if printverbose: print "Make Cone"
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"
if printverbose: print("Make Frustum")
mycyl=doc.addObject("Part::FeaturePython",'frustum')
Frustum(mycyl,r1,r2,n,h)
if gui:
@ -949,7 +949,7 @@ def p_cylinder_action(p):
FreeCAD.Console.PrintWarning('cylinder with height <= zero\n')
mycyl=doc.addObject("Part::Feature","emptycyl")
mycyl.Shape = Part.Compound([])
if printverbose: print "Center = ",tocenter
if printverbose: print("Center = ",tocenter)
if tocenter=='true' :
center(mycyl,0,0,h)
if False :
@ -967,14 +967,14 @@ def p_cylinder_action(p):
p[0] = [newobj]
else :
p[0] = [mycyl]
if printverbose: print "End Cylinder"
if printverbose: print("End Cylinder")
def p_cube_action(p):
'cube_action : cube LPAREN keywordargument_list RPAREN SEMICOL'
global doc
l,w,h = [float(str1) for str1 in p[3]['size']]
if (l > 0 and w > 0 and h >0):
if printverbose: print "cube : ",p[3]
if printverbose: print("cube : ",p[3])
mycube=doc.addObject('Part::Box',p[1])
mycube.Length=l
mycube.Width=w
@ -986,11 +986,11 @@ def p_cube_action(p):
if p[3]['center']=='true' :
center(mycube,l,w,h);
p[0] = [mycube]
if printverbose: print "End Cube"
if printverbose: print("End Cube")
def p_circle_action(p) :
'circle_action : circle LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Circle : "+str(p[3])
if printverbose: print("Circle : "+str(p[3]))
r = float(p[3]['r'])
n = int(p[3]['$fn'])
fnmax = FreeCAD.ParamGet(\
@ -1017,12 +1017,12 @@ def p_circle_action(p) :
mycircle.MakeFace = True
if gui:
Draft._ViewProviderDraft(mycircle.ViewObject)
if printverbose: print "Push Circle"
if printverbose: print("Push Circle")
p[0] = [mycircle]
def p_square_action(p) :
'square_action : square LPAREN keywordargument_list RPAREN SEMICOL'
if printverbose: print "Square"
if printverbose: print("Square")
size = p[3]['size']
x = float(size[0])
y = float(size[1])
@ -1061,45 +1061,45 @@ def p_text_action(p) :
def convert_points_list_to_vector(l):
v = []
for i in l :
if printverbose: print i
if printverbose: print(i)
v.append(FreeCAD.Vector(i[0],i[1]))
if printverbose: print v
if printverbose: print(v)
return(v)
def p_polygon_action_nopath(p) :
'polygon_action_nopath : polygon LPAREN points EQ OSQUARE points_list_2d ESQUARE COMMA paths EQ undef COMMA keywordargument_list RPAREN SEMICOL'
if printverbose: print "Polygon"
if printverbose: print p[6]
if printverbose: print("Polygon")
if printverbose: print(p[6])
v = convert_points_list_to_vector(p[6])
mypolygon = doc.addObject('Part::Feature',p[1])
if printverbose: print "Make Parts"
if printverbose: print("Make Parts")
# Close Polygon
v.append(v[0])
parts = Part.makePolygon(v)
if printverbose: print "update object"
if printverbose: print("update object")
mypolygon.Shape = Part.Face(parts)
p[0] = [mypolygon]
def p_polygon_action_plus_path(p) :
'polygon_action_plus_path : polygon LPAREN points EQ OSQUARE points_list_2d ESQUARE COMMA paths EQ OSQUARE path_set ESQUARE COMMA keywordargument_list RPAREN SEMICOL'
if printverbose: print "Polygon with Path"
if printverbose: print p[6]
if printverbose: print("Polygon with Path")
if printverbose: print(p[6])
v = convert_points_list_to_vector(p[6])
if printverbose: print "Path Set List"
if printverbose: print p[12]
if printverbose: print("Path Set List")
if printverbose: print(p[12])
for i in p[12] :
if printverbose: print i
if printverbose: print(i)
mypolygon = doc.addObject('Part::Feature','wire')
path_list = []
for j in i :
j = int(j)
if printverbose: print j
if printverbose: print(j)
path_list.append(v[j])
# Close path
path_list.append(v[int(i[0])])
if printverbose: print 'Path List'
if printverbose: print path_list
if printverbose: print('Path List')
if printverbose: print(path_list)
wire = Part.makePolygon(path_list)
mypolygon.Shape = Part.Face(wire)
p[0] = [mypolygon]
@ -1113,19 +1113,19 @@ def make_face(v1,v2,v3):
def p_polyhedron_action(p) :
'''polyhedron_action : polyhedron LPAREN points EQ OSQUARE points_list_3d ESQUARE COMMA faces EQ OSQUARE points_list_3d ESQUARE COMMA keywordargument_list RPAREN SEMICOL
| polyhedron LPAREN points EQ OSQUARE points_list_3d ESQUARE COMMA triangles EQ OSQUARE points_list_3d ESQUARE COMMA keywordargument_list RPAREN SEMICOL'''
if printverbose: print "Polyhedron Points"
if printverbose: print("Polyhedron Points")
v = []
for i in p[6] :
if printverbose: print i
if printverbose: print(i)
v.append(FreeCAD.Vector(float(i[0]),float(i[1]),float(i[2])))
if printverbose:
print v
print "Polyhedron triangles"
print p[12]
print(v)
print("Polyhedron triangles")
print(p[12])
faces_list = []
mypolyhed = doc.addObject('Part::Feature',p[1])
for i in p[12] :
if printverbose: print i
if printverbose: print(i)
f = make_face(v[int(i[0])],v[int(i[1])],v[int(i[2])])
faces_list.append(f)
shell=Part.makeShell(faces_list)
@ -1137,7 +1137,7 @@ def p_polyhedron_action(p) :
def p_projection_action(p) :
'projection_action : projection LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE'
if printverbose: print 'Projection'
if printverbose: print('Projection')
if p[3]['cut']=='true' :
planedim=1e9 # large but finite
#inifinite planes look bad in the GUI

View File

@ -35,7 +35,7 @@ def openscadmesh(doc,scadstr,objname):
obj.Shape=solid#.removeSplitter()
return obj
else:
print scadstr
print(scadstr)
class Node:
#fnmin=12 # maximal fn for implicit polygon renderfing
@ -544,7 +544,7 @@ class Node:
argstr = ' (%s)' % self.arguments
else:
argstr = ''
print '%s %s%s' %(' '*level,self.name,argstr)
print('%s %s%s' %(' '*level,self.name,argstr))
for child in self.children:
child.pprint(level+1)
@ -554,7 +554,7 @@ class Node:
argstr = ' (%s)' % self.arguments
else:
argstr = ''
print '%s %s%s' %(path.ljust(pathjust),self.name,argstr)
print('%s %s%s' %(path.ljust(pathjust),self.name,argstr))
for i,child in enumerate(self.children):
child.pprint2('%s[%d]'%(path,i),pathjust)
@ -603,7 +603,7 @@ def parseargs(argstring):
else:
a.append(char)
tok.append(''.join(a).strip())
#print tok
#print(tok)
argdict=dict(zip(tok[0::2],[parseexpression(argstring) for argstring in tok[1::2]]))
# argdict={}
# for key, value in re.findall(r"(\$?\w+)\s*=\s*(\[?\w+]?),?\s*",argstring):

View File

@ -45,8 +45,8 @@ def replaceobj(parent,oldchild,newchild):
else:
if propvalue == oldchild:
setattr(parent,propname,newchild)
print propname, parent.getPropertyByName(propname)
#else: print propname,propvalue
print(propname, parent.getPropertyByName(propname))
#else: print(propname,propvalue)
parent.touch()
def replaceobjfromselection(objs):

View File

@ -132,5 +132,5 @@ t_ignore = " \t\r"
# Error handling rule
def t_error(t):
print "Illegal character '%s'" % t.value[0]
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)