App/Part: add getPartOfObject() to search a part for object

This commit is contained in:
Alexander Golubev 2015-09-08 10:20:25 +03:00 committed by Stefan Tröger
parent 1a26f7551f
commit 56823eeb9d
2 changed files with 31 additions and 2 deletions

View File

@ -66,6 +66,26 @@ Part::~Part(void)
{
}
App::Part *Part::getPartOfObject (const DocumentObject* obj, bool indirect) {
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsOfType ( Part::getClassTypeId() );
for (auto partObj: grps) {
Part* part = static_cast <Part* >(partObj);
if ( indirect ) {
if ( part->geoHasObject (obj) ) {
return part;
}
} else {
if ( part->hasObject (obj) ) {
return part;
}
}
}
return 0;
}
PyObject *Part::getPyObject()
{
@ -73,7 +93,7 @@ PyObject *Part::getPyObject()
// ref counter is set to 1
PythonObject = Py::Object(new PartPy(this),true);
}
return Py::new_reference_to(PythonObject);
return Py::new_reference_to(PythonObject);
}
// Python feature ---------------------------------------------------------

View File

@ -50,7 +50,7 @@ public:
//@{
/// Id e.g. Part number
App::PropertyString Id;
/// unique identifier of the Item
/// unique identifier of the Item
App::PropertyUUID Uid;
/// material descriptons
App::PropertyMap Material;
@ -84,6 +84,15 @@ public:
return "Gui::ViewProviderPart";
}
/**
* Returns the part which contains this object.
* In case this object is not belongs to any Part 0 is returned.
* @param obj the object to search for
* @param indirect if true return if the part that so-called geoHas the object, @see geoHasObject()
* default is true
*/
static App::Part* getPartOfObject (const DocumentObject* obj, bool indirect=true);
virtual PyObject *getPyObject(void);
};