Draft: Fix Draft_SelectPlane ignores nesting

This commit is contained in:
Roy-043
2021-10-20 10:15:12 +02:00
committed by GitHub
parent 3b310cfdf2
commit 25c3da4f0b

View File

@@ -521,7 +521,7 @@ class Plane:
self.v = v2
self.axis = v3
def alignToFace(self, shape, offset=0):
def alignToFace(self, shape, offset=0, parent=None):
"""Align the plane to a face.
It uses the center of mass of the face as `position`,
@@ -542,6 +542,10 @@ class Plane:
Defaults to zero. A value which will be used to offset
the plane in the direction of its `axis`.
parent : object
Defaults to None. The ParentGeoFeatureGroup of the object
the face belongs to.
Returns
-------
bool
@@ -554,17 +558,21 @@ class Plane:
"""
# Set face to the unique selected face, if found
if shape.ShapeType == 'Face':
self.alignToPointAndAxis(shape.Faces[0].CenterOfMass,
shape.Faces[0].normalAt(0, 0),
offset)
if parent:
place = parent.getGlobalPlacement()
else:
place = FreeCAD.Placement()
cen = place.multVec(shape.Faces[0].CenterOfMass)
place.Base = FreeCAD.Vector(0, 0, 0) # Reset the Base for the conversion of the normal.
nor = place.multVec(shape.Faces[0].normalAt(0, 0))
self.alignToPointAndAxis(cen, nor, offset)
import DraftGeomUtils
q = DraftGeomUtils.getQuad(shape)
if q:
self.u = q[1]
self.v = q[2]
self.u = place.multVec(q[1])
self.v = place.multVec(q[2])
if not DraftVecUtils.equals(self.u.cross(self.v), self.axis):
self.u = q[2]
self.v = q[1]
self.u, self.v = self.v, self.u
if DraftVecUtils.equals(self.u, Vector(0, 0, 1)):
# the X axis is vertical: rotate 90 degrees
self.u, self.v = self.v.negative(), self.u