From 02dfb8551d8dbd77acf358e5c9330189293ee372 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Sat, 4 May 2013 10:52:54 +0430 Subject: [PATCH] Moved some methods from PartDesign::Body to Part::BodyBase so the SketchObjects will be removed cleanly from the Body when deleted --- src/Mod/Part/App/BodyBase.cpp | 25 ++++++++++++++++++- src/Mod/Part/App/BodyBase.h | 19 ++++++++++++++ src/Mod/Part/Gui/ViewProvider.cpp | 25 +++++++++++++++++++ src/Mod/Part/Gui/ViewProvider.h | 4 ++- src/Mod/PartDesign/App/Body.cpp | 21 ---------------- src/Mod/PartDesign/App/Body.h | 9 +------ src/Mod/PartDesign/Gui/Command.cpp | 2 +- src/Mod/PartDesign/Gui/ViewProvider.cpp | 24 ------------------ src/Mod/PartDesign/Gui/ViewProvider.h | 2 -- src/Mod/PartDesign/Gui/ViewProviderDatum.cpp | 2 +- .../PartDesign/Gui/ViewProviderDatumLine.cpp | 2 +- .../PartDesign/Gui/ViewProviderDatumPlane.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 2 +- 13 files changed, 77 insertions(+), 62 deletions(-) diff --git a/src/Mod/Part/App/BodyBase.cpp b/src/Mod/Part/App/BodyBase.cpp index 8a5510f2f..8474a0de7 100644 --- a/src/Mod/Part/App/BodyBase.cpp +++ b/src/Mod/Part/App/BodyBase.cpp @@ -25,6 +25,8 @@ #ifndef _PreComp_ #endif +#include +#include #include #include "BodyBase.h" @@ -55,4 +57,25 @@ App::DocumentObjectExecReturn *BodyBase::execute(void) return App::DocumentObject::StdReturn; } -} \ No newline at end of file +const bool BodyBase::hasFeature(const App::DocumentObject* f) const +{ + const std::vector features = Model.getValues(); + return std::find(features.begin(), features.end(), f) != features.end(); +} + +BodyBase* BodyBase::findBodyOf(const App::DocumentObject* f) +{ + App::Document* doc = App::GetApplication().getActiveDocument(); + if (doc != NULL) { + std::vector bodies = doc->getObjectsOfType(BodyBase::getClassTypeId()); + for (std::vector::const_iterator b = bodies.begin(); b != bodies.end(); b++) { + BodyBase* body = static_cast(*b); + if (body->hasFeature(f)) + return body; + } + } + + return NULL; +} + +} diff --git a/src/Mod/Part/App/BodyBase.h b/src/Mod/Part/App/BodyBase.h index e17bf9ad0..6ed022060 100644 --- a/src/Mod/Part/App/BodyBase.h +++ b/src/Mod/Part/App/BodyBase.h @@ -56,6 +56,25 @@ public: // return "PartDesignGui::ViewProviderBodyBase"; //} //@} + + // These methods are located here to avoid a dependency of ViewProviderSketchObject on PartDesign + /// Remove the feature from the body + virtual void removeFeature(App::DocumentObject* feature){} + + /// Return true if the feature belongs to this body + const bool hasFeature(const App::DocumentObject *f) const; + + /** + * Return the solid feature before the given feature, or before the Tip feature + * That is, sketches and datum features are skipped + * If inclusive is true, start or the Tip is returned if it is a solid feature + */ + virtual App::DocumentObject *getPrevSolidFeature(App::DocumentObject *start = NULL, const bool inclusive = true){} + + /// Return the body which this feature belongs too, or NULL + static BodyBase* findBodyOf(const App::DocumentObject* f); + + }; } //namespace Part diff --git a/src/Mod/Part/Gui/ViewProvider.cpp b/src/Mod/Part/Gui/ViewProvider.cpp index 9e1261487..e819feea6 100644 --- a/src/Mod/Part/Gui/ViewProvider.cpp +++ b/src/Mod/Part/Gui/ViewProvider.cpp @@ -83,6 +83,7 @@ #include #include #include +#include #include #include @@ -90,6 +91,7 @@ #include "ViewProvider.h" #include "SoFCShapeObject.h" +#include #include #include @@ -123,6 +125,29 @@ bool ViewProviderPart::doubleClicked(void) } } +bool ViewProviderPart::onDelete(const std::vector &) +{ + // Body feature housekeeping + Part::BodyBase* body = Part::BodyBase::findBodyOf(getObject()); + if (body != NULL) { + body->removeFeature(getObject()); + // Make the new Tip and the previous solid feature visible again + App::DocumentObject* tip = body->Tip.getValue(); + App::DocumentObject* prev = body->getPrevSolidFeature(); + if (tip != NULL) { + Gui::Application::Instance->getViewProvider(tip)->show(); + if ((tip != prev) && (prev != NULL)) + Gui::Application::Instance->getViewProvider(prev)->show(); + } + } + + // TODO: Ask user what to do about dependent objects, e.g. Sketches that have this feature as their support + // 1. Delete + // 2. Suppress + // 3. Re-route + return true; +} + void ViewProviderPart::applyColor(const Part::ShapeHistory& hist, const std::vector& colBase, std::vector& colBool) diff --git a/src/Mod/Part/Gui/ViewProvider.h b/src/Mod/Part/Gui/ViewProvider.h index 5a11239e7..a7314de89 100644 --- a/src/Mod/Part/Gui/ViewProvider.h +++ b/src/Mod/Part/Gui/ViewProvider.h @@ -31,7 +31,7 @@ #include #include -class SoSeparator; +class SoSeparator; namespace Part { struct ShapeHistory; } @@ -57,6 +57,8 @@ public: virtual ~ViewProviderPart(); virtual bool doubleClicked(void); + virtual bool onDelete(const std::vector &); + protected: void applyColor(const Part::ShapeHistory& hist, const std::vector& colBase, diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 4ed343a75..5ed05e42b 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -165,12 +165,6 @@ App::DocumentObject* Body::getNextSolidFeature(App::DocumentObject *start, const return *it; } -const bool Body::hasFeature(const App::DocumentObject* f) const -{ - const std::vector features = Model.getValues(); - return std::find(features.begin(), features.end(), f) != features.end(); -} - const bool Body::isAfterTip(const App::DocumentObject *f) { std::vector features = Model.getValues(); std::vector::const_iterator it = std::find(features.begin(), features.end(), f); @@ -196,21 +190,6 @@ const bool Body::isAllowed(const App::DocumentObject* f) f->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())); } -Body* Body::findBodyOf(const App::DocumentObject* f) -{ - App::Document* doc = App::GetApplication().getActiveDocument(); - if (doc != NULL) { - std::vector bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId()); - for (std::vector::const_iterator b = bodies.begin(); b != bodies.end(); b++) { - PartDesign::Body* body = static_cast(*b); - if (body->hasFeature(f)) - return body; - } - } - - return NULL; -} - void Body::addFeature(App::DocumentObject *feature) { // Set the BaseFeature property diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index 519f7486a..909b92808 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -75,9 +75,6 @@ public: // Return the shape of the feature preceding this feature //const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f); - /// Return true if the feature belongs to this body - const bool hasFeature(const App::DocumentObject *f) const; - /// Return true if the feature is located after the current Tip feature const bool isAfterTip(const App::DocumentObject *f); @@ -87,7 +84,6 @@ public: /// Remove the feature from the body void removeFeature(App::DocumentObject* feature); - /** * Return true if the given feature is a solid feature allowed in a Body. Currently this is only valid * for features derived from PartDesign::Feature @@ -99,10 +95,7 @@ public: * Return true if the given feature is allowed in a Body. Currently allowed are * all features derived from PartDesign::Feature and Part::Datum and sketches */ - static const bool isAllowed(const App::DocumentObject* f); - - /// Return the body which this feature belongs too, or NULL - static Body* findBodyOf(const App::DocumentObject* f); + static const bool isAllowed(const App::DocumentObject* f); PyObject *getPyObject(void); diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index e5ea1da9f..bbdec5054 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -179,7 +179,7 @@ void CmdPartDesignMoveTip::activated(int iMsg) if (!pcActiveBody->hasFeature(selFeature)) { // Switch to other body - pcActiveBody = PartDesign::Body::findBodyOf(selFeature); + pcActiveBody = static_cast(Part::BodyBase::findBodyOf(selFeature)); if (pcActiveBody != NULL) Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)", pcActiveBody->getNameInDocument()); diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index 7dc15728e..89658c81a 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -72,27 +72,3 @@ void ViewProvider::updateData(const App::Property* prop) } inherited::updateData(prop); } - -bool ViewProvider::onDelete(const std::vector &) -{ - // Body feature housekeeping - PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject()); - if (body != NULL) { - body->removeFeature(getObject()); - // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = body->Tip.getValue(); - App::DocumentObject* prev = body->getPrevSolidFeature(); - if (tip != NULL) { - Gui::Application::Instance->getViewProvider(tip)->show(); - if ((tip != prev) && (prev != NULL)) - Gui::Application::Instance->getViewProvider(prev)->show(); - } - } - - // TODO: Ask user what to do about dependent objects, e.g. Sketches that have this feature as their support - // 1. Delete - // 2. Suppress - // 3. Re-route - - return true; -} diff --git a/src/Mod/PartDesign/Gui/ViewProvider.h b/src/Mod/PartDesign/Gui/ViewProvider.h index fd023e0c2..178f84afd 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.h +++ b/src/Mod/PartDesign/Gui/ViewProvider.h @@ -42,8 +42,6 @@ public: virtual bool doubleClicked(void); void updateData(const App::Property*); - virtual bool onDelete(const std::vector &); - protected: std::string oldWb; }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp index badcc5176..c5aafe547 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp @@ -105,7 +105,7 @@ void ViewProviderDatum::attach(App::DocumentObject *obj) bool ViewProviderDatum::onDelete(const std::vector &) { // Body feature housekeeping - PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject()); + Part::BodyBase* body = Part::BodyBase::findBodyOf(getObject()); if (body != NULL) { body->removeFeature(getObject()); // Make the new Tip and the previous solid feature visible again diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp index 00630a5e4..76b9be4ae 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumLine.cpp @@ -82,7 +82,7 @@ void ViewProviderDatumLine::updateData(const App::Property* prop) Base::Vector3d dir = pcDatum->_Direction.getValue(); // Get limits of the line from bounding box of the body - PartDesign::Body* body = PartDesign::Body::findBodyOf(this->getObject()); + PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); if (body == NULL) return; Part::Feature* tipSolid = static_cast(body->getPrevSolidFeature()); diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp index 2265c72db..44af8dddf 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumPlane.cpp @@ -82,7 +82,7 @@ void ViewProviderDatumPlane::updateData(const App::Property* prop) Base::Vector3d normal = pcDatum->_Normal.getValue(); // Get limits of the plane from bounding box of the body - PartDesign::Body* body = PartDesign::Body::findBodyOf(this->getObject()); + PartDesign::Body* body = static_cast(Part::BodyBase::findBodyOf(this->getObject())); if (body == NULL) return; Part::Feature* tipSolid = static_cast(body->getPrevSolidFeature()); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index a77323db2..468ca2249 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -4875,5 +4875,5 @@ bool ViewProviderSketch::onDelete(const std::vector &subList) return false; } // if not in edit delete the whole object - return true; + return PartGui::ViewProviderPart::onDelete(subList); }