Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUISelectedStorage Class Reference

Storage for "selected" objects. More...

#include <GUISelectedStorage.h>

Collaboration diagram for GUISelectedStorage:
[legend]

Data Structures

class  SingleTypeSelections
 A container for ids of selected objects of a certain type. More...
 
class  UpdateTarget
 

Public Member Functions

void add2Update (UpdateTarget *updateTarget)
 Adds a dialog to be updated.
 
void clear ()
 Clears the list of selected objects.
 
void deselect (GUIGlID id)
 Deselects the object with the given id.
 
const std::unordered_set< GUIGlID > & getSelected () const
 Returns the set of ids of all selected objects.
 
const std::unordered_set< GUIGlID > & getSelected (GUIGlObjectType type)
 Returns the set of ids of all selected objects' of a certain type.
 
 GUISelectedStorage ()
 Constructor.
 
bool isSelected (const GUIGlObject *o)
 
bool isSelected (GUIGlObjectType type, GUIGlID id)
 Returns the information whether the object with the given type and id is selected.
 
std::string load (const std::string &filename, GUIGlObjectType type=GLO_MAX, std::ostream *dynamicNotFound=nullptr)
 Loads a selection list (optionally with restricted type)
 
std::string load (std::istream &strm, GUIGlObjectType type=GLO_MAX, std::ostream *dynamicNotFound=nullptr)
 
std::set< GUIGlIDloadIDs (std::istream &strm, std::string &msgOut, GUIGlObjectType type=GLO_MAX, std::ostream *dynamicNotFound=nullptr, int maxErrors=16)
 Loads a selection list (optionally with restricted type) and returns the ids of all active objects.
 
void notifyChanged ()
 inform the update target of earlier changes
 
void remove2Update ()
 Removes the dialog to be updated.
 
void save (const std::string &filename) const
 Saves the combined selection of all types.
 
void save (GUIGlObjectType type, const std::string &filename)
 Saves a selection list.
 
void select (GUIGlID id, bool update=true)
 Adds the object with the given id.
 
void toggleSelection (GUIGlID id)
 Toggles selection of an object.
 
 ~GUISelectedStorage ()
 Destructor.
 

Static Private Member Functions

static void save (const std::string &filename, const std::unordered_set< GUIGlID > &ids)
 saves items from the given set
 

Private Attributes

std::unordered_set< GUIGlIDmyAllSelected
 List of selected objects.
 
std::map< GUIGlObjectType, SingleTypeSelectionsmySelections
 map with the selections
 
UpdateTargetmyUpdateTarget
 The dialog to be updated.
 

Friends

class SingleTypeSelections
 set SingleTypeSelections as friend class
 

Detailed Description

Storage for "selected" objects.

Object selection is done by storing the "gl-ids" of selectable objects (GUIGlObjects) within internal containers of this class. Each id is stored twice - in a global container and within one of the type-aware containers.

This class allows adding and removing objects (their ids) from the lists of selected objects, saving the lists into a file, and obtaining the lists of selected objects (both all and type-aware).

Most of the adding/removing methods do not require a GUIGlObjectType as parameter, but an integer. This is done to perform the action on objects with a yet unknown type - in this case, the type is obtained internally.

Besides this, the class forces an active view of selected items to refresh its contents if an item is added/removed. For this, an FXWindow has to make itself visible to GUISelectedStorage.

See also
GUIGlObject
GUIGlObjectType
GUIDialog_GLChosenEditor

Definition at line 67 of file GUISelectedStorage.h.

Constructor & Destructor Documentation

◆ GUISelectedStorage()

GUISelectedStorage::GUISelectedStorage ( )

Constructor.

Definition at line 87 of file GUISelectedStorage.cpp.

◆ ~GUISelectedStorage()

GUISelectedStorage::~GUISelectedStorage ( )

Destructor.

Definition at line 90 of file GUISelectedStorage.cpp.

Member Function Documentation

◆ add2Update()

void GUISelectedStorage::add2Update ( UpdateTarget updateTarget)

Adds a dialog to be updated.

Parameters
[in]updateTargetthe callback for selection changes

Definition at line 283 of file GUISelectedStorage.cpp.

References myUpdateTarget.

◆ clear()

void GUISelectedStorage::clear ( )

Clears the list of selected objects.

Clears the global container and all sub-containers via SingleTypeSelections::clear.

The optionally listening UpdateTarget is informed about the change.

Definition at line 176 of file GUISelectedStorage.cpp.

References myAllSelected, mySelections, myUpdateTarget, and GUISelectedStorage::UpdateTarget::selectionUpdated().

Referenced by GUIApplicationWindow::closeAllWindows(), GUIDialog_GLChosenEditor::onCmdClear(), GUIViewTraffic::onGamingRightClick(), and GUIViewTraffic::showLaneReachability().

Here is the caller graph for this function:

◆ deselect()

void GUISelectedStorage::deselect ( GUIGlID  id)

Deselects the object with the given id.

The id of the object is removed from the sub-container that is responsible for objects of the determined type using SingleTypeSelections::deselect and from the global list of chosen items if it is there.

The optionally listening UpdateTarget is informed about the change.

Parameters
[in]idThe id of the object
Exceptions
ProcessErrorIf the object is not known or the type is not covered by a sub-container
See also
GUIGlObject
GUIGlObjectType
SingleTypeSelections::deselect
GUIDialog_GLChosenEditor

Definition at line 130 of file GUISelectedStorage.cpp.

References GUIGlObjectStorage::getObjectBlocking(), GUIGlObjectStorage::gIDStorage, myAllSelected, mySelections, myUpdateTarget, GUISelectedStorage::UpdateTarget::selectionUpdated(), toString(), and GUIGlObjectStorage::unblockObject().

Referenced by GUIDialog_ChooserAbstract::deselect(), GUIDialog_GLChosenEditor::onCmdDeselect(), GUIGLObjectPopupMenu::onCmdRemoveSelected(), toggleSelection(), and GNEAttributeCarrier::unselectAttributeCarrier().

Here is the caller graph for this function:

◆ getSelected() [1/2]

const std::unordered_set< GUIGlID > & GUISelectedStorage::getSelected ( ) const

Returns the set of ids of all selected objects.

Definition at line 164 of file GUISelectedStorage.cpp.

References myAllSelected.

Referenced by GNENetHelper::AttributeCarriers::getSelectedAttributeCarriers(), GUIViewTraffic::onGamingClick(), GUIViewTraffic::onGamingRightClick(), and GUIDialog_GLChosenEditor::rebuildList().

Here is the caller graph for this function:

◆ getSelected() [2/2]

const std::unordered_set< GUIGlID > & GUISelectedStorage::getSelected ( GUIGlObjectType  type)

Returns the set of ids of all selected objects' of a certain type.

Parameters
[in]typeThe type of the object
Returns
A set containing the ids of all selected objects of the given type
See also
SingleTypeSelections::getSelected

Definition at line 170 of file GUISelectedStorage.cpp.

References mySelections.

◆ isSelected() [1/2]

bool GUISelectedStorage::isSelected ( const GUIGlObject o)

◆ isSelected() [2/2]

bool GUISelectedStorage::isSelected ( GUIGlObjectType  type,
GUIGlID  id 
)

Returns the information whether the object with the given type and id is selected.

If the type is ==-1, it is determined, first. If it could not be obtained, or if the type is not covered by any selection container, a ProcessError is thrown.

Otherwise, the container holding objects of the determined type is asked whether the given id is stored using SingleTypeSelections::isSelected().

Parameters
[in]typeThe type of the object (GUIGlObjectType or -1)
[in]idThe id of the object
Returns
Whether the object is selected
Exceptions
ProcessErrorIf the object is not known or the type is not covered by a sub-container
See also
GUIGlObject
GUIGlObjectType
SingleTypeSelections::isSelected

Definition at line 94 of file GUISelectedStorage.cpp.

References GLO_NETWORK, and mySelections.

Referenced by GUIGlObject::buildSelectionPopupEntry(), GUIEdge::drawGL(), GUILane::drawGL(), GUIJunctionWrapper::getColorValue(), GUIVehicle::getColorValue(), GUIMEVehicle::getColorValue(), GUIContainer::getColorValue(), GUIEdge::getColorValue(), GUIPerson::getColorValue(), GUIVisualizationSizeSettings::getExaggeration(), GUIEdge::getScaleValue(), GUILane::isLaneOrEdgeSelected(), GUIVehicle::isSelected(), GUIContainer::isSelected(), GUIEdge::isSelected(), GUILane::isSelected(), GUIPerson::isSelected(), isSelected(), GUINet::isSelected(), GUISUMOViewParent::isSelected(), GUIGlChildWindow::isSelected(), GUIPointOfInterest::setColor(), GUIPolygon::setColor(), GUIVisualizationTextSettings::show(), and toggleSelection().

Here is the caller graph for this function:

◆ load() [1/2]

std::string GUISelectedStorage::load ( const std::string &  filename,
GUIGlObjectType  type = GLO_MAX,
std::ostream *  dynamicNotFound = nullptr 
)

Loads a selection list (optionally with restricted type)

Parameters
[in]filenameThe name of the file to load the list of selected objects from
[in]typeThe type of the objects to load if changed from default
Returns
error messages if errors occurred or the empty string

Definition at line 245 of file GUISelectedStorage.cpp.

References load(), and TLF.

Referenced by GUIApplicationWindow::handleEvent_SimulationLoaded(), GUIApplicationWindow::handleEvent_SimulationStep(), load(), and GUIDialog_GLChosenEditor::onCmdLoad().

Here is the caller graph for this function:

◆ load() [2/2]

std::string GUISelectedStorage::load ( std::istream &  strm,
GUIGlObjectType  type = GLO_MAX,
std::ostream *  dynamicNotFound = nullptr 
)

◆ loadIDs()

std::set< GUIGlID > GUISelectedStorage::loadIDs ( std::istream &  strm,
std::string &  msgOut,
GUIGlObjectType  type = GLO_MAX,
std::ostream *  dynamicNotFound = nullptr,
int  maxErrors = 16 
)

Loads a selection list (optionally with restricted type) and returns the ids of all active objects.

Parameters
[in]filenameThe name of the file to load the list of selected objects from
[out]msgAny error messages while loading or the empty string
[in]typeThe type of the objects to load if changed from default
[in]maxErrorsThe maximum Number of errors to return
Returns
the set of loaded ids

Definition at line 196 of file GUISelectedStorage.cpp.

References GUIGlObjectStorage::getObjectBlocking(), GUIGlObjectStorage::gIDStorage, GLO_MAX, StringUtils::replace(), StringUtils::startsWith(), TLF, and toString().

Referenced by load().

Here is the caller graph for this function:

◆ notifyChanged()

void GUISelectedStorage::notifyChanged ( )

inform the update target of earlier changes

Definition at line 188 of file GUISelectedStorage.cpp.

References myUpdateTarget, and GUISelectedStorage::UpdateTarget::selectionUpdated().

Referenced by GUIViewTraffic::showLaneReachability().

Here is the caller graph for this function:

◆ remove2Update()

void GUISelectedStorage::remove2Update ( )

Removes the dialog to be updated.

Definition at line 289 of file GUISelectedStorage.cpp.

References myUpdateTarget.

Referenced by GUIDialog_GLChosenEditor::~GUIDialog_GLChosenEditor().

Here is the caller graph for this function:

◆ save() [1/3]

void GUISelectedStorage::save ( const std::string &  filename) const

Saves the combined selection of all types.

Parameters
[in]filenameThe name of the file to save the list of selected objects into

Definition at line 277 of file GUISelectedStorage.cpp.

References myAllSelected, and save().

◆ save() [2/3]

void GUISelectedStorage::save ( const std::string &  filename,
const std::unordered_set< GUIGlID > &  ids 
)
staticprivate

◆ save() [3/3]

void GUISelectedStorage::save ( GUIGlObjectType  type,
const std::string &  filename 
)

Saves a selection list.

Parameters
[in]typeThe type of the objects to save
[in]filenameThe name of the file to save the list of selected objects into

Definition at line 271 of file GUISelectedStorage.cpp.

References mySelections.

Referenced by GUIDialog_GLChosenEditor::onCmdSave(), GUISelectedStorage::SingleTypeSelections::save(), and save().

Here is the caller graph for this function:

◆ select()

void GUISelectedStorage::select ( GUIGlID  id,
bool  update = true 
)

Adds the object with the given id.

The id of the object is added to the sub-container that is responsible for objects of the determined type using SingleTypeSelections::select and to the global list of chosen items if it is not already there.

The optionally listening window is informed about the change.

Parameters
[in]idThe id of the object
Exceptions
ProcessErrorIf the object is not known or the type is not covered by a sub-container
See also
GUIGlObject
GUIGlObjectType
SingleTypeSelections::select
GUIDialog_GLChosenEditor

Definition at line 113 of file GUISelectedStorage.cpp.

References GUIGlObjectStorage::getObjectBlocking(), GUIGlObjectStorage::gIDStorage, myAllSelected, mySelections, myUpdateTarget, GUISelectedStorage::UpdateTarget::selectionUpdated(), toString(), and GUIGlObjectStorage::unblockObject().

Referenced by load(), GUIGLObjectPopupMenu::onCmdAddSelected(), GUIApplicationWindow::onCmdEditChosen(), GUIBaseVehicle::GUIBaseVehiclePopupMenu::onCmdSelectTransported(), GUIViewTraffic::onGamingClick(), GUIDialog_ChooserAbstract::select(), GNEAttributeCarrier::selectAttributeCarrier(), GUIVehicle::selectBlockingFoes(), GUIViewTraffic::showLaneReachability(), and toggleSelection().

Here is the caller graph for this function:

◆ toggleSelection()

void GUISelectedStorage::toggleSelection ( GUIGlID  id)

Toggles selection of an object.

If the object can not be obtained a ProcessError is thrown.

Otherwise, it is determined whether the object is already selected or not. If so, it is deselected by calling "deselect", otherwise it is selected via "select".

Parameters
[in]idThe id of the object
Exceptions
ProcessErrorIf the object is not known or the type is not covered by a sub-container
See also
GUIGlObject
deselect
select

Definition at line 147 of file GUISelectedStorage.cpp.

References deselect(), GUIGlObjectStorage::getObjectBlocking(), GUIGlObjectStorage::gIDStorage, isSelected(), select(), toString(), and GUIGlObjectStorage::unblockObject().

Referenced by GUISUMOAbstractView::onLeftBtnPress(), GUIMessageWindow::setCursorPos(), and GUIDialog_ChooserAbstract::toggleSelection().

Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ SingleTypeSelections

friend class SingleTypeSelections
friend

set SingleTypeSelections as friend class

Definition at line 269 of file GUISelectedStorage.h.

Field Documentation

◆ myAllSelected

std::unordered_set<GUIGlID> GUISelectedStorage::myAllSelected
private

List of selected objects.

Definition at line 277 of file GUISelectedStorage.h.

Referenced by clear(), deselect(), getSelected(), save(), and select().

◆ mySelections

std::map<GUIGlObjectType, SingleTypeSelections> GUISelectedStorage::mySelections
private

map with the selections

Definition at line 274 of file GUISelectedStorage.h.

Referenced by clear(), deselect(), getSelected(), isSelected(), save(), and select().

◆ myUpdateTarget

UpdateTarget* GUISelectedStorage::myUpdateTarget
private

The dialog to be updated.

Definition at line 280 of file GUISelectedStorage.h.

Referenced by add2Update(), clear(), deselect(), load(), notifyChanged(), remove2Update(), and select().


The documentation for this class was generated from the following files: