fixed objects without Dir fort SVG export
This commit is contained in:
parent
35b44967cd
commit
8fd9bcbff5
|
|
@ -210,30 +210,51 @@ class WindowDialog():
|
|||
|
||||
# -------- END -------- #
|
||||
|
||||
def searchDir(self, obj, xres, yres, zres):
|
||||
x, y, z = xres, yres, zres
|
||||
def getLargestFaceDir(self, obj):
|
||||
if not hasattr(obj, "Shape") or not obj.Shape.Faces:
|
||||
return None
|
||||
|
||||
if hasattr(obj, "Dir"):
|
||||
if obj.Dir.x != 0.0:
|
||||
x = obj.Dir.x
|
||||
if obj.Dir.y != 0.0:
|
||||
y = obj.Dir.y
|
||||
if obj.Dir.z != 0.0:
|
||||
z = obj.Dir.z
|
||||
maxArea = 0.0
|
||||
largestFace = None
|
||||
|
||||
if not hasattr(obj, "Objects"):
|
||||
return FreeCAD.Vector(x, y, z)
|
||||
else:
|
||||
res = FreeCAD.Vector(x, y, z)
|
||||
for i in obj.Objects:
|
||||
res = self.searchDir(i, x, y, z)
|
||||
return res
|
||||
for face in obj.Shape.Faces:
|
||||
area = face.Area
|
||||
if area > maxArea:
|
||||
maxArea = area
|
||||
largestFace = face
|
||||
|
||||
elif hasattr(obj, "Objects"):
|
||||
res = FreeCAD.Vector(x, y, z)
|
||||
for i in obj.Objects:
|
||||
res = self.searchDir(i, x, y, z)
|
||||
return res
|
||||
if largestFace:
|
||||
# Get normal at center of face (parametric center)
|
||||
u, v = largestFace.Surface.parameter(largestFace.CenterOfMass)
|
||||
normal = largestFace.normalAt(u, v)
|
||||
return normal.normalize()
|
||||
|
||||
return None
|
||||
|
||||
# def searchDir(self, obj, xres, yres, zres):
|
||||
# x, y, z = xres, yres, zres
|
||||
|
||||
# if hasattr(obj, "Dir"):
|
||||
# if obj.Dir.x != 0.0:
|
||||
# x = obj.Dir.x
|
||||
# if obj.Dir.y != 0.0:
|
||||
# y = obj.Dir.y
|
||||
# if obj.Dir.z != 0.0:
|
||||
# z = obj.Dir.z
|
||||
|
||||
# if not hasattr(obj, "Objects"):
|
||||
# return FreeCAD.Vector(x, y, z)
|
||||
# else:
|
||||
# res = FreeCAD.Vector(x, y, z)
|
||||
# for i in obj.Objects:
|
||||
# res = self.searchDir(i, x, y, z)
|
||||
# return res
|
||||
|
||||
# elif hasattr(obj, "Objects"):
|
||||
# res = FreeCAD.Vector(x, y, z)
|
||||
# for i in obj.Objects:
|
||||
# res = self.searchDir(i, x, y, z)
|
||||
# return res
|
||||
|
||||
def exportSVG(self, isCalepinage):
|
||||
plateLength = self.form.doubleSpinBoxLength.value()
|
||||
|
|
@ -255,7 +276,12 @@ class WindowDialog():
|
|||
break
|
||||
|
||||
for _ in range(count):
|
||||
vector = self.searchDir(obj, 0, 0, 0)
|
||||
if hasattr(obj, "Dir"):
|
||||
vector = FreeCAD.Vector(obj.Dir.x, obj.Dir.y, obj.Dir.z)
|
||||
else:
|
||||
vector = self.getLargestFaceDir(obj)
|
||||
|
||||
# vector = self.searchDir(obj, 0, 0, 0)
|
||||
sv0 = Draft.make_shape2dview(obj, vector)
|
||||
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
|
|
|||
Loading…
Reference in a new issue