Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/guisim/GUIE3Collector.cpp
169666 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 GUIE3Collector.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Jan 2004
19
///
20
// The gui-version of a MSE3Collector
21
/****************************************************************************/
22
#include <config.h>
23
24
#include "GUIE3Collector.h"
25
#include "GUIEdge.h"
26
#include <utils/common/MsgHandler.h>
27
#include <utils/gui/div/GUIParameterTableWindow.h>
28
#include <utils/gui/div/GLHelper.h>
29
#include <microsim/logging/FunctionBinding.h>
30
#include <microsim/MSLane.h>
31
#include <utils/gui/globjects/GLIncludes.h>
32
33
34
// ===========================================================================
35
// method definitions
36
// ===========================================================================
37
38
// -------------------------------------------------------------------------
39
// GUIE3Collector::MyWrapper-methods
40
// -------------------------------------------------------------------------
41
42
GUIE3Collector::MyWrapper::MyWrapper(GUIE3Collector& detector) :
43
GUIDetectorWrapper(GLO_E3DETECTOR, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E3)),
44
myDetector(detector) {
45
const CrossSectionVector& entries = detector.getEntries();
46
const CrossSectionVector& exits = detector.getExits();
47
CrossSectionVectorConstIt i;
48
for (i = entries.begin(); i != entries.end(); ++i) {
49
SingleCrossingDefinition def = buildDefinition(*i);
50
myBoundary.add(def.myFGPosition);
51
myEntryDefinitions.push_back(def);
52
}
53
for (i = exits.begin(); i != exits.end(); ++i) {
54
SingleCrossingDefinition def = buildDefinition(*i);
55
myBoundary.add(def.myFGPosition);
56
myExitDefinitions.push_back(def);
57
}
58
}
59
60
61
GUIE3Collector::MyWrapper::~MyWrapper() {}
62
63
64
GUIE3Collector::MyWrapper::SingleCrossingDefinition
65
GUIE3Collector::MyWrapper::buildDefinition(const MSCrossSection& section) {
66
SingleCrossingDefinition def;
67
def.myFGPosition = section.myLane->geometryPositionAtOffset(section.myPosition);
68
def.myFGRotation = -section.myLane->getShape().rotationDegreeAtOffset(section.myPosition);
69
return def;
70
}
71
72
73
GUIParameterTableWindow*
74
GUIE3Collector::MyWrapper::getParameterWindow(GUIMainWindow& app,
75
GUISUMOAbstractView&) {
76
GUIParameterTableWindow* ret =
77
new GUIParameterTableWindow(app, *this);
78
// add items
79
// values
80
ret->mkItem(TL("name"), false, myDetector.myName);
81
if (myDetector.isTyped()) {
82
ret->mkItem(TL("vTypes"), false, toString(myDetector.getVehicleTypes()));
83
}
84
ret->mkItem(TL("vehicles within [#]"), true,
85
new FunctionBinding<MSE3Collector, int>(&myDetector, &MSE3Collector::getVehiclesWithin));
86
ret->mkItem(TL("mean speed [m/s]"), true,
87
new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getCurrentMeanSpeed));
88
ret->mkItem(TL("haltings [#]"), true,
89
new FunctionBinding<MSE3Collector, int>(&myDetector, &MSE3Collector::getCurrentHaltingNumber));
90
ret->mkItem(TL("last interval mean travel time [s]"), true,
91
new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getLastIntervalMeanTravelTime));
92
ret->mkItem(TL("last interval mean haltings [#]"), true,
93
new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getLastIntervalMeanHaltsPerVehicle));
94
ret->mkItem(TL("last interval mean time loss [s]"), true,
95
new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getLastIntervalMeanTimeLoss));
96
ret->mkItem(TL("last interval mean vehicle count [#]"), true,
97
new FunctionBinding<MSE3Collector, int>(&myDetector, &MSE3Collector::getLastIntervalVehicleSum));
98
99
// close building
100
ret->closeBuilding(&myDetector);
101
return ret;
102
}
103
104
105
void
106
GUIE3Collector::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
107
GLHelper::pushName(getGlID());
108
GLHelper::pushMatrix();
109
glTranslated(0, 0, GLO_JUNCTION + 0.4); // do not draw on top of linkRules
110
typedef std::vector<SingleCrossingDefinition> CrossingDefinitions;
111
CrossingDefinitions::const_iterator i;
112
GLHelper::setColor(s.detectorSettings.E3EntryColor);
113
const double exaggeration = getExaggeration(s);
114
for (i = myEntryDefinitions.begin(); i != myEntryDefinitions.end(); ++i) {
115
drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, exaggeration);
116
}
117
GLHelper::setColor(s.detectorSettings.E3ExitColor);
118
for (i = myExitDefinitions.begin(); i != myExitDefinitions.end(); ++i) {
119
drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, exaggeration);
120
}
121
GLHelper::popMatrix();
122
drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
123
GLHelper::popName();
124
}
125
126
127
void
128
GUIE3Collector::MyWrapper::drawSingleCrossing(const Position& pos,
129
double rot, double upscale) const {
130
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
131
GLHelper::pushMatrix();
132
glTranslated(pos.x(), pos.y(), 0);
133
glRotated(rot, 0, 0, 1);
134
glScaled(upscale, upscale, 1);
135
glBegin(GL_LINES);
136
glVertex2d(1.7, 0);
137
glVertex2d(-1.7, 0);
138
glEnd();
139
glBegin(GL_QUADS);
140
glVertex2d(-1.7, .5);
141
glVertex2d(-1.7, -.5);
142
glVertex2d(1.7, -.5);
143
glVertex2d(1.7, .5);
144
glEnd();
145
// arrows
146
glTranslated(1.5, 0, 0);
147
GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
148
GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
149
glTranslated(-3, 0, 0);
150
GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
151
GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
152
GLHelper::popMatrix();
153
}
154
155
156
double
157
GUIE3Collector::MyWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
158
return s.addSize.getExaggeration(s, this);
159
}
160
161
162
Boundary
163
GUIE3Collector::MyWrapper::getCenteringBoundary() const {
164
Boundary b(myBoundary);
165
b.grow(20);
166
return b;
167
}
168
169
170
GUIE3Collector&
171
GUIE3Collector::MyWrapper::getDetector() {
172
return myDetector;
173
}
174
175
176
/* -------------------------------------------------------------------------
177
* GUIE3Collector-methods
178
* ----------------------------------------------------------------------- */
179
GUIE3Collector::GUIE3Collector(const std::string& id,
180
const CrossSectionVector& entries, const CrossSectionVector& exits,
181
double haltingSpeedThreshold,
182
SUMOTime haltingTimeThreshold,
183
const std::string name, const std::string& vTypes,
184
const std::string& nextEdges,
185
int detectPersons,
186
bool openEntry, bool expectArrival):
187
MSE3Collector(id, entries, exits, haltingSpeedThreshold, haltingTimeThreshold, name, vTypes, nextEdges, detectPersons, openEntry, expectArrival)
188
{}
189
190
191
GUIE3Collector::~GUIE3Collector() {}
192
193
194
const CrossSectionVector&
195
GUIE3Collector::getEntries() const {
196
return myEntries;
197
}
198
199
200
const CrossSectionVector&
201
GUIE3Collector::getExits() const {
202
return myExits;
203
}
204
205
206
207
GUIDetectorWrapper*
208
GUIE3Collector::buildDetectorGUIRepresentation() {
209
return new MyWrapper(*this);
210
}
211
212
213
/****************************************************************************/
214
215