#2818 Selection manager. Add strict method variant

This commit is contained in:
Bjørn Erik Jensen 2018-05-07 09:44:38 +02:00
parent 9885c9d2d7
commit 0e8eae33db
2 changed files with 29 additions and 0 deletions

View File

@ -103,6 +103,22 @@ public:
}
}
template <typename T>
void objectsByTypeStrict(std::vector<T*>* typedObjects, int role = SelectionManager::APPLICATION_GLOBAL)
{
std::vector<PdmUiItem*> items;
this->selectedItems(items, role);
for (size_t i = 0; i < items.size(); i++)
{
T* obj = dynamic_cast<T*>(items[i]);
if (!obj)
{
typedObjects->clear();
break;
}
typedObjects->push_back(obj);
}
}
private:
SelectionManager();

View File

@ -75,4 +75,17 @@ std::vector<T> selectedObjectsByType()
return objectByType;
}
//--------------------------------------------------------------------------------------------------
/// Return all objects of given type from the selection manager.
/// If objects of different type are selected, an empty list is returned.
//--------------------------------------------------------------------------------------------------
template<typename T>
std::vector<T> selectedObjectsByTypeStrict()
{
std::vector<T> objectByType;
caf::SelectionManager::instance()->objectsByTypeStrict(&objectByType);
return objectByType;
}
} // end namespace caf