Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/mesogui/GUIMEInductLoop.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 GUIMEInductLoop.cpp
15
/// @author Daniel Krajzewicz
16
/// @date Thu, 21.07.2005
17
///
18
// The gui-version of the MEInductLoop
19
/****************************************************************************/
20
#include <config.h>
21
22
23
#include <utils/gui/globjects/GLIncludes.h>
24
#include <utils/gui/globjects/GUIGlObject.h>
25
#include <utils/geom/PositionVector.h>
26
#include <guisim/GUILane.h>
27
#include <utils/gui/div/GLHelper.h>
28
#include <utils/gui/div/GUIParameterTableWindow.h>
29
#include <microsim/logging/FuncBinding_IntParam.h>
30
#include <microsim/logging/FunctionBinding.h>
31
#include <mesosim/MEInductLoop.h>
32
#include <mesosim/MESegment.h>
33
#include "GUIMEInductLoop.h"
34
35
36
// ===========================================================================
37
// method definitions
38
// ===========================================================================
39
/* -------------------------------------------------------------------------
40
* GUIMEInductLoop-methods
41
* ----------------------------------------------------------------------- */
42
GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
43
double position,
44
const std::string name, const std::string& vTypes,
45
const std::string& nextEdges,
46
int detectPersons,
47
bool /*show*/):
48
MEInductLoop(id, s, position, name, vTypes, nextEdges, detectPersons)
49
{}
50
51
52
GUIMEInductLoop::~GUIMEInductLoop() {}
53
54
55
GUIDetectorWrapper*
56
GUIMEInductLoop::buildDetectorGUIRepresentation() {
57
return new MyWrapper(*this, myPosition);
58
}
59
60
// -----------------------------------------------------------------------
61
// GUIMEInductLoop::MyWrapper-methods
62
// -----------------------------------------------------------------------
63
64
GUIMEInductLoop::MyWrapper::MyWrapper(GUIMEInductLoop& detector, double pos)
65
: GUIDetectorWrapper(GLO_E1DETECTOR_ME, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E1)),
66
myDetector(detector), myPosition(pos) {
67
const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
68
myFGPosition = lane->geometryPositionAtOffset(pos);
69
myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
70
myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
71
myFGRotation = -lane->getShape().rotationDegreeAtOffset(pos);
72
}
73
74
75
GUIMEInductLoop::MyWrapper::~MyWrapper() {}
76
77
78
double
79
GUIMEInductLoop::MyWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
80
return s.addSize.getExaggeration(s, this);
81
}
82
83
84
Boundary
85
GUIMEInductLoop::MyWrapper::getCenteringBoundary() const {
86
Boundary b(myBoundary);
87
b.grow(20);
88
return b;
89
}
90
91
92
93
GUIParameterTableWindow*
94
GUIMEInductLoop::MyWrapper::getParameterWindow(GUIMainWindow& app,
95
GUISUMOAbstractView& /* parent */) {
96
GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
97
// add items
98
/*
99
ret->mkItem("flow [veh/h]", true,
100
new FuncBinding_IntParam<GUIMEInductLoop, double>(
101
&(getLoop()), &GUIMEInductLoop::getFlow, 1));
102
ret->mkItem("mean speed [m/s]", true,
103
new FuncBinding_IntParam<GUIMEInductLoop, double>(
104
&(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
105
ret->mkItem("occupancy [%]", true,
106
new FuncBinding_IntParam<GUIMEInductLoop, double>(
107
&(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
108
ret->mkItem("mean vehicle length [m]", true,
109
new FuncBinding_IntParam<GUIMEInductLoop, double>(
110
&(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
111
ret->mkItem("empty time [s]", true,
112
new FunctionBinding<GUIMEInductLoop, double>(
113
&(getLoop()), &GUIMEInductLoop::getTimeSinceLastDetection));
114
*/
115
//
116
ret->mkItem("position [m]", false, myPosition);
117
ret->mkItem("lane", false, myDetector.mySegment->getID());
118
// close building
119
ret->closeBuilding();
120
return ret;
121
}
122
123
124
void
125
GUIMEInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
126
GLHelper::pushName(getGlID());
127
glPolygonOffset(0, -2);
128
double width = (double) 2.0 * s.scale;
129
glLineWidth(1.0);
130
const double exaggeration = getExaggeration(s);
131
// shape
132
glColor3d(1, 1, 0);
133
GLHelper::pushMatrix();
134
glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
135
glRotated(myFGRotation, 0, 0, 1);
136
glScaled(exaggeration, exaggeration, exaggeration);
137
glBegin(GL_QUADS);
138
glVertex2d(0 - 1.0, 2);
139
glVertex2d(-1.0, -2);
140
glVertex2d(1.0, -2);
141
glVertex2d(1.0, 2);
142
glEnd();
143
glBegin(GL_LINES);
144
// without the subtracted offsets, lines are partially longer
145
// than the boxes
146
glVertex2d(0, 2 - .1);
147
glVertex2d(0, -2 + .1);
148
glEnd();
149
150
// outline
151
if (width * exaggeration > 1) {
152
glColor3d(1, 1, 1);
153
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
154
glBegin(GL_QUADS);
155
glVertex2d(0 - 1.0, 2);
156
glVertex2d(-1.0, -2);
157
glVertex2d(1.0, -2);
158
glVertex2d(1.0, 2);
159
glEnd();
160
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
161
}
162
163
// position indicator
164
if (width * exaggeration > 1) {
165
glRotated(90, 0, 0, -1);
166
glColor3d(1, 1, 1);
167
glBegin(GL_LINES);
168
glVertex2d(0, 1.7);
169
glVertex2d(0, -1.7);
170
glEnd();
171
}
172
GLHelper::popMatrix();
173
drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
174
GLHelper::popName();
175
}
176
177
178
GUIMEInductLoop&
179
GUIMEInductLoop::MyWrapper::getLoop() {
180
return myDetector;
181
}
182
183
184
/****************************************************************************/
185
186