SUMO - Simulation of Urban MObility
|
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< GUIGlID > | 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. | |
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< GUIGlID > | myAllSelected |
List of selected objects. | |
std::map< GUIGlObjectType, SingleTypeSelections > | mySelections |
UpdateTarget * | myUpdateTarget |
The dialog to be updated. | |
Friends | |
class | SingleTypeSelections |
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.
Definition at line 77 of file GUISelectedStorage.h.
Constructor.
Definition at line 98 of file GUISelectedStorage.cpp.
Destructor.
Definition at line 101 of file GUISelectedStorage.cpp.
void GUISelectedStorage::add2Update | ( | UpdateTarget * | updateTarget | ) |
Adds a dialog to be updated.
[in] | updateTarget | the 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.
[in] | id | The id of the object |
ProcessError | If the object is not known or the type is not covered by a sub-container |
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.
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.
[in] | type | The type of the object |
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().
[in] | type | The type of the object (GUIGlObjectType or -1) |
[in] | id | The id of the object |
ProcessError | If the object is not known or the type is not covered by a sub-container |
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)
[in] | filename | The name of the file to load the list of selected objects from |
[in] | type | The type of the objects to load if changed from default |
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.
[in] | filename | The name of the file to load the list of selected objects from |
[out] | msg | Any error messages while loading or the empty string |
[in] | type | The type of the objects to load if changed from default |
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.
[in] | type | The type of the objects to save |
[in] | filename | The 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.
[in] | filename | The 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 | ||
) | [static, private] |
saves items from the given set
Definition at line 265 of file GUISelectedStorage.cpp.
References OutputDevice::close(), OutputDevice::getDevice(), GUIGlObject::getFullName(), GUIGlObjectStorage::getObjectBlocking(), GUIGlObjectStorage::gIDStorage, and GUIGlObjectStorage::unblockObject().
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.
[in] | id | The id of the object |
ProcessError | If the object is not known or the type is not covered by a sub-container |
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".
[in] | id | The id of the object |
ProcessError | If the object is not known or the type is not covered by a sub-container |
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().
friend class SingleTypeSelections [friend] |
Definition at line 290 of file GUISelectedStorage.h.
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().