1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file GUIMEInductLoop.cpp
11 /// @author Daniel Krajzewicz
12 /// @date Thu, 21.07.2005
13 /// @version $Id$
14 ///
15 // The gui-version of the MEInductLoop
16 /****************************************************************************/
17
18
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23
24
25 #include <utils/gui/globjects/GLIncludes.h>
26 #include <utils/gui/globjects/GUIGlObject.h>
27 #include <utils/geom/PositionVector.h>
28 #include <guisim/GUILane.h>
29 #include <utils/gui/div/GLHelper.h>
30 #include <utils/gui/div/GUIParameterTableWindow.h>
31 #include <microsim/logging/FuncBinding_IntParam.h>
32 #include <microsim/logging/FunctionBinding.h>
33 #include <mesosim/MEInductLoop.h>
34 #include <mesosim/MESegment.h>
35 #include "GUIMEInductLoop.h"
36
37
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 /* -------------------------------------------------------------------------
42 * GUIMEInductLoop-methods
43 * ----------------------------------------------------------------------- */
GUIMEInductLoop(const std::string & id,MESegment * s,double position,const std::string & vTypes)44 GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
45 double position, const std::string& vTypes)
46 : MEInductLoop(id, s, position, vTypes) {}
47
48
~GUIMEInductLoop()49 GUIMEInductLoop::~GUIMEInductLoop() {}
50
51
52 GUIDetectorWrapper*
buildDetectorGUIRepresentation()53 GUIMEInductLoop::buildDetectorGUIRepresentation() {
54 return new MyWrapper(*this, myPosition);
55 }
56
57 // -----------------------------------------------------------------------
58 // GUIMEInductLoop::MyWrapper-methods
59 // -----------------------------------------------------------------------
60
MyWrapper(GUIMEInductLoop & detector,double pos)61 GUIMEInductLoop::MyWrapper::MyWrapper(GUIMEInductLoop& detector, double pos)
62 : GUIDetectorWrapper(GLO_E1DETECTOR_ME, detector.getID()),
63 myDetector(detector), myPosition(pos) {
64 const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
65 myFGPosition = lane->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 = -lane->getShape().rotationDegreeAtOffset(pos);
69 }
70
71
~MyWrapper()72 GUIMEInductLoop::MyWrapper::~MyWrapper() {}
73
74
75 Boundary
getCenteringBoundary() const76 GUIMEInductLoop::MyWrapper::getCenteringBoundary() const {
77 Boundary b(myBoundary);
78 b.grow(20);
79 return b;
80 }
81
82
83
84 GUIParameterTableWindow*
getParameterWindow(GUIMainWindow & app,GUISUMOAbstractView &)85 GUIMEInductLoop::MyWrapper::getParameterWindow(GUIMainWindow& app,
86 GUISUMOAbstractView& /* parent */) {
87 GUIParameterTableWindow* ret =
88 new GUIParameterTableWindow(app, *this, 2);
89 // add items
90 /*
91 ret->mkItem("flow [veh/h]", true,
92 new FuncBinding_IntParam<GUIMEInductLoop, double>(
93 &(getLoop()), &GUIMEInductLoop::getFlow, 1));
94 ret->mkItem("mean speed [m/s]", true,
95 new FuncBinding_IntParam<GUIMEInductLoop, double>(
96 &(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
97 ret->mkItem("occupancy [%]", true,
98 new FuncBinding_IntParam<GUIMEInductLoop, double>(
99 &(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
100 ret->mkItem("mean vehicle length [m]", true,
101 new FuncBinding_IntParam<GUIMEInductLoop, double>(
102 &(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
103 ret->mkItem("empty time [s]", true,
104 new FunctionBinding<GUIMEInductLoop, double>(
105 &(getLoop()), &GUIMEInductLoop::getTimeSinceLastDetection));
106 */
107 //
108 ret->mkItem("position [m]", false, myPosition);
109 ret->mkItem("lane", false, myDetector.mySegment->getID());
110 // close building
111 ret->closeBuilding();
112 return ret;
113 }
114
115
116 void
drawGL(const GUIVisualizationSettings & s) const117 GUIMEInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
118 glPushName(getGlID());
119 glPolygonOffset(0, -2);
120 double width = (double) 2.0 * s.scale;
121 glLineWidth(1.0);
122 const double exaggeration = s.addSize.getExaggeration(s, this);
123 // shape
124 glColor3d(1, 1, 0);
125 glPushMatrix();
126 glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
127 glRotated(myFGRotation, 0, 0, 1);
128 glScaled(exaggeration, exaggeration, exaggeration);
129 glBegin(GL_QUADS);
130 glVertex2d(0 - 1.0, 2);
131 glVertex2d(-1.0, -2);
132 glVertex2d(1.0, -2);
133 glVertex2d(1.0, 2);
134 glEnd();
135 glBegin(GL_LINES);
136 // without the substracted offsets, lines are partially longer
137 // than the boxes
138 glVertex2d(0, 2 - .1);
139 glVertex2d(0, -2 + .1);
140 glEnd();
141
142 // outline
143 if (width * exaggeration > 1) {
144 glColor3d(1, 1, 1);
145 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
146 glBegin(GL_QUADS);
147 glVertex2f(0 - 1.0, 2);
148 glVertex2f(-1.0, -2);
149 glVertex2f(1.0, -2);
150 glVertex2f(1.0, 2);
151 glEnd();
152 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
153 }
154
155 // position indicator
156 if (width * exaggeration > 1) {
157 glRotated(90, 0, 0, -1);
158 glColor3d(1, 1, 1);
159 glBegin(GL_LINES);
160 glVertex2d(0, 1.7);
161 glVertex2d(0, -1.7);
162 glEnd();
163 }
164 glPopMatrix();
165 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
166 glPopName();
167 }
168
169
170 GUIMEInductLoop&
getLoop()171 GUIMEInductLoop::MyWrapper::getLoop() {
172 return myDetector;
173 }
174
175
176 /****************************************************************************/
177
178