SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
10 #ifndef smtk_view_Selection_h
11 #define smtk_view_Selection_h
13 #include "smtk/CoreExports.h"
17 #include "smtk/resource/Component.h"
18 #include "smtk/view/SelectionAction.h"
19 #include "smtk/view/SelectionObserver.h"
130 static Ptr instance();
177 selectionSources = m_selectionSources;
191 registerSelectionValue(
const std::string& valueLabel,
int value,
bool valueMustBeUnique =
true);
195 return m_selectionValueLabels.erase(valueLabel) > 0;
198 bool unregisterSelectionValue(
int value);
202 int selectionValueFromLabel(
const std::string& label)
const;
204 int findOrCreateLabeledValue(
const std::string& label);
241 bool modifySelection(
243 const std::string& source,
246 bool bitwise =
false,
247 bool postponeNotification =
false);
256 bool resetSelectionBits(
const std::string& source,
int value);
296 void visitSelection(std::function<
void(Object::Ptr,
int)> visitor)
299 for (
const auto& entry : m_selection)
301 visitor(entry.first, entry.second);
305 SelectionMap& currentSelection(SelectionMap& selection)
const;
306 const SelectionMap& currentSelection()
const {
return m_selection; }
309 T& currentSelectionByValue(T& selection,
int value,
bool exactMatch =
true)
const;
311 T& currentSelectionByValue(T& selection,
const std::string& valueLabel,
bool exactMatch =
true)
315 T currentSelectionByValueAs(
int value,
bool exactMatch =
true)
const
318 this->currentSelectionByValue(result, value, exactMatch);
322 T currentSelectionByValueAs(
const std::string& valueLabel,
bool exactMatch =
true)
const
325 this->currentSelectionByValue(result, valueLabel, exactMatch);
332 const Observers& observers()
const {
return m_observers; }
338 void setFilter(
const SelectionFilter& fn,
bool refilterSelection =
true);
371 const std::shared_ptr<smtk::attribute::ReferenceItem>& item,
373 bool exactMatch =
false,
374 bool clearItem =
true)
const;
385 SelectionMap& suggested,
387 bool refilter(
const std::string& source);
392 std::set<std::string> m_selectionSources;
393 std::map<std::string, int> m_selectionValueLabels;
394 SelectionMap m_selection;
395 Observers m_observers;
396 SelectionFilter m_filter;
404 for (
const auto& entry : m_selection)
406 if ((entry.second & value) == value)
408 auto entryT = std::dynamic_pointer_cast<typename T::value_type::element_type>(entry.first);
411 selection.insert(selection.end(), entryT);
418 for (
const auto& entry : m_selection)
420 if (entry.second & value)
422 auto entryT = std::dynamic_pointer_cast<typename T::value_type::element_type>(entry.first);
425 selection.insert(selection.end(), entryT);
444 const std::string& source,
448 bool postponeNotification)
450 bool modified =
false;
460 modified = !m_selection.empty();
470 for (
auto& entry : m_selection)
472 auto it = std::find(objects.begin(), objects.end(), entry.first);
474 if ((it == objects.end() && ((entry.second & mask) == 0)) || value == 0)
476 willErase.insert(entry.first);
479 else if (it == objects.end() && ((entry.second & mask) != 0))
481 entry.second &= mask;
490 if (!willErase.empty())
493 for (
const auto& key : willErase)
495 m_selection.erase(key);
499 for (
const auto&
object : objects)
501 modified |= this->
performAction(
object, value, action, suggestions, bitwise);
503 if (modified && !postponeNotification)
505 this->
observers()(source, shared_from_this());
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
@ UNFILTERED_REPLACE
Replace all the current selection and do not filter it.
SelectionAction defaultAction() const
Return the current method used to modify selections when.
Definition: Selection.h:279
bool performAction(smtk::resource::PersistentObjectPtr comp, int value, SelectionAction action, SelectionMap &suggested, bool bitwise)
Perform the action (ignoring m_defaultAction!!!), returning true if it had an effect.
Definition: Selection.cxx:276
T & currentSelectionByValue(T &selection, int value, bool exactMatch=true) const
Return the subset of selected elements that match the given selection value.
Definition: Selection.h:400
Observers & observers()
Return the observers associated with this phrase model.
Definition: Selection.h:331
void getSelectionSources(std::set< std::string > &selectionSources) const
Populate a set with the names of all registered selection sources.
Definition: Selection.h:175
bool registerSelectionSource(std::string name)
Selection sources.
Definition: Selection.h:166
SelectionAction
Descriptors for how lists passed to the selection should modify the selection-map.
Definition: SelectionAction.h:19
An Observer is a functor that is called when certain actions are performed.
Definition: Observers.h:66
std::map< Object::Ptr, int > SelectionMap
This is the underlying storage type that holds selections.
Definition: Selection.h:133
smtk::common::Observers< SelectionObserver > SelectionObservers
A class for holding SelectionObserver functors that observe selection events.
Definition: SelectionObserver.h:29
bool modifySelection(const T &objects, const std::string &source, int value, SelectionAction action=SelectionAction::DEFAULT, bool bitwise=false, bool postponeNotification=false)
Modify the current selection.
Definition: Selection.h:442
#define smtkCreateMacro(...)
Add static create() methods to a class.
Definition: SharedFromThis.h:173
#define smtkEnableSharedPtr(...)
An abbreviation for enabling shared pointers.
Definition: SharedFromThis.h:214
@ DEFAULT
Use the default SelectionAction provided by the Selection.
std::function< bool(Object::Ptr, int, SelectionMap &)> SelectionFilter
Selection filters take functions of this form.
Definition: Selection.h:150
int selectionValueFromLabel(const std::string &label) const
Return the selection value for the given label, or 0 if there is no such label registered.
Definition: Selection.cxx:115
bool unregisterSelectionSource(std::string name)
Unregister a selection source; if false is returned, the source was not recognized.
Definition: Selection.h:169
bool unregisterSelectionValue(const std::string &valueLabel)
Unregister a selection value. If the value was not registered, returns false.
Definition: Selection.h:193
@ FILTERED_SUBTRACT
Filter the input selection, then subtract it from the current selection.
A class to manage linked selections in a context.
Definition: Selection.h:116
@ FILTERED_REPLACE
Replace all the current selection and filter it.
const std::set< std::string > & getSelectionSources() const
Populate a set with the names of all registered selection sources.
Definition: Selection.h:172
std::set< smtk::resource::PersistentObjectPtr > PersistentObjectSet
Definition: PublicPointerDefs.h:291
@ FILTERED_ADD
Filter the input selection and add it to the current selection.
Component is the base class for records stored in an smtk::resource::Resource.
Definition: Component.h:43
smtk::shared_ptr< smtk::resource::PersistentObject > PersistentObjectPtr
Definition: PublicPointerDefs.h:285
Macros for dealing with shared-pointer classes.
#define smtkTypeMacroBase(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:131
const std::map< std::string, int > & selectionValueLabels() const
Return the map of selection values.
Definition: Selection.h:200
std::function< void(const std::string &, SelectionPtr)> SelectionObserver
Events that alter the selection trigger callbacks of this type.
Definition: SelectionObserver.h:26
An abstract base class for SMTK resources and their components.
Definition: PersistentObject.h:39