Merge pull request #5119 from Roy-043/Draft-Fix-Draft_SelectPlane-ignores-nesting

Draft: Fix Draft_SelectPlane ignores nesting
This commit is contained in:
Yorik van Havre
2021-10-25 14:16:44 +02:00
committed by GitHub
2 changed files with 19 additions and 9 deletions

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

View File

@@ -209,7 +209,9 @@ class Draft_SelectPlane:
if len(sel.SubElementNames) == 1:
# look for a face or a plane
if "Face" in sel.SubElementNames[0]:
FreeCAD.DraftWorkingPlane.alignToFace(sel.SubObjects[0], self.getOffset())
FreeCAD.DraftWorkingPlane.alignToFace(sel.SubObjects[0],
self.getOffset(),
sel.Object.getParentGeoFeatureGroup())
self.display(FreeCAD.DraftWorkingPlane.axis)
return True
elif sel.SubElementNames[0] == "Plane":