From ba17aa283988fc8652ebb41cda8062f3015c9d62 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Fri, 10 May 2013 14:22:02 +0430 Subject: [PATCH] Try to be consistent with sketch plane orientation PartDesign module <-> Sketcher module --- src/Mod/Part/App/Part2DObject.cpp | 27 +++++++++++++++------------ src/Mod/PartDesign/App/DatumPlane.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/Mod/Part/App/Part2DObject.cpp b/src/Mod/Part/App/Part2DObject.cpp index b170d05d5..8bc7f5624 100644 --- a/src/Mod/Part/App/Part2DObject.cpp +++ b/src/Mod/Part/App/Part2DObject.cpp @@ -95,7 +95,10 @@ void Part2DObject::positionBySupport(void) // Set placement identical to the way it used to be done in the Sketcher::SketchOrientationDialog if (dir == Base::Vector3d(0,0,1)) { - Place = Base::Placement(Base::Vector3d(0,0,0),Base::Rotation(Reverse ? -1.0 : 0.0, 0.0,0.0,0.0)); + if (Reverse) + Place = Base::Placement(Base::Vector3d(0,0,0),Base::Rotation(-1.0, 0.0,0.0,0.0)); + else + Place = Base::Placement(Base::Vector3d(0,0,0),Base::Rotation()); } else if (dir == Base::Vector3d(0,1,0)) { if (Reverse) Place = Base::Placement(Base::Vector3d(0,0,0),Base::Rotation(Base::Vector3d(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0),M_PI)); @@ -113,18 +116,18 @@ void Part2DObject::positionBySupport(void) Place.getRotation().multVec(Base::Vector3d(0,0,1),dir); Base::Vector3d pos = Place.getPosition(); plane = gp_Pln(gp_Pnt(pos.x, pos.y, pos.z), gp_Dir(dir.x, dir.y, dir.z)); - } else if (support->getTypeId() == Part::Datum::getClassTypeId()) { + } else if (support->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { + const std::vector &sub = Support.getSubValues(); + assert(sub.size()==1); + Part::Datum* pcDatum = static_cast(support); - TopoDS_Shape plane = pcDatum->Shape.getValue(); - if (plane.ShapeType() != TopAbs_FACE) - return; - BRepAdaptor_Surface adapt(TopoDS::Face(plane)); - if (adapt.GetType() != GeomAbs_Plane) - return; - gp_Pln pl = adapt.Plane(); - Base::Vector3d pos(pl.Location().X(), pl.Location().Y(), pl.Location().Z()); - Base::Vector3d normal(pl.Axis().Direction().X(), pl.Axis().Direction().Y(), pl.Axis().Direction().Z()); - this->Placement.setValue(Base::Placement(pos, Base::Rotation(Base::Vector3d(0,0,1), normal))); + Place = pcDatum->Placement.getValue(); + Base::Vector3d dir; + Place.getRotation().multVec(Base::Vector3d(0,0,1),dir); + if (!sub.empty() && (sub[0] == "back")) + dir *= -1.0; + Base::Vector3d pos = Place.getPosition(); + plane = gp_Pln(gp_Pnt(pos.x, pos.y, pos.z), gp_Dir(dir.x, dir.y, dir.z)); } else { Part::Feature *part = static_cast(support); if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) diff --git a/src/Mod/PartDesign/App/DatumPlane.cpp b/src/Mod/PartDesign/App/DatumPlane.cpp index 76408b61a..676588bbf 100644 --- a/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/src/Mod/PartDesign/App/DatumPlane.cpp @@ -44,6 +44,7 @@ # include # include # include +# include # include # include # include @@ -213,10 +214,10 @@ void Plane::onChanged(const App::Property *prop) normal = new Base::Vector3d; if (strcmp(p->getNameInDocument(), "BaseplaneXY") == 0) *normal = Base::Vector3d(0,0,1); - else if (strcmp(p->getNameInDocument(), "BaseplaneYZ") == 0) - *normal = Base::Vector3d(1,0,0); else if (strcmp(p->getNameInDocument(), "BaseplaneXZ") == 0) *normal = Base::Vector3d(0,1,0); + else if (strcmp(p->getNameInDocument(), "BaseplaneYZ") == 0) + *normal = Base::Vector3d(1,0,0); } else if (refs[i]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { Part::Feature* feature = static_cast(refs[i]); const TopoDS_Shape& sh = feature->Shape.getValue(); @@ -247,8 +248,26 @@ void Plane::onChanged(const App::Property *prop) BRepAdaptor_Surface adapt(f); if (adapt.GetType() != GeomAbs_Plane) return; // Non-planar face - gp_Pnt b = adapt.Plane().Location(); + + // Ensure that the front and back of the plane corresponds with the face's idea of front and back + bool reverse = (f.Orientation() == TopAbs_REVERSED); + gp_Pln plane = adapt.Plane(); + if (!plane.Direct()) { + // toggle if plane has a left-handed coordinate system + plane.UReverse(); + reverse = !reverse; + } gp_Dir d = adapt.Plane().Axis().Direction(); + if (reverse) d.Reverse(); + + // Ensure that the position of the placement corresponds to what the face would yield in + // Part2DObject::positionBySupport() + Base::Vector3d pos = feature->Placement.getValue().getPosition(); + gp_Pnt gp_pos(pos.x,pos.y,pos.z); + Handle (Geom_Plane) gPlane = new Geom_Plane(plane); + GeomAPI_ProjectPointOnSurf projector(gp_pos,gPlane); + gp_Pnt b = projector.NearestPoint(); + p1 = new Base::Vector3d(b.X(), b.Y(), b.Z()); normal = new Base::Vector3d(d.X(), d.Y(), d.Z()); }