diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index bcbfbead1..f5d593b00 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -394,6 +394,30 @@ std::vector SelectionSingleton::getSelectionEx(const char* pDoc return temp; } +int SelectionSingleton::getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const +{ + std::vector sel = this->getSelectionEx(); + std::vector objs; objs.reserve(sel.size()*2); + std::vector subs; subs.reserve(sel.size()*2); + for( int iobj = 0 ; iobj < sel.size() ; iobj++ ){ + Gui::SelectionObject &selitem = sel[iobj]; + App::DocumentObject* obj = selitem.getObject(); + const std::vector &subnames = selitem.getSubNames(); + if (subnames.size() == 0){//whole object is selected + objs.push_back(obj); + subs.push_back(std::string()); + } else { + for( int isub = 0 ; isub < subnames.size() ; isub++ ){ + objs.push_back(obj); + subs.push_back(subnames[isub]); + } + } + } + assert(objs.size()==subs.size()); + prop.setValues(objs, subs); + return objs.size(); +} + vector SelectionSingleton::getObjectsOfType(const Base::Type& typeId, const char* pDocName) const { std::vector temp; diff --git a/src/Gui/Selection.h b/src/Gui/Selection.h index 6e411d319..064ec402d 100644 --- a/src/Gui/Selection.h +++ b/src/Gui/Selection.h @@ -287,6 +287,13 @@ public: */ std::vector getSelectionEx(const char* pDocName=0,Base::Type typeId=App::DocumentObject::getClassTypeId()) const; + /** + * @brief getAsPropertyLinkSubList fills PropertyLinkSubList with current selection. + * @param prop (output). The property object to recieve links + * @return the number of items written to the link + */ + int getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const; + /** Returns a vector of all selection objects of all documents. */ std::vector getCompleteSelection() const; bool hasSelection() const;