Selection: add getAsPropertyLinkSubList method

Got tired of collecting selection into such properties over and over.
This commit is contained in:
DeepSOIC 2015-07-07 18:15:50 +03:00 committed by Stefan Tröger
parent 03e354f7ac
commit 5449001083
2 changed files with 31 additions and 0 deletions

View File

@ -394,6 +394,30 @@ std::vector<SelectionObject> SelectionSingleton::getSelectionEx(const char* pDoc
return temp;
}
int SelectionSingleton::getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const
{
std::vector<Gui::SelectionObject> sel = this->getSelectionEx();
std::vector<App::DocumentObject*> objs; objs.reserve(sel.size()*2);
std::vector<std::string> 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<std::string> &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<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const Base::Type& typeId, const char* pDocName) const
{
std::vector<App::DocumentObject*> temp;

View File

@ -287,6 +287,13 @@ public:
*/
std::vector<Gui::SelectionObject> 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<SelObj> getCompleteSelection() const;
bool hasSelection() const;