Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/guisim/GUIInstantInductLoop.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2003-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 GUIInstantInductLoop.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Aug 2003
19
///
20
// The gui-version of the MSInstantInductLoop
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <utils/common/MsgHandler.h>
25
#include <utils/gui/globjects/GUIGlObject.h>
26
#include <utils/geom/PositionVector.h>
27
#include "GUIInstantInductLoop.h"
28
#include <utils/gui/div/GLHelper.h>
29
#include <utils/gui/div/GUIParameterTableWindow.h>
30
#include <microsim/logging/FunctionBinding.h>
31
#include <microsim/output/MSInstantInductLoop.h>
32
#include <microsim/MSLane.h>
33
#include "GUIEdge.h"
34
#include <utils/gui/globjects/GLIncludes.h>
35
36
37
// ===========================================================================
38
// method definitions
39
// ===========================================================================
40
/* -------------------------------------------------------------------------
41
* GUIInstantInductLoop-methods
42
* ----------------------------------------------------------------------- */
43
GUIInstantInductLoop::GUIInstantInductLoop(const std::string& id, OutputDevice& od,
44
MSLane* const lane, double positionInMeters,
45
const std::string name, const std::string& vTypes,
46
const std::string& nextEdges) :
47
MSInstantInductLoop(id, od, lane, positionInMeters, name, vTypes, nextEdges) {}
48
49
50
GUIInstantInductLoop::~GUIInstantInductLoop() {}
51
52
53
GUIDetectorWrapper*
54
GUIInstantInductLoop::buildDetectorGUIRepresentation() {
55
return new MyWrapper(*this, myPosition);
56
}
57
58
// -------------------------------------------------------------------------
59
// GUIInstantInductLoop::MyWrapper-methods
60
// -------------------------------------------------------------------------
61
62
GUIInstantInductLoop::MyWrapper::MyWrapper(GUIInstantInductLoop& detector, double pos) :
63
GUIDetectorWrapper(GLO_E1DETECTOR_INSTANT, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E1INSTANT)),
64
myDetector(detector), myPosition(pos) {
65
myFGPosition = detector.getLane()->geometryPositionAtOffset(pos);
66
myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
67
myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
68
myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
69
}
70
71
72
GUIInstantInductLoop::MyWrapper::~MyWrapper() {}
73
74
75
double
76
GUIInstantInductLoop::MyWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
77
return s.addSize.getExaggeration(s, this);
78
}
79
80
81
Boundary
82
GUIInstantInductLoop::MyWrapper::getCenteringBoundary() const {
83
Boundary b(myBoundary);
84
b.grow(20);
85
return b;
86
}
87
88
89
90
GUIParameterTableWindow*
91
GUIInstantInductLoop::MyWrapper::getParameterWindow(GUIMainWindow& app,
92
GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
93
GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
94
// add items
95
// parameter
96
ret->mkItem(TL("name"), false, myDetector.myName);
97
ret->mkItem(TL("position [m]"), false, myPosition);
98
ret->mkItem(TL("lane"), false, myDetector.getLane()->getID());
99
if (myDetector.isTyped()) {
100
ret->mkItem(TL("vTypes"), false, toString(myDetector.getVehicleTypes()));
101
}
102
// values
103
// close building
104
ret->closeBuilding(&myDetector);
105
return ret;
106
}
107
108
109
void
110
GUIInstantInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
111
GLHelper::pushName(getGlID());
112
double width = (double) 2.0 * s.scale;
113
glLineWidth(1.0);
114
const double exaggeration = getExaggeration(s);
115
// shape
116
glColor3d(1, 0, 1);
117
GLHelper::pushMatrix();
118
glTranslated(0, 0, GLO_JUNCTION + 0.4); // do not draw on top of linkRules
119
glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
120
glRotated(myFGRotation, 0, 0, 1);
121
glScaled(exaggeration, exaggeration, 1);
122
glBegin(GL_QUADS);
123
glVertex2d(0 - 1.0, 2);
124
glVertex2d(-1.0, -2);
125
glVertex2d(1.0, -2);
126
glVertex2d(1.0, 2);
127
glEnd();
128
glTranslated(0, 0, .01);
129
glBegin(GL_LINES);
130
glVertex2d(0, 2 - .1);
131
glVertex2d(0, -2 + .1);
132
glEnd();
133
134
// outline
135
if (width * exaggeration > 1) {
136
glColor3d(1, 1, 1);
137
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
138
glBegin(GL_QUADS);
139
glVertex2d(0 - 1.0, 2);
140
glVertex2d(-1.0, -2);
141
glVertex2d(1.0, -2);
142
glVertex2d(1.0, 2);
143
glEnd();
144
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
145
}
146
147
// position indicator
148
if (width * exaggeration > 1) {
149
glRotated(90, 0, 0, -1);
150
glColor3d(1, 1, 1);
151
glBegin(GL_LINES);
152
glVertex2d(0, 1.7);
153
glVertex2d(0, -1.7);
154
glEnd();
155
}
156
GLHelper::popMatrix();
157
drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
158
GLHelper::popName();
159
}
160
161
162
GUIInstantInductLoop&
163
GUIInstantInductLoop::MyWrapper::getLoop() {
164
return myDetector;
165
}
166
167
168
/****************************************************************************/
169
170