Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIGlObject_AbstractAdd.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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// Base class for additional objects (detectors etc.)
21/****************************************************************************/
22#include <config.h>
23
25#include <cassert>
26#include <iostream>
27#include <algorithm>
29
30
31// ===========================================================================
32// static member definitions
33// ===========================================================================
34
35std::map<std::string, GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjects;
36std::vector<GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjectList;
37
38// ===========================================================================
39// method definitions
40// ===========================================================================
41
42GUIGlObject_AbstractAdd::GUIGlObject_AbstractAdd(GUIGlObjectType type, const std::string& id, FXIcon* icon) :
43 GUIGlObject(type, id, icon) {
44 myObjects[getFullName()] = this;
45 myObjectList.push_back(this);
46}
47
48
50
51
52void
54 std::map<std::string, GUIGlObject_AbstractAdd*>::iterator i;
55 for (i = myObjects.begin(); i != myObjects.end(); i++) {
57 }
58 myObjects.clear();
59 myObjectList.clear();
60}
61
62
64GUIGlObject_AbstractAdd::get(const std::string& name) {
65 auto i = myObjects.find(name);
66 if (i == myObjects.end()) {
67 return nullptr;
68 } else {
69 return i->second;
70 }
71}
72
73
74void
79
80
81const std::vector<GUIGlObject_AbstractAdd*>&
85
86
87std::vector<GUIGlID>
89 std::vector<GUIGlID> ret;
90 if (typeFilter == GLO_NETWORK) {
91 return ret;
92 } else if (typeFilter == GLO_NETWORKELEMENT) {
93 // obtain all network elements
94 for (auto i : myObjectList) {
95 if ((i->getType() > GLO_NETWORKELEMENT) && (i->getType() < GLO_ADDITIONALELEMENT)) {
96 ret.push_back(i->getGlID());
97 }
98 }
99 } else if (typeFilter == GLO_ADDITIONALELEMENT) {
100 // obtain all additionals
101 for (auto i : myObjectList) {
102 if ((i->getType() > GLO_ADDITIONALELEMENT) && (i->getType() < GLO_SHAPE)) {
103 ret.push_back(i->getGlID());
104 }
105 }
106 } else if (typeFilter == GLO_SHAPE) {
107 // obtain all Shapes
108 for (auto i : myObjectList) {
109 if ((i->getType() > GLO_SHAPE) && (i->getType() < GLO_ROUTEELEMENT)) {
110 ret.push_back(i->getGlID());
111 }
112 }
113 } else if (typeFilter == GLO_ROUTEELEMENT) {
114 // obtain all Shapes
115 for (auto i : myObjectList) {
116 if ((i->getType() > GLO_ROUTEELEMENT) && (i->getType() < GLO_MAX)) {
117 ret.push_back(i->getGlID());
118 }
119 }
120 } else {
121 for (auto i : myObjectList) {
122 if ((i->getType() & typeFilter) != 0) {
123 ret.push_back(i->getGlID());
124 }
125 }
126 }
127 return ret;
128}
129
130
131/****************************************************************************/
GUIGlObjectType
@ GLO_ROUTEELEMENT
reserved GLO type to pack all RouteElements (note: In this case the sorting of GLO_<element> is impor...
@ GLO_MAX
empty max
@ GLO_ADDITIONALELEMENT
reserved GLO type for packing all additionals elements
@ GLO_NETWORK
The network - empty.
@ GLO_SHAPE
reserved GLO type to pack shapes
@ GLO_NETWORKELEMENT
reserved GLO type to pack all network elements
static const std::vector< GUIGlObject_AbstractAdd * > & getObjectList()
Returns the list of all additional objects.
static void remove(GUIGlObject_AbstractAdd *o)
Removes an object.
static void clearDictionary()
Clears the dictionary (the objects will not be deleted)
static GUIGlObject_AbstractAdd * get(const std::string &name)
Returns a named object.
static std::vector< GUIGlObject_AbstractAdd * > myObjectList
The list of all addtional objects currently loaded.
GUIGlObject_AbstractAdd(GUIGlObjectType type, const std::string &id, FXIcon *icon)
constructor
static std::vector< GUIGlID > getIDList(GUIGlObjectType typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.
static std::map< std::string, GUIGlObject_AbstractAdd * > myObjects
Map from names of loaded additional objects to the objects themselves.
const std::string & getFullName() const
Definition GUIGlObject.h:94