Eclipse 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::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< GUIGlID > | 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. | |
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< GUIGlID > | myAllSelected |
List of selected objects. | |
std::map< GUIGlObjectType, SingleTypeSelections > | mySelections |
map with the selections | |
UpdateTarget * | myUpdateTarget |
The dialog to be updated. | |
Friends | |
class | SingleTypeSelections |
set SingleTypeSelections as friend class | |
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 67 of file GUISelectedStorage.h.
GUISelectedStorage::GUISelectedStorage | ( | ) |
Constructor.
Definition at line 87 of file GUISelectedStorage.cpp.
GUISelectedStorage::~GUISelectedStorage | ( | ) |
Destructor.
Definition at line 90 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 283 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 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().
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 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().
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().
const std::unordered_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 170 of file GUISelectedStorage.cpp.
References mySelections.
bool GUISelectedStorage::isSelected | ( | const GUIGlObject * | o | ) |
Definition at line 104 of file GUISelectedStorage.cpp.
References GUIGlObject::getGlID(), GUIGlObject::getType(), and isSelected().
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 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().
std::string GUISelectedStorage::load | ( | const std::string & | filename, |
GUIGlObjectType | type = GLO_MAX , |
||
std::ostream * | dynamicNotFound = nullptr |
||
) |
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 245 of file GUISelectedStorage.cpp.
Referenced by GUIApplicationWindow::handleEvent_SimulationLoaded(), GUIApplicationWindow::handleEvent_SimulationStep(), load(), and GUIDialog_GLChosenEditor::onCmdLoad().
std::string GUISelectedStorage::load | ( | std::istream & | strm, |
GUIGlObjectType | type = GLO_MAX , |
||
std::ostream * | dynamicNotFound = nullptr |
||
) |
Definition at line 257 of file GUISelectedStorage.cpp.
References loadIDs(), myUpdateTarget, select(), and GUISelectedStorage::UpdateTarget::selectionUpdated().
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.
[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 |
[in] | maxErrors | The maximum Number of errors to return |
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().
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().
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().
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 277 of file GUISelectedStorage.cpp.
References myAllSelected, and save().
|
staticprivate |
saves items from the given set
Definition at line 295 of file GUISelectedStorage.cpp.
References OutputDevice::close(), OutputDevice::getDevice(), GUIGlObject::getFullName(), GUIGlObjectStorage::getObjectBlocking(), GUIGlObjectStorage::gIDStorage, and GUIGlObjectStorage::unblockObject().
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 271 of file GUISelectedStorage.cpp.
References mySelections.
Referenced by GUIDialog_GLChosenEditor::onCmdSave(), GUISelectedStorage::SingleTypeSelections::save(), and save().
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 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().
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 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().
|
friend |
set SingleTypeSelections as friend class
Definition at line 269 of file GUISelectedStorage.h.
|
private |
List of selected objects.
Definition at line 277 of file GUISelectedStorage.h.
Referenced by clear(), deselect(), getSelected(), save(), and select().
|
private |
map with the selections
Definition at line 274 of file GUISelectedStorage.h.
Referenced by clear(), deselect(), getSelected(), isSelected(), save(), and select().
|
private |
The dialog to be updated.
Definition at line 280 of file GUISelectedStorage.h.
Referenced by add2Update(), clear(), deselect(), load(), notifyChanged(), remove2Update(), and select().