Eclipse SUMO - Simulation of Urban MObility
GUIInductLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 /****************************************************************************/
20 // The gui-version of the MSInductLoop, together with the according
21 /****************************************************************************/
22 #include <config.h>
23 
26 #include "GUIInductLoop.h"
27 #include <utils/gui/div/GLHelper.h>
31 #include <microsim/MSLane.h>
33 #include "GUIEdge.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 /* -------------------------------------------------------------------------
41  * GUIInductLoop-methods
42  * ----------------------------------------------------------------------- */
43 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
44  double position, const std::string& vTypes, bool show) :
45  MSInductLoop(id, lane, position, vTypes, true),
46  myWrapper(nullptr),
47  myShow(show)
48 {}
49 
50 
52 
53 
56  // caller (GUINet) takes responsibility for pointer
57  myWrapper = new MyWrapper(*this, myPosition);
58  return myWrapper;
59 }
60 
61 
62 void
64  if (myWrapper != nullptr) {
65  myWrapper->setSpecialColor(color);
66  }
67 }
68 
69 
70 // -------------------------------------------------------------------------
71 // GUIInductLoop::MyWrapper-methods
72 // -------------------------------------------------------------------------
73 
75  GUIDetectorWrapper(GLO_E1DETECTOR, detector.getID()),
76  myDetector(detector), myPosition(pos),
77  mySpecialColor(nullptr) {
79  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
80  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
82 }
83 
84 
86 
87 
90  Boundary b(myBoundary);
91  b.grow(20);
92  return b;
93 }
94 
95 
96 
99  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
100  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
101  // add items
102  // parameter
103  ret->mkItem("position [m]", false, myPosition);
104  ret->mkItem("lane", false, myDetector.getLane()->getID());
105  // values
106  ret->mkItem("entered vehicles [#]", true,
108  ret->mkItem("speed [m/s]", true,
110  ret->mkItem("occupancy [%]", true,
112  ret->mkItem("vehicle length [m]", true,
114  ret->mkItem("empty time [s]", true,
116  // close building
117  ret->closeBuilding();
118  return ret;
119 }
120 
121 
122 void
124  if (!myDetector.isVisible()) {
125  return;
126  }
127  glPushName(getGlID());
128  double width = (double) 2.0 * s.scale;
129  glLineWidth(1.0);
130  const double exaggeration = s.addSize.getExaggeration(s, this);
131  // shape
132  glColor3d(1, 1, 0);
133  glPushMatrix();
134  glTranslated(0, 0, getType());
135  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
136  glRotated(myFGRotation, 0, 0, 1);
137  glScaled(exaggeration, exaggeration, 1);
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  glTranslated(0, 0, .01);
145  glBegin(GL_LINES);
146  glVertex2d(0, 2 - .1);
147  glVertex2d(0, -2 + .1);
148  glEnd();
149 
150  if (mySpecialColor == nullptr) {
151  glColor3d(1, 1, 1);
152  } else {
153  GLHelper::setColor(*mySpecialColor);
154  }
155 
156  // outline
157  if (width * exaggeration > 1) {
158  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
159  glBegin(GL_QUADS);
160  glVertex2f(0 - 1.0, 2);
161  glVertex2f(-1.0, -2);
162  glVertex2f(1.0, -2);
163  glVertex2f(1.0, 2);
164  glEnd();
165  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
166  }
167 
168  // position indicator
169  if (width * exaggeration > 1) {
170  glRotated(90, 0, 0, -1);
171  glBegin(GL_LINES);
172  glVertex2d(0, 1.7);
173  glVertex2d(0, -1.7);
174  glEnd();
175  }
176  glPopMatrix();
177  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
178  glPopName();
179 }
180 
181 
182 /****************************************************************************/
@ GLO_E1DETECTOR
a E1 detector
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
A MSInductLoop-visualiser.
Definition: GUIInductLoop.h:84
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void setSpecialColor(const RGBColor *color)
set (outline) color for extra visualiaztion
Boundary myBoundary
The detector's boundary.
double myFGRotation
The rotation in full-geometry mode.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
MyWrapper(GUIInductLoop &detector, double pos)
Constructor.
Position myFGPosition
The position in full-geometry mode.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:45
MyWrapper * myWrapper
the glObject wrapper for this induction loop
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector's visualisation-wrapper.
~GUIInductLoop()
Destructor.
void setSpecialColor(const RGBColor *color)
sets special caller for myWrapper
GUIInductLoop(const std::string &id, MSLane *const lane, double position, const std::string &vTypes, bool show)
Constructor.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings addSize
double scale
information about a lane's width (temporary, used for a single view)
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:62
double getOccupancy() const
Returns the current occupancy.
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
const double myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:313
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:476
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:503
const MSLane * getLane() const
Returns the lane the reminder works on.
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values