Skip to content

Commit

Permalink
python: OpenSCAD: *.py: Fix python3 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
plaes authored and looooo committed Feb 12, 2017
1 parent 34a3039 commit 159dbe2
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 200 deletions.
32 changes: 16 additions & 16 deletions src/Mod/OpenSCAD/OpenSCAD2Dgeom.py
Expand Up @@ -95,7 +95,7 @@ def finddepth(dict1,faceidx,curdepth=0):
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):
Expand Down Expand Up @@ -139,7 +139,7 @@ def directchildren(isinsidedict,parent):
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]
Expand Down Expand Up @@ -206,22 +206,22 @@ def hasnoparent(faceindex):
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)
Expand Down Expand Up @@ -269,7 +269,7 @@ def vertindex(forward):
#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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -424,7 +424,7 @@ def median(v1,v2):
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]
Expand All @@ -442,7 +442,7 @@ def median(v1,v2):
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:
Expand All @@ -462,16 +462,16 @@ def median(v1,v2):
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):
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/OpenSCAD/OpenSCADCommands.py
Expand Up @@ -308,7 +308,7 @@ def addelement(self):
except OSError:
pass

except OpenSCADUtils.OpenSCADError, e:
except OpenSCADUtils.OpenSCADError as e:
FreeCAD.Console.PrintError(e.value)

class OpenSCADMeshBooleanWidget(QtGui.QWidget):
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/OpenSCAD/OpenSCADFeatures.py
Expand Up @@ -396,7 +396,7 @@ def createGeometry(self,fp):
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()
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/OpenSCAD/OpenSCADUtils.py
Expand Up @@ -44,7 +44,7 @@ def translate(context, text):
try:
import FreeCAD
BaseError = FreeCAD.Base.FreeCADError
except ImportError,AttributeError:
except (ImportError, AttributeError):
BaseError = RuntimeError

class OpenSCADError(BaseError):
Expand Down
70 changes: 35 additions & 35 deletions src/Mod/OpenSCAD/exportCSG.py
Expand Up @@ -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")
Expand All @@ -155,19 +155,19 @@ 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
if ptype == "Polygon" :
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")
Expand All @@ -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))
Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 159dbe2

Please sign in to comment.