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