Try to be consistent with sketch plane orientation PartDesign module <-> Sketcher module
This commit is contained in:
parent
fe2e490645
commit
ba17aa2839
|
@ -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<std::string> &sub = Support.getSubValues();
|
||||
assert(sub.size()==1);
|
||||
|
||||
Part::Datum* pcDatum = static_cast<Part::Datum*>(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<Part::Feature*>(support);
|
||||
if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
# include <GeomAPI_IntCS.hxx>
|
||||
# include <GeomAPI_IntSS.hxx>
|
||||
# include <GeomAPI_ExtremaCurveCurve.hxx>
|
||||
# include <GeomAPI_ProjectPointOnSurf.hxx>
|
||||
# include <Precision.hxx>
|
||||
# include <Standard_Real.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
|
@ -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<Part::Feature*>(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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user