Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUISelectedStorage.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Storage for "selected" objects
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <unordered_set>
26#include <string>
27#include <map>
28#include <fstream>
32
33
34// ===========================================================================
35// class declarations
36// ===========================================================================
37class OutputDevice;
38
39
40// ===========================================================================
41// class definitions
42// ===========================================================================
68
69public:
72
73 public:
75 virtual ~UpdateTarget() {};
76
78 virtual void selectionUpdated() = 0;
79 };
80
81public:
84
87
104 bool isSelected(GUIGlObjectType type, GUIGlID id);
105
106 bool isSelected(const GUIGlObject* o);
107
123 void select(GUIGlID id, bool update = true);
124
140 void deselect(GUIGlID id);
141
142 void deselect(GUIGlObjectType type, GUIGlID id);
143
158 void toggleSelection(GUIGlID id);
159
161 const std::unordered_set<GUIGlID>& getSelected() const;
162
169 const std::unordered_set<GUIGlID>& getSelected(GUIGlObjectType type);
170
177 void clear();
178
180 void notifyChanged();
181
188 std::string load(const std::string& filename, GUIGlObjectType type = GLO_MAX, std::ostream* dynamicNotFound = nullptr);
189 std::string load(std::istream& strm, GUIGlObjectType type = GLO_MAX, std::ostream* dynamicNotFound = nullptr);
190
200 std::set<GUIGlID> loadIDs(std::istream& strm, std::string& msgOut, GUIGlObjectType type = GLO_MAX, std::ostream* dynamicNotFound = nullptr, int maxErrors = 16);
201
207 void save(GUIGlObjectType type, const std::string& filename);
208
213 void save(const std::string& filename) const;
214
218 void add2Update(UpdateTarget* updateTarget);
219
221 void remove2Update();
222
228
229 public:
232
235
240 bool isSelected(GUIGlID id);
241
245 void select(GUIGlID id);
246
250 void deselect(GUIGlID id);
251
253 void clear();
254
258 void save(const std::string& filename);
259
263 const std::unordered_set<GUIGlID>& getSelected() const;
264
265 private:
267 std::unordered_set<GUIGlID> mySelected;
268 };
269
272
273
274private:
276 std::map<GUIGlObjectType, SingleTypeSelections> mySelections;
277
279 std::unordered_set<GUIGlID> myAllSelected;
280
283
285 static void save(const std::string& filename, const std::unordered_set<GUIGlID>& ids);
286};
unsigned int GUIGlID
Definition GUIGlObject.h:44
GUIGlObjectType
@ GLO_MAX
empty max
A container for ids of selected objects of a certain type.
void clear()
Clears the list of selected objects.
void select(GUIGlID id)
Adds the object with the given id to the list of selected objects.
const std::unordered_set< GUIGlID > & getSelected() const
Returns the list of selected ids.
void deselect(GUIGlID id)
Deselects the object with the given id from the list of selected objects.
std::unordered_set< GUIGlID > mySelected
The list of selected ids.
void save(const std::string &filename)
Saves the list of selected objects to a file named as given.
bool isSelected(GUIGlID id)
Returns the information whether the object with the given id is qithin the selection.
virtual ~UpdateTarget()
virtual destructor
virtual void selectionUpdated()=0
called when selection is updated
Storage for "selected" objects.
void save(GUIGlObjectType type, const std::string &filename)
Saves a selection list.
std::map< GUIGlObjectType, SingleTypeSelections > mySelections
map with the selections
void notifyChanged()
inform the update target of earlier changes
~GUISelectedStorage()
Destructor.
void clear()
Clears the list of selected objects.
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 toggleSelection(GUIGlID id)
Toggles selection of an object.
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
UpdateTarget * myUpdateTarget
The dialog to be updated.
void add2Update(UpdateTarget *updateTarget)
Adds a dialog to be updated.
void remove2Update()
Removes the dialog to be updated.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
GUISelectedStorage()
Constructor.
std::unordered_set< GUIGlID > myAllSelected
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.
std::string load(const std::string &filename, GUIGlObjectType type=GLO_MAX, std::ostream *dynamicNotFound=nullptr)
Loads a selection list (optionally with restricted type)
Static storage of an output device and its base (abstract) implementation.