Eclipse SUMO - Simulation of Urban MObility
GUISelectedStorage.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Storage for "selected" objects
18 /****************************************************************************/
19 #ifndef GUISelectedStorage_h
20 #define GUISelectedStorage_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <set>
29 #include <string>
30 #include <map>
31 #include <fstream>
32 #include <fx.h>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class OutputDevice;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
71 
72 public:
74  class UpdateTarget {
75 
76  public:
78  virtual ~UpdateTarget() {};
79 
81  virtual void selectionUpdated() = 0;
82  };
83 
84 public:
87 
90 
107  bool isSelected(GUIGlObjectType type, GUIGlID id);
108 
109  bool isSelected(const GUIGlObject* o);
110 
126  void select(GUIGlID id, bool update = true);
127 
143  void deselect(GUIGlID id);
144 
159  void toggleSelection(GUIGlID id);
160 
162  const std::set<GUIGlID>& getSelected() const;
163 
170  const std::set<GUIGlID>& getSelected(GUIGlObjectType type);
171 
178  void clear();
179 
186  std::string load(const std::string& filename, GUIGlObjectType type = GLO_MAX);
187 
197  std::set<GUIGlID> loadIDs(const std::string& filename, std::string& msgOut, GUIGlObjectType type = GLO_MAX, int maxErrors = 16);
198 
204  void save(GUIGlObjectType type, const std::string& filename);
205 
210  void save(const std::string& filename) const;
211 
215  void add2Update(UpdateTarget* updateTarget);
216 
218  void remove2Update();
219 
225 
226  public:
229 
232 
237  bool isSelected(GUIGlID id);
238 
242  void select(GUIGlID id);
243 
247  void deselect(GUIGlID id);
248 
250  void clear();
251 
255  void save(const std::string& filename);
256 
260  const std::set<GUIGlID>& getSelected() const;
261 
262  private:
264  std::set<GUIGlID> mySelected;
265 
266  };
267 
269  friend class SingleTypeSelections;
270 
271 
272 private:
274  std::map<GUIGlObjectType, SingleTypeSelections> mySelections;
275 
277  std::set<GUIGlID> myAllSelected;
278 
281 
283  std::string load(GUIGlObjectType type, const std::string& filename, bool restrictType, std::set<GUIGlID>& into);
284 
286  static void save(const std::string& filename, const std::set<GUIGlID>& ids);
287 };
288 
289 
290 #endif
291 
292 /****************************************************************************/
293 
GLO_MAX
empty max
Definition: GUIGlObjectTypes.h:166
GUIGlObject.h
GUISelectedStorage::SingleTypeSelections::select
void select(GUIGlID id)
Adds the object with the given id to the list of selected objects.
Definition: GUISelectedStorage.cpp:56
GUISelectedStorage::SingleTypeSelections::SingleTypeSelections
SingleTypeSelections()
Constructor.
Definition: GUISelectedStorage.cpp:43
GUISelectedStorage::UpdateTarget::selectionUpdated
virtual void selectionUpdated()=0
called when selection is updated
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
GUISelectedStorage::save
void save(GUIGlObjectType type, const std::string &filename)
Saves a selection list.
Definition: GUISelectedStorage.cpp:248
GUISelectedStorage::SingleTypeSelections::clear
void clear()
Clears the list of selected objects.
Definition: GUISelectedStorage.cpp:68
GUISelectedStorage::SingleTypeSelections::save
void save(const std::string &filename)
Saves the list of selected objects to a file named as given.
Definition: GUISelectedStorage.cpp:74
GUISelectedStorage::mySelections
std::map< GUIGlObjectType, SingleTypeSelections > mySelections
map with the selections
Definition: GUISelectedStorage.h:274
GUISelectedStorage::loadIDs
std::set< GUIGlID > loadIDs(const std::string &filename, std::string &msgOut, GUIGlObjectType type=GLO_MAX, int maxErrors=16)
Loads a selection list (optionally with restricted type) and returns the ids of all active objects.
Definition: GUISelectedStorage.cpp:189
GUISelectedStorage::load
std::string load(const std::string &filename, GUIGlObjectType type=GLO_MAX)
Loads a selection list (optionally with restricted type)
Definition: GUISelectedStorage.cpp:234
GUISelectedStorage::SingleTypeSelections::~SingleTypeSelections
~SingleTypeSelections()
Destructor.
Definition: GUISelectedStorage.cpp:46
GUIGlObjectType
GUIGlObjectType
Definition: GUIGlObjectTypes.h:40
GUISelectedStorage::select
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
Definition: GUISelectedStorage.cpp:114
update
GUISelectedStorage::remove2Update
void remove2Update()
Removes the dialog to be updated.
Definition: GUISelectedStorage.cpp:266
GUISelectedStorage::myAllSelected
std::set< GUIGlID > myAllSelected
List of selected objects.
Definition: GUISelectedStorage.h:277
GUISelectedStorage::SingleTypeSelections
A container for ids of selected objects of a certain type.
Definition: GUISelectedStorage.h:224
UtilExceptions.h
GUISelectedStorage::SingleTypeSelections::getSelected
const std::set< GUIGlID > & getSelected() const
Returns the list of selected ids.
Definition: GUISelectedStorage.cpp:80
GUIGlObject
Definition: GUIGlObject.h:66
GUISelectedStorage::clear
void clear()
Clears the list of selected objects.
Definition: GUISelectedStorage.cpp:177
GUISelectedStorage::SingleTypeSelections::isSelected
bool isSelected(GUIGlID id)
Returns the information whether the object with the given id is qithin the selection.
Definition: GUISelectedStorage.cpp:50
GUIGlID
unsigned int GUIGlID
Definition: GUIGlObject.h:43
GUISelectedStorage::UpdateTarget::~UpdateTarget
virtual ~UpdateTarget()
virtual destructor
Definition: GUISelectedStorage.h:78
GUISelectedStorage::GUISelectedStorage
GUISelectedStorage()
Constructor.
Definition: GUISelectedStorage.cpp:88
GUISelectedStorage
Storage for "selected" objects.
Definition: GUISelectedStorage.h:70
config.h
GUISelectedStorage::SingleTypeSelections::mySelected
std::set< GUIGlID > mySelected
The list of selected ids.
Definition: GUISelectedStorage.h:264
GUISelectedStorage::myUpdateTarget
UpdateTarget * myUpdateTarget
The dialog to be updated.
Definition: GUISelectedStorage.h:280
GUISelectedStorage::UpdateTarget
Definition: GUISelectedStorage.h:74
GUISelectedStorage::getSelected
const std::set< GUIGlID > & getSelected() const
Returns the set of ids of all selected objects.
Definition: GUISelectedStorage.cpp:165
GUISelectedStorage::toggleSelection
void toggleSelection(GUIGlID id)
Toggles selection of an object.
Definition: GUISelectedStorage.cpp:148
GUISelectedStorage::~GUISelectedStorage
~GUISelectedStorage()
Destructor.
Definition: GUISelectedStorage.cpp:91
GUISelectedStorage::SingleTypeSelections::deselect
void deselect(GUIGlID id)
Deselects the object with the given id from the list of selected objects.
Definition: GUISelectedStorage.cpp:62
GUISelectedStorage::deselect
void deselect(GUIGlID id)
Deselects the object with the given id.
Definition: GUISelectedStorage.cpp:131
GUISelectedStorage::add2Update
void add2Update(UpdateTarget *updateTarget)
Adds a dialog to be updated.
Definition: GUISelectedStorage.cpp:260
GUISelectedStorage::isSelected
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Definition: GUISelectedStorage.cpp:95