From d1fca44fb61636494712c1eaf77ab13ed1eff098 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Wed, 20 Oct 2021 10:15:12 +0200 Subject: [PATCH 1/2] Draft: Fix Draft_SelectPlane ignores nesting --- src/Mod/Draft/WorkingPlane.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Mod/Draft/WorkingPlane.py b/src/Mod/Draft/WorkingPlane.py index af53f6695c..3e130699dc 100644 --- a/src/Mod/Draft/WorkingPlane.py +++ b/src/Mod/Draft/WorkingPlane.py @@ -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 From d0b34efa279fdaa4c3a4269202d6d38ccf59d277 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Wed, 20 Oct 2021 10:16:49 +0200 Subject: [PATCH 2/2] Draft: Fix Draft_SelectPlane ignores nesting --- src/Mod/Draft/draftguitools/gui_selectplane.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Mod/Draft/draftguitools/gui_selectplane.py b/src/Mod/Draft/draftguitools/gui_selectplane.py index adf753db5c..22d97e722d 100644 --- a/src/Mod/Draft/draftguitools/gui_selectplane.py +++ b/src/Mod/Draft/draftguitools/gui_selectplane.py @@ -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":