diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 4c1682f6c..de1014f9b 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -317,7 +317,6 @@ App::DocumentObjectExecReturn *Body::execute(void) return App::DocumentObject::StdReturn; Shape.setValue(TipShape); - return App::DocumentObject::StdReturn; } @@ -338,13 +337,13 @@ Base::BoundBox3d Body::getBoundBox() for (std::vector::const_iterator m = model.begin(); m != model.end(); m++) { if ((*m)->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) { PartDesign::Point* point = static_cast(*m); - result.Add(point->_Point.getValue()); + result.Add(point->getPoint()); } else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { PartDesign::Line* line = static_cast(*m); - result.Add(line->_Base.getValue()); + result.Add(line->getBasePoint()); } else if ((*m)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { PartDesign::Plane* plane = static_cast(*m); - result.Add(plane->_Base.getValue()); + result.Add(plane->getBasePoint()); } else if ((*m)->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { // Note: We only take into account the base planes here result.Add(Base::Vector3d(0,0,0)); diff --git a/src/Mod/PartDesign/App/DatumLine.cpp b/src/Mod/PartDesign/App/DatumLine.cpp index 37c7c5b31..bed809869 100644 --- a/src/Mod/PartDesign/App/DatumLine.cpp +++ b/src/Mod/PartDesign/App/DatumLine.cpp @@ -116,12 +116,14 @@ PROPERTY_SOURCE(PartDesign::Line, Part::Datum) Line::Line() { - ADD_PROPERTY_TYPE(_Base,(Base::Vector3d(0,0,0)),"DatumLine", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Coordinates of the line base point"); - ADD_PROPERTY_TYPE(_Direction,(Base::Vector3d(1,1,1)),"DatumLine", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Coordinates of the line direction"); + // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of + // Sketcher on the PartDesign module + BRepBuilderAPI_MakeEdge builder(gp_Lin(gp_Pnt(0,0,0), gp_Dir(0,0,1))); + if (!builder.IsDone()) + return; + Shape.setValue(builder.Shape()); + + References.touch(); } Line::~Line() @@ -155,17 +157,17 @@ void Line::onChanged(const App::Property *prop) if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) { PartDesign::Point* p = static_cast(refs[i]); if (p1 == NULL) - p1 = new Base::Vector3d (p->_Point.getValue()); + p1 = new Base::Vector3d (p->getPoint()); else - p2 = new Base::Vector3d (p->_Point.getValue()); + p2 = new Base::Vector3d (p->getPoint()); } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { PartDesign::Line* l = static_cast(refs[i]); - base = new Base::Vector3d (l->_Base.getValue()); - direction = new Base::Vector3d (l->_Direction.getValue()); + base = new Base::Vector3d (l->getBasePoint()); + direction = new Base::Vector3d (l->getDirection()); } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { PartDesign::Plane* p = static_cast(refs[i]); - Base::Vector3d base = p->_Base.getValue(); - Base::Vector3d normal = p->_Normal.getValue(); + Base::Vector3d base = p->getBasePoint(); + Base::Vector3d normal = p->getNormal(); if (s1.IsNull()) s1 = new Geom_Plane(gp_Pnt(base.x, base.y, base.z), gp_Dir(normal.x, normal.y, normal.z)); else @@ -247,16 +249,7 @@ void Line::onChanged(const App::Property *prop) return; } - _Base.setValue(*base); - _Direction.setValue(*direction); - _Base.touch(); // This triggers ViewProvider::updateData() - - // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of - // Sketcher on the PartDesign module - BRepBuilderAPI_MakeEdge builder(gp_Lin(gp_Pnt(base->x, base->y, base->z), gp_Dir(direction->x, direction->y, direction->z))); - if (!builder.IsDone()) - return; - Shape.setValue(builder.Shape()); + Placement.setValue(Base::Placement(*base, Base::Rotation(Base::Vector3d(0,0,1), *direction))); delete base; delete direction; @@ -268,7 +261,6 @@ void Line::onChanged(const App::Property *prop) Part::Datum::onChanged(prop); } - const std::set Line::getHint() { if (hints.find(refTypes) != hints.end()) @@ -276,3 +268,16 @@ const std::set Line::getHint() else return std::set(); } + +Base::Vector3d Line::getBasePoint() +{ + return Placement.getValue().getPosition(); +} + +Base::Vector3d Line::getDirection() +{ + Base::Rotation rot = Placement.getValue().getRotation(); + Base::Vector3d dir; + rot.multVec(Base::Vector3d(0,0,1), dir); + return dir; +} diff --git a/src/Mod/PartDesign/App/DatumLine.h b/src/Mod/PartDesign/App/DatumLine.h index 6ca976106..a70956a26 100644 --- a/src/Mod/PartDesign/App/DatumLine.h +++ b/src/Mod/PartDesign/App/DatumLine.h @@ -37,9 +37,6 @@ class PartDesignExport Line : public Part::Datum PROPERTY_HEADER(PartDesign::Line); public: - App::PropertyVector _Base; - App::PropertyVector _Direction; - Line(); virtual ~Line(); @@ -50,6 +47,9 @@ public: static void initHints(); const std::set getHint(); + Base::Vector3d getBasePoint(); + Base::Vector3d getDirection(); + protected: virtual void onChanged(const App::Property* prop); diff --git a/src/Mod/PartDesign/App/DatumPlane.cpp b/src/Mod/PartDesign/App/DatumPlane.cpp index f42f71339..76408b61a 100644 --- a/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/src/Mod/PartDesign/App/DatumPlane.cpp @@ -131,7 +131,6 @@ void Plane::initHints() key.insert(LINE); key.insert(PLANE); key.insert(ANGLE); hints[key] = DONE; // {LINE, PLANE, ANGLE} -> DONE. Plane through line with angle to other plane - key.clear(); value.clear(); value.insert(POINT); value.insert(LINE); value.insert(PLANE); value.insert(ANGLE); hints[key] = value; @@ -143,12 +142,18 @@ PROPERTY_SOURCE(PartDesign::Plane, Part::Datum) Plane::Plane() { -ADD_PROPERTY_TYPE(_Base,(Base::Vector3d(0,0,0)),"DatumPlane", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Coordinates of the plane base point"); -ADD_PROPERTY_TYPE(_Normal,(Base::Vector3d(1,1,1)),"DatumPlane", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Coordinates of the plane normal"); + // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of + // Sketcher on the PartDesign module + BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(0,0,0), gp_Dir(0,0,1))); + if (!builder.IsDone()) + return; + Shape.setValue(builder.Shape()); + + References.touch(); +} + +Plane::~Plane() +{ } void Plane::onChanged(const App::Property *prop) @@ -187,20 +192,20 @@ void Plane::onChanged(const App::Property *prop) if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) { PartDesign::Point* p = static_cast(refs[i]); if (p1 == NULL) - p1 = new Base::Vector3d (p->_Point.getValue()); + p1 = new Base::Vector3d (p->getPoint()); else if (p2 == NULL) - p2 = new Base::Vector3d (p->_Point.getValue()); + p2 = new Base::Vector3d (p->getPoint()); else - p3 = new Base::Vector3d (p->_Point.getValue()); + p3 = new Base::Vector3d (p->getPoint()); } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { PartDesign::Line* l = static_cast(refs[i]); - Base::Vector3d base = l->_Base.getValue(); - Base::Vector3d dir = l->_Direction.getValue(); + Base::Vector3d base = l->getBasePoint(); + Base::Vector3d dir = l->getDirection(); line = new gp_Lin(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z)); } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { PartDesign::Plane* p = static_cast(refs[i]); - p1 = new Base::Vector3d(p->_Base.getValue()); - normal = new Base::Vector3d(p->_Normal.getValue()); + p1 = new Base::Vector3d(p->getBasePoint()); + normal = new Base::Vector3d(p->getNormal()); } else if (refs[i]->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { App::Plane* p = static_cast(refs[i]); // Note: We only handle the three base planes here @@ -284,16 +289,7 @@ void Plane::onChanged(const App::Property *prop) if (fabs(Offset.getValue()) > Precision::Confusion()) *p1 += Offset.getValue() * *normal; - _Base.setValue(*p1); - _Normal.setValue(*normal); - _Base.touch(); // This triggers ViewProvider::updateData() - - // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of - // Sketcher on the PartDesign module - BRepBuilderAPI_MakeFace builder(gp_Pln(gp_Pnt(p1->x, p1->y, p1->z), gp_Dir(normal->x, normal->y, normal->z))); - if (!builder.IsDone()) - return; - Shape.setValue(builder.Shape()); + Placement.setValue(Base::Placement(*p1,Base::Rotation(Base::Vector3d(0,0,1), *normal))); delete p1; delete normal; @@ -313,3 +309,16 @@ const std::set Plane::getHint() else return std::set(); } + +Base::Vector3d Plane::getBasePoint() +{ + return Placement.getValue().getPosition(); +} + +Base::Vector3d Plane::getNormal() +{ + Base::Rotation rot = Placement.getValue().getRotation(); + Base::Vector3d normal; + rot.multVec(Base::Vector3d(0,0,1), normal); + return normal; +} diff --git a/src/Mod/PartDesign/App/DatumPlane.h b/src/Mod/PartDesign/App/DatumPlane.h index 03e2026b3..d64ed6900 100644 --- a/src/Mod/PartDesign/App/DatumPlane.h +++ b/src/Mod/PartDesign/App/DatumPlane.h @@ -36,10 +36,8 @@ class PartDesignExport Plane : public Part::Datum PROPERTY_HEADER(PartDesign::Plane); public: - App::PropertyVector _Base; - App::PropertyVector _Normal; - Plane(); + virtual ~Plane(); const char* getViewProviderName(void) const { return "PartDesignGui::ViewProviderDatumPlane"; @@ -48,6 +46,9 @@ public: static void initHints(); const std::set getHint(); + Base::Vector3d getBasePoint(); + Base::Vector3d getNormal(); + protected: virtual void onChanged(const App::Property* prop); diff --git a/src/Mod/PartDesign/App/DatumPoint.cpp b/src/Mod/PartDesign/App/DatumPoint.cpp index e9f5d3387..b54d98d2c 100644 --- a/src/Mod/PartDesign/App/DatumPoint.cpp +++ b/src/Mod/PartDesign/App/DatumPoint.cpp @@ -129,9 +129,14 @@ PROPERTY_SOURCE(PartDesign::Point, Part::Datum) Point::Point() { - ADD_PROPERTY_TYPE(_Point,(Base::Vector3d(0,0,0)),"DatumPoint", - App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Coordinates of the datum point"); + // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of + // Sketcher on the PartDesign module + BRepBuilderAPI_MakeVertex builder(gp_Pnt(0,0,0)); + if (!builder.IsDone()) + return; + Shape.setValue(builder.Shape()); + + References.touch(); } Point::~Point() @@ -163,19 +168,19 @@ void Point::onChanged(const App::Property* prop) for (int i = 0; i < refs.size(); i++) { if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())) { PartDesign::Point* p = static_cast(refs[i]); - point = new Base::Vector3d (p->_Point.getValue()); + point = new Base::Vector3d (p->getPoint()); } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { PartDesign::Line* l = static_cast(refs[i]); - Base::Vector3d base = l->_Base.getValue(); - Base::Vector3d dir = l->_Direction.getValue(); + Base::Vector3d base = l->getBasePoint(); + Base::Vector3d dir = l->getDirection(); if (c1.IsNull()) c1 = new Geom_Line(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z)); else c2 = new Geom_Line(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z)); } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { PartDesign::Plane* p = static_cast(refs[i]); - Base::Vector3d base = p->_Base.getValue(); - Base::Vector3d normal = p->_Normal.getValue(); + Base::Vector3d base = p->getBasePoint(); + Base::Vector3d normal = p->getNormal(); if (s1.IsNull()) s1 = new Geom_Plane(gp_Pnt(base.x, base.y, base.z), gp_Dir(normal.x, normal.y, normal.z)); else if (s2.IsNull()) @@ -278,15 +283,7 @@ void Point::onChanged(const App::Property* prop) return; } - _Point.setValue(*point); - _Point.touch(); // This triggers ViewProvider::updateData() - - // Create a shape, which will be used by the Sketcher. Them main function is to avoid a dependency of - // Sketcher on the PartDesign module - BRepBuilderAPI_MakeVertex builder(gp_Pnt(point->x, point->y, point->z)); - if (!builder.IsDone()) - return; - Shape.setValue(builder.Shape()); + Placement.setValue(Base::Placement(*point, Base::Rotation())); delete point; } @@ -294,6 +291,11 @@ void Point::onChanged(const App::Property* prop) Part::Datum::onChanged(prop); } +Base::Vector3d Point::getPoint() +{ + return Placement.getValue().getPosition(); +} + const std::set Point::getHint() { diff --git a/src/Mod/PartDesign/App/DatumPoint.h b/src/Mod/PartDesign/App/DatumPoint.h index e36abf1a3..8f9be2b2d 100644 --- a/src/Mod/PartDesign/App/DatumPoint.h +++ b/src/Mod/PartDesign/App/DatumPoint.h @@ -37,8 +37,6 @@ class PartDesignExport Point : public Part::Datum PROPERTY_HEADER(PartDesign::Point); public: - App::PropertyVector _Point; - Point(); virtual ~Point(); @@ -49,7 +47,7 @@ public: static void initHints(); const std::set getHint(); - + Base::Vector3d getPoint(); protected: virtual void onChanged(const App::Property* prop); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index a7dcb8fee..73a47eb72 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -185,16 +185,16 @@ void ViewProviderBody::updateData(const App::Property* prop) PartDesign::Body* body = static_cast(getObject()); std::vector features = body->Model.getValues(); for (std::vector::const_iterator f = features.begin(); f != features.end(); f++) { - App::PropertyVector* baseProp = NULL; + App::PropertyPlacement* plm = NULL; if ((*f)->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) - baseProp = &(static_cast(*f)->_Base); + plm = &(static_cast(*f)->Placement); else if ((*f)->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) - baseProp = &(static_cast(*f)->_Base); + plm = &(static_cast(*f)->Placement); - if (baseProp != NULL) { + if (plm != NULL) { Gui::ViewProviderDocumentObject* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*f)); if (vp != NULL) - vp->updateData(baseProp); + vp->updateData(plm); } } diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp index d490c0459..79426eaff 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp @@ -77,15 +77,18 @@ void ViewProviderDatumLine::updateData(const App::Property* prop) // Gets called whenever a property of the attached object changes PartDesign::Line* pcDatum = static_cast(this->getObject()); - if (strcmp(prop->getName(),"_Base") == 0) { - Base::Vector3d base = pcDatum->_Base.getValue(); - Base::Vector3d dir = pcDatum->_Direction.getValue(); + if (strcmp(prop->getName(),"Placement") == 0) { + Base::Placement plm = pcDatum->Placement.getValue(); + plm.invert(); + Base::Vector3d base(0,0,0); + Base::Vector3d dir(0,0,1); // Get limits of the line from bounding box of the body PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); if (body == NULL) return; Base::BoundBox3d bbox = body->getBoundBox(); + bbox = bbox.Transformed(plm.toMatrix()); bbox.Enlarge(0.1 * bbox.CalcDiagonalLength()); Base::Vector3d p1, p2; if (bbox.IsInBox(base)) { diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp index 97ddf1997..a1bfb78cd 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp @@ -77,15 +77,18 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop) // Gets called whenever a property of the attached object changes PartDesign::Plane* pcDatum = static_cast(this->getObject()); - if (strcmp(prop->getName(),"_Base") == 0) { - Base::Vector3d base = pcDatum->_Base.getValue(); - Base::Vector3d normal = pcDatum->_Normal.getValue(); + if (strcmp(prop->getName(),"Placement") == 0) { + Base::Placement plm = pcDatum->Placement.getValue(); + plm.invert(); + Base::Vector3d base(0,0,0); + Base::Vector3d normal(0,0,1); // Get limits of the plane from bounding box of the body PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); if (body == NULL) return; Base::BoundBox3d bbox = body->getBoundBox(); + bbox = bbox.Transformed(plm.toMatrix()); double dlength = bbox.CalcDiagonalLength(); bbox.Enlarge(0.1 * dlength); diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp index 2ec1fe8ff..008858392 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp @@ -62,39 +62,29 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumPoint,PartDesignGui::ViewProvide ViewProviderDatumPoint::ViewProviderDatumPoint() { SoMarkerSet* points = new SoMarkerSet(); - points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9; - points->numPoints = 0; + points->markerIndex = SoMarkerSet::DIAMOND_FILLED_9_9; + SoMFVec3f v; + v.setNum(1); + v.set1Value(0, 0,0,0); + SoVertexProperty* vprop = new SoVertexProperty(); + vprop->vertex = v; + points->vertexProperty = vprop; + points->numPoints = 1; pShapeSep->addChild(points); } ViewProviderDatumPoint::~ViewProviderDatumPoint() { - } void ViewProviderDatumPoint::updateData(const App::Property* prop) { - // Gets called whenever a property of the attached object changes - PartDesign::Point* pcDatum = static_cast(this->getObject()); - - if (strcmp(prop->getName(),"_Point") == 0) { - Base::Vector3d p = pcDatum->_Point.getValue(); - SoMFVec3f v; - v.setNum(1); - v.set1Value(0, p.x, p.y, p.z); + if (strcmp(prop->getName(),"Placement") == 0) { + // The only reason to do this is to display the point in the correct position after loading the document SoMarkerSet* points = static_cast(pShapeSep->getChild(0)); - - SoVertexProperty* vprop; - if (points->vertexProperty.getValue() == NULL) { - vprop = new SoVertexProperty(); - vprop->vertex = v; - points->vertexProperty = vprop; - } else { - vprop = static_cast(points->vertexProperty.getValue()); - vprop->vertex = v; - } - - points->numPoints = 1; + points->touch(); + //points->numPoints = 0; + //points->numPoints = 1; } ViewProviderDatum::updateData(prop);