Share code for finding a body containing a feature
This commit is contained in:
committed by
Stefan Tröger
parent
16e4ce20f0
commit
ffc6cc2f23
@@ -232,6 +232,12 @@ const bool Body::isAllowed(const App::DocumentObject* f)
|
||||
}
|
||||
|
||||
|
||||
Body* Body::findBodyOf(const App::DocumentObject* feature)
|
||||
{
|
||||
return static_cast<Body*>(BodyBase::findBodyOf(feature));
|
||||
}
|
||||
|
||||
|
||||
void Body::addFeature(App::DocumentObject *feature)
|
||||
{
|
||||
insertFeature (feature, Tip.getValue(), /*after = */ true);
|
||||
|
||||
@@ -117,6 +117,12 @@ public:
|
||||
*/
|
||||
static const bool isAllowed(const App::DocumentObject* f);
|
||||
|
||||
/**
|
||||
* Return the body which this feature belongs too, or NULL
|
||||
* The only difference to BodyBase::findBodyOf() is that this one casts value to Body*
|
||||
*/
|
||||
static Body *findBodyOf(const App::DocumentObject* feature);
|
||||
|
||||
/// Return the bounding box of the Tip Shape, taking into account datum features
|
||||
Base::BoundBox3d getBoundBox();
|
||||
|
||||
|
||||
@@ -85,18 +85,13 @@ App::DocumentObjectExecReturn *Boolean::execute(void)
|
||||
if (baseTopShape._Shape.IsNull())
|
||||
return new App::DocumentObjectExecReturn("Cannot do boolean operation with invalid base shape");
|
||||
|
||||
// TODO: move PartDesignGui::getBodyFor() from Gui to App and use it here
|
||||
//get the body this boolean feature belongs to
|
||||
PartDesign::Body* baseBody = NULL;
|
||||
for(PartDesign::Body* b : this->getDocument()->getObjectsOfType<PartDesign::Body>()) {
|
||||
if(b->hasFeature(this)) {
|
||||
baseBody = b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Part::BodyBase* baseBody = Part::BodyBase::findBodyOf(this);
|
||||
|
||||
if(!baseBody)
|
||||
return new App::DocumentObjectExecReturn("Cannot do boolean on feature which is not in a body");
|
||||
|
||||
// TODO: share the code snippet with PartDesignGui::getPartFor()
|
||||
//get the part every body should belong to
|
||||
App::Part* part = NULL;
|
||||
for(App::Part* p : this->getDocument()->getObjectsOfType<App::Part>()) {
|
||||
|
||||
Reference in New Issue
Block a user