SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUISelectedStorage Class Reference

Storage for "selected" objects. More...

#include <GUISelectedStorage.h>

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::set< GUIGlID > & getSelected () const
 Returns the list of ids of all selected objects.
const std::set< GUIGlID > & getSelected (GUIGlObjectType type)
 Returns the set of ids of all selected objects' of a certain type.
 GUISelectedStorage ()
 Constructor.
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)
 Loads a selection list (optionally with restricted type)
std::set< GUIGlIDloadIDs (const std::string &filename, std::string &msgOut, GUIGlObjectType type=GLO_MAX)
 Loads a selection list (optionally with restricted type) and returns the ids of all active objects.
void remove2Update ()
 Removes the dialog to be updated.
void save (GUIGlObjectType type, const std::string &filename)
 Saves a selection list.
void save (const std::string &filename) const
 Saves the combined selection of all types.
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.

Private Member Functions

std::string load (GUIGlObjectType type, const std::string &filename, bool restrictType, std::set< GUIGlID > &into)

Static Private Member Functions

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

Private Attributes

std::set< GUIGlIDmyAllSelected
 List of selected objects.
std::map< GUIGlObjectType,
SingleTypeSelections
mySelections
UpdateTargetmyUpdateTarget
 The dialog to be updated.

Friends

class SingleTypeSelections

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 77 of file GUISelectedStorage.h.

Constructor & Destructor Documentation

GUISelectedStorage::GUISelectedStorage ( )

Constructor.

Definition at line 98 of file GUISelectedStorage.cpp.

GUISelectedStorage::~GUISelectedStorage ( )

Destructor.

Definition at line 101 of file GUISelectedStorage.cpp.

Member Function Documentation

void GUISelectedStorage::add2Update ( UpdateTarget updateTarget)

Adds a dialog to be updated.

Parameters
[in]updateTargetthe callback for selection changes

Definition at line 253 of file GUISelectedStorage.cpp.

References myUpdateTarget.

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 181 of file GUISelectedStorage.cpp.

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

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

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 135 of file GUISelectedStorage.cpp.

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

Referenced by GUIDialog_GLChosenEditor::onCmdDeselect(), GUIGLObjectPopupMenu::onCmdRemoveSelected(), and toggleSelection().

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

Returns the list of ids of all selected objects.

Returns
The set of all selected objects (ids)

Definition at line 169 of file GUISelectedStorage.cpp.

References myAllSelected.

Referenced by GUIDialog_GLChosenEditor::rebuildList().

const std::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 175 of file GUISelectedStorage.cpp.

References mySelections.

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 105 of file GUISelectedStorage.cpp.

References GLO_ADDITIONAL, GLO_DETECTOR, GLO_NETWORK, GLO_TRIGGER, and mySelections.

Referenced by GUIGlObject::buildSelectionPopupEntry(), MSLaneChanger::change(), MSVehicle::checkRewindLinkLanes(), MSVehicle::getBestLanes(), GUILaneWrapper::getColorValue(), GUIGlChildWindow::isSelected(), GUISUMOViewParent::isSelected(), MSVehicle::moveChecked(), MSVehicle::moveRegardingCritical(), MSLCM_DK2004::patchSpeed(), toggleSelection(), MSVehicle::vsafeCriticalCont(), MSLCM_DK2004::wantsChangeToLeft(), and MSLCM_DK2004::wantsChangeToRight().

std::string GUISelectedStorage::load ( const std::string &  filename,
GUIGlObjectType  type = GLO_MAX 
)

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 occured or the empty string

Definition at line 227 of file GUISelectedStorage.cpp.

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

Referenced by GUIDialog_GLChosenEditor::onCmdLoad().

std::string GUISelectedStorage::load ( GUIGlObjectType  type,
const std::string &  filename,
bool  restrictType,
std::set< GUIGlID > &  into 
)
private
std::set< GUIGlID > GUISelectedStorage::loadIDs ( const std::string &  filename,
std::string &  msgOut,
GUIGlObjectType  type = GLO_MAX 
)

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
Returns
the set of loaded ids

Definition at line 193 of file GUISelectedStorage.cpp.

References GUIGlObject::getGlID(), GUIGlObjectStorage::getObjectBlocking(), GUIGlObject::getType(), GUIGlObjectStorage::gIDStorage, GLO_MAX, and toString().

Referenced by load().

void GUISelectedStorage::remove2Update ( )

Removes the dialog to be updated.

Definition at line 259 of file GUISelectedStorage.cpp.

References myUpdateTarget.

Referenced by GUIDialog_GLChosenEditor::~GUIDialog_GLChosenEditor().

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 241 of file GUISelectedStorage.cpp.

References mySelections.

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

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 247 of file GUISelectedStorage.cpp.

References myAllSelected, and save().

void GUISelectedStorage::save ( const std::string &  filename,
const std::set< GUIGlID > &  ids 
)
staticprivate
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 118 of file GUISelectedStorage.cpp.

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

Referenced by load(), GUIGLObjectPopupMenu::onCmdAddSelected(), and 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 152 of file GUISelectedStorage.cpp.

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

Referenced by GUISUMOAbstractView::onLeftBtnPress().

Friends And Related Function Documentation

friend class SingleTypeSelections
friend

Definition at line 290 of file GUISelectedStorage.h.

Field Documentation

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

List of selected objects.

Definition at line 297 of file GUISelectedStorage.h.

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

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

Definition at line 294 of file GUISelectedStorage.h.

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

UpdateTarget* GUISelectedStorage::myUpdateTarget
private

The dialog to be updated.

Definition at line 300 of file GUISelectedStorage.h.

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


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