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 /****************************************************************************/
16 // Storage for "selected" objects
17 /****************************************************************************/
18 #ifndef GUISelectedStorage_h
19 #define GUISelectedStorage_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <set>
28 #include <string>
29 #include <map>
30 #include <fstream>
31 #include <fx.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class OutputDevice;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
70 
71 public:
73  class UpdateTarget {
74 
75  public:
77  virtual ~UpdateTarget() {};
78 
80  virtual void selectionUpdated() = 0;
81  };
82 
83 public:
86 
89 
106  bool isSelected(GUIGlObjectType type, GUIGlID id);
107 
108  bool isSelected(const GUIGlObject* o);
109 
125  void select(GUIGlID id, bool update = true);
126 
142  void deselect(GUIGlID id);
143 
158  void toggleSelection(GUIGlID id);
159 
161  const std::set<GUIGlID>& getSelected() const;
162 
169  const std::set<GUIGlID>& getSelected(GUIGlObjectType type);
170 
177  void clear();
178 
185  std::string load(const std::string& filename, GUIGlObjectType type = GLO_MAX);
186 
196  std::set<GUIGlID> loadIDs(const std::string& filename, std::string& msgOut, GUIGlObjectType type = GLO_MAX, int maxErrors = 16);
197 
203  void save(GUIGlObjectType type, const std::string& filename);
204 
209  void save(const std::string& filename) const;
210 
214  void add2Update(UpdateTarget* updateTarget);
215 
217  void remove2Update();
218 
224 
225  public:
228 
231 
236  bool isSelected(GUIGlID id);
237 
241  void select(GUIGlID id);
242 
246  void deselect(GUIGlID id);
247 
249  void clear();
250 
254  void save(const std::string& filename);
255 
259  const std::set<GUIGlID>& getSelected() const;
260 
261  private:
263  std::set<GUIGlID> mySelected;
264 
265  };
266 
268  friend class SingleTypeSelections;
269 
270 
271 private:
273  std::map<GUIGlObjectType, SingleTypeSelections> mySelections;
274 
276  std::set<GUIGlID> myAllSelected;
277 
280 
282  std::string load(GUIGlObjectType type, const std::string& filename, bool restrictType, std::set<GUIGlID>& into);
283 
285  static void save(const std::string& filename, const std::set<GUIGlID>& ids);
286 };
287 
288 
289 #endif
290 
291 /****************************************************************************/
292 
GLO_MAX
@ GLO_MAX
empty max
Definition: GUIGlObjectTypes.h:165
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:55
GUISelectedStorage::SingleTypeSelections::SingleTypeSelections
SingleTypeSelections()
Constructor.
Definition: GUISelectedStorage.cpp:42
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:63
GUISelectedStorage::save
void save(GUIGlObjectType type, const std::string &filename)
Saves a selection list.
Definition: GUISelectedStorage.cpp:247
GUISelectedStorage::SingleTypeSelections::clear
void clear()
Clears the list of selected objects.
Definition: GUISelectedStorage.cpp:67
GUISelectedStorage::SingleTypeSelections::save
void save(const std::string &filename)
Saves the list of selected objects to a file named as given.
Definition: GUISelectedStorage.cpp:73
GUISelectedStorage::mySelections
std::map< GUIGlObjectType, SingleTypeSelections > mySelections
map with the selections
Definition: GUISelectedStorage.h:273
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:188
GUISelectedStorage::load
std::string load(const std::string &filename, GUIGlObjectType type=GLO_MAX)
Loads a selection list (optionally with restricted type)
Definition: GUISelectedStorage.cpp:233
GUISelectedStorage::SingleTypeSelections::~SingleTypeSelections
~SingleTypeSelections()
Destructor.
Definition: GUISelectedStorage.cpp:45
GUIGlObjectType
GUIGlObjectType
Definition: GUIGlObjectTypes.h:39
GUISelectedStorage::select
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
Definition: GUISelectedStorage.cpp:113
update
GUISelectedStorage::remove2Update
void remove2Update()
Removes the dialog to be updated.
Definition: GUISelectedStorage.cpp:265
GUISelectedStorage::myAllSelected
std::set< GUIGlID > myAllSelected
List of selected objects.
Definition: GUISelectedStorage.h:276
GUISelectedStorage::SingleTypeSelections
A container for ids of selected objects of a certain type.
Definition: GUISelectedStorage.h:223
UtilExceptions.h
GUISelectedStorage::SingleTypeSelections::getSelected
const std::set< GUIGlID > & getSelected() const
Returns the list of selected ids.
Definition: GUISelectedStorage.cpp:79
GUIGlObject
Definition: GUIGlObject.h:65
GUISelectedStorage::clear
void clear()
Clears the list of selected objects.
Definition: GUISelectedStorage.cpp:176
GUISelectedStorage::SingleTypeSelections::isSelected
bool isSelected(GUIGlID id)
Returns the information whether the object with the given id is qithin the selection.
Definition: GUISelectedStorage.cpp:49
GUIGlID
unsigned int GUIGlID
Definition: GUIGlObject.h:42
GUISelectedStorage::UpdateTarget::~UpdateTarget
virtual ~UpdateTarget()
virtual destructor
Definition: GUISelectedStorage.h:77
GUISelectedStorage::GUISelectedStorage
GUISelectedStorage()
Constructor.
Definition: GUISelectedStorage.cpp:87
GUISelectedStorage
Storage for "selected" objects.
Definition: GUISelectedStorage.h:69
config.h
GUISelectedStorage::SingleTypeSelections::mySelected
std::set< GUIGlID > mySelected
The list of selected ids.
Definition: GUISelectedStorage.h:263
GUISelectedStorage::myUpdateTarget
UpdateTarget * myUpdateTarget
The dialog to be updated.
Definition: GUISelectedStorage.h:279
GUISelectedStorage::UpdateTarget
Definition: GUISelectedStorage.h:73
GUISelectedStorage::getSelected
const std::set< GUIGlID > & getSelected() const
Returns the set of ids of all selected objects.
Definition: GUISelectedStorage.cpp:164
GUISelectedStorage::toggleSelection
void toggleSelection(GUIGlID id)
Toggles selection of an object.
Definition: GUISelectedStorage.cpp:147
GUISelectedStorage::~GUISelectedStorage
~GUISelectedStorage()
Destructor.
Definition: GUISelectedStorage.cpp:90
GUISelectedStorage::SingleTypeSelections::deselect
void deselect(GUIGlID id)
Deselects the object with the given id from the list of selected objects.
Definition: GUISelectedStorage.cpp:61
GUISelectedStorage::load
std::string load(GUIGlObjectType type, const std::string &filename, bool restrictType, std::set< GUIGlID > &into)
load items into the given set, optionally restricting to type
GUISelectedStorage::deselect
void deselect(GUIGlID id)
Deselects the object with the given id.
Definition: GUISelectedStorage.cpp:130
GUISelectedStorage::add2Update
void add2Update(UpdateTarget *updateTarget)
Adds a dialog to be updated.
Definition: GUISelectedStorage.cpp:259
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:94