Draft: Adapted Draft module for python3 compatibility - issue #995
This commit is contained in:
parent
8d2e08ffa0
commit
daedcf4f1c
|
@ -23,7 +23,7 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
from __future__ import division
|
#from __future__ import division
|
||||||
|
|
||||||
__title__="FreeCAD Draft Workbench"
|
__title__="FreeCAD Draft Workbench"
|
||||||
__author__ = "Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, Dmitry Chigrin, Daniel Falck"
|
__author__ = "Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline, Dmitry Chigrin, Daniel Falck"
|
||||||
|
@ -81,7 +81,7 @@ if FreeCAD.GuiUp:
|
||||||
import FreeCADGui, WorkingPlane
|
import FreeCADGui, WorkingPlane
|
||||||
gui = True
|
gui = True
|
||||||
else:
|
else:
|
||||||
#print "FreeCAD Gui not present. Draft module will have some features disabled."
|
#print("FreeCAD Gui not present. Draft module will have some features disabled.")
|
||||||
gui = False
|
gui = False
|
||||||
|
|
||||||
arrowtypes = ["Dot","Circle","Arrow"]
|
arrowtypes = ["Dot","Circle","Arrow"]
|
||||||
|
@ -95,7 +95,7 @@ def stringencodecoin(str):
|
||||||
try:
|
try:
|
||||||
from pivy import coin
|
from pivy import coin
|
||||||
coin4 = coin.COIN_MAJOR_VERSION >= 4
|
coin4 = coin.COIN_MAJOR_VERSION >= 4
|
||||||
except ImportError, AttributeError:
|
except (ImportError, AttributeError):
|
||||||
coin4 = False
|
coin4 = False
|
||||||
if coin4:
|
if coin4:
|
||||||
return str.encode('utf-8')
|
return str.encode('utf-8')
|
||||||
|
@ -136,7 +136,7 @@ def getParam(param,default=None):
|
||||||
"getParam(parameterName): returns a Draft parameter value from the current config"
|
"getParam(parameterName): returns a Draft parameter value from the current config"
|
||||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||||
t = getParamType(param)
|
t = getParamType(param)
|
||||||
#print "getting param ",param, " of type ",t, " default: ",str(default)
|
#print("getting param ",param, " of type ",t, " default: ",str(default))
|
||||||
if t == "int":
|
if t == "int":
|
||||||
if default == None:
|
if default == None:
|
||||||
default = 0
|
default = 0
|
||||||
|
@ -284,7 +284,7 @@ def dimSymbol(symbol=None,invert=False):
|
||||||
marker.addChild(c)
|
marker.addChild(c)
|
||||||
return marker
|
return marker
|
||||||
elif symbol == 3:
|
elif symbol == 3:
|
||||||
print "Draft.dimsymbol: Not implemented"
|
print("Draft.dimsymbol: Not implemented")
|
||||||
return coin.SoSphere()
|
return coin.SoSphere()
|
||||||
|
|
||||||
def shapify(obj):
|
def shapify(obj):
|
||||||
|
@ -335,7 +335,7 @@ def getGroupContents(objectslist,walls=False,addgroups=False):
|
||||||
newlist.append(obj)
|
newlist.append(obj)
|
||||||
newlist.extend(getGroupContents(obj.Group,walls,addgroups))
|
newlist.extend(getGroupContents(obj.Group,walls,addgroups))
|
||||||
else:
|
else:
|
||||||
#print "adding ",obj.Name
|
#print("adding ",obj.Name)
|
||||||
newlist.append(obj)
|
newlist.append(obj)
|
||||||
if walls:
|
if walls:
|
||||||
if getType(obj) in ["Wall","Structure"]:
|
if getType(obj) in ["Wall","Structure"]:
|
||||||
|
@ -360,32 +360,32 @@ def removeHidden(objectslist):
|
||||||
|
|
||||||
def printShape(shape):
|
def printShape(shape):
|
||||||
"""prints detailed information of a shape"""
|
"""prints detailed information of a shape"""
|
||||||
print "solids: ", len(shape.Solids)
|
print("solids: ", len(shape.Solids))
|
||||||
print "faces: ", len(shape.Faces)
|
print("faces: ", len(shape.Faces))
|
||||||
print "wires: ", len(shape.Wires)
|
print("wires: ", len(shape.Wires))
|
||||||
print "edges: ", len(shape.Edges)
|
print("edges: ", len(shape.Edges))
|
||||||
print "verts: ", len(shape.Vertexes)
|
print("verts: ", len(shape.Vertexes))
|
||||||
if shape.Faces:
|
if shape.Faces:
|
||||||
for f in range(len(shape.Faces)):
|
for f in range(len(shape.Faces)):
|
||||||
print "face ",f,":"
|
print("face ",f,":")
|
||||||
for v in shape.Faces[f].Vertexes:
|
for v in shape.Faces[f].Vertexes:
|
||||||
print " ",v.Point
|
print(" ",v.Point)
|
||||||
elif shape.Wires:
|
elif shape.Wires:
|
||||||
for w in range(len(shape.Wires)):
|
for w in range(len(shape.Wires)):
|
||||||
print "wire ",w,":"
|
print("wire ",w,":")
|
||||||
for v in shape.Wires[w].Vertexes:
|
for v in shape.Wires[w].Vertexes:
|
||||||
print " ",v.Point
|
print(" ",v.Point)
|
||||||
else:
|
else:
|
||||||
for v in shape.Vertexes:
|
for v in shape.Vertexes:
|
||||||
print " ",v.Point
|
print(" ",v.Point)
|
||||||
|
|
||||||
def compareObjects(obj1,obj2):
|
def compareObjects(obj1,obj2):
|
||||||
"Prints the differences between 2 objects"
|
"Prints the differences between 2 objects"
|
||||||
|
|
||||||
if obj1.TypeId != obj2.TypeId:
|
if obj1.TypeId != obj2.TypeId:
|
||||||
print obj1.Name + " and " + obj2.Name + " are of different types"
|
print(obj1.Name + " and " + obj2.Name + " are of different types")
|
||||||
elif getType(obj1) != getType(obj2):
|
elif getType(obj1) != getType(obj2):
|
||||||
print obj1.Name + " and " + obj2.Name + " are of different types"
|
print(obj1.Name + " and " + obj2.Name + " are of different types")
|
||||||
else:
|
else:
|
||||||
for p in obj1.PropertiesList:
|
for p in obj1.PropertiesList:
|
||||||
if p in obj2.PropertiesList:
|
if p in obj2.PropertiesList:
|
||||||
|
@ -393,12 +393,12 @@ def compareObjects(obj1,obj2):
|
||||||
pass
|
pass
|
||||||
elif p == "Placement":
|
elif p == "Placement":
|
||||||
delta = str((obj1.Placement.Base.sub(obj2.Placement.Base)).Length)
|
delta = str((obj1.Placement.Base.sub(obj2.Placement.Base)).Length)
|
||||||
print "Objects have different placements. Distance between the 2: " + delta + " units"
|
print("Objects have different placements. Distance between the 2: " + delta + " units")
|
||||||
else:
|
else:
|
||||||
if getattr(obj1,p) != getattr(obj2,p):
|
if getattr(obj1,p) != getattr(obj2,p):
|
||||||
print "Property " + p + " has a different value"
|
print("Property " + p + " has a different value")
|
||||||
else:
|
else:
|
||||||
print "Property " + p + " doesn't exist in one of the objects"
|
print("Property " + p + " doesn't exist in one of the objects")
|
||||||
|
|
||||||
def formatObject(target,origin=None):
|
def formatObject(target,origin=None):
|
||||||
'''
|
'''
|
||||||
|
@ -538,7 +538,7 @@ def loadTexture(filename,size=None):
|
||||||
# p = QtGui.QImage(filename)
|
# p = QtGui.QImage(filename)
|
||||||
size = coin.SbVec2s(p.width(), p.height())
|
size = coin.SbVec2s(p.width(), p.height())
|
||||||
buffersize = p.numBytes()
|
buffersize = p.numBytes()
|
||||||
numcomponents = int (buffersize / ( size[0] * size[1] ))
|
numcomponents = int (float(buffersize) / ( size[0] * size[1] ))
|
||||||
|
|
||||||
img = coin.SoSFImage()
|
img = coin.SoSFImage()
|
||||||
width = size[0]
|
width = size[0]
|
||||||
|
@ -567,7 +567,7 @@ def loadTexture(filename,size=None):
|
||||||
|
|
||||||
img.setValue(size, numcomponents, bytes)
|
img.setValue(size, numcomponents, bytes)
|
||||||
except:
|
except:
|
||||||
print "Draft: unable to load texture"
|
print("Draft: unable to load texture")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return img
|
return img
|
||||||
|
@ -757,9 +757,9 @@ def makeWire(pointslist,closed=False,placement=None,face=True,support=None):
|
||||||
closed = True
|
closed = True
|
||||||
pointslist = nlist
|
pointslist = nlist
|
||||||
if len(pointslist) == 0:
|
if len(pointslist) == 0:
|
||||||
print "Invalid input points: ",pointslist
|
print("Invalid input points: ",pointslist)
|
||||||
#print pointslist
|
#print(pointslist)
|
||||||
#print closed
|
#print(closed)
|
||||||
if placement: typecheck([(placement,FreeCAD.Placement)], "makeWire")
|
if placement: typecheck([(placement,FreeCAD.Placement)], "makeWire")
|
||||||
if len(pointslist) == 2: fname = "Line"
|
if len(pointslist) == 2: fname = "Line"
|
||||||
else: fname = "DWire"
|
else: fname = "DWire"
|
||||||
|
@ -986,7 +986,7 @@ def makeCopy(obj,force=None,reparent=False):
|
||||||
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature",getRealName(obj.Name))
|
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature",getRealName(obj.Name))
|
||||||
newobj.Shape = obj.Shape
|
newobj.Shape = obj.Shape
|
||||||
else:
|
else:
|
||||||
print "Error: Object type cannot be copied"
|
print("Error: Object type cannot be copied")
|
||||||
return None
|
return None
|
||||||
for p in obj.PropertiesList:
|
for p in obj.PropertiesList:
|
||||||
if not p in ["Proxy"]:
|
if not p in ["Proxy"]:
|
||||||
|
@ -1233,7 +1233,7 @@ def move(objectslist,vector,copy=False,arch=True):
|
||||||
newobj.End = obj.End.add(vector)
|
newobj.End = obj.End.add(vector)
|
||||||
newobj.Dimline = obj.Dimline.add(vector)
|
newobj.Dimline = obj.Dimline.add(vector)
|
||||||
else:
|
else:
|
||||||
if copy: print "Mesh copy not supported at the moment" # TODO
|
if copy: print("Mesh copy not supported at the moment") # TODO
|
||||||
newobj = obj
|
newobj = obj
|
||||||
if "Placement" in obj.PropertiesList:
|
if "Placement" in obj.PropertiesList:
|
||||||
pla = obj.Placement
|
pla = obj.Placement
|
||||||
|
@ -1273,7 +1273,7 @@ def array(objectslist,arg1,arg2,arg3,arg4=None):
|
||||||
def polarArray(objectslist,center,angle,num):
|
def polarArray(objectslist,center,angle,num):
|
||||||
typecheck([(center,Vector), (num,int)], "polarArray")
|
typecheck([(center,Vector), (num,int)], "polarArray")
|
||||||
if not isinstance(objectslist,list): objectslist = [objectslist]
|
if not isinstance(objectslist,list): objectslist = [objectslist]
|
||||||
fraction = angle/num
|
fraction = float(angle)/num
|
||||||
for i in range(num):
|
for i in range(num):
|
||||||
currangle = fraction + (i*fraction)
|
currangle = fraction + (i*fraction)
|
||||||
rotate(objectslist,currangle,center,copy=True)
|
rotate(objectslist,currangle,center,copy=True)
|
||||||
|
@ -1396,7 +1396,7 @@ def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy
|
||||||
elif getType(obj) == "Wire":
|
elif getType(obj) == "Wire":
|
||||||
p = []
|
p = []
|
||||||
for v in sh.Vertexes: p.append(v.Point)
|
for v in sh.Vertexes: p.append(v.Point)
|
||||||
print p
|
#print(p)
|
||||||
newobj.Points = p
|
newobj.Points = p
|
||||||
elif getType(obj) == "BSpline":
|
elif getType(obj) == "BSpline":
|
||||||
p = []
|
p = []
|
||||||
|
@ -1451,7 +1451,7 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
|
||||||
|
|
||||||
if getType(obj) in ["Sketch","Part"]:
|
if getType(obj) in ["Sketch","Part"]:
|
||||||
copy = True
|
copy = True
|
||||||
print "the offset tool is currently unable to offset a non-Draft object directly - Creating a copy"
|
print("the offset tool is currently unable to offset a non-Draft object directly - Creating a copy")
|
||||||
|
|
||||||
def getRect(p,obj):
|
def getRect(p,obj):
|
||||||
"returns length,heigh,placement"
|
"returns length,heigh,placement"
|
||||||
|
@ -1561,7 +1561,7 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
|
||||||
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Offset")
|
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Offset")
|
||||||
newobj.Shape = newwire
|
newobj.Shape = newwire
|
||||||
else:
|
else:
|
||||||
print "Unable to create an offset"
|
print("Unable to create an offset")
|
||||||
if newobj:
|
if newobj:
|
||||||
formatObject(newobj,obj)
|
formatObject(newobj,obj)
|
||||||
else:
|
else:
|
||||||
|
@ -1574,9 +1574,9 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
|
||||||
obj.Tool = None
|
obj.Tool = None
|
||||||
obj.Points = p
|
obj.Points = p
|
||||||
elif getType(obj) == "BSpline":
|
elif getType(obj) == "BSpline":
|
||||||
#print delta
|
#print(delta)
|
||||||
obj.Points = delta
|
obj.Points = delta
|
||||||
#print "done"
|
#print("done")
|
||||||
elif getType(obj) == "Rectangle":
|
elif getType(obj) == "Rectangle":
|
||||||
length,height,plac = getRect(p,obj)
|
length,height,plac = getRect(p,obj)
|
||||||
obj.Placement = plac
|
obj.Placement = plac
|
||||||
|
@ -1587,7 +1587,7 @@ def offset(obj,delta,copy=False,bind=False,sym=False,occ=False):
|
||||||
elif getType(obj) == "Polygon":
|
elif getType(obj) == "Polygon":
|
||||||
obj.Radius = getRadius(obj,delta)
|
obj.Radius = getRadius(obj,delta)
|
||||||
elif getType(obj) == 'Part':
|
elif getType(obj) == 'Part':
|
||||||
print "unsupported object" # TODO
|
print("unsupported object") # TODO
|
||||||
newobj = obj
|
newobj = obj
|
||||||
if copy and getParam("selectBaseObjects",False):
|
if copy and getParam("selectBaseObjects",False):
|
||||||
select(newobj)
|
select(newobj)
|
||||||
|
@ -1676,7 +1676,7 @@ def getDXF(obj,direction=None):
|
||||||
result += Drawing.projectToDXF(obj.Shape,direction)
|
result += Drawing.projectToDXF(obj.Shape,direction)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "Draft.getDXF: Unsupported object: ",obj.Label
|
print("Draft.getDXF: Unsupported object: ",obj.Label)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -1689,8 +1689,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
scale parameter allows to scale linewidths down, so they are resolution-independant.'''
|
scale parameter allows to scale linewidths down, so they are resolution-independant.'''
|
||||||
import Part, DraftGeomUtils
|
import Part, DraftGeomUtils
|
||||||
svg = ""
|
svg = ""
|
||||||
linewidth = linewidth/scale
|
linewidth = float(linewidth)/scale
|
||||||
fontsize = (fontsize/scale)/2
|
fontsize = (float(fontsize)/scale)/2
|
||||||
pointratio = .75 # the number of times the dots are smaller than the arrow size
|
pointratio = .75 # the number of times the dots are smaller than the arrow size
|
||||||
plane = None
|
plane = None
|
||||||
if direction:
|
if direction:
|
||||||
|
@ -1770,7 +1770,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
try:
|
try:
|
||||||
bspline=bspline.approximateBSpline(0.05,20, 3,'C0')
|
bspline=bspline.approximateBSpline(0.05,20, 3,'C0')
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
print "Debug: unable to approximate bspline"
|
print("Debug: unable to approximate bspline")
|
||||||
if bspline.Degree <= 3 and not bspline.isRational():
|
if bspline.Degree <= 3 and not bspline.isRational():
|
||||||
for bezierseg in bspline.toBezier():
|
for bezierseg in bspline.toBezier():
|
||||||
if bezierseg.Degree>3: #should not happen
|
if bezierseg.Degree>3: #should not happen
|
||||||
|
@ -1785,7 +1785,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
v = getProj(pole)
|
v = getProj(pole)
|
||||||
svg += str(v.x) +' '+ str(v.y) + ' '
|
svg += str(v.x) +' '+ str(v.y) + ' '
|
||||||
else:
|
else:
|
||||||
print "Debug: one edge (hash ",e.hashCode(),") has been discretized with parameter 0.1"
|
print("Debug: one edge (hash ",e.hashCode(),") has been discretized with parameter 0.1")
|
||||||
for linepoint in bspline.discretize(0.1)[1:]:
|
for linepoint in bspline.discretize(0.1)[1:]:
|
||||||
v = getProj(linepoint)
|
v = getProj(linepoint)
|
||||||
svg += 'L '+ str(v.x) +' '+ str(v.y) + ' '
|
svg += 'L '+ str(v.x) +' '+ str(v.y) + ' '
|
||||||
|
@ -1841,7 +1841,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
svg += 'style="stroke-miterlimit:4;stroke-dasharray:none" '
|
svg += 'style="stroke-miterlimit:4;stroke-dasharray:none" '
|
||||||
svg += 'd="M 0 0 L 4 1 L 4 -1 Z"/>\n'
|
svg += 'd="M 0 0 L 4 1 L 4 -1 Z"/>\n'
|
||||||
else:
|
else:
|
||||||
print "getSVG: arrow type not implemented"
|
print("getSVG: arrow type not implemented")
|
||||||
return svg
|
return svg
|
||||||
|
|
||||||
def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center",flip=True):
|
def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center",flip=True):
|
||||||
|
@ -1898,8 +1898,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
if obj.ViewObject.Proxy:
|
if obj.ViewObject.Proxy:
|
||||||
if hasattr(obj.ViewObject.Proxy,"p1"):
|
if hasattr(obj.ViewObject.Proxy,"p1"):
|
||||||
prx = obj.ViewObject.Proxy
|
prx = obj.ViewObject.Proxy
|
||||||
ts = (len(prx.string)*obj.ViewObject.FontSize.Value)/4
|
ts = (len(prx.string)*obj.ViewObject.FontSize.Value)/4.0
|
||||||
rm = ((prx.p3.sub(prx.p2)).Length/2)-ts
|
rm = ((prx.p3.sub(prx.p2)).Length/2.0)-ts
|
||||||
p2a = getProj(prx.p2.add(DraftVecUtils.scaleTo(prx.p3.sub(prx.p2),rm)))
|
p2a = getProj(prx.p2.add(DraftVecUtils.scaleTo(prx.p3.sub(prx.p2),rm)))
|
||||||
p2b = getProj(prx.p3.add(DraftVecUtils.scaleTo(prx.p2.sub(prx.p3),rm)))
|
p2b = getProj(prx.p3.add(DraftVecUtils.scaleTo(prx.p2.sub(prx.p3),rm)))
|
||||||
p1 = getProj(prx.p1)
|
p1 = getProj(prx.p1)
|
||||||
|
@ -1927,7 +1927,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
svg += 'L '+str(p4.x)+' '+str(p4.y)+'" '
|
svg += 'L '+str(p4.x)+' '+str(p4.y)+'" '
|
||||||
else:
|
else:
|
||||||
tangle = 0
|
tangle = 0
|
||||||
tbase = tbase.add(Vector(0,-2/scale,0))
|
tbase = tbase.add(Vector(0,-2.0/scale,0))
|
||||||
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
|
||||||
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
|
||||||
svg += 'L '+str(p2a.x)+' '+str(p2a.y)+' '
|
svg += 'L '+str(p2a.x)+' '+str(p2a.y)+' '
|
||||||
|
@ -1993,14 +1993,14 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
|
|
||||||
# drawing text
|
# drawing text
|
||||||
if obj.ViewObject.DisplayMode == "2D":
|
if obj.ViewObject.DisplayMode == "2D":
|
||||||
t = prx.circle.tangentAt(prx.circle.FirstParameter+(prx.circle.LastParameter-prx.circle.FirstParameter)/2)
|
t = prx.circle.tangentAt(prx.circle.FirstParameter+(prx.circle.LastParameter-prx.circle.FirstParameter)/2.0)
|
||||||
t = getProj(t)
|
t = getProj(t)
|
||||||
tangle = DraftVecUtils.angle(t)
|
tangle = DraftVecUtils.angle(t)
|
||||||
if (tangle <= -math.pi/2) or (tangle > math.pi/2):
|
if (tangle <= -math.pi/2) or (tangle > math.pi/2):
|
||||||
tangle = tangle + math.pi
|
tangle = tangle + math.pi
|
||||||
tbase = getProj(prx.circle.valueAt(prx.circle.FirstParameter+(prx.circle.LastParameter-prx.circle.FirstParameter)/2))
|
tbase = getProj(prx.circle.valueAt(prx.circle.FirstParameter+(prx.circle.LastParameter-prx.circle.FirstParameter)/2.0))
|
||||||
tbase = tbase.add(DraftVecUtils.rotate(Vector(0,2/scale,0),tangle))
|
tbase = tbase.add(DraftVecUtils.rotate(Vector(0,2.0/scale,0),tangle))
|
||||||
print tbase
|
#print(tbase)
|
||||||
else:
|
else:
|
||||||
tangle = 0
|
tangle = 0
|
||||||
tbase = getProj(prx.tbase)
|
tbase = getProj(prx.tbase)
|
||||||
|
@ -2011,7 +2011,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
n = obj.ViewObject.FontName
|
n = obj.ViewObject.FontName
|
||||||
a = obj.ViewObject.Rotation.getValueAs("rad")
|
a = obj.ViewObject.Rotation.getValueAs("rad")
|
||||||
t = obj.LabelText
|
t = obj.LabelText
|
||||||
l = obj.ViewObject.LineSpacing/2
|
l = obj.ViewObject.LineSpacing/2.0
|
||||||
j = obj.ViewObject.Justification
|
j = obj.ViewObject.Justification
|
||||||
svg += getText(stroke,fontsize,n,a,getProj(obj.Position),t,l,j)
|
svg += getText(stroke,fontsize,n,a,getProj(obj.Position),t,l,j)
|
||||||
|
|
||||||
|
@ -2037,7 +2037,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
svg += 'style="text-anchor:middle;'
|
svg += 'style="text-anchor:middle;'
|
||||||
svg += 'text-align:center;'
|
svg += 'text-align:center;'
|
||||||
svg += 'font-family: sans;" '
|
svg += 'font-family: sans;" '
|
||||||
svg += 'transform="translate(' + str(center.x+rad/4) + ',' + str(center.y-rad/3) + ') '
|
svg += 'transform="translate(' + str(center.x+rad/4.0) + ',' + str(center.y-rad/3.0) + ') '
|
||||||
svg += 'scale(1,-1)"> '
|
svg += 'scale(1,-1)"> '
|
||||||
svg += '<tspan>' + obj.ViewObject.Proxy.getNumber(n) + '</tspan>\n'
|
svg += '<tspan>' + obj.ViewObject.Proxy.getNumber(n) + '</tspan>\n'
|
||||||
svg += '</text>\n'
|
svg += '</text>\n'
|
||||||
|
@ -2054,7 +2054,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||||
f1 = fontsize*scale
|
f1 = fontsize*scale
|
||||||
p2 = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
|
p2 = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
|
||||||
p1 = p2.add(FreeCAD.Vector(obj.ViewObject.Proxy.header.translation.getValue().getValue()))
|
p1 = p2.add(FreeCAD.Vector(obj.ViewObject.Proxy.header.translation.getValue().getValue()))
|
||||||
l = obj.ViewObject.LineSpacing/2
|
l = obj.ViewObject.LineSpacing/2.0
|
||||||
j = obj.ViewObject.TextAlign
|
j = obj.ViewObject.TextAlign
|
||||||
svg += getText(c,f1,n,a,getProj(p1),t1,l,j,flip=False)
|
svg += getText(c,f1,n,a,getProj(p1),t1,l,j,flip=False)
|
||||||
if t2:
|
if t2:
|
||||||
|
@ -2115,7 +2115,7 @@ def getrgb(color,testbw=True):
|
||||||
col = "#"+r+g+b
|
col = "#"+r+g+b
|
||||||
if testbw:
|
if testbw:
|
||||||
if col == "#ffffff":
|
if col == "#ffffff":
|
||||||
#print getParam('SvgLinesBlack')
|
#print(getParam('SvgLinesBlack'))
|
||||||
if getParam('SvgLinesBlack',True):
|
if getParam('SvgLinesBlack',True):
|
||||||
col = "#000000"
|
col = "#000000"
|
||||||
return col
|
return col
|
||||||
|
@ -2150,7 +2150,7 @@ def makeDrawingView(obj,page,lwmod=None,tmod=None):
|
||||||
if lwmod: viewobj.LineweightModifier = lwmod
|
if lwmod: viewobj.LineweightModifier = lwmod
|
||||||
if tmod: viewobj.TextModifier = tmod
|
if tmod: viewobj.TextModifier = tmod
|
||||||
if hasattr(obj.ViewObject,"Pattern"):
|
if hasattr(obj.ViewObject,"Pattern"):
|
||||||
if str(obj.ViewObject.Pattern) in svgpatterns().keys():
|
if str(obj.ViewObject.Pattern) in list(svgpatterns().keys()):
|
||||||
viewobj.FillStyle = str(obj.ViewObject.Pattern)
|
viewobj.FillStyle = str(obj.ViewObject.Pattern)
|
||||||
if hasattr(obj.ViewObject,"DrawStyle"):
|
if hasattr(obj.ViewObject,"DrawStyle"):
|
||||||
viewobj.LineStyle = obj.ViewObject.DrawStyle
|
viewobj.LineStyle = obj.ViewObject.DrawStyle
|
||||||
|
@ -2203,7 +2203,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,delete=False,name="S
|
||||||
ok = False
|
ok = False
|
||||||
tp = getType(obj)
|
tp = getType(obj)
|
||||||
if tp == "BSpline":
|
if tp == "BSpline":
|
||||||
print "makeSketch: BSplines not supported"
|
print("makeSketch: BSplines not supported")
|
||||||
elif tp == "Circle":
|
elif tp == "Circle":
|
||||||
g = (DraftGeomUtils.geom(obj.Shape.Edges[0],nobj.Placement))
|
g = (DraftGeomUtils.geom(obj.Shape.Edges[0],nobj.Placement))
|
||||||
nobj.addGeometry(g)
|
nobj.addGeometry(g)
|
||||||
|
@ -2237,7 +2237,7 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,delete=False,name="S
|
||||||
nobj.addGeometry(edge.Curve)
|
nobj.addGeometry(edge.Curve)
|
||||||
if autoconstraints:
|
if autoconstraints:
|
||||||
last = nobj.GeometryCount
|
last = nobj.GeometryCount
|
||||||
segs = range(last-len(obj.Shape.Edges),last-1)
|
segs = list(range(last-len(obj.Shape.Edges),last-1))
|
||||||
for seg in segs:
|
for seg in segs:
|
||||||
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
|
nobj.addConstraint(Constraint("Coincident",seg,EndPoint,seg+1,StartPoint))
|
||||||
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
|
if DraftGeomUtils.isAligned(nobj.Geometry[seg],"x"):
|
||||||
|
@ -2249,11 +2249,11 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None,delete=False,name="S
|
||||||
ok = True
|
ok = True
|
||||||
if (not ok) and obj.isDerivedFrom("Part::Feature"):
|
if (not ok) and obj.isDerivedFrom("Part::Feature"):
|
||||||
if not DraftGeomUtils.isPlanar(obj.Shape):
|
if not DraftGeomUtils.isPlanar(obj.Shape):
|
||||||
print "Error: The given object is not planar and cannot be converted into a sketch."
|
print("Error: The given object is not planar and cannot be converted into a sketch.")
|
||||||
return None
|
return None
|
||||||
for e in obj.Shape.Edges:
|
for e in obj.Shape.Edges:
|
||||||
if DraftGeomUtils.geomType(e) == "BSplineCurve":
|
if DraftGeomUtils.geomType(e) == "BSplineCurve":
|
||||||
print "Error: One of the selected object contains BSplines, unable to convert"
|
print("Error: One of the selected object contains BSplines, unable to convert")
|
||||||
return None
|
return None
|
||||||
if not addTo:
|
if not addTo:
|
||||||
nobj.Placement.Rotation = DraftGeomUtils.calculatePlacement(obj.Shape).Rotation
|
nobj.Placement.Rotation = DraftGeomUtils.calculatePlacement(obj.Shape).Rotation
|
||||||
|
@ -2353,10 +2353,10 @@ def heal(objlist=None,delete=True,reparent=True):
|
||||||
|
|
||||||
if not objlist:
|
if not objlist:
|
||||||
objlist = FreeCAD.ActiveDocument.Objects
|
objlist = FreeCAD.ActiveDocument.Objects
|
||||||
print "Automatic mode: Healing whole document..."
|
print("Automatic mode: Healing whole document...")
|
||||||
auto = True
|
auto = True
|
||||||
else:
|
else:
|
||||||
print "Manual mode: Force-healing selected objects..."
|
print("Manual mode: Force-healing selected objects...")
|
||||||
|
|
||||||
if not isinstance(objlist,list):
|
if not isinstance(objlist,list):
|
||||||
objlist = [objlist]
|
objlist = [objlist]
|
||||||
|
@ -2377,34 +2377,34 @@ def heal(objlist=None,delete=True,reparent=True):
|
||||||
dellist.append(obj.Name)
|
dellist.append(obj.Name)
|
||||||
props = obj.PropertiesList
|
props = obj.PropertiesList
|
||||||
if ("Dimline" in props) and ("Start" in props):
|
if ("Dimline" in props) and ("Start" in props):
|
||||||
print "Healing " + obj.Name + " of type Dimension"
|
print("Healing " + obj.Name + " of type Dimension")
|
||||||
nobj = makeCopy(obj,force="Dimension",reparent=reparent)
|
nobj = makeCopy(obj,force="Dimension",reparent=reparent)
|
||||||
elif ("Height" in props) and ("Length" in props):
|
elif ("Height" in props) and ("Length" in props):
|
||||||
print "Healing " + obj.Name + " of type Rectangle"
|
print("Healing " + obj.Name + " of type Rectangle")
|
||||||
nobj = makeCopy(obj,force="Rectangle",reparent=reparent)
|
nobj = makeCopy(obj,force="Rectangle",reparent=reparent)
|
||||||
elif ("Points" in props) and ("Closed" in props):
|
elif ("Points" in props) and ("Closed" in props):
|
||||||
if "BSpline" in obj.Name:
|
if "BSpline" in obj.Name:
|
||||||
print "Healing " + obj.Name + " of type BSpline"
|
print("Healing " + obj.Name + " of type BSpline")
|
||||||
nobj = makeCopy(obj,force="BSpline",reparent=reparent)
|
nobj = makeCopy(obj,force="BSpline",reparent=reparent)
|
||||||
else:
|
else:
|
||||||
print "Healing " + obj.Name + " of type Wire"
|
print("Healing " + obj.Name + " of type Wire")
|
||||||
nobj = makeCopy(obj,force="Wire",reparent=reparent)
|
nobj = makeCopy(obj,force="Wire",reparent=reparent)
|
||||||
elif ("Radius" in props) and ("FirstAngle" in props):
|
elif ("Radius" in props) and ("FirstAngle" in props):
|
||||||
print "Healing " + obj.Name + " of type Circle"
|
print("Healing " + obj.Name + " of type Circle")
|
||||||
nobj = makeCopy(obj,force="Circle",reparent=reparent)
|
nobj = makeCopy(obj,force="Circle",reparent=reparent)
|
||||||
elif ("DrawMode" in props) and ("FacesNumber" in props):
|
elif ("DrawMode" in props) and ("FacesNumber" in props):
|
||||||
print "Healing " + obj.Name + " of type Polygon"
|
print("Healing " + obj.Name + " of type Polygon")
|
||||||
nobj = makeCopy(obj,force="Polygon",reparent=reparent)
|
nobj = makeCopy(obj,force="Polygon",reparent=reparent)
|
||||||
elif ("FillStyle" in props) and ("FontSize" in props):
|
elif ("FillStyle" in props) and ("FontSize" in props):
|
||||||
nobj = makeCopy(obj,force="DrawingView",reparent=reparent)
|
nobj = makeCopy(obj,force="DrawingView",reparent=reparent)
|
||||||
else:
|
else:
|
||||||
dellist.pop()
|
dellist.pop()
|
||||||
print "Object " + obj.Name + " is not healable"
|
print("Object " + obj.Name + " is not healable")
|
||||||
|
|
||||||
if not got:
|
if not got:
|
||||||
print "No object seems to need healing"
|
print("No object seems to need healing")
|
||||||
else:
|
else:
|
||||||
print "Healed ",len(dellist)," objects"
|
print("Healed ",len(dellist)," objects")
|
||||||
|
|
||||||
if dellist and delete:
|
if dellist and delete:
|
||||||
for n in dellist:
|
for n in dellist:
|
||||||
|
@ -2620,7 +2620,7 @@ def upgrade(objects,delete=False,force=None):
|
||||||
edges.append(e)
|
edges.append(e)
|
||||||
try:
|
try:
|
||||||
nedges = DraftGeomUtils.sortEdges(edges[:])
|
nedges = DraftGeomUtils.sortEdges(edges[:])
|
||||||
# for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point
|
# for e in nedges: print("debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point)
|
||||||
w = Part.Wire(nedges)
|
w = Part.Wire(nedges)
|
||||||
except Part.OCCError:
|
except Part.OCCError:
|
||||||
return None
|
return None
|
||||||
|
@ -2671,8 +2671,8 @@ def upgrade(objects,delete=False,force=None):
|
||||||
meshes.append(ob)
|
meshes.append(ob)
|
||||||
objects = parts
|
objects = parts
|
||||||
|
|
||||||
#print "objects:",objects," edges:",edges," wires:",wires," openwires:",openwires," faces:",faces
|
#print("objects:",objects," edges:",edges," wires:",wires," openwires:",openwires," faces:",faces)
|
||||||
#print "groups:",groups," curves:",curves," facewires:",facewires, "loneedges:", loneedges
|
#print("groups:",groups," curves:",curves," facewires:",facewires, "loneedges:", loneedges)
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
if force in ["makeCompound","closeGroupWires","makeSolid","closeWire","turnToParts","makeFusion",
|
if force in ["makeCompound","closeGroupWires","makeSolid","closeWire","turnToParts","makeFusion",
|
||||||
|
@ -2928,7 +2928,7 @@ def downgrade(objects,delete=False,force=None):
|
||||||
# we have one multi-solids compound object: extract its solids
|
# we have one multi-solids compound object: extract its solids
|
||||||
elif (len(objects) == 1) and (getType(objects[0]) == "Part") and (len(solids) > 1):
|
elif (len(objects) == 1) and (getType(objects[0]) == "Part") and (len(solids) > 1):
|
||||||
result = splitCompounds(objects)
|
result = splitCompounds(objects)
|
||||||
print result
|
#print(result)
|
||||||
if result: msg(translate("draft", "Found 1 multi-solids compound: exploding it\n"))
|
if result: msg(translate("draft", "Found 1 multi-solids compound: exploding it\n"))
|
||||||
|
|
||||||
# special case, we have one parametric object: we "de-parametrize" it
|
# special case, we have one parametric object: we "de-parametrize" it
|
||||||
|
@ -3015,7 +3015,7 @@ class _ViewProviderDraft:
|
||||||
"Draft","Defines a hatch pattern")
|
"Draft","Defines a hatch pattern")
|
||||||
vobj.addProperty("App::PropertyFloat","PatternSize",
|
vobj.addProperty("App::PropertyFloat","PatternSize",
|
||||||
"Draft","Sets the size of the pattern")
|
"Draft","Sets the size of the pattern")
|
||||||
vobj.Pattern = ["None"]+svgpatterns().keys()
|
vobj.Pattern = ["None"]+list(svgpatterns().keys())
|
||||||
vobj.PatternSize = 1
|
vobj.PatternSize = 1
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
@ -3054,7 +3054,7 @@ class _ViewProviderDraft:
|
||||||
path = vobj.TextureImage
|
path = vobj.TextureImage
|
||||||
if not path:
|
if not path:
|
||||||
if hasattr(vobj,"Pattern"):
|
if hasattr(vobj,"Pattern"):
|
||||||
if str(vobj.Pattern) in svgpatterns().keys():
|
if str(vobj.Pattern) in list(svgpatterns().keys()):
|
||||||
path = svgpatterns()[vobj.Pattern][1]
|
path = svgpatterns()[vobj.Pattern][1]
|
||||||
if path and vobj.RootNode:
|
if path and vobj.RootNode:
|
||||||
if vobj.RootNode.getChildren().getLength() > 2:
|
if vobj.RootNode.getChildren().getLength() > 2:
|
||||||
|
@ -3400,8 +3400,8 @@ class _ViewProviderDimension(_ViewProviderDraft):
|
||||||
# set the lines
|
# set the lines
|
||||||
if m == "3D":
|
if m == "3D":
|
||||||
# calculate the spacing of the text
|
# calculate the spacing of the text
|
||||||
textsize = (len(self.string)*obj.ViewObject.FontSize.Value)/4
|
textsize = (len(self.string)*obj.ViewObject.FontSize.Value)/4.0
|
||||||
spacing = ((self.p3.sub(self.p2)).Length/2) - textsize
|
spacing = ((self.p3.sub(self.p2)).Length/2.0) - textsize
|
||||||
self.p2a = self.p2.add(DraftVecUtils.scaleTo(self.p3.sub(self.p2),spacing))
|
self.p2a = self.p2.add(DraftVecUtils.scaleTo(self.p3.sub(self.p2),spacing))
|
||||||
self.p2b = self.p3.add(DraftVecUtils.scaleTo(self.p2.sub(self.p3),spacing))
|
self.p2b = self.p3.add(DraftVecUtils.scaleTo(self.p2.sub(self.p3),spacing))
|
||||||
self.coords.point.setValues([[self.p1.x,self.p1.y,self.p1.z],
|
self.coords.point.setValues([[self.p1.x,self.p1.y,self.p1.z],
|
||||||
|
@ -3687,7 +3687,7 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
|
||||||
# set the arc
|
# set the arc
|
||||||
if m == "3D":
|
if m == "3D":
|
||||||
# calculate the spacing of the text
|
# calculate the spacing of the text
|
||||||
spacing = (len(self.string)*obj.ViewObject.FontSize.Value)/8
|
spacing = (len(self.string)*obj.ViewObject.FontSize.Value)/8.0
|
||||||
pts1 = []
|
pts1 = []
|
||||||
cut = None
|
cut = None
|
||||||
pts2 = []
|
pts2 = []
|
||||||
|
@ -3704,7 +3704,7 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
|
||||||
self.coords.point.setValues(pts1+pts2)
|
self.coords.point.setValues(pts1+pts2)
|
||||||
i1 = len(pts1)
|
i1 = len(pts1)
|
||||||
i2 = i1+len(pts2)
|
i2 = i1+len(pts2)
|
||||||
self.arc.coordIndex.setValues(0,len(pts1)+len(pts2)+1,range(len(pts1))+[-1]+range(i1,i2))
|
self.arc.coordIndex.setValues(0,len(pts1)+len(pts2)+1,list(range(len(pts1)))+[-1]+list(range(i1,i2)))
|
||||||
if (len(pts1) >= 3) and (len(pts2) >= 3):
|
if (len(pts1) >= 3) and (len(pts2) >= 3):
|
||||||
self.circle1 = Part.Arc(Vector(pts1[0][0],pts1[0][1],pts1[0][2]),Vector(pts1[1][0],pts1[1][1],pts1[1][2]),Vector(pts1[-1][0],pts1[-1][1],pts1[-1][2])).toShape()
|
self.circle1 = Part.Arc(Vector(pts1[0][0],pts1[0][1],pts1[0][2]),Vector(pts1[1][0],pts1[1][1],pts1[1][2]),Vector(pts1[-1][0],pts1[-1][1],pts1[-1][2])).toShape()
|
||||||
self.circle2 = Part.Arc(Vector(pts2[0][0],pts2[0][1],pts2[0][2]),Vector(pts2[1][0],pts2[1][1],pts2[1][2]),Vector(pts2[-1][0],pts2[-1][1],pts2[-1][2])).toShape()
|
self.circle2 = Part.Arc(Vector(pts2[0][0],pts2[0][1],pts2[0][2]),Vector(pts2[1][0],pts2[1][1],pts2[1][2]),Vector(pts2[-1][0],pts2[-1][1],pts2[-1][2])).toShape()
|
||||||
|
@ -3714,7 +3714,7 @@ class _ViewProviderAngularDimension(_ViewProviderDraft):
|
||||||
p = self.circle.valueAt(self.circle.FirstParameter+((self.circle.LastParameter-self.circle.FirstParameter)/arcsegs)*i)
|
p = self.circle.valueAt(self.circle.FirstParameter+((self.circle.LastParameter-self.circle.FirstParameter)/arcsegs)*i)
|
||||||
pts.append([p.x,p.y,p.z])
|
pts.append([p.x,p.y,p.z])
|
||||||
self.coords.point.setValues(pts)
|
self.coords.point.setValues(pts)
|
||||||
self.arc.coordIndex.setValues(0,arcsegs+1,range(arcsegs+1))
|
self.arc.coordIndex.setValues(0,arcsegs+1,list(range(arcsegs+1)))
|
||||||
|
|
||||||
# set the arrow coords and rotation
|
# set the arrow coords and rotation
|
||||||
self.trans1.translation.setValue((self.p2.x,self.p2.y,self.p2.z))
|
self.trans1.translation.setValue((self.p2.x,self.p2.y,self.p2.z))
|
||||||
|
@ -4151,7 +4151,7 @@ class _Polygon(_DraftObject):
|
||||||
if obj.DrawMode == 'inscribed':
|
if obj.DrawMode == 'inscribed':
|
||||||
delta = obj.Radius.Value
|
delta = obj.Radius.Value
|
||||||
else:
|
else:
|
||||||
delta = obj.Radius.Value/math.cos(angle/2)
|
delta = obj.Radius.Value/math.cos(angle/2.0)
|
||||||
pts = [Vector(delta,0,0)]
|
pts = [Vector(delta,0,0)]
|
||||||
for i in range(obj.FacesNumber-1):
|
for i in range(obj.FacesNumber-1):
|
||||||
ang = (i+1)*angle
|
ang = (i+1)*angle
|
||||||
|
@ -4187,7 +4187,7 @@ class _DrawingView(_DraftObject):
|
||||||
obj.addProperty("App::PropertyLink","Source","Base","The linked object")
|
obj.addProperty("App::PropertyLink","Source","Base","The linked object")
|
||||||
obj.addProperty("App::PropertyEnumeration","FillStyle","View Style","Shape Fill Style")
|
obj.addProperty("App::PropertyEnumeration","FillStyle","View Style","Shape Fill Style")
|
||||||
obj.addProperty("App::PropertyEnumeration","LineStyle","View Style","Line Style")
|
obj.addProperty("App::PropertyEnumeration","LineStyle","View Style","Line Style")
|
||||||
obj.FillStyle = ['shape color'] + svgpatterns().keys()
|
obj.FillStyle = ['shape color'] + list(svgpatterns().keys())
|
||||||
obj.LineStyle = ['Solid','Dashed','Dotted','Dashdot']
|
obj.LineStyle = ['Solid','Dashed','Dotted','Dashdot']
|
||||||
obj.LineWidth = 0.35
|
obj.LineWidth = 0.35
|
||||||
obj.FontSize = 12
|
obj.FontSize = 12
|
||||||
|
@ -4313,7 +4313,7 @@ class _BezCurve(_DraftObject):
|
||||||
else:
|
else:
|
||||||
poles=[]
|
poles=[]
|
||||||
return [poles[x:x+fp.Degree] for x in \
|
return [poles[x:x+fp.Degree] for x in \
|
||||||
xrange(0, len(poles), (fp.Degree or 1))]
|
range(0, len(poles), (fp.Degree or 1))]
|
||||||
|
|
||||||
def resetcontinuity(self,fp):
|
def resetcontinuity(self,fp):
|
||||||
fp.Continuity = [0]*(len(self._segpoleslst(fp))-1+1*fp.Closed)
|
fp.Continuity = [0]*(len(self._segpoleslst(fp))-1+1*fp.Closed)
|
||||||
|
@ -4629,14 +4629,14 @@ class _Array(_DraftObject):
|
||||||
return Part.makeCompound(base)
|
return Part.makeCompound(base)
|
||||||
|
|
||||||
def polarArray(self,shape,center,angle,num,axis,axisvector):
|
def polarArray(self,shape,center,angle,num,axis,axisvector):
|
||||||
#print "angle ",angle," num ",num
|
#print("angle ",angle," num ",num)
|
||||||
import Part
|
import Part
|
||||||
if angle == 360:
|
if angle == 360:
|
||||||
fraction = angle/num
|
fraction = float(angle)/num
|
||||||
else:
|
else:
|
||||||
if num == 0:
|
if num == 0:
|
||||||
return shape
|
return shape
|
||||||
fraction = angle/(num-1)
|
fraction = float(angle)/(num-1)
|
||||||
base = [shape.copy()]
|
base = [shape.copy()]
|
||||||
for i in range(num-1):
|
for i in range(num-1):
|
||||||
currangle = fraction + (i*fraction)
|
currangle = fraction + (i*fraction)
|
||||||
|
@ -4783,7 +4783,7 @@ class _PathArray(_DraftObject):
|
||||||
stop = count
|
stop = count
|
||||||
else:
|
else:
|
||||||
stop = count - 1
|
stop = count - 1
|
||||||
step = cdist/stop
|
step = float(cdist)/stop
|
||||||
remain = 0
|
remain = 0
|
||||||
travel = step
|
travel = step
|
||||||
for i in range(1,stop):
|
for i in range(1,stop):
|
||||||
|
@ -5050,8 +5050,8 @@ class _Facebinder(_DraftObject):
|
||||||
try:
|
try:
|
||||||
fnum = int(f[1][4:])-1
|
fnum = int(f[1][4:])-1
|
||||||
faces.append(f[0].Shape.Faces[fnum])
|
faces.append(f[0].Shape.Faces[fnum])
|
||||||
except IndexError,Part.OCCError:
|
except(IndexError,Part.OCCError):
|
||||||
print "Draft: wrong face index"
|
print("Draft: wrong face index")
|
||||||
return
|
return
|
||||||
if not faces:
|
if not faces:
|
||||||
return
|
return
|
||||||
|
@ -5062,7 +5062,7 @@ class _Facebinder(_DraftObject):
|
||||||
sh = sh.fuse(f)
|
sh = sh.fuse(f)
|
||||||
sh = sh.removeSplitter()
|
sh = sh.removeSplitter()
|
||||||
except Part.OCCError:
|
except Part.OCCError:
|
||||||
print "Draft: error building facebinder"
|
print("Draft: error building facebinder")
|
||||||
return
|
return
|
||||||
obj.Shape = sh
|
obj.Shape = sh
|
||||||
obj.Placement = pl
|
obj.Placement = pl
|
||||||
|
|
|
@ -437,7 +437,7 @@ def findIntersection(edge1,edge2,infinite1=False,infinite2=False,ex1=False,ex2=F
|
||||||
|
|
||||||
return int
|
return int
|
||||||
else :
|
else :
|
||||||
print "DraftGeomUtils: Unsupported curve type: (" + str(edge1.Curve) + ", " + str(edge2.Curve) + ")"
|
print("DraftGeomUtils: Unsupported curve type: (" + str(edge1.Curve) + ", " + str(edge2.Curve) + ")")
|
||||||
|
|
||||||
def wiresIntersect(wire1,wire2):
|
def wiresIntersect(wire1,wire2):
|
||||||
"wiresIntersect(wire1,wire2): returns True if some of the edges of the wires are intersecting otherwise False"
|
"wiresIntersect(wire1,wire2): returns True if some of the edges of the wires are intersecting otherwise False"
|
||||||
|
@ -467,43 +467,43 @@ def pocket2d(shape,offset):
|
||||||
if not o.Wires:
|
if not o.Wires:
|
||||||
return []
|
return []
|
||||||
offsetWires = o.Wires
|
offsetWires = o.Wires
|
||||||
print "base offset wires:",offsetWires
|
print("base offset wires:",offsetWires)
|
||||||
if not innerWires:
|
if not innerWires:
|
||||||
return offsetWires
|
return offsetWires
|
||||||
for innerWire in innerWires:
|
for innerWire in innerWires:
|
||||||
i = innerWire.makeOffset(offset)
|
i = innerWire.makeOffset(offset)
|
||||||
if i.Wires:
|
if i.Wires:
|
||||||
print "offsetting island ",innerWire," : ",i.Wires
|
print("offsetting island ",innerWire," : ",i.Wires)
|
||||||
for w in i.Wires:
|
for w in i.Wires:
|
||||||
added = False
|
added = False
|
||||||
print "checking wire ",w
|
print("checking wire ",w)
|
||||||
k = range(len(offsetWires))
|
k = list(range(len(offsetWires)))
|
||||||
for j in k:
|
for j in k:
|
||||||
print "checking against existing wire ",j
|
print("checking against existing wire ",j)
|
||||||
ow = offsetWires[j]
|
ow = offsetWires[j]
|
||||||
if ow:
|
if ow:
|
||||||
if wiresIntersect(w,ow):
|
if wiresIntersect(w,ow):
|
||||||
print "intersect"
|
print("intersect")
|
||||||
f1 = Part.Face(ow)
|
f1 = Part.Face(ow)
|
||||||
f2 = Part.Face(w)
|
f2 = Part.Face(w)
|
||||||
f3 = f1.cut(f2)
|
f3 = f1.cut(f2)
|
||||||
print "made new wires: ",f3.Wires
|
print("made new wires: ",f3.Wires)
|
||||||
offsetWires[j] = f3.Wires[0]
|
offsetWires[j] = f3.Wires[0]
|
||||||
if len(f3.Wires) > 1:
|
if len(f3.Wires) > 1:
|
||||||
print "adding more"
|
print("adding more")
|
||||||
offsetWires.extend(f3.Wires[1:])
|
offsetWires.extend(f3.Wires[1:])
|
||||||
added = True
|
added = True
|
||||||
else:
|
else:
|
||||||
a = w.BoundBox
|
a = w.BoundBox
|
||||||
b = ow.BoundBox
|
b = ow.BoundBox
|
||||||
if (a.XMin <= b.XMin) and (a.YMin <= b.YMin) and (a.ZMin <= b.ZMin) and (a.XMax >= b.XMax) and (a.YMax >= b.YMax) and (a.ZMax >= b.ZMax):
|
if (a.XMin <= b.XMin) and (a.YMin <= b.YMin) and (a.ZMin <= b.ZMin) and (a.XMax >= b.XMax) and (a.YMax >= b.YMax) and (a.ZMax >= b.ZMax):
|
||||||
print "this wire is bigger than the outer wire"
|
print("this wire is bigger than the outer wire")
|
||||||
offsetWires[j] = None
|
offsetWires[j] = None
|
||||||
added = True
|
added = True
|
||||||
else:
|
else:
|
||||||
print "doesn't intersect"
|
print("doesn't intersect")
|
||||||
if not added:
|
if not added:
|
||||||
print "doesn't intersect with any other"
|
print("doesn't intersect with any other")
|
||||||
offsetWires.append(w)
|
offsetWires.append(w)
|
||||||
offsetWires = [o for o in offsetWires if o != None]
|
offsetWires = [o for o in offsetWires if o != None]
|
||||||
return offsetWires
|
return offsetWires
|
||||||
|
@ -530,7 +530,7 @@ def geom(edge,plac=FreeCAD.Placement()):
|
||||||
# direction check
|
# direction check
|
||||||
if edge.Curve.Axis.getAngle(normal) > 1:
|
if edge.Curve.Axis.getAngle(normal) > 1:
|
||||||
a1,a2 = a2,a1
|
a1,a2 = a2,a1
|
||||||
#print "creating sketch arc from ",cu, ", p1=",v1, " (",math.degrees(a1), "d) p2=",v2," (", math.degrees(a2),"d)"
|
#print("creating sketch arc from ",cu, ", p1=",v1, " (",math.degrees(a1), "d) p2=",v2," (", math.degrees(a2),"d)")
|
||||||
|
|
||||||
p= Part.ArcOfCircle(cu,a1,a2)
|
p= Part.ArcOfCircle(cu,a1,a2)
|
||||||
return p
|
return p
|
||||||
|
@ -617,7 +617,7 @@ def concatenate(shape):
|
||||||
wire=Part.Wire(edges)
|
wire=Part.Wire(edges)
|
||||||
face=Part.Face(wire)
|
face=Part.Face(wire)
|
||||||
except:
|
except:
|
||||||
print "DraftGeomUtils: Couldn't join faces into one"
|
print("DraftGeomUtils: Couldn't join faces into one")
|
||||||
return(shape)
|
return(shape)
|
||||||
else:
|
else:
|
||||||
if not wire.isClosed(): return(wire)
|
if not wire.isClosed(): return(wire)
|
||||||
|
@ -633,7 +633,7 @@ def getBoundary(shape):
|
||||||
for f in shape.Faces:
|
for f in shape.Faces:
|
||||||
for e in f.Edges:
|
for e in f.Edges:
|
||||||
hc= e.hashCode()
|
hc= e.hashCode()
|
||||||
if lut.has_key(hc): lut[hc]=lut[hc]+1
|
if hc in lut: lut[hc]=lut[hc]+1
|
||||||
else: lut[hc]=1
|
else: lut[hc]=1
|
||||||
# filter out the edges shared by more than one sub-face
|
# filter out the edges shared by more than one sub-face
|
||||||
bound=[]
|
bound=[]
|
||||||
|
@ -688,14 +688,14 @@ def sortEdgesNew(edges):
|
||||||
# in the sdict dictionary but not in the edict dictionary, and has
|
# in the sdict dictionary but not in the edict dictionary, and has
|
||||||
# only one edge ending there.
|
# only one edge ending there.
|
||||||
startedge = None
|
startedge = None
|
||||||
for v, se in sdict.iteritems():
|
for v, se in sdict.items():
|
||||||
if v not in edict and len (se) == 1:
|
if v not in edict and len (se) == 1:
|
||||||
startedge = se
|
startedge = se
|
||||||
break
|
break
|
||||||
# The above may not find a start vertex; if the start edge is reversed,
|
# The above may not find a start vertex; if the start edge is reversed,
|
||||||
# the start vertex will appear in edict (and not sdict).
|
# the start vertex will appear in edict (and not sdict).
|
||||||
if not startedge:
|
if not startedge:
|
||||||
for v, se in edict.iteritems():
|
for v, se in edict.xitems():
|
||||||
if v not in sdict and len (se) == 1:
|
if v not in sdict and len (se) == 1:
|
||||||
startedge = se
|
startedge = se
|
||||||
break
|
break
|
||||||
|
@ -709,7 +709,7 @@ def sortEdgesNew(edges):
|
||||||
# end check is simply the count of input elements (that works for closed
|
# end check is simply the count of input elements (that works for closed
|
||||||
# as well as open paths).
|
# as well as open paths).
|
||||||
ret = list()
|
ret = list()
|
||||||
for i in xrange(len(edges)):
|
for i in range(len(edges)):
|
||||||
try:
|
try:
|
||||||
eset = sdict[v]
|
eset = sdict[v]
|
||||||
e = eset.pop()
|
e = eset.pop()
|
||||||
|
@ -725,7 +725,7 @@ def sortEdgesNew(edges):
|
||||||
v = e.Vertexes[0]
|
v = e.Vertexes[0]
|
||||||
e.reverse()
|
e.reverse()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print "DraftGeomUtils.sortEdges failed"
|
print("DraftGeomUtils.sortEdges failed")
|
||||||
return sortEdgesOld(edges)
|
return sortEdgesOld(edges)
|
||||||
ret.append(e)
|
ret.append(e)
|
||||||
v = vpoint(v)
|
v = vpoint(v)
|
||||||
|
@ -739,7 +739,7 @@ def sortEdgesOld(lEdges, aVertex=None):
|
||||||
#has exactly two vertices (wmayer)
|
#has exactly two vertices (wmayer)
|
||||||
#for e in lEdges:
|
#for e in lEdges:
|
||||||
# if not isinstance(e.Curve,Part.Line):
|
# if not isinstance(e.Curve,Part.Line):
|
||||||
# print "Warning: sortedges cannot treat wired containing curves yet."
|
# print("Warning: sortedges cannot treat wired containing curves yet.")
|
||||||
# return lEdges
|
# return lEdges
|
||||||
|
|
||||||
def lookfor(aVertex, inEdges):
|
def lookfor(aVertex, inEdges):
|
||||||
|
@ -787,20 +787,20 @@ def sortEdgesOld(lEdges, aVertex=None):
|
||||||
olEdges = sortEdgesOld(lEdges, result[3].Vertexes[result[2]])
|
olEdges = sortEdgesOld(lEdges, result[3].Vertexes[result[2]])
|
||||||
return olEdges
|
return olEdges
|
||||||
# if the wire is closed there is no end so choose 1st Vertex
|
# if the wire is closed there is no end so choose 1st Vertex
|
||||||
# print "closed wire, starting from ",lEdges[0].Vertexes[0].Point
|
# print("closed wire, starting from ",lEdges[0].Vertexes[0].Point)
|
||||||
return sortEdgesOld(lEdges, lEdges[0].Vertexes[0])
|
return sortEdgesOld(lEdges, lEdges[0].Vertexes[0])
|
||||||
else :
|
else :
|
||||||
#print "looking ",aVertex.Point
|
#print("looking ",aVertex.Point)
|
||||||
result = lookfor(aVertex,lEdges)
|
result = lookfor(aVertex,lEdges)
|
||||||
if result[0] != 0 :
|
if result[0] != 0 :
|
||||||
del lEdges[result[1]]
|
del lEdges[result[1]]
|
||||||
next = sortEdgesOld(lEdges, result[3].Vertexes[-((-result[2])^1)])
|
next = sortEdgesOld(lEdges, result[3].Vertexes[-((-result[2])^1)])
|
||||||
#print "result ",result[3].Vertexes[0].Point," ",result[3].Vertexes[1].Point, " compared to ",aVertex.Point
|
#print("result ",result[3].Vertexes[0].Point," ",result[3].Vertexes[1].Point, " compared to ",aVertex.Point)
|
||||||
if aVertex.Point == result[3].Vertexes[0].Point:
|
if aVertex.Point == result[3].Vertexes[0].Point:
|
||||||
#print "keeping"
|
#print("keeping")
|
||||||
olEdges += [result[3]] + next
|
olEdges += [result[3]] + next
|
||||||
else:
|
else:
|
||||||
#print "inverting", result[3].Curve
|
#print("inverting", result[3].Curve)
|
||||||
if geomType(result[3]) == "Line":
|
if geomType(result[3]) == "Line":
|
||||||
newedge = Part.Line(aVertex.Point,result[3].Vertexes[0].Point).toShape()
|
newedge = Part.Line(aVertex.Point,result[3].Vertexes[0].Point).toShape()
|
||||||
olEdges += [newedge] + next
|
olEdges += [newedge] + next
|
||||||
|
@ -898,7 +898,7 @@ def findWires(edgeslist):
|
||||||
try:
|
try:
|
||||||
wi = Part.Wire(w)
|
wi = Part.Wire(w)
|
||||||
except:
|
except:
|
||||||
print "couldn't join some edges"
|
print("couldn't join some edges")
|
||||||
else:
|
else:
|
||||||
nwires.append(wi)
|
nwires.append(wi)
|
||||||
return nwires
|
return nwires
|
||||||
|
@ -911,7 +911,7 @@ def superWire(edgeslist,closed=False):
|
||||||
vd.scale(.5,.5,.5)
|
vd.scale(.5,.5,.5)
|
||||||
return v1.add(vd)
|
return v1.add(vd)
|
||||||
edges = sortEdges(edgeslist)
|
edges = sortEdges(edgeslist)
|
||||||
print edges
|
print(edges)
|
||||||
newedges = []
|
newedges = []
|
||||||
for i in range(len(edges)):
|
for i in range(len(edges)):
|
||||||
curr = edges[i]
|
curr = edges[i]
|
||||||
|
@ -929,7 +929,7 @@ def superWire(edgeslist,closed=False):
|
||||||
next = None
|
next = None
|
||||||
else:
|
else:
|
||||||
next = edges[i+1]
|
next = edges[i+1]
|
||||||
print i,prev,curr,next
|
print(i,prev,curr,next)
|
||||||
if prev:
|
if prev:
|
||||||
if curr.Vertexes[0].Point == prev.Vertexes[-1].Point:
|
if curr.Vertexes[0].Point == prev.Vertexes[-1].Point:
|
||||||
p1 = curr.Vertexes[0].Point
|
p1 = curr.Vertexes[0].Point
|
||||||
|
@ -945,16 +945,16 @@ def superWire(edgeslist,closed=False):
|
||||||
else:
|
else:
|
||||||
p2 = curr.Vertexes[-1].Point
|
p2 = curr.Vertexes[-1].Point
|
||||||
if geomType(curr) == "Line":
|
if geomType(curr) == "Line":
|
||||||
print "line",p1,p2
|
print("line",p1,p2)
|
||||||
newedges.append(Part.Line(p1,p2).toShape())
|
newedges.append(Part.Line(p1,p2).toShape())
|
||||||
elif geomType(curr) == "Circle":
|
elif geomType(curr) == "Circle":
|
||||||
p3 = findMidpoint(curr)
|
p3 = findMidpoint(curr)
|
||||||
print "arc",p1,p3,p2
|
print("arc",p1,p3,p2)
|
||||||
newedges.append(Part.Arc(p1,p3,p2).toShape())
|
newedges.append(Part.Arc(p1,p3,p2).toShape())
|
||||||
else:
|
else:
|
||||||
print "Cannot superWire edges that are not lines or arcs"
|
print("Cannot superWire edges that are not lines or arcs")
|
||||||
return None
|
return None
|
||||||
print newedges
|
print(newedges)
|
||||||
return Part.Wire(newedges)
|
return Part.Wire(newedges)
|
||||||
|
|
||||||
def findMidpoint(edge):
|
def findMidpoint(edge):
|
||||||
|
@ -1185,7 +1185,7 @@ def connect(edges,closed=False):
|
||||||
nedges = []
|
nedges = []
|
||||||
for i in range(len(edges)):
|
for i in range(len(edges)):
|
||||||
curr = edges[i]
|
curr = edges[i]
|
||||||
#print "debug: DraftGeomUtils.connect edge ",i," : ",curr.Vertexes[0].Point,curr.Vertexes[-1].Point
|
#print("debug: DraftGeomUtils.connect edge ",i," : ",curr.Vertexes[0].Point,curr.Vertexes[-1].Point)
|
||||||
if i > 0:
|
if i > 0:
|
||||||
prev = edges[i-1]
|
prev = edges[i-1]
|
||||||
else:
|
else:
|
||||||
|
@ -1200,7 +1200,7 @@ def connect(edges,closed=False):
|
||||||
else:
|
else:
|
||||||
next = None
|
next = None
|
||||||
if prev:
|
if prev:
|
||||||
#print "debug: DraftGeomUtils.connect prev : ",prev.Vertexes[0].Point,prev.Vertexes[-1].Point
|
#print("debug: DraftGeomUtils.connect prev : ",prev.Vertexes[0].Point,prev.Vertexes[-1].Point)
|
||||||
i = findIntersection(curr,prev,True,True)
|
i = findIntersection(curr,prev,True,True)
|
||||||
if i:
|
if i:
|
||||||
v1 = i[0]
|
v1 = i[0]
|
||||||
|
@ -1209,7 +1209,7 @@ def connect(edges,closed=False):
|
||||||
else:
|
else:
|
||||||
v1 = curr.Vertexes[0].Point
|
v1 = curr.Vertexes[0].Point
|
||||||
if next:
|
if next:
|
||||||
#print "debug: DraftGeomUtils.connect next : ",next.Vertexes[0].Point,next.Vertexes[-1].Point
|
#print("debug: DraftGeomUtils.connect next : ",next.Vertexes[0].Point,next.Vertexes[-1].Point)
|
||||||
i = findIntersection(curr,next,True,True)
|
i = findIntersection(curr,next,True,True)
|
||||||
if i:
|
if i:
|
||||||
v2 = i[0]
|
v2 = i[0]
|
||||||
|
@ -1226,7 +1226,7 @@ def connect(edges,closed=False):
|
||||||
try:
|
try:
|
||||||
return Part.Wire(nedges)
|
return Part.Wire(nedges)
|
||||||
except:
|
except:
|
||||||
print "DraftGeomUtils.connect: unable to connect edges:",nedges
|
print("DraftGeomUtils.connect: unable to connect edges:",nedges)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def findDistance(point,edge,strict=False):
|
def findDistance(point,edge,strict=False):
|
||||||
|
@ -1286,15 +1286,15 @@ def findDistance(point,edge,strict=False):
|
||||||
np = edge.Curve.value(pr)
|
np = edge.Curve.value(pr)
|
||||||
dist = np.sub(point)
|
dist = np.sub(point)
|
||||||
except:
|
except:
|
||||||
print "DraftGeomUtils: Unable to get curve parameter for point ",point
|
print("DraftGeomUtils: Unable to get curve parameter for point ",point)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return dist
|
return dist
|
||||||
else:
|
else:
|
||||||
print "DraftGeomUtils: Couldn't project point"
|
print("DraftGeomUtils: Couldn't project point")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print "DraftGeomUtils: Couldn't project point"
|
print("DraftGeomUtils: Couldn't project point")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -1427,7 +1427,7 @@ def bind(w1,w2):
|
||||||
w4 = Part.Line(w1.Vertexes[-1].Point,w2.Vertexes[-1].Point).toShape()
|
w4 = Part.Line(w1.Vertexes[-1].Point,w2.Vertexes[-1].Point).toShape()
|
||||||
return Part.Face(Part.Wire(w1.Edges+[w3]+w2.Edges+[w4]))
|
return Part.Face(Part.Wire(w1.Edges+[w3]+w2.Edges+[w4]))
|
||||||
except:
|
except:
|
||||||
print "DraftGeomUtils: unable to bind wires"
|
print("DraftGeomUtils: unable to bind wires")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def cleanFaces(shape):
|
def cleanFaces(shape):
|
||||||
|
@ -1458,13 +1458,13 @@ def cleanFaces(shape):
|
||||||
lut[edge.hashCode()].append(face.hashCode())
|
lut[edge.hashCode()].append(face.hashCode())
|
||||||
else:
|
else:
|
||||||
lut[edge.hashCode()] = [face.hashCode()]
|
lut[edge.hashCode()] = [face.hashCode()]
|
||||||
# print "lut:",lut
|
# print("lut:",lut)
|
||||||
# take edges shared by 2 faces
|
# take edges shared by 2 faces
|
||||||
sharedhedges = []
|
sharedhedges = []
|
||||||
for k,v in lut.iteritems():
|
for k,v in lut.items():
|
||||||
if len(v) == 2:
|
if len(v) == 2:
|
||||||
sharedhedges.append(k)
|
sharedhedges.append(k)
|
||||||
# print len(sharedhedges)," shared edges:",sharedhedges
|
# print(len(sharedhedges)," shared edges:",sharedhedges)
|
||||||
# find those with same normals
|
# find those with same normals
|
||||||
targethedges = []
|
targethedges = []
|
||||||
for hedge in sharedhedges:
|
for hedge in sharedhedges:
|
||||||
|
@ -1473,7 +1473,7 @@ def cleanFaces(shape):
|
||||||
n2 = find(faces[1]).normalAt(0.5,0.5)
|
n2 = find(faces[1]).normalAt(0.5,0.5)
|
||||||
if n1 == n2:
|
if n1 == n2:
|
||||||
targethedges.append(hedge)
|
targethedges.append(hedge)
|
||||||
# print len(targethedges)," target edges:",targethedges
|
# print(len(targethedges)," target edges:",targethedges)
|
||||||
# get target faces
|
# get target faces
|
||||||
hfaces = []
|
hfaces = []
|
||||||
for hedge in targethedges:
|
for hedge in targethedges:
|
||||||
|
@ -1481,7 +1481,7 @@ def cleanFaces(shape):
|
||||||
if not f in hfaces:
|
if not f in hfaces:
|
||||||
hfaces.append(f)
|
hfaces.append(f)
|
||||||
|
|
||||||
# print len(hfaces)," target faces:",hfaces
|
# print(len(hfaces)," target faces:",hfaces)
|
||||||
# sort islands
|
# sort islands
|
||||||
islands = [[hfaces.pop(0)]]
|
islands = [[hfaces.pop(0)]]
|
||||||
currentisle = 0
|
currentisle = 0
|
||||||
|
@ -1503,7 +1503,7 @@ def cleanFaces(shape):
|
||||||
islands[currentisle].append(hfaces.pop(f))
|
islands[currentisle].append(hfaces.pop(f))
|
||||||
else:
|
else:
|
||||||
found = False
|
found = False
|
||||||
# print len(islands)," islands:",islands
|
# print(len(islands)," islands:",islands)
|
||||||
# make new faces from islands
|
# make new faces from islands
|
||||||
newfaces = []
|
newfaces = []
|
||||||
treated = []
|
treated = []
|
||||||
|
@ -1517,12 +1517,12 @@ def cleanFaces(shape):
|
||||||
if shp.normalAt(0.5,0.5) != find(isle[0]).normalAt(0.5,0.5):
|
if shp.normalAt(0.5,0.5) != find(isle[0]).normalAt(0.5,0.5):
|
||||||
shp.reverse()
|
shp.reverse()
|
||||||
newfaces.append(shp)
|
newfaces.append(shp)
|
||||||
# print "new faces:",newfaces
|
# print("new faces:",newfaces)
|
||||||
# add remaining faces
|
# add remaining faces
|
||||||
for f in faceset:
|
for f in faceset:
|
||||||
if not f.hashCode() in treated:
|
if not f.hashCode() in treated:
|
||||||
newfaces.append(f)
|
newfaces.append(f)
|
||||||
# print "final faces"
|
# print("final faces")
|
||||||
# finishing
|
# finishing
|
||||||
fshape = Part.makeShell(newfaces)
|
fshape = Part.makeShell(newfaces)
|
||||||
if shape.isClosed():
|
if shape.isClosed():
|
||||||
|
@ -1585,7 +1585,7 @@ def getCubicDimensions(shape):
|
||||||
for e in shape.Faces[i].Edges:
|
for e in shape.Faces[i].Edges:
|
||||||
if basepoint in [e.Vertexes[0].Point,e.Vertexes[1].Point]:
|
if basepoint in [e.Vertexes[0].Point,e.Vertexes[1].Point]:
|
||||||
vtemp = vec(e)
|
vtemp = vec(e)
|
||||||
# print vtemp
|
# print(vtemp)
|
||||||
if round(vtemp.getAngle(vx),precision()) == rpi:
|
if round(vtemp.getAngle(vx),precision()) == rpi:
|
||||||
if round(vtemp.getAngle(vy),precision()) == rpi:
|
if round(vtemp.getAngle(vy),precision()) == rpi:
|
||||||
vz = vtemp
|
vz = vtemp
|
||||||
|
@ -1626,7 +1626,7 @@ def arcFromSpline(edge):
|
||||||
segments such as those from imported svg files. Use this only
|
segments such as those from imported svg files. Use this only
|
||||||
if you are sure your edge is really an arc..."""
|
if you are sure your edge is really an arc..."""
|
||||||
if geomType(edge) == "Line":
|
if geomType(edge) == "Line":
|
||||||
print "This edge is straight, cannot build an arc on it"
|
print("This edge is straight, cannot build an arc on it")
|
||||||
return None
|
return None
|
||||||
if len(edge.Vertexes) > 1:
|
if len(edge.Vertexes) > 1:
|
||||||
# 2-point arc
|
# 2-point arc
|
||||||
|
@ -1637,7 +1637,7 @@ def arcFromSpline(edge):
|
||||||
try:
|
try:
|
||||||
return Part.Arc(p1,p3,p2).toShape()
|
return Part.Arc(p1,p3,p2).toShape()
|
||||||
except:
|
except:
|
||||||
print "Couldn't make an arc out of this edge"
|
print("Couldn't make an arc out of this edge")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
# circle
|
# circle
|
||||||
|
@ -1651,7 +1651,7 @@ def arcFromSpline(edge):
|
||||||
try:
|
try:
|
||||||
return Part.makeCircle(radius,center)
|
return Part.makeCircle(radius,center)
|
||||||
except:
|
except:
|
||||||
print "couldn't make a circle out of this edge"
|
print("couldn't make a circle out of this edge")
|
||||||
|
|
||||||
# Fillet code graciously donated by Jacques-Antoine Gaudin
|
# Fillet code graciously donated by Jacques-Antoine Gaudin
|
||||||
|
|
||||||
|
@ -1678,7 +1678,7 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
if r <= 0 :
|
if r <= 0 :
|
||||||
print "DraftGeomUtils.fillet : Error : radius is negative."
|
print("DraftGeomUtils.fillet : Error : radius is negative.")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
curveType = getCurveType(rndEdges[0])
|
curveType = getCurveType(rndEdges[0])
|
||||||
|
@ -1700,7 +1700,7 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
r = (r/2)/math.cos(beta)
|
r = (r/2)/math.cos(beta)
|
||||||
|
|
||||||
if round(alpha,precision()) == 0 or round(alpha - math.pi,precision()) == 0: # Edges have same direction
|
if round(alpha,precision()) == 0 or round(alpha - math.pi,precision()) == 0: # Edges have same direction
|
||||||
print "DraftGeomUtils.fillet : Warning : edges have same direction. Did nothing"
|
print("DraftGeomUtils.fillet : Warning : edges have same direction. Did nothing")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
dToCenter = r / math.sin(alpha/2.)
|
dToCenter = r / math.sin(alpha/2.)
|
||||||
|
@ -1716,7 +1716,7 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
arcPt3 = lVertexes[1].Point.add(dirVect)
|
arcPt3 = lVertexes[1].Point.add(dirVect)
|
||||||
|
|
||||||
if (dToTangent>lEdges[0].Length) or (dToTangent>lEdges[1].Length) :
|
if (dToTangent>lEdges[0].Length) or (dToTangent>lEdges[1].Length) :
|
||||||
print "DraftGeomUtils.fillet : Error : radius value ", r," is too high"
|
print("DraftGeomUtils.fillet : Error : radius value ", r," is too high")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
if chamfer:
|
if chamfer:
|
||||||
rndEdges[1] = Part.Edge(Part.Line(arcPt1,arcPt3))
|
rndEdges[1] = Part.Edge(Part.Line(arcPt1,arcPt3))
|
||||||
|
@ -1761,14 +1761,14 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
elif round(projCenter,precision()) < 0 or (round(projCenter,precision()) == 0 and U1.dot(T) > 0):
|
elif round(projCenter,precision()) < 0 or (round(projCenter,precision()) == 0 and U1.dot(T) > 0):
|
||||||
newRadius = arcRadius + r
|
newRadius = arcRadius + r
|
||||||
else :
|
else :
|
||||||
print "DraftGeomUtils.fillet : Warning : edges are already tangent. Did nothing"
|
print("DraftGeomUtils.fillet : Warning : edges are already tangent. Did nothing")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
toNewCent = newRadius**2-dCenterToLine**2
|
toNewCent = newRadius**2-dCenterToLine**2
|
||||||
if toNewCent > 0 :
|
if toNewCent > 0 :
|
||||||
toNewCent = abs(abs(projCenter) - toNewCent**(0.5))
|
toNewCent = abs(abs(projCenter) - toNewCent**(0.5))
|
||||||
else :
|
else :
|
||||||
print "DraftGeomUtils.fillet : Error : radius value ", r," is too high"
|
print("DraftGeomUtils.fillet : Error : radius value ", r," is too high")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
U1.scale(toNewCent,toNewCent,toNewCent)
|
U1.scale(toNewCent,toNewCent,toNewCent)
|
||||||
|
@ -1801,7 +1801,7 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
|
|
||||||
delLength = arcRadius * V[0].sub(arcCenter).getAngle(toCenter)
|
delLength = arcRadius * V[0].sub(arcCenter).getAngle(toCenter)
|
||||||
if delLength > arcLength or toNewCent > curveType['Line'][0].Length:
|
if delLength > arcLength or toNewCent > curveType['Line'][0].Length:
|
||||||
print "DraftGeomUtils.fillet : Error : radius value ", r," is too high"
|
print("DraftGeomUtils.fillet : Error : radius value ", r," is too high")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
arcAsEdge = arcFrom2Pts(V[-arcFirst],V[-myTrick],arcCenter,arcAxis)
|
arcAsEdge = arcFrom2Pts(V[-arcFirst],V[-myTrick],arcCenter,arcAxis)
|
||||||
|
@ -1847,7 +1847,7 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
newRadius += [arcRadius[0]+r]
|
newRadius += [arcRadius[0]+r]
|
||||||
newRadius += [arcRadius[1]+r]
|
newRadius += [arcRadius[1]+r]
|
||||||
else :
|
else :
|
||||||
print "DraftGeomUtils.fillet : Warning : edges are already tangent. Did nothing"
|
print("DraftGeomUtils.fillet : Warning : edges are already tangent. Did nothing")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
elif not sameDirection :
|
elif not sameDirection :
|
||||||
if round(TcrossT.dot(arcAxis[0]),precision()) > 0 :
|
if round(TcrossT.dot(arcAxis[0]),precision()) > 0 :
|
||||||
|
@ -1864,16 +1864,16 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
newRadius += [arcRadius[0]+r]
|
newRadius += [arcRadius[0]+r]
|
||||||
newRadius += [arcRadius[1]-r]
|
newRadius += [arcRadius[1]-r]
|
||||||
else :
|
else :
|
||||||
print "DraftGeomUtils.fillet : Warning : arcs are coincident. Did nothing"
|
print("DraftGeomUtils.fillet : Warning : arcs are coincident. Did nothing")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
else :
|
else :
|
||||||
print "DraftGeomUtils.fillet : Warning : edges are already tangent. Did nothing"
|
print("DraftGeomUtils.fillet : Warning : edges are already tangent. Did nothing")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
if newRadius[0]+newRadius[1] < dCentToCent or \
|
if newRadius[0]+newRadius[1] < dCentToCent or \
|
||||||
newRadius[0]-newRadius[1] > dCentToCent or \
|
newRadius[0]-newRadius[1] > dCentToCent or \
|
||||||
newRadius[1]-newRadius[0] > dCentToCent :
|
newRadius[1]-newRadius[0] > dCentToCent :
|
||||||
print "DraftGeomUtils.fillet : Error : radius value ", r," is too high"
|
print("DraftGeomUtils.fillet : Error : radius value ", r," is too high")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
|
|
||||||
x = (dCentToCent**2+newRadius[0]**2-newRadius[1]**2)/(2*dCentToCent)
|
x = (dCentToCent**2+newRadius[0]**2-newRadius[1]**2)/(2*dCentToCent)
|
||||||
|
@ -1906,7 +1906,7 @@ def fillet(lEdges,r,chamfer=False):
|
||||||
toCenter[i].scale(-1,-1,-1)
|
toCenter[i].scale(-1,-1,-1)
|
||||||
delLength = arcRadius[i] * arcPt[-i].sub(arcCenter[i]).getAngle(toCenter[i])
|
delLength = arcRadius[i] * arcPt[-i].sub(arcCenter[i]).getAngle(toCenter[i])
|
||||||
if delLength > arcLength[i] :
|
if delLength > arcLength[i] :
|
||||||
print "DraftGeomUtils.fillet : Error : radius value ", r," is too high"
|
print("DraftGeomUtils.fillet : Error : radius value ", r," is too high")
|
||||||
return rndEdges
|
return rndEdges
|
||||||
V = [arcPt[-i],lVertexes[-i].Point]
|
V = [arcPt[-i],lVertexes[-i].Point]
|
||||||
arcAsEdge += [arcFrom2Pts(V[i-1],V[-i],arcCenter[i],arcAxis[i])]
|
arcAsEdge += [arcFrom2Pts(V[i-1],V[-i],arcCenter[i],arcAxis[i])]
|
||||||
|
@ -1967,7 +1967,7 @@ def getCircleFromSpline(edge):
|
||||||
c = i[0]
|
c = i[0]
|
||||||
r = (p1.sub(c)).Length
|
r = (p1.sub(c)).Length
|
||||||
circle = Part.makeCircle(r,c,n)
|
circle = Part.makeCircle(r,c,n)
|
||||||
#print circle.Curve
|
#print(circle.Curve)
|
||||||
return circle
|
return circle
|
||||||
|
|
||||||
def curvetowire(obj,steps):
|
def curvetowire(obj,steps):
|
||||||
|
@ -2021,7 +2021,7 @@ def cleanProjection(shape,tessellate=True,seglength=.05):
|
||||||
else:
|
else:
|
||||||
newedges.append(e)
|
newedges.append(e)
|
||||||
except:
|
except:
|
||||||
print "Debug: error cleaning edge ",e
|
print("Debug: error cleaning edge ",e)
|
||||||
return Part.makeCompound(newedges)
|
return Part.makeCompound(newedges)
|
||||||
|
|
||||||
def curvetosegment(curve,seglen):
|
def curvetosegment(curve,seglen):
|
||||||
|
@ -2052,7 +2052,7 @@ def tessellateProjection(shape,seglen):
|
||||||
else:
|
else:
|
||||||
newedges.append(e)
|
newedges.append(e)
|
||||||
except:
|
except:
|
||||||
print "Debug: error cleaning edge ",e
|
print("Debug: error cleaning edge ",e)
|
||||||
return Part.makeCompound(newedges)
|
return Part.makeCompound(newedges)
|
||||||
|
|
||||||
# circle functions *********************************************************
|
# circle functions *********************************************************
|
||||||
|
@ -2382,7 +2382,7 @@ def outerSoddyCircle(circle1, circle2, circle3):
|
||||||
|
|
||||||
X = -z.real
|
X = -z.real
|
||||||
Y = -z.imag
|
Y = -z.imag
|
||||||
print "Outer Soddy circle: " + str(X) + " " + str(Y) + "\n" # Debug
|
print("Outer Soddy circle: " + str(X) + " " + str(Y) + "\n") # Debug
|
||||||
|
|
||||||
# The Radius of the outer soddy circle can also be calculated with the following formula:
|
# The Radius of the outer soddy circle can also be calculated with the following formula:
|
||||||
# radiusOuter = abs(r1*r2*r3 / (r1*r2 + r1*r3 + r2*r3 - 2 * math.sqrt(r1*r2*r3 * (r1+r2+r3))))
|
# radiusOuter = abs(r1*r2*r3 / (r1*r2 + r1*r3 + r2*r3 - 2 * math.sqrt(r1*r2*r3 * (r1+r2+r3))))
|
||||||
|
@ -2390,7 +2390,7 @@ def outerSoddyCircle(circle1, circle2, circle3):
|
||||||
return circ
|
return circ
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: outerSoddyCircle bad parameters!\n"
|
print("debug: outerSoddyCircle bad parameters!\n")
|
||||||
# FreeCAD.Console.PrintMessage("debug: outerSoddyCircle bad parameters!\n")
|
# FreeCAD.Console.PrintMessage("debug: outerSoddyCircle bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2434,7 +2434,7 @@ def innerSoddyCircle(circle1, circle2, circle3):
|
||||||
|
|
||||||
X = z.real
|
X = z.real
|
||||||
Y = z.imag
|
Y = z.imag
|
||||||
print "Outer Soddy circle: " + str(X) + " " + str(Y) + "\n" # Debug
|
print("Outer Soddy circle: " + str(X) + " " + str(Y) + "\n") # Debug
|
||||||
|
|
||||||
# The Radius of the inner soddy circle can also be calculated with the following formula:
|
# The Radius of the inner soddy circle can also be calculated with the following formula:
|
||||||
# radiusInner = abs(r1*r2*r3 / (r1*r2 + r1*r3 + r2*r3 + 2 * math.sqrt(r1*r2*r3 * (r1+r2+r3))))
|
# radiusInner = abs(r1*r2*r3 / (r1*r2 + r1*r3 + r2*r3 + 2 * math.sqrt(r1*r2*r3 * (r1+r2+r3))))
|
||||||
|
@ -2442,7 +2442,7 @@ def innerSoddyCircle(circle1, circle2, circle3):
|
||||||
return circ
|
return circ
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: innerSoddyCircle bad parameters!\n"
|
print("debug: innerSoddyCircle bad parameters!\n")
|
||||||
# FreeCAD.Console.PrintMessage("debug: innerSoddyCircle bad parameters!\n")
|
# FreeCAD.Console.PrintMessage("debug: innerSoddyCircle bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2472,10 +2472,10 @@ def circleFrom3CircleTangents(circle1, circle2, circle3):
|
||||||
r2 = circle2.Curve.Radius
|
r2 = circle2.Curve.Radius
|
||||||
r3 = circle3.Curve.Radius
|
r3 = circle3.Curve.Radius
|
||||||
outerSoddy = outerSoddyCircle(circle1, circle2, circle3)
|
outerSoddy = outerSoddyCircle(circle1, circle2, circle3)
|
||||||
# print str(outerSoddy) + "\n" # Debug
|
# print(str(outerSoddy) + "\n") # Debug
|
||||||
|
|
||||||
innerSoddy = innerSoddyCircle(circle1, circle2, circle3)
|
innerSoddy = innerSoddyCircle(circle1, circle2, circle3)
|
||||||
# print str(innerSoddy) + "\n" # Debug
|
# print(str(innerSoddy) + "\n") # Debug
|
||||||
|
|
||||||
circles = []
|
circles = []
|
||||||
if outerSoddy:
|
if outerSoddy:
|
||||||
|
@ -2495,7 +2495,7 @@ def circleFrom3CircleTangents(circle1, circle2, circle3):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: circleFrom3CircleTangents bad parameters!\n"
|
print("debug: circleFrom3CircleTangents bad parameters!\n")
|
||||||
# FreeCAD.Console.PrintMessage("debug: circleFrom3CircleTangents bad parameters!\n")
|
# FreeCAD.Console.PrintMessage("debug: circleFrom3CircleTangents bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2593,7 +2593,7 @@ def findHomotheticCenterOfCircles(circle1, circle2):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: findHomotheticCenterOfCircles bad parameters!\n"
|
print("debug: findHomotheticCenterOfCircles bad parameters!\n")
|
||||||
FreeCAD.Console.PrintMessage("debug: findHomotheticCenterOfCirclescleFrom3tan bad parameters!\n")
|
FreeCAD.Console.PrintMessage("debug: findHomotheticCenterOfCirclescleFrom3tan bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2644,7 +2644,7 @@ def findRadicalAxis(circle1, circle2):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print "debug: findRadicalAxis bad parameters!\n"
|
print("debug: findRadicalAxis bad parameters!\n")
|
||||||
FreeCAD.Console.PrintMessage("debug: findRadicalAxis bad parameters!\n")
|
FreeCAD.Console.PrintMessage("debug: findRadicalAxis bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2678,7 +2678,7 @@ def findRadicalCenter(circle1, circle2, circle3):
|
||||||
# No radical center could be calculated.
|
# No radical center could be calculated.
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
print "debug: findRadicalCenter bad parameters!\n"
|
print("debug: findRadicalCenter bad parameters!\n")
|
||||||
FreeCAD.Console.PrintMessage("debug: findRadicalCenter bad parameters!\n")
|
FreeCAD.Console.PrintMessage("debug: findRadicalCenter bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2714,7 +2714,7 @@ def pointInversion(circle, point):
|
||||||
return invPoint
|
return invPoint
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: pointInversion bad parameters!\n"
|
print("debug: pointInversion bad parameters!\n")
|
||||||
FreeCAD.Console.PrintMessage("debug: pointInversion bad parameters!\n")
|
FreeCAD.Console.PrintMessage("debug: pointInversion bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2736,7 +2736,7 @@ def polarInversion(circle, edge):
|
||||||
return inversionPole
|
return inversionPole
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: circleInversionPole bad parameters!\n"
|
print("debug: circleInversionPole bad parameters!\n")
|
||||||
FreeCAD.Console.PrintMessage("debug: circleInversionPole bad parameters!\n")
|
FreeCAD.Console.PrintMessage("debug: circleInversionPole bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -2761,7 +2761,7 @@ def circleInversion(circle, circle2):
|
||||||
return Part.Circle(invCen2, norm, DraftVecUtils.dist(invCen2, invPointOnCircle2))
|
return Part.Circle(invCen2, norm, DraftVecUtils.dist(invCen2, invPointOnCircle2))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "debug: circleInversion bad parameters!\n"
|
print("debug: circleInversion bad parameters!\n")
|
||||||
FreeCAD.Console.PrintMessage("debug: circleInversion bad parameters!\n")
|
FreeCAD.Console.PrintMessage("debug: circleInversion bad parameters!\n")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ class todo:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def doTasks():
|
def doTasks():
|
||||||
# print "debug: doing delayed tasks: commitlist: ",todo.commitlist," itinerary: ",todo.itinerary
|
# print("debug: doing delayed tasks: commitlist: ",todo.commitlist," itinerary: ",todo.itinerary)
|
||||||
for f, arg in todo.itinerary:
|
for f, arg in todo.itinerary:
|
||||||
try:
|
try:
|
||||||
# print "debug: executing",f
|
# print("debug: executing",f)
|
||||||
if arg:
|
if arg:
|
||||||
f(arg)
|
f(arg)
|
||||||
else:
|
else:
|
||||||
|
@ -64,7 +64,7 @@ class todo:
|
||||||
todo.itinerary = []
|
todo.itinerary = []
|
||||||
if todo.commitlist:
|
if todo.commitlist:
|
||||||
for name,func in todo.commitlist:
|
for name,func in todo.commitlist:
|
||||||
#print "debug: committing ",str(name)
|
#print("debug: committing ",str(name))
|
||||||
try:
|
try:
|
||||||
name = str(name)
|
name = str(name)
|
||||||
FreeCAD.ActiveDocument.openTransaction(name)
|
FreeCAD.ActiveDocument.openTransaction(name)
|
||||||
|
@ -84,14 +84,14 @@ class todo:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delay (f, arg):
|
def delay (f, arg):
|
||||||
# print "debug: delaying",f
|
# print("debug: delaying",f)
|
||||||
if todo.itinerary == []:
|
if todo.itinerary == []:
|
||||||
QtCore.QTimer.singleShot(0, todo.doTasks)
|
QtCore.QTimer.singleShot(0, todo.doTasks)
|
||||||
todo.itinerary.append((f,arg))
|
todo.itinerary.append((f,arg))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delayCommit (cl):
|
def delayCommit (cl):
|
||||||
# print "debug: delaying commit",cl
|
# print("debug: delaying commit",cl)
|
||||||
QtCore.QTimer.singleShot(0, todo.doTasks)
|
QtCore.QTimer.singleShot(0, todo.doTasks)
|
||||||
todo.commitlist = cl
|
todo.commitlist = cl
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ class DraftToolBar:
|
||||||
self.cancel = None
|
self.cancel = None
|
||||||
self.pointcallback = None
|
self.pointcallback = None
|
||||||
self.taskmode = Draft.getParam("UiMode",1)
|
self.taskmode = Draft.getParam("UiMode",1)
|
||||||
#print "taskmode: ",str(self.taskmode)
|
#print("taskmode: ",str(self.taskmode))
|
||||||
self.paramcolor = Draft.getParam("color",255)>>8
|
self.paramcolor = Draft.getParam("color",255)>>8
|
||||||
self.color = QtGui.QColor(self.paramcolor)
|
self.color = QtGui.QColor(self.paramcolor)
|
||||||
self.facecolor = QtGui.QColor(204,204,204)
|
self.facecolor = QtGui.QColor(204,204,204)
|
||||||
|
@ -1138,13 +1138,13 @@ class DraftToolBar:
|
||||||
last = self.sourceCmd.node[0]
|
last = self.sourceCmd.node[0]
|
||||||
else:
|
else:
|
||||||
last = self.sourceCmd.node[-1]
|
last = self.sourceCmd.node[-1]
|
||||||
#print "last:",last
|
#print("last:",last)
|
||||||
v = FreeCAD.Vector(numx,numy,numz)
|
v = FreeCAD.Vector(numx,numy,numz)
|
||||||
#print "orig:",v
|
#print("orig:",v)
|
||||||
if FreeCAD.DraftWorkingPlane:
|
if FreeCAD.DraftWorkingPlane:
|
||||||
v = FreeCAD.Vector(numx,numy,numz)
|
v = FreeCAD.Vector(numx,numy,numz)
|
||||||
v = FreeCAD.DraftWorkingPlane.getGlobalRot(v)
|
v = FreeCAD.DraftWorkingPlane.getGlobalRot(v)
|
||||||
#print "rotated:",v
|
#print("rotated:",v)
|
||||||
numx = last.x + v.x
|
numx = last.x + v.x
|
||||||
numy = last.y + v.y
|
numy = last.y + v.y
|
||||||
numz = last.z + v.z
|
numz = last.z + v.z
|
||||||
|
@ -1175,7 +1175,7 @@ class DraftToolBar:
|
||||||
if self.sourceCmd:
|
if self.sourceCmd:
|
||||||
if (self.labelSString.isVisible()):
|
if (self.labelSString.isVisible()):
|
||||||
if self.SStringValue.text():
|
if self.SStringValue.text():
|
||||||
# print "debug: D_G DraftToolBar.validateSString type(SStringValue.text): " str(type(self.SStringValue.text))
|
#print("debug: D_G DraftToolBar.validateSString type(SStringValue.text): " str(type(self.SStringValue.text)))
|
||||||
#self.sourceCmd.validSString(str(self.SStringValue.text())) # QString to QByteArray to PyString
|
#self.sourceCmd.validSString(str(self.SStringValue.text())) # QString to QByteArray to PyString
|
||||||
self.sourceCmd.validSString(self.SStringValue.text()) # PySide returns Unicode from QString
|
self.sourceCmd.validSString(self.SStringValue.text()) # PySide returns Unicode from QString
|
||||||
else:
|
else:
|
||||||
|
@ -1194,15 +1194,15 @@ class DraftToolBar:
|
||||||
dialogCaption,
|
dialogCaption,
|
||||||
dialogDir,
|
dialogDir,
|
||||||
dialogFilter)
|
dialogFilter)
|
||||||
# print fname
|
# print(fname)
|
||||||
#fname = str(fname.toUtf8()) # QString to PyString
|
#fname = str(fname.toUtf8()) # QString to PyString
|
||||||
fname = fname[0].decode("utf8")
|
fname = fname[0].decode("utf8")
|
||||||
# print "debug: D_G DraftToolBar.pickFile type(fname): " str(type(fname))
|
# print("debug: D_G DraftToolBar.pickFile type(fname): " str(type(fname)))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
FreeCAD.Console.PrintMessage("DraftGui.pickFile: unable to select a font file.")
|
FreeCAD.Console.PrintMessage("DraftGui.pickFile: unable to select a font file.")
|
||||||
print type(e)
|
print(type(e))
|
||||||
print e.args
|
print(e.args)
|
||||||
else:
|
else:
|
||||||
if fname:
|
if fname:
|
||||||
self.FFileValue.setText(fname)
|
self.FFileValue.setText(fname)
|
||||||
|
@ -1444,7 +1444,8 @@ class DraftToolBar:
|
||||||
r = color.red()/255.0
|
r = color.red()/255.0
|
||||||
g = color.green()/255.0
|
g = color.green()/255.0
|
||||||
b = color.blue()/255.0
|
b = color.blue()/255.0
|
||||||
else: print "draft: error: couldn't get a color for ",type," type."
|
else:
|
||||||
|
print("draft: error: couldn't get a color for ",type," type.")
|
||||||
if rgb:
|
if rgb:
|
||||||
return("rgb("+str(int(r*255))+","+str(int(g*255))+","+str(int(b*255))+")")
|
return("rgb("+str(int(r*255))+","+str(int(g*255))+","+str(int(b*255))+")")
|
||||||
else:
|
else:
|
||||||
|
@ -1545,13 +1546,13 @@ class DraftToolBar:
|
||||||
self.delButton.setChecked(False)
|
self.delButton.setChecked(False)
|
||||||
|
|
||||||
def setRadiusValue(self,val,unit=None):
|
def setRadiusValue(self,val,unit=None):
|
||||||
#print "DEBUG: setRadiusValue val: ", val, " unit: ", unit
|
#print("DEBUG: setRadiusValue val: ", val, " unit: ", unit)
|
||||||
if not isinstance(val, (int, long, float)): #??some code passes strings or ???
|
if not isinstance(val, (int, float)): #??some code passes strings or ???
|
||||||
t = val
|
t = val
|
||||||
elif unit:
|
elif unit:
|
||||||
t= displayExternal(val,self.DECIMALS, unit)
|
t= displayExternal(val,self.DECIMALS, unit)
|
||||||
else:
|
else:
|
||||||
print "Error: setRadiusValue called for number without Dimension"
|
print("Error: setRadiusValue called for number without Dimension")
|
||||||
t = displayExternal(val,self.DECIMALS, None)
|
t = displayExternal(val,self.DECIMALS, None)
|
||||||
self.radiusValue.setText(t)
|
self.radiusValue.setText(t)
|
||||||
self.radiusValue.setFocus()
|
self.radiusValue.setFocus()
|
||||||
|
@ -1667,7 +1668,7 @@ class DraftToolBar:
|
||||||
|
|
||||||
def changeEvent(self, event):
|
def changeEvent(self, event):
|
||||||
if event.type() == QtCore.QEvent.LanguageChange:
|
if event.type() == QtCore.QEvent.LanguageChange:
|
||||||
#print "Language changed!"
|
#print("Language changed!")
|
||||||
self.ui.retranslateUi(self)
|
self.ui.retranslateUi(self)
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
|
|
|
@ -164,7 +164,7 @@ class Snapper:
|
||||||
elif isinstance(screenpos,coin.SbVec2s):
|
elif isinstance(screenpos,coin.SbVec2s):
|
||||||
screenpos = tuple(screenpos.getValue())
|
screenpos = tuple(screenpos.getValue())
|
||||||
elif not isinstance(screenpos,tuple):
|
elif not isinstance(screenpos,tuple):
|
||||||
print "snap needs valid screen position (list, tuple or sbvec2s)"
|
print("snap needs valid screen position (list, tuple or sbvec2s)")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# setup trackers if needed
|
# setup trackers if needed
|
||||||
|
@ -366,7 +366,7 @@ class Snapper:
|
||||||
for snap in snaps:
|
for snap in snaps:
|
||||||
if (not snap) or (snap[0] == None):
|
if (not snap) or (snap[0] == None):
|
||||||
pass
|
pass
|
||||||
#print "debug: Snapper: invalid snap point: ",snaps
|
#print("debug: Snapper: invalid snap point: ",snaps)
|
||||||
else:
|
else:
|
||||||
delta = snap[0].sub(origin)
|
delta = snap[0].sub(origin)
|
||||||
if delta.Length < shortest:
|
if delta.Length < shortest:
|
||||||
|
@ -1078,7 +1078,7 @@ class Snapper:
|
||||||
self.masterbutton.setChecked(True)
|
self.masterbutton.setChecked(True)
|
||||||
QtCore.QObject.connect(self.masterbutton,QtCore.SIGNAL("toggled(bool)"),self.toggle)
|
QtCore.QObject.connect(self.masterbutton,QtCore.SIGNAL("toggled(bool)"),self.toggle)
|
||||||
self.toolbar.addWidget(self.masterbutton)
|
self.toolbar.addWidget(self.masterbutton)
|
||||||
for c,i in self.cursors.iteritems():
|
for c,i in self.cursors.items():
|
||||||
if i:
|
if i:
|
||||||
b = QtGui.QPushButton(None)
|
b = QtGui.QPushButton(None)
|
||||||
b.setIcon(QtGui.QIcon(i))
|
b.setIcon(QtGui.QIcon(i))
|
||||||
|
@ -1225,5 +1225,5 @@ if not hasattr(FreeCADGui,"Snapper"):
|
||||||
if not hasattr(FreeCAD,"DraftWorkingPlane"):
|
if not hasattr(FreeCAD,"DraftWorkingPlane"):
|
||||||
import WorkingPlane, Draft_rc
|
import WorkingPlane, Draft_rc
|
||||||
FreeCAD.DraftWorkingPlane = WorkingPlane.plane()
|
FreeCAD.DraftWorkingPlane = WorkingPlane.plane()
|
||||||
#print FreeCAD.DraftWorkingPlane
|
#print(FreeCAD.DraftWorkingPlane)
|
||||||
FreeCADGui.addIconPath(":/icons")
|
FreeCADGui.addIconPath(":/icons")
|
||||||
|
|
|
@ -269,7 +269,6 @@ class DraftTool:
|
||||||
|
|
||||||
def commit(self,name,func):
|
def commit(self,name,func):
|
||||||
"stores actions to be committed to the FreeCAD document"
|
"stores actions to be committed to the FreeCAD document"
|
||||||
# print "committing"
|
|
||||||
self.commitList.append((name,func))
|
self.commitList.append((name,func))
|
||||||
|
|
||||||
def getStrings(self,addrot=None):
|
def getStrings(self,addrot=None):
|
||||||
|
@ -670,7 +669,7 @@ class BSpline(Line):
|
||||||
['points='+pts,
|
['points='+pts,
|
||||||
'Draft.makeBSpline(points,closed='+str(closed)+',face='+fil+',support='+sup+')'])
|
'Draft.makeBSpline(points,closed='+str(closed)+',face='+fil+',support='+sup+')'])
|
||||||
except:
|
except:
|
||||||
print "Draft: error delaying commit"
|
print("Draft: error delaying commit")
|
||||||
Creator.finish(self)
|
Creator.finish(self)
|
||||||
if self.ui:
|
if self.ui:
|
||||||
if self.ui.continueMode:
|
if self.ui.continueMode:
|
||||||
|
@ -773,7 +772,7 @@ class BezCurve(Line):
|
||||||
['points='+pts,
|
['points='+pts,
|
||||||
'Draft.makeBezCurve(points,closed='+str(closed)+',support='+sup+')'])
|
'Draft.makeBezCurve(points,closed='+str(closed)+',support='+sup+')'])
|
||||||
except:
|
except:
|
||||||
print "Draft: error delaying commit"
|
print("Draft: error delaying commit")
|
||||||
Creator.finish(self)
|
Creator.finish(self)
|
||||||
if self.ui:
|
if self.ui:
|
||||||
if self.ui.continueMode:
|
if self.ui.continueMode:
|
||||||
|
@ -908,7 +907,7 @@ class Rectangle(Creator):
|
||||||
'pl.Base = '+DraftVecUtils.toString(p1),
|
'pl.Base = '+DraftVecUtils.toString(p1),
|
||||||
'Draft.makeRectangle(length='+str(length)+',height='+str(height)+',placement=pl,face='+fil+',support='+sup+')'])
|
'Draft.makeRectangle(length='+str(length)+',height='+str(height)+',placement=pl,face='+fil+',support='+sup+')'])
|
||||||
except:
|
except:
|
||||||
print "Draft: error delaying commit"
|
print("Draft: error delaying commit")
|
||||||
self.finish(cont=True)
|
self.finish(cont=True)
|
||||||
|
|
||||||
def action(self,arg):
|
def action(self,arg):
|
||||||
|
@ -1166,7 +1165,7 @@ class Arc(Creator):
|
||||||
'pl.Base='+DraftVecUtils.toString(self.center),
|
'pl.Base='+DraftVecUtils.toString(self.center),
|
||||||
'Draft.makeCircle(radius='+str(self.rad)+',placement=pl,face='+fil+',support='+sup+')'])
|
'Draft.makeCircle(radius='+str(self.rad)+',placement=pl,face='+fil+',support='+sup+')'])
|
||||||
except:
|
except:
|
||||||
print "Draft: error delaying commit"
|
print("Draft: error delaying commit")
|
||||||
else:
|
else:
|
||||||
sta = math.degrees(self.firstangle)
|
sta = math.degrees(self.firstangle)
|
||||||
end = math.degrees(self.firstangle+self.angle)
|
end = math.degrees(self.firstangle+self.angle)
|
||||||
|
@ -1192,7 +1191,7 @@ class Arc(Creator):
|
||||||
'pl.Base='+DraftVecUtils.toString(self.center),
|
'pl.Base='+DraftVecUtils.toString(self.center),
|
||||||
'Draft.makeCircle(radius='+str(self.rad)+',placement=pl,face='+fil+',startangle='+str(sta)+',endangle='+str(end)+',support='+sup+')'])
|
'Draft.makeCircle(radius='+str(self.rad)+',placement=pl,face='+fil+',startangle='+str(sta)+',endangle='+str(end)+',support='+sup+')'])
|
||||||
except:
|
except:
|
||||||
print "Draft: error delaying commit"
|
print("Draft: error delaying commit")
|
||||||
self.finish(cont=True)
|
self.finish(cont=True)
|
||||||
|
|
||||||
def numericInput(self,numx,numy,numz):
|
def numericInput(self,numx,numy,numz):
|
||||||
|
@ -1518,7 +1517,7 @@ class Ellipse(Creator):
|
||||||
'pl.Base = '+DraftVecUtils.toString(center),
|
'pl.Base = '+DraftVecUtils.toString(center),
|
||||||
'Draft.makeEllipse('+str(r1)+','+str(r2)+',placement=pl,face='+fil+',support='+sup+')'])
|
'Draft.makeEllipse('+str(r1)+','+str(r2)+',placement=pl,face='+fil+',support='+sup+')'])
|
||||||
except:
|
except:
|
||||||
print "Draft: Error: Unable to create object."
|
print("Draft: Error: Unable to create object.")
|
||||||
self.finish(cont=True)
|
self.finish(cont=True)
|
||||||
|
|
||||||
def action(self,arg):
|
def action(self,arg):
|
||||||
|
@ -1598,7 +1597,7 @@ class Text(Creator):
|
||||||
for l in self.text:
|
for l in self.text:
|
||||||
if len(tx) > 1:
|
if len(tx) > 1:
|
||||||
tx += ','
|
tx += ','
|
||||||
tx += '"'+str(unicode(l).encode("utf8"))+'"'
|
tx += '"'+str(unicode(l).encode("utf8"))+'"' #Python3 no more unicode
|
||||||
tx += ']'
|
tx += ']'
|
||||||
FreeCADGui.addModule("Draft")
|
FreeCADGui.addModule("Draft")
|
||||||
self.commit(translate("draft","Create Text"),
|
self.commit(translate("draft","Create Text"),
|
||||||
|
@ -1843,7 +1842,7 @@ class Dimension(Creator):
|
||||||
if (not self.node) and (not self.support):
|
if (not self.node) and (not self.support):
|
||||||
getSupport(arg)
|
getSupport(arg)
|
||||||
if (hasMod(arg,MODALT) or self.selectmode) and (len(self.node)<3):
|
if (hasMod(arg,MODALT) or self.selectmode) and (len(self.node)<3):
|
||||||
#print "snapped: ",self.info
|
#print("snapped: ",self.info)
|
||||||
if self.info:
|
if self.info:
|
||||||
ob = self.doc.getObject(self.info['Object'])
|
ob = self.doc.getObject(self.info['Object'])
|
||||||
if 'Edge' in self.info['Component']:
|
if 'Edge' in self.info['Component']:
|
||||||
|
@ -1878,7 +1877,7 @@ class Dimension(Creator):
|
||||||
self.node[3],
|
self.node[3],
|
||||||
True,True)
|
True,True)
|
||||||
if c:
|
if c:
|
||||||
#print "centers:",c
|
#print("centers:",c)
|
||||||
self.center = c[0]
|
self.center = c[0]
|
||||||
self.arctrack.setCenter(self.center)
|
self.arctrack.setCenter(self.center)
|
||||||
self.arctrack.on()
|
self.arctrack.on()
|
||||||
|
@ -1894,7 +1893,7 @@ class Dimension(Creator):
|
||||||
else:
|
else:
|
||||||
self.node.append(self.point)
|
self.node.append(self.point)
|
||||||
self.selectmode = False
|
self.selectmode = False
|
||||||
#print "node",self.node
|
#print("node",self.node)
|
||||||
self.dimtrack.update(self.node)
|
self.dimtrack.update(self.node)
|
||||||
if (len(self.node) == 2):
|
if (len(self.node) == 2):
|
||||||
self.point2 = self.node[1]
|
self.point2 = self.node[1]
|
||||||
|
@ -1959,18 +1958,18 @@ class ShapeString(Creator):
|
||||||
|
|
||||||
def createObject(self):
|
def createObject(self):
|
||||||
"creates object in the current doc"
|
"creates object in the current doc"
|
||||||
#print "debug: D_T ShapeString.createObject type(self.SString): " str(type(self.SString))
|
#print("debug: D_T ShapeString.createObject type(self.SString): " str(type(self.SString)))
|
||||||
|
|
||||||
dquote = '"'
|
dquote = '"'
|
||||||
if type(self.SString) == unicode:
|
if type(self.SString) == unicode: # Python3: no more unicode
|
||||||
String = 'u' + dquote + self.SString.encode('unicode_escape') + dquote
|
String = 'u' + dquote + self.SString.encode('unicode_escape') + dquote
|
||||||
else:
|
else:
|
||||||
String = dquote + self.SString + dquote
|
String = dquote + self.SString + dquote
|
||||||
Size = str(self.SSSize) # numbers are ascii so this should always work
|
Size = str(self.SSSize) # numbers are ascii so this should always work
|
||||||
Tracking = str(self.SSTrack) # numbers are ascii so this should always work
|
Tracking = str(self.SSTrack) # numbers are ascii so this should always work
|
||||||
FFile = dquote + self.FFile + dquote
|
FFile = dquote + self.FFile + dquote
|
||||||
# print "debug: D_T ShapeString.createObject type(String): " str(type(String))
|
# print("debug: D_T ShapeString.createObject type(String): " str(type(String)))
|
||||||
# print "debug: D_T ShapeString.createObject type(FFile): " str(type(FFile))
|
# print("debug: D_T ShapeString.createObject type(FFile): " str(type(FFile)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qr,sup,points,fil = self.getStrings()
|
qr,sup,points,fil = self.getStrings()
|
||||||
|
@ -2529,7 +2528,7 @@ class Offset(Modifier):
|
||||||
if hasMod(arg,MODALT) or self.ui.isCopy.isChecked(): copymode = True
|
if hasMod(arg,MODALT) or self.ui.isCopy.isChecked(): copymode = True
|
||||||
FreeCADGui.addModule("Draft")
|
FreeCADGui.addModule("Draft")
|
||||||
if self.npts:
|
if self.npts:
|
||||||
print "offset:npts=",self.npts
|
print("offset:npts=",self.npts)
|
||||||
self.commit(translate("draft","Offset"),
|
self.commit(translate("draft","Offset"),
|
||||||
['Draft.offset(FreeCAD.ActiveDocument.'+self.sel.Name+','+DraftVecUtils.toString(self.npts)+',copy='+str(copymode)+')',
|
['Draft.offset(FreeCAD.ActiveDocument.'+self.sel.Name+','+DraftVecUtils.toString(self.npts)+',copy='+str(copymode)+')',
|
||||||
'FreeCAD.ActiveDocument.recompute()'])
|
'FreeCAD.ActiveDocument.recompute()'])
|
||||||
|
@ -2837,7 +2836,7 @@ class Trimex(Modifier):
|
||||||
self.ui.labelRadius.setText("Angle")
|
self.ui.labelRadius.setText("Angle")
|
||||||
dist = math.degrees(-ang2)
|
dist = math.degrees(-ang2)
|
||||||
# if ang1 > ang2: ang1,ang2 = ang2,ang1
|
# if ang1 > ang2: ang1,ang2 = ang2,ang1
|
||||||
#print "last calculated:",math.degrees(-ang1),math.degrees(-ang2)
|
#print("last calculated:",math.degrees(-ang1),math.degrees(-ang2))
|
||||||
ghost.setEndAngle(-ang2)
|
ghost.setEndAngle(-ang2)
|
||||||
ghost.setStartAngle(-ang1)
|
ghost.setStartAngle(-ang1)
|
||||||
ghost.setCenter(center)
|
ghost.setCenter(center)
|
||||||
|
@ -2855,9 +2854,11 @@ class Trimex(Modifier):
|
||||||
ghost.on()
|
ghost.on()
|
||||||
|
|
||||||
# resetting the visible edges
|
# resetting the visible edges
|
||||||
if not reverse: list = range(npoint+1,len(self.edges))
|
if not reverse:
|
||||||
else: list = range(npoint-1,-1,-1)
|
li = list(range(npoint+1,len(self.edges)))
|
||||||
for i in list:
|
else:
|
||||||
|
li = list(range(npoint-1,-1,-1))
|
||||||
|
for i in li:
|
||||||
edge = self.edges[i]
|
edge = self.edges[i]
|
||||||
ghost = self.ghost[i]
|
ghost = self.ghost[i]
|
||||||
if DraftGeomUtils.geomType(edge) == "Line":
|
if DraftGeomUtils.geomType(edge) == "Line":
|
||||||
|
@ -2882,7 +2883,7 @@ class Trimex(Modifier):
|
||||||
"trims the actual object"
|
"trims the actual object"
|
||||||
if self.extrudeMode:
|
if self.extrudeMode:
|
||||||
delta = self.extrude(self.shift,real=True)
|
delta = self.extrude(self.shift,real=True)
|
||||||
#print "delta",delta
|
#print("delta",delta)
|
||||||
self.doc.openTransaction("Extrude")
|
self.doc.openTransaction("Extrude")
|
||||||
obj = Draft.extrude(self.obj,delta)
|
obj = Draft.extrude(self.obj,delta)
|
||||||
self.doc.commitTransaction()
|
self.doc.commitTransaction()
|
||||||
|
@ -2928,8 +2929,8 @@ class Trimex(Modifier):
|
||||||
self.obj.Z1 = p[0].z
|
self.obj.Z1 = p[0].z
|
||||||
elif Draft.getType(self.obj) == "Circle":
|
elif Draft.getType(self.obj) == "Circle":
|
||||||
angles = self.ghost[0].getAngles()
|
angles = self.ghost[0].getAngles()
|
||||||
#print "original",self.obj.FirstAngle," ",self.obj.LastAngle
|
#print("original",self.obj.FirstAngle," ",self.obj.LastAngle)
|
||||||
#print "new",angles
|
#print("new",angles)
|
||||||
if angles[0] > angles[1]: angles = (angles[1],angles[0])
|
if angles[0] > angles[1]: angles = (angles[1],angles[0])
|
||||||
self.obj.FirstAngle = angles[0]
|
self.obj.FirstAngle = angles[0]
|
||||||
self.obj.LastAngle = angles[1]
|
self.obj.LastAngle = angles[1]
|
||||||
|
@ -3930,7 +3931,7 @@ class Shape2DView(Modifier):
|
||||||
for e in s.SubElementNames:
|
for e in s.SubElementNames:
|
||||||
if "Face" in e:
|
if "Face" in e:
|
||||||
faces.append(int(e[4:])-1)
|
faces.append(int(e[4:])-1)
|
||||||
#print objs,faces
|
#print(objs,faces)
|
||||||
if len(objs) == 1:
|
if len(objs) == 1:
|
||||||
if faces:
|
if faces:
|
||||||
Draft.makeShape2DView(objs[0],facenumbers=faces)
|
Draft.makeShape2DView(objs[0],facenumbers=faces)
|
||||||
|
@ -4041,7 +4042,7 @@ class PathArray(Modifier):
|
||||||
if self.ui:
|
if self.ui:
|
||||||
self.ui.selectUi()
|
self.ui.selectUi()
|
||||||
msg(translate("draft", "Please select base and path objects\n"))
|
msg(translate("draft", "Please select base and path objects\n"))
|
||||||
# print "Please select base and path objects"
|
# print("Please select base and path objects")
|
||||||
self.call = self.view.addEventCallback("SoEvent",selectObject)
|
self.call = self.view.addEventCallback("SoEvent",selectObject)
|
||||||
else:
|
else:
|
||||||
self.proceed()
|
self.proceed()
|
||||||
|
|
|
@ -468,7 +468,7 @@ class arcTracker(Tracker):
|
||||||
center = Vector(c[0],c[1],c[2])
|
center = Vector(c[0],c[1],c[2])
|
||||||
rad = pt.sub(center)
|
rad = pt.sub(center)
|
||||||
a = DraftVecUtils.angle(rad,self.basevector,self.normal)
|
a = DraftVecUtils.angle(rad,self.basevector,self.normal)
|
||||||
#print a
|
#print(a)
|
||||||
return(a)
|
return(a)
|
||||||
|
|
||||||
def getAngles(self):
|
def getAngles(self):
|
||||||
|
@ -600,7 +600,7 @@ class ghostTracker(Tracker):
|
||||||
sep.addChild(coinobj.getChildren()[1])
|
sep.addChild(coinobj.getChildren()[1])
|
||||||
# sep.addChild(coinobj)
|
# sep.addChild(coinobj)
|
||||||
except:
|
except:
|
||||||
print "Error retrieving coin node"
|
print("Error retrieving coin node")
|
||||||
return sep
|
return sep
|
||||||
|
|
||||||
class editTracker(Tracker):
|
class editTracker(Tracker):
|
||||||
|
|
|
@ -75,12 +75,12 @@ def equals(u,v):
|
||||||
|
|
||||||
def scale(u,scalar):
|
def scale(u,scalar):
|
||||||
"scale(Vector,Float) - scales (multiplies) a vector by a factor"
|
"scale(Vector,Float) - scales (multiplies) a vector by a factor"
|
||||||
typecheck ([(u,Vector), (scalar,(int,long,float))], "scale")
|
typecheck ([(u,Vector), (scalar,(int,float))], "scale")
|
||||||
return Vector(u.x*scalar, u.y*scalar, u.z*scalar)
|
return Vector(u.x*scalar, u.y*scalar, u.z*scalar)
|
||||||
|
|
||||||
def scaleTo(u,l):
|
def scaleTo(u,l):
|
||||||
"scaleTo(Vector,length) - scales a vector to a given length"
|
"scaleTo(Vector,length) - scales a vector to a given length"
|
||||||
typecheck ([(u,Vector),(l,(int,long,float))], "scaleTo")
|
typecheck ([(u,Vector),(l,(int,float))], "scaleTo")
|
||||||
if u.Length == 0:
|
if u.Length == 0:
|
||||||
return Vector(u)
|
return Vector(u)
|
||||||
else:
|
else:
|
||||||
|
@ -137,7 +137,7 @@ def rotate(u,angle,axis=Vector(0,0,1)):
|
||||||
'''rotate(Vector,Float,axis=Vector): rotates the first Vector
|
'''rotate(Vector,Float,axis=Vector): rotates the first Vector
|
||||||
around the given axis, at the given angle.
|
around the given axis, at the given angle.
|
||||||
If axis is omitted, the rotation is made on the xy plane.'''
|
If axis is omitted, the rotation is made on the xy plane.'''
|
||||||
typecheck ([(u,Vector), (angle,(int,long,float)), (axis,Vector)], "rotate")
|
typecheck ([(u,Vector), (angle,(int,float)), (axis,Vector)], "rotate")
|
||||||
|
|
||||||
if angle == 0:
|
if angle == 0:
|
||||||
return u
|
return u
|
||||||
|
|
|
@ -100,7 +100,7 @@ class DraftWorkbench (Workbench):
|
||||||
FreeCADGui.addLanguagePath(":/translations")
|
FreeCADGui.addLanguagePath(":/translations")
|
||||||
FreeCADGui.addIconPath(":/icons")
|
FreeCADGui.addIconPath(":/icons")
|
||||||
except Exception as inst:
|
except Exception as inst:
|
||||||
print inst
|
print(inst)
|
||||||
FreeCAD.Console.PrintError("Error: Initializing one or more of the Draft modules failed, Draft will not work as expected.\n")
|
FreeCAD.Console.PrintError("Error: Initializing one or more of the Draft modules failed, Draft will not work as expected.\n")
|
||||||
|
|
||||||
# setup menus
|
# setup menus
|
||||||
|
|
|
@ -41,7 +41,7 @@ def decodeName(name):
|
||||||
try:
|
try:
|
||||||
decodedName = (name.decode("latin1"))
|
decodedName = (name.decode("latin1"))
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
print "AirfoilDAT: error: couldn't determine character encoding"
|
print("AirfoilDAT: error: couldn't determine character encoding")
|
||||||
decodedName = name
|
decodedName = name
|
||||||
return decodedName
|
return decodedName
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ def process(doc,filename):
|
||||||
|
|
||||||
|
|
||||||
if len(coords) < 3:
|
if len(coords) < 3:
|
||||||
print 'Did not find enough coordinates\n'
|
print('Did not find enough coordinates\n')
|
||||||
return
|
return
|
||||||
|
|
||||||
# sometimes coords are divided in upper an lower side
|
# sometimes coords are divided in upper an lower side
|
||||||
|
|
|
@ -91,15 +91,15 @@ def convertToDxf(dwgfilename):
|
||||||
outdir = tempfile.mkdtemp()
|
outdir = tempfile.mkdtemp()
|
||||||
basename = os.path.basename(dwgfilename)
|
basename = os.path.basename(dwgfilename)
|
||||||
cmdline = '"%s" "%s" "%s" "ACAD2000" "DXF" "0" "1" "%s"' % (teigha, indir, outdir, basename)
|
cmdline = '"%s" "%s" "%s" "ACAD2000" "DXF" "0" "1" "%s"' % (teigha, indir, outdir, basename)
|
||||||
print "Converting: " + cmdline
|
print("Converting: " + cmdline)
|
||||||
os.system(cmdline)
|
os.system(cmdline)
|
||||||
result = outdir + os.sep + os.path.splitext(basename)[0] + ".dxf"
|
result = outdir + os.sep + os.path.splitext(basename)[0] + ".dxf"
|
||||||
if os.path.exists(result):
|
if os.path.exists(result):
|
||||||
print "Conversion successful"
|
print("Conversion successful")
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
print "Error during DWG to DXF conversion. Try moving the DWG file to a directory path"
|
print("Error during DWG to DXF conversion. Try moving the DWG file to a directory path")
|
||||||
print "without spaces and non-english characters, or try saving to a lower DWG version"
|
print("without spaces and non-english characters, or try saving to a lower DWG version")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def convertToDwg(dxffilename,dwgfilename):
|
def convertToDwg(dxffilename,dwgfilename):
|
||||||
|
@ -111,7 +111,7 @@ def convertToDwg(dxffilename,dwgfilename):
|
||||||
outdir = os.path.dirname(dwgfilename)
|
outdir = os.path.dirname(dwgfilename)
|
||||||
basename = os.path.basename(dxffilename)
|
basename = os.path.basename(dxffilename)
|
||||||
cmdline = '"%s" "%s" "%s" "ACAD2000" "DWG" "0" "1" "%s"' % (teigha, indir, outdir, basename)
|
cmdline = '"%s" "%s" "%s" "ACAD2000" "DWG" "0" "1" "%s"' % (teigha, indir, outdir, basename)
|
||||||
print "converting " + cmdline
|
print("converting " + cmdline)
|
||||||
os.system(cmdline)
|
os.system(cmdline)
|
||||||
return dwgfilename
|
return dwgfilename
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -106,7 +106,7 @@ def decodeName(name):
|
||||||
try:
|
try:
|
||||||
decodedName = (name.decode("latin1"))
|
decodedName = (name.decode("latin1"))
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
print "dxf: error: couldn't determine character encoding"
|
print("dxf: error: couldn't determine character encoding")
|
||||||
decodedName = name
|
decodedName = name
|
||||||
return decodedName
|
return decodedName
|
||||||
|
|
||||||
|
@ -114,17 +114,17 @@ def deformat(text):
|
||||||
"removes weird formats in texts and wipes UTF characters"
|
"removes weird formats in texts and wipes UTF characters"
|
||||||
# remove ACAD string formatation
|
# remove ACAD string formatation
|
||||||
#t = re.sub('{([^!}]([^}]|\n)*)}', '', text)
|
#t = re.sub('{([^!}]([^}]|\n)*)}', '', text)
|
||||||
#print "input text: ",text
|
#print("input text: ",text)
|
||||||
t = text.strip("{}")
|
t = text.strip("{}")
|
||||||
t = re.sub("\\\.*?;","",t)
|
t = re.sub("\\\.*?;","",t)
|
||||||
# replace UTF codes by utf chars
|
# replace UTF codes by utf chars
|
||||||
sts = re.split("\\\\(U\+....)",t)
|
sts = re.split("\\\\(U\+....)",t)
|
||||||
ns = u""
|
ns = u""
|
||||||
for ss in sts:
|
for ss in sts:
|
||||||
#print ss, type(ss)
|
#print(ss, type(ss))
|
||||||
if ss.startswith("U+"):
|
if ss.startswith("U+"):
|
||||||
ucode = "0x"+ss[2:]
|
ucode = "0x"+ss[2:]
|
||||||
ns += unichr(eval(ucode))
|
ns += unichr(eval(ucode)) #Python3 - unichr doesn't exist anymore
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
ns += ss.decode("utf8")
|
ns += ss.decode("utf8")
|
||||||
|
@ -132,12 +132,12 @@ def deformat(text):
|
||||||
try:
|
try:
|
||||||
ns += ss.decode("latin1")
|
ns += ss.decode("latin1")
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
print "unable to decode text: ",text
|
print("unable to decode text: ",text)
|
||||||
t = ns
|
t = ns
|
||||||
# replace degrees, diameters chars
|
# replace degrees, diameters chars
|
||||||
t = re.sub('%%d','°',t)
|
t = re.sub('%%d','°',t)
|
||||||
t = re.sub('%%c','Ø',t)
|
t = re.sub('%%c','Ø',t)
|
||||||
#print "output text: ",t
|
#print("output text: ",t)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def locateLayer(wantedLayer,color=None):
|
def locateLayer(wantedLayer,color=None):
|
||||||
|
@ -585,7 +585,7 @@ def drawSpline(spline,forceShape=False):
|
||||||
return ob
|
return ob
|
||||||
else:
|
else:
|
||||||
sp = Part.BSplineCurve()
|
sp = Part.BSplineCurve()
|
||||||
# print knots
|
# print(knots)
|
||||||
sp.interpolate(verts)
|
sp.interpolate(verts)
|
||||||
sh = Part.Wire(sp.toShape())
|
sh = Part.Wire(sp.toShape())
|
||||||
if closed:
|
if closed:
|
||||||
|
@ -602,9 +602,9 @@ def drawBlock(blockref,num=None,createObject=False):
|
||||||
if blockref.name[0] == '*':
|
if blockref.name[0] == '*':
|
||||||
return None
|
return None
|
||||||
if len(blockref.entities.data) == 0:
|
if len(blockref.entities.data) == 0:
|
||||||
print "skipping empty block ",blockref.name
|
print("skipping empty block ",blockref.name)
|
||||||
return None
|
return None
|
||||||
#print "creating block ", blockref.name, " containing ", len(blockref.entities.data), " entities"
|
#print("creating block ", blockref.name, " containing ", len(blockref.entities.data), " entities")
|
||||||
shapes = []
|
shapes = []
|
||||||
for line in blockref.entities.get_type('line'):
|
for line in blockref.entities.get_type('line'):
|
||||||
s = drawLine(line,forceShape=True)
|
s = drawLine(line,forceShape=True)
|
||||||
|
@ -622,7 +622,7 @@ def drawBlock(blockref,num=None,createObject=False):
|
||||||
s = drawCircle(circle,forceShape=True)
|
s = drawCircle(circle,forceShape=True)
|
||||||
if s: shapes.append(s)
|
if s: shapes.append(s)
|
||||||
for insert in blockref.entities.get_type('insert'):
|
for insert in blockref.entities.get_type('insert'):
|
||||||
#print "insert ",insert," in block ",insert.block[0]
|
#print("insert ",insert," in block ",insert.block[0])
|
||||||
if dxfStarBlocks or insert.block[0] != '*':
|
if dxfStarBlocks or insert.block[0] != '*':
|
||||||
s = drawInsert(insert)
|
s = drawInsert(insert)
|
||||||
if s: shapes.append(s)
|
if s: shapes.append(s)
|
||||||
|
@ -639,7 +639,7 @@ def drawBlock(blockref,num=None,createObject=False):
|
||||||
for text in blockref.entities.get_type('mtext'):
|
for text in blockref.entities.get_type('mtext'):
|
||||||
if dxfImportTexts:
|
if dxfImportTexts:
|
||||||
if dxfImportLayouts or (not rawValue(text,67)):
|
if dxfImportLayouts or (not rawValue(text,67)):
|
||||||
print "adding block text",text.value, " from ",blockref
|
print("adding block text",text.value, " from ",blockref)
|
||||||
addText(text)
|
addText(text)
|
||||||
try: shape = Part.makeCompound(shapes)
|
try: shape = Part.makeCompound(shapes)
|
||||||
except Part.OCCError: warn(blockref)
|
except Part.OCCError: warn(blockref)
|
||||||
|
@ -659,7 +659,7 @@ def drawInsert(insert,num=None,clone=False):
|
||||||
for a in attrs:
|
for a in attrs:
|
||||||
addText(a,attrib=True)
|
addText(a,attrib=True)
|
||||||
if clone:
|
if clone:
|
||||||
if blockobjects.has_key(insert.block):
|
if insert.block in blockobjects:
|
||||||
newob = Draft.clone(blockobjects[insert.block])
|
newob = Draft.clone(blockobjects[insert.block])
|
||||||
tsf = FreeCAD.Matrix()
|
tsf = FreeCAD.Matrix()
|
||||||
rot = math.radians(insert.rotation)
|
rot = math.radians(insert.rotation)
|
||||||
|
@ -674,7 +674,7 @@ def drawInsert(insert,num=None,clone=False):
|
||||||
else:
|
else:
|
||||||
shape = None
|
shape = None
|
||||||
else:
|
else:
|
||||||
if blockshapes.has_key(insert):
|
if insert in blockshapes:
|
||||||
shape = blockshapes[insert.block].copy()
|
shape = blockshapes[insert.block].copy()
|
||||||
else:
|
else:
|
||||||
shape = None
|
shape = None
|
||||||
|
@ -799,7 +799,7 @@ def addText(text,attrib=False):
|
||||||
yv = ax.cross(xv)
|
yv = ax.cross(xv)
|
||||||
if text.alignment in [1,2,3]:
|
if text.alignment in [1,2,3]:
|
||||||
sup = DraftVecUtils.scaleTo(yv,fsize/TEXTSCALING).negative()
|
sup = DraftVecUtils.scaleTo(yv,fsize/TEXTSCALING).negative()
|
||||||
print ax,sup
|
#print(ax,sup)
|
||||||
pos = pos.add(sup)
|
pos = pos.add(sup)
|
||||||
elif text.alignment in [4,5,6]:
|
elif text.alignment in [4,5,6]:
|
||||||
sup = DraftVecUtils.scaleTo(yv,fsize/(2*TEXTSCALING)).negative()
|
sup = DraftVecUtils.scaleTo(yv,fsize/(2*TEXTSCALING)).negative()
|
||||||
|
@ -1254,8 +1254,8 @@ def processdxf(document,filename,getShapes=False):
|
||||||
# make blocks, if any
|
# make blocks, if any
|
||||||
|
|
||||||
if dxfMakeBlocks:
|
if dxfMakeBlocks:
|
||||||
print "creating layerblocks..."
|
print("creating layerblocks...")
|
||||||
for k,l in layerBlocks.iteritems():
|
for k,l in layerBlocks.items():
|
||||||
shape = drawLayerBlock(l)
|
shape = drawLayerBlock(l)
|
||||||
if shape:
|
if shape:
|
||||||
newob = addObject(shape,k)
|
newob = addObject(shape,k)
|
||||||
|
@ -1263,24 +1263,25 @@ def processdxf(document,filename,getShapes=False):
|
||||||
|
|
||||||
# hide block objects, if any
|
# hide block objects, if any
|
||||||
|
|
||||||
for k,o in blockobjects.iteritems():
|
for k,o in blockobjects.items():
|
||||||
if o.ViewObject:
|
if o.ViewObject:
|
||||||
o.ViewObject.hide()
|
o.ViewObject.hide()
|
||||||
del blockobjects
|
del blockobjects
|
||||||
|
|
||||||
# finishing
|
# finishing
|
||||||
|
|
||||||
print "done processing"
|
print("done processing")
|
||||||
|
|
||||||
doc.recompute()
|
doc.recompute()
|
||||||
FreeCAD.Console.PrintMessage("successfully imported "+filename+"\n")
|
FreeCAD.Console.PrintMessage("successfully imported "+filename+"\n")
|
||||||
if badobjects: print "dxf: ",len(badobjects)," objects were not imported"
|
if badobjects:
|
||||||
|
print("dxf: ",len(badobjects)," objects were not imported")
|
||||||
del doc
|
del doc
|
||||||
del blockshapes
|
del blockshapes
|
||||||
|
|
||||||
def warn(dxfobject,num=None):
|
def warn(dxfobject,num=None):
|
||||||
"outputs a warning if a dxf object couldn't be imported"
|
"outputs a warning if a dxf object couldn't be imported"
|
||||||
print "dxf: couldn't import ", dxfobject, " (",num,")"
|
print("dxf: couldn't import ", dxfobject, " (",num,")")
|
||||||
badobjects.append(dxfobject)
|
badobjects.append(dxfobject)
|
||||||
|
|
||||||
def open(filename):
|
def open(filename):
|
||||||
|
@ -1321,7 +1322,7 @@ def projectShape(shape,direction):
|
||||||
try:
|
try:
|
||||||
groups = Drawing.projectEx(shape,direction)
|
groups = Drawing.projectEx(shape,direction)
|
||||||
except OCCError:
|
except OCCError:
|
||||||
print "unable to project shape on direction ",direction
|
print("unable to project shape on direction ",direction)
|
||||||
return shape
|
return shape
|
||||||
else:
|
else:
|
||||||
for g in groups[0:5]:
|
for g in groups[0:5]:
|
||||||
|
@ -1366,15 +1367,15 @@ def getArcData(edge):
|
||||||
# method 2 - check the midpoint - not reliable either
|
# method 2 - check the midpoint - not reliable either
|
||||||
#ve3 = DraftGeomUtils.findMidpoint(edge)
|
#ve3 = DraftGeomUtils.findMidpoint(edge)
|
||||||
#ang3 = -math.degrees(DraftVecUtils.angle(ve3.sub(ce)))
|
#ang3 = -math.degrees(DraftVecUtils.angle(ve3.sub(ce)))
|
||||||
#print "edge ",edge.hashCode()," data ",ang1, " , ",ang2," , ", ang3
|
#print ("edge ",edge.hashCode()," data ",ang1, " , ",ang2," , ", ang3)
|
||||||
#if (ang3 < ang1) and (ang2 < ang3):
|
#if (ang3 < ang1) and (ang2 < ang3):
|
||||||
# print "inverting, case1"
|
# print ("inverting, case1")
|
||||||
# ang1, ang2 = ang2, ang1
|
# ang1, ang2 = ang2, ang1
|
||||||
#elif (ang3 > ang1) and (ang3 > ang2):
|
#elif (ang3 > ang1) and (ang3 > ang2):
|
||||||
# print "inverting, case2"
|
# print ("inverting, case2")
|
||||||
# ang1, ang2 = ang2, ang1
|
# ang1, ang2 = ang2, ang1
|
||||||
#elif (ang3 < ang1) and (ang3 < ang2):
|
#elif (ang3 < ang1) and (ang3 < ang2):
|
||||||
# print "inverting, case3"
|
# print ("inverting, case3")
|
||||||
# ang1, ang2 = ang2, ang1
|
# ang1, ang2 = ang2, ang1
|
||||||
return DraftVecUtils.tup(ce), radius, ang1, ang2
|
return DraftVecUtils.tup(ce), radius, ang1, ang2
|
||||||
|
|
||||||
|
@ -1392,7 +1393,7 @@ def getSplineSegs(edge):
|
||||||
nbsegs = int(math.ceil(edge.Length/seglength))
|
nbsegs = int(math.ceil(edge.Length/seglength))
|
||||||
step = (edge.LastParameter-edge.FirstParameter)/nbsegs
|
step = (edge.LastParameter-edge.FirstParameter)/nbsegs
|
||||||
for nv in range(1,nbsegs):
|
for nv in range(1,nbsegs):
|
||||||
#print "value at",nv*step,"=",edge.valueAt(nv*step)
|
#print("value at",nv*step,"=",edge.valueAt(nv*step))
|
||||||
v = edge.valueAt(edge.FirstParameter+(nv*step))
|
v = edge.valueAt(edge.FirstParameter+(nv*step))
|
||||||
points.append(v)
|
points.append(v)
|
||||||
points.append(edge.valueAt(edge.LastParameter))
|
points.append(edge.valueAt(edge.LastParameter))
|
||||||
|
@ -1409,7 +1410,7 @@ def getWire(wire,nospline=False,lw=True):
|
||||||
return ((v.x,v.y,v.z),None,[None,None],b)
|
return ((v.x,v.y,v.z),None,[None,None],b)
|
||||||
edges = DraftGeomUtils.sortEdges(wire.Edges)
|
edges = DraftGeomUtils.sortEdges(wire.Edges)
|
||||||
points = []
|
points = []
|
||||||
# print "processing wire ",wire.Edges
|
# print("processing wire ",wire.Edges)
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
v1 = edge.Vertexes[0].Point
|
v1 = edge.Vertexes[0].Point
|
||||||
if DraftGeomUtils.geomType(edge) == "Circle":
|
if DraftGeomUtils.geomType(edge) == "Circle":
|
||||||
|
@ -1453,7 +1454,7 @@ def getWire(wire,nospline=False,lw=True):
|
||||||
if not DraftGeomUtils.isReallyClosed(wire):
|
if not DraftGeomUtils.isReallyClosed(wire):
|
||||||
v = edges[-1].Vertexes[-1].Point
|
v = edges[-1].Vertexes[-1].Point
|
||||||
points.append(fmt(v))
|
points.append(fmt(v))
|
||||||
# print "wire verts: ",points
|
# print("wire verts: ",points)
|
||||||
return points
|
return points
|
||||||
|
|
||||||
def getBlock(sh,obj,lwPoly=False):
|
def getBlock(sh,obj,lwPoly=False):
|
||||||
|
@ -1495,7 +1496,7 @@ def writeShape(sh,ob,dxfobject,nospline=False,lwPoly=False):
|
||||||
loneedges = []
|
loneedges = []
|
||||||
for e in sh.Edges:
|
for e in sh.Edges:
|
||||||
if not(e.hashCode() in processededges): loneedges.append(e)
|
if not(e.hashCode() in processededges): loneedges.append(e)
|
||||||
# print "lone edges ",loneedges
|
# print("lone edges ",loneedges)
|
||||||
for edge in loneedges:
|
for edge in loneedges:
|
||||||
if (DraftGeomUtils.geomType(edge) in ["BSplineCurve","BezierCurve"]): # splines
|
if (DraftGeomUtils.geomType(edge) in ["BSplineCurve","BezierCurve"]): # splines
|
||||||
if (len(edge.Vertexes) == 1) and (edge.Curve.isClosed()):
|
if (len(edge.Vertexes) == 1) and (edge.Curve.isClosed()):
|
||||||
|
@ -1544,7 +1545,7 @@ def writeShape(sh,ob,dxfobject,nospline=False,lwPoly=False):
|
||||||
ax = edge.Curve.Focus1.sub(edge.Curve.Center)
|
ax = edge.Curve.Focus1.sub(edge.Curve.Center)
|
||||||
major = DraftVecUtils.tup(DraftVecUtils.scaleTo(ax,edge.Curve.MajorRadius))
|
major = DraftVecUtils.tup(DraftVecUtils.scaleTo(ax,edge.Curve.MajorRadius))
|
||||||
minor = edge.Curve.MinorRadius/edge.Curve.MajorRadius
|
minor = edge.Curve.MinorRadius/edge.Curve.MajorRadius
|
||||||
# print "exporting ellipse: ",center,norm,start,end,major,minor
|
# print("exporting ellipse: ",center,norm,start,end,major,minor)
|
||||||
dxfobject.append(dxfLibrary.Ellipse(center=center,majorAxis=major,normalAxis=norm,
|
dxfobject.append(dxfLibrary.Ellipse(center=center,majorAxis=major,normalAxis=norm,
|
||||||
minorAxisRatio=minor,startParameter=start,
|
minorAxisRatio=minor,startParameter=start,
|
||||||
endParameter=end,
|
endParameter=end,
|
||||||
|
@ -1563,14 +1564,14 @@ def writeShape(sh,ob,dxfobject,nospline=False,lwPoly=False):
|
||||||
def writeMesh(ob,dxfobject):
|
def writeMesh(ob,dxfobject):
|
||||||
"export a shape as a polyface mesh"
|
"export a shape as a polyface mesh"
|
||||||
meshdata = ob.Shape.tessellate(0.5)
|
meshdata = ob.Shape.tessellate(0.5)
|
||||||
# print meshdata
|
# print(meshdata)
|
||||||
points = []
|
points = []
|
||||||
faces = []
|
faces = []
|
||||||
for p in meshdata[0]:
|
for p in meshdata[0]:
|
||||||
points.append([p.x,p.y,p.z])
|
points.append([p.x,p.y,p.z])
|
||||||
for f in meshdata[1]:
|
for f in meshdata[1]:
|
||||||
faces.append([f[0]+1,f[1]+1,f[2]+1])
|
faces.append([f[0]+1,f[1]+1,f[2]+1])
|
||||||
# print len(points),len(faces)
|
# print(len(points),len(faces))
|
||||||
dxfobject.append(dxfLibrary.PolyLine([points,faces], [0.0,0.0,0.0],
|
dxfobject.append(dxfLibrary.PolyLine([points,faces], [0.0,0.0,0.0],
|
||||||
64, color=getACI(ob),
|
64, color=getACI(ob),
|
||||||
layer=getGroup(ob)))
|
layer=getGroup(ob)))
|
||||||
|
@ -1599,7 +1600,7 @@ def export(objectslist,filename,nospline=False,lwPoly=False):
|
||||||
# other cases, treat edges
|
# other cases, treat edges
|
||||||
dxf = dxfLibrary.Drawing()
|
dxf = dxfLibrary.Drawing()
|
||||||
for ob in exportList:
|
for ob in exportList:
|
||||||
print "processing ",ob.Name
|
print("processing ",ob.Name)
|
||||||
if ob.isDerivedFrom("Part::Feature"):
|
if ob.isDerivedFrom("Part::Feature"):
|
||||||
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("dxfmesh"):
|
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("dxfmesh"):
|
||||||
sh = None
|
sh = None
|
||||||
|
@ -1687,7 +1688,7 @@ def exportPage(page,filename):
|
||||||
template = template.replace(editables[i],values[i])
|
template = template.replace(editables[i],values[i])
|
||||||
else:
|
else:
|
||||||
# dummy default template
|
# dummy default template
|
||||||
print "DXF version of the template not found. Creating a default empty template."
|
print("DXF version of the template not found. Creating a default empty template.")
|
||||||
template = "999\nFreeCAD DXF exporter v"+FreeCAD.Version()[0]+"."+FreeCAD.Version()[1]+"-"+FreeCAD.Version()[2]+"\n"
|
template = "999\nFreeCAD DXF exporter v"+FreeCAD.Version()[0]+"."+FreeCAD.Version()[1]+"-"+FreeCAD.Version()[2]+"\n"
|
||||||
template += "0\nSECTION\n2\nHEADER\n9\n$ACADVER\n1\nAC1009\n0\nENDSEC\n"
|
template += "0\nSECTION\n2\nHEADER\n9\n$ACADVER\n1\nAC1009\n0\nENDSEC\n"
|
||||||
template += "0\nSECTION\n2\nBLOCKS\n$blocks\n0\nENDSEC\n"
|
template += "0\nSECTION\n2\nBLOCKS\n$blocks\n0\nENDSEC\n"
|
||||||
|
@ -1765,7 +1766,7 @@ def getViewDXF(view):
|
||||||
dxfhandle += 1
|
dxfhandle += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "Unable to get DXF representation from view: ",view.Label
|
print("Unable to get DXF representation from view: ",view.Label)
|
||||||
return block,insert
|
return block,insert
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||||
|
|
||||||
def getpoint(data):
|
def getpoint(data):
|
||||||
"turns an OCA point definition into a FreeCAD Vector"
|
"turns an OCA point definition into a FreeCAD Vector"
|
||||||
print "found point ",data
|
print("found point ",data)
|
||||||
if (len(data) == 3):
|
if (len(data) == 3):
|
||||||
return Vector(float(data[0]),float(data[1]),float(data[2]))
|
return Vector(float(data[0]),float(data[1]),float(data[2]))
|
||||||
elif (data[0] == "P") and (len(data) == 4):
|
elif (data[0] == "P") and (len(data) == 4):
|
||||||
|
@ -69,7 +69,7 @@ def getpoint(data):
|
||||||
|
|
||||||
def getarea(data):
|
def getarea(data):
|
||||||
"turns an OCA area definition into a FreeCAD Part Wire"
|
"turns an OCA area definition into a FreeCAD Part Wire"
|
||||||
print "found area ",data
|
print("found area ",data)
|
||||||
if (data[0] == "S"):
|
if (data[0] == "S"):
|
||||||
if (data[1] == "POL"):
|
if (data[1] == "POL"):
|
||||||
pts = data[2:]
|
pts = data[2:]
|
||||||
|
@ -82,7 +82,7 @@ def getarea(data):
|
||||||
|
|
||||||
def getarc(data):
|
def getarc(data):
|
||||||
"turns an OCA arc definition into a FreeCAD Part Edge"
|
"turns an OCA arc definition into a FreeCAD Part Edge"
|
||||||
print "found arc ", data
|
print("found arc ", data)
|
||||||
c = None
|
c = None
|
||||||
if (data[0] == "ARC"):
|
if (data[0] == "ARC"):
|
||||||
# 3-points arc
|
# 3-points arc
|
||||||
|
@ -126,7 +126,7 @@ def getarc(data):
|
||||||
if c: return c.toShape()
|
if c: return c.toShape()
|
||||||
|
|
||||||
def getline(data):
|
def getline(data):
|
||||||
print "found line ", data
|
print("found line ", data)
|
||||||
"turns an OCA line definition into a FreeCAD Part Edge"
|
"turns an OCA line definition into a FreeCAD Part Edge"
|
||||||
verts = []
|
verts = []
|
||||||
for p in range(len(data)):
|
for p in range(len(data)):
|
||||||
|
@ -139,7 +139,7 @@ def getline(data):
|
||||||
|
|
||||||
def gettranslation(data):
|
def gettranslation(data):
|
||||||
"retrieves a transformation vector"
|
"retrieves a transformation vector"
|
||||||
print "found translation ",data
|
print("found translation ",data)
|
||||||
if (data[0] == "Z"):
|
if (data[0] == "Z"):
|
||||||
return Vector(0,0,float(data[1]))
|
return Vector(0,0,float(data[1]))
|
||||||
elif (data[0] == "Y"):
|
elif (data[0] == "Y"):
|
||||||
|
@ -214,7 +214,7 @@ def decodeName(name):
|
||||||
try:
|
try:
|
||||||
decodedName = (name.decode("latin1"))
|
decodedName = (name.decode("latin1"))
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
print "oca: error: couldn't determine character encoding"
|
print("oca: error: couldn't determine character encoding")
|
||||||
decodedName = name
|
decodedName = name
|
||||||
return decodedName
|
return decodedName
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ def export(exportList,filename):
|
||||||
for e in ob.Shape.Edges:
|
for e in ob.Shape.Edges:
|
||||||
edges.append(e)
|
edges.append(e)
|
||||||
if not (edges or faces):
|
if not (edges or faces):
|
||||||
print "oca: found no data to export"
|
print("oca: found no data to export")
|
||||||
return
|
return
|
||||||
|
|
||||||
# writing file
|
# writing file
|
||||||
|
|
|
@ -201,7 +201,7 @@ svgcolors = {
|
||||||
'OldLace': (253, 245, 230)
|
'OldLace': (253, 245, 230)
|
||||||
}
|
}
|
||||||
svgcolorslower = dict((key.lower(),value) for key,value in \
|
svgcolorslower = dict((key.lower(),value) for key,value in \
|
||||||
svgcolors.items())
|
list(svgcolors.items()))
|
||||||
|
|
||||||
def getcolor(color):
|
def getcolor(color):
|
||||||
"checks if the given string is a RGB value, or if it is a named color. returns 1-based RGBA tuple."
|
"checks if the given string is a RGB value, or if it is a named color. returns 1-based RGBA tuple."
|
||||||
|
@ -411,7 +411,7 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
FreeCAD.Console.PrintMessage('existing group transform: %s\n'%(str(self.grouptransform)))
|
FreeCAD.Console.PrintMessage('existing group transform: %s\n'%(str(self.grouptransform)))
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
for (keyword,content) in attrs.items():
|
for (keyword,content) in list(attrs.items()):
|
||||||
#print keyword,content
|
#print keyword,content
|
||||||
content = content.replace(',',' ')
|
content = content.replace(',',' ')
|
||||||
content = content.split()
|
content = content.split()
|
||||||
|
@ -670,9 +670,9 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
(d =="S" or d == "s"):
|
(d =="S" or d == "s"):
|
||||||
smooth = (d == 'S' or d == 's')
|
smooth = (d == 'S' or d == 's')
|
||||||
if smooth:
|
if smooth:
|
||||||
piter = zip(pointlist[2::4],pointlist[3::4],pointlist[0::4],pointlist[1::4],pointlist[2::4],pointlist[3::4])
|
piter = list(zip(pointlist[2::4],pointlist[3::4],pointlist[0::4],pointlist[1::4],pointlist[2::4],pointlist[3::4]))
|
||||||
else:
|
else:
|
||||||
piter = zip(pointlist[0::6],pointlist[1::6],pointlist[2::6],pointlist[3::6],pointlist[4::6],pointlist[5::6])
|
piter = list(zip(pointlist[0::6],pointlist[1::6],pointlist[2::6],pointlist[3::6],pointlist[4::6],pointlist[5::6]))
|
||||||
for p1x,p1y,p2x,p2y,x,y in piter:
|
for p1x,p1y,p2x,p2y,x,y in piter:
|
||||||
if smooth:
|
if smooth:
|
||||||
if lastpole is not None and lastpole[0]=='cubic':
|
if lastpole is not None and lastpole[0]=='cubic':
|
||||||
|
@ -714,9 +714,9 @@ class svgHandler(xml.sax.ContentHandler):
|
||||||
(d =="T" or d == "t"):
|
(d =="T" or d == "t"):
|
||||||
smooth = (d == 'T' or d == 't')
|
smooth = (d == 'T' or d == 't')
|
||||||
if smooth:
|
if smooth:
|
||||||
piter = zip(pointlist[1::2],pointlist[1::2],pointlist[0::2],pointlist[1::2])
|
piter = list(zip(pointlist[1::2],pointlist[1::2],pointlist[0::2],pointlist[1::2]))
|
||||||
else:
|
else:
|
||||||
piter = zip(pointlist[0::4],pointlist[1::4],pointlist[2::4],pointlist[3::4])
|
piter = list(zip(pointlist[0::4],pointlist[1::4],pointlist[2::4],pointlist[3::4]))
|
||||||
for px,py,x,y in piter:
|
for px,py,x,y in piter:
|
||||||
if smooth:
|
if smooth:
|
||||||
if lastpole is not None and lastpole[0]=='quadratic':
|
if lastpole is not None and lastpole[0]=='quadratic':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user