App/Part: add getPartOfObject() to search a part for object
This commit is contained in:
parent
1a26f7551f
commit
56823eeb9d
|
@ -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 ---------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user