SUMO - Simulation of Urban MObility
GUIGlObject_AbstractAdd.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 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 // Base class for additional objects (detectors etc.)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
27 #include <cassert>
28 #include <iostream>
29 #include <algorithm>
30 #include <utils/gui/div/GLHelper.h>
31 
32 
33 // ===========================================================================
34 // static member definitions
35 // ===========================================================================
36 
37 std::map<std::string, GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjects;
38 std::vector<GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjectList;
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 
45  GUIGlObject(type, id) {
46  myObjects[getFullName()] = this;
47  myObjectList.push_back(this);
48 }
49 
50 
52 
53 
54 void
56  std::map<std::string, GUIGlObject_AbstractAdd*>::iterator i;
57  for (i = myObjects.begin(); i != myObjects.end(); i++) {
59  }
60  myObjects.clear();
61  myObjectList.clear();
62 }
63 
64 
66 GUIGlObject_AbstractAdd::get(const std::string& name) {
67  auto i = myObjects.find(name);
68  if (i == myObjects.end()) {
69  return nullptr;
70  } else {
71  return i->second;
72  }
73 }
74 
75 
76 void
78  myObjects.erase(o->getFullName());
79  myObjectList.erase(std::remove(myObjectList.begin(), myObjectList.end(), o), myObjectList.end());
80 }
81 
82 
83 const std::vector<GUIGlObject_AbstractAdd*>&
85  return myObjectList;
86 }
87 
88 
89 std::vector<GUIGlID>
91  std::vector<GUIGlID> ret;
92  if (typeFilter == GLO_NETWORK) {
93  return ret;
94  } else if (typeFilter == GLO_NETELEMENT) {
95  // obtain all netElements
96  for (auto i : myObjectList) {
97  if ((i->getType() > GLO_NETELEMENT) && (i->getType() < GLO_ADDITIONAL)) {
98  ret.push_back(i->getGlID());
99  }
100  }
101  } else if (typeFilter == GLO_ADDITIONAL) {
102  // obtain all additionals
103  for (auto i : myObjectList) {
104  if ((i->getType() > GLO_ADDITIONAL) && (i->getType() < GLO_SHAPE)) {
105  ret.push_back(i->getGlID());
106  }
107  }
108  } else if (typeFilter == GLO_SHAPE) {
109  // obtain all Shapes
110  for (auto i : myObjectList) {
111  if ((i->getType() > GLO_SHAPE) && (i->getType() < GLO_ROUTEELEMENT)) {
112  ret.push_back(i->getGlID());
113  }
114  }
115  } else if (typeFilter == GLO_ROUTEELEMENT) {
116  // obtain all Shapes
117  for (auto i : myObjectList) {
118  if ((i->getType() > GLO_ROUTEELEMENT) && (i->getType() < GLO_MAX)) {
119  ret.push_back(i->getGlID());
120  }
121  }
122  } else {
123  for (auto i : myObjectList) {
124  if ((i->getType() & typeFilter) != 0) {
125  ret.push_back(i->getGlID());
126  }
127  }
128  }
129  return ret;
130 }
131 
132 /****************************************************************************/
133 
GUIGlObject_AbstractAdd(GUIGlObjectType type, const std::string &id)
constructor
static std::map< std::string, GUIGlObject_AbstractAdd * > myObjects
Map from names of loaded additional objects to the objects themselves.
static void remove(GUIGlObject_AbstractAdd *o)
Removes an object.
GUIGlObjectType
static GUIGlObject_AbstractAdd * get(const std::string &name)
Returns a named object.
reserved GLO type to pack shapes
static std::vector< GUIGlObject_AbstractAdd * > myObjectList
The list of all addtional objects currently loaded.
static void clearDictionary()
Clears the dictionary (the objects will not be deleted)
reserved GLO type to pack all RouteElments
reserved GLO type to pack all additionals
The network - empty.
static const std::vector< GUIGlObject_AbstractAdd * > & getObjectList()
Returns the list of all additional objects.
empty max
const std::string & getFullName() const
static std::vector< GUIGlID > getIDList(GUIGlObjectType typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.
reserved GLO type to pack all netElements