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 
virtual void selectionUpdated()=0
called when selection is updated
const std::set< GUIGlID > & getSelected() const
Returns the set of ids of all selected objects.
~GUISelectedStorage()
Destructor.
GUIGlObjectType
std::set< GUIGlID > mySelected
The list of selected ids.
void toggleSelection(GUIGlID id)
Toggles selection of an object.
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
friend class SingleTypeSelections
set SingleTypeSelections as friend class
void remove2Update()
Removes the dialog to be updated.
std::set< GUIGlID > myAllSelected
List of selected objects.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
std::map< GUIGlObjectType, SingleTypeSelections > mySelections
map with the selections
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...
virtual ~UpdateTarget()
virtual destructor
A container for ids of selected objects of a certain type.
std::string load(const std::string &filename, GUIGlObjectType type=GLO_MAX)
Loads a selection list (optionally with restricted type)
Storage for "selected" objects.
unsigned int GUIGlID
Definition: GUIGlObject.h:43
void deselect(GUIGlID id)
Deselects the object with the given id.
void add2Update(UpdateTarget *updateTarget)
Adds a dialog to be updated.
void clear()
Clears the list of selected objects.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
empty max
GUISelectedStorage()
Constructor.
void save(GUIGlObjectType type, const std::string &filename)
Saves a selection list.
UpdateTarget * myUpdateTarget
The dialog to be updated.