diff --git a/src/Mod/PartDesign/App/DatumCS.cpp b/src/Mod/PartDesign/App/DatumCS.cpp index ba8af598cd..d070de182f 100644 --- a/src/Mod/PartDesign/App/DatumCS.cpp +++ b/src/Mod/PartDesign/App/DatumCS.cpp @@ -32,6 +32,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #ifndef M_PI @@ -47,22 +52,32 @@ using namespace PartDesign; #define POINT QObject::tr("DPOINT") #define ANGLE QObject::tr("Angle") #define CS QObject::tr("DCOORDINATESYSTEM") +#define DONE QObject::tr("Done") std::map, std::set > CoordinateSystem::hints = std::map, std::set >(); void CoordinateSystem::initHints() { - std::set DONE; - DONE.insert(QObject::tr("Done")); + std::set Done; + Done.insert(QObject::tr("Done")); std::multiset key; std::set value; key.insert(POINT); - hints[key] = DONE; - + hints[key] = Done; + key.clear(); value.clear(); key.insert(PLANE); - hints[key] = DONE; + value.insert(LINE); + value.insert(DONE); + hints[key] = value; + + key.clear(); value.clear(); + key.insert(PLANE); + key.insert(LINE); + value.insert(LINE); + value.insert(DONE); + hints[key] = value; } // ============================================================================ @@ -106,20 +121,20 @@ void CoordinateSystem::onChanged(const App::Property *prop) //build the placement from the references bool plane = false; - Base::Vector3d pl_base, pl_normal; + Base::Vector3d pl_base(0,0,0), pl_normal(0,0,1); int count = 0; - for(App::DocumentObject* obj : refs) { + for(int i = 0; i < refs.size(); i++) { - if (obj->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { - PartDesign::Plane* p = static_cast(obj); + if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { + PartDesign::Plane* p = static_cast(refs[i]); if(!plane) { pl_base = p->getBasePoint(); pl_normal = p->getNormal(); plane=true; } - } else if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { - PartDesign::Plane* p = static_cast(obj); + } else if (refs[i]->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { + PartDesign::Plane* p = static_cast(refs[i]); if(!plane) { pl_base = Base::Vector3d(0,0,0); if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0) @@ -132,6 +147,50 @@ void CoordinateSystem::onChanged(const App::Property *prop) plane=true; } } + else if (refs[i]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + Part::Feature* feature = static_cast(refs[i]); + const TopoDS_Shape& sh = feature->Shape.getValue(); + if (sh.IsNull()) + return; // "PartDesign::Plane: Reference has NULL shape" + // Get subshape + TopoDS_Shape subshape = feature->Shape.getShape().getSubShape(subrefs[i].c_str()); + if (subshape.IsNull()) + return; // "PartDesign::Plane: Reference has NULL subshape"; + + if (subshape.ShapeType() == TopAbs_VERTEX) {/* + TopoDS_Vertex v = TopoDS::Vertex(subshape); + gp_Pnt p = BRep_Tool::Pnt(v); + if (p1 == NULL) + p1 = new Base::Vector3d(p.X(), p.Y(), p.Z()); + else if (p2 == NULL) + p2 = new Base::Vector3d(p.X(), p.Y(), p.Z()); + else + p3 = new Base::Vector3d(p.X(), p.Y(), p.Z());*/ + } else if (subshape.ShapeType() == TopAbs_EDGE) { /* + TopoDS_Edge e = TopoDS::Edge(subshape); + BRepAdaptor_Curve adapt(e); + if (adapt.GetType() != GeomAbs_Line) + return; // Non-linear edge + line = new gp_Lin(adapt.Line());*/ + } else if (subshape.ShapeType() == TopAbs_FACE) { + TopoDS_Face f = TopoDS::Face(subshape); + BRepAdaptor_Surface adapt(f); + if (adapt.GetType() == GeomAbs_Plane) { + // 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 pl = adapt.Plane(); + gp_Dir d = pl.Axis().Direction(); + const gp_Pnt& p = pl.Location(); + if (reverse) d.Reverse(); + + pl_base = Base::Vector3d(p.X(), p.Y(), p.Z()); + pl_normal = Base::Vector3d(d.X(), d.Y(), d.Z()); + plane = true; + } else { + return; // invalid surface type + } + } + } count++; }; @@ -142,12 +201,12 @@ void CoordinateSystem::onChanged(const App::Property *prop) //add the offsets Base::Vector3d o1; - plm.multVec(Offset.getValue()*Base::Vector3d(1,0,0), o1); + plm.getRotation().multVec(Base::Vector3d(1,0,0), o1); Base::Vector3d o2; - plm.multVec(Offset2.getValue()*Base::Vector3d(0,1,0), o2); + plm.getRotation().multVec(Offset2.getValue()*Base::Vector3d(0,1,0), o2); Base::Vector3d o3; - plm.multVec(Offset3.getValue()*Base::Vector3d(0,0,1), o3); - plm.move(o1+o2+o3); + plm.getRotation().multVec(Offset3.getValue()*Base::Vector3d(0,0,1), o3); + plm.move(Offset.getValue()*o1+Offset2.getValue()*o2+Offset3.getValue()*o3); Placement.setValue(plm); }