Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/globjects/GUIGlObject_AbstractAdd.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file GUIGlObject_AbstractAdd.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date 2004
19
///
20
// Base class for additional objects (detectors etc.)
21
/****************************************************************************/
22
#include <config.h>
23
24
#include "GUIGlObject_AbstractAdd.h"
25
#include <cassert>
26
#include <iostream>
27
#include <algorithm>
28
#include <utils/gui/div/GLHelper.h>
29
30
31
// ===========================================================================
32
// static member definitions
33
// ===========================================================================
34
35
std::map<std::string, GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjects;
36
std::vector<GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjectList;
37
38
// ===========================================================================
39
// method definitions
40
// ===========================================================================
41
42
GUIGlObject_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
49
GUIGlObject_AbstractAdd::~GUIGlObject_AbstractAdd() {}
50
51
52
void
53
GUIGlObject_AbstractAdd::clearDictionary() {
54
std::map<std::string, GUIGlObject_AbstractAdd*>::iterator i;
55
for (i = myObjects.begin(); i != myObjects.end(); i++) {
56
//!!! delete (*i).second;
57
}
58
myObjects.clear();
59
myObjectList.clear();
60
}
61
62
63
GUIGlObject_AbstractAdd*
64
GUIGlObject_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
74
void
75
GUIGlObject_AbstractAdd::remove(GUIGlObject_AbstractAdd* o) {
76
myObjects.erase(o->getFullName());
77
myObjectList.erase(std::remove(myObjectList.begin(), myObjectList.end(), o), myObjectList.end());
78
}
79
80
81
const std::vector<GUIGlObject_AbstractAdd*>&
82
GUIGlObject_AbstractAdd::getObjectList() {
83
return myObjectList;
84
}
85
86
87
std::vector<GUIGlID>
88
GUIGlObject_AbstractAdd::getIDList(GUIGlObjectType typeFilter) {
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
/****************************************************************************/
132
133