Moved some methods from PartDesign::Body to Part::BodyBase so the SketchObjects will be removed cleanly from the Body when deleted

This commit is contained in:
jrheinlaender 2013-05-04 10:52:54 +04:30 committed by Stefan Tröger
parent 5b3d5e6bd8
commit 02dfb8551d
13 changed files with 77 additions and 62 deletions

View File

@ -25,6 +25,8 @@
#ifndef _PreComp_
#endif
#include <App/Application.h>
#include <App/Document.h>
#include <Base/Placement.h>
#include "BodyBase.h"
@ -55,4 +57,25 @@ App::DocumentObjectExecReturn *BodyBase::execute(void)
return App::DocumentObject::StdReturn;
}
}
const bool BodyBase::hasFeature(const App::DocumentObject* f) const
{
const std::vector<App::DocumentObject*> 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<App::DocumentObject*> bodies = doc->getObjectsOfType(BodyBase::getClassTypeId());
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++) {
BodyBase* body = static_cast<BodyBase*>(*b);
if (body->hasFeature(f))
return body;
}
}
return NULL;
}
}

View File

@ -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

View File

@ -83,6 +83,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Command.h>
#include <Gui/Application.h>
#include <Gui/Selection.h>
#include <Gui/View3DInventorViewer.h>
@ -90,6 +91,7 @@
#include "ViewProvider.h"
#include "SoFCShapeObject.h"
#include <Mod/Part/App/BodyBase.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/PrimitiveFeature.h>
@ -123,6 +125,29 @@ bool ViewProviderPart::doubleClicked(void)
}
}
bool ViewProviderPart::onDelete(const std::vector<std::string> &)
{
// 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<App::Color>& colBase,
std::vector<App::Color>& colBool)

View File

@ -31,7 +31,7 @@
#include <Gui/ViewProviderBuilder.h>
#include <Mod/Part/Gui/ViewProviderExt.h>
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<std::string> &);
protected:
void applyColor(const Part::ShapeHistory& hist,
const std::vector<App::Color>& colBase,

View File

@ -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<App::DocumentObject*> features = Model.getValues();
return std::find(features.begin(), features.end(), f) != features.end();
}
const bool Body::isAfterTip(const App::DocumentObject *f) {
std::vector<App::DocumentObject*> features = Model.getValues();
std::vector<App::DocumentObject*>::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<App::DocumentObject*> bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId());
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++) {
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);
if (body->hasFeature(f))
return body;
}
}
return NULL;
}
void Body::addFeature(App::DocumentObject *feature)
{
// Set the BaseFeature property

View File

@ -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);

View File

@ -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<PartDesign::Body*>(Part::BodyBase::findBodyOf(selFeature));
if (pcActiveBody != NULL)
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)",
pcActiveBody->getNameInDocument());

View File

@ -72,27 +72,3 @@ void ViewProvider::updateData(const App::Property* prop)
}
inherited::updateData(prop);
}
bool ViewProvider::onDelete(const std::vector<std::string> &)
{
// 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;
}

View File

@ -42,8 +42,6 @@ public:
virtual bool doubleClicked(void);
void updateData(const App::Property*);
virtual bool onDelete(const std::vector<std::string> &);
protected:
std::string oldWb;
};

View File

@ -105,7 +105,7 @@ void ViewProviderDatum::attach(App::DocumentObject *obj)
bool ViewProviderDatum::onDelete(const std::vector<std::string> &)
{
// 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

View File

@ -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<PartDesign::Body*>(Part::BodyBase::findBodyOf(this->getObject()));
if (body == NULL)
return;
Part::Feature* tipSolid = static_cast<Part::Feature*>(body->getPrevSolidFeature());

View File

@ -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<PartDesign::Body*>(Part::BodyBase::findBodyOf(this->getObject()));
if (body == NULL)
return;
Part::Feature* tipSolid = static_cast<Part::Feature*>(body->getPrevSolidFeature());

View File

@ -4875,5 +4875,5 @@ bool ViewProviderSketch::onDelete(const std::vector<std::string> &subList)
return false;
}
// if not in edit delete the whole object
return true;
return PartGui::ViewProviderPart::onDelete(subList);
}