diff --git a/src/App/Part.cpp b/src/App/Part.cpp index 67b0c0470..bea977748 100644 --- a/src/App/Part.cpp +++ b/src/App/Part.cpp @@ -66,6 +66,26 @@ Part::~Part(void) { } +App::Part *Part::getPartOfObject (const DocumentObject* obj, bool indirect) { + const Document* doc = obj->getDocument(); + std::vector grps = doc->getObjectsOfType ( Part::getClassTypeId() ); + + for (auto partObj: grps) { + Part* part = static_cast (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 --------------------------------------------------------- diff --git a/src/App/Part.h b/src/App/Part.h index 3827332f1..4de2806f9 100644 --- a/src/App/Part.h +++ b/src/App/Part.h @@ -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); };