SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIInductLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The gui-version of the MSInductLoop, together with the according
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
35 #include "GUILaneWrapper.h"
36 #include "GUIInductLoop.h"
37 #include <utils/gui/div/GLHelper.h>
38 #include <utils/geom/Line.h>
42 #include <microsim/MSLane.h>
44 #include "GUIEdge.h"
45 
46 #ifdef _WIN32
47 #include <windows.h>
48 #endif
49 
50 #include <GL/gl.h>
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 /* -------------------------------------------------------------------------
61  * GUIInductLoop-methods
62  * ----------------------------------------------------------------------- */
63 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
64  SUMOReal position, bool splitByType)
65  : MSInductLoop(id, lane, position, splitByType) {}
66 
67 
69 
70 
73  return new MyWrapper(*this, static_cast<GUIEdge&>(getLane()->getEdge()).getLaneGeometry(getLane()), myPosition);
74 }
75 
76 
77 void
79  myLock.lock();
81  myLock.unlock();
82 }
83 
84 
85 void
87  myLock.lock();
88  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
89  myLock.unlock();
90 }
91 
92 void
94  myLock.lock();
95  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
96  myLock.unlock();
97 }
98 
99 void
101  myLock.lock();
103  myLock.unlock();
104 }
105 
106 
107 std::vector<MSInductLoop::VehicleData>
109  myLock.lock();
110  std::vector<VehicleData> ret = MSInductLoop::collectVehiclesOnDet(t);
111  myLock.unlock();
112  return ret;
113 }
114 
115 
116 /* -------------------------------------------------------------------------
117  * GUIInductLoop::MyWrapper-methods
118  * ----------------------------------------------------------------------- */
120  GUILaneWrapper& wrapper, SUMOReal pos)
121  : GUIDetectorWrapper("induct loop", detector.getID()),
122  myDetector(detector), myPosition(pos) {
123  const PositionVector& v = wrapper.getShape();
125  Line l(v.getBegin(), v.getEnd());
126  SUMOReal sgPos = pos / v.length() * l.length();
127  myBoundary.add(myFGPosition.x() + (SUMOReal) 5.5, myFGPosition.y() + (SUMOReal) 5.5);
128  myBoundary.add(myFGPosition.x() - (SUMOReal) 5.5, myFGPosition.y() - (SUMOReal) 5.5);
130 }
131 
132 
134 
135 
136 Boundary
138  Boundary b(myBoundary);
139  b.grow(20);
140  return b;
141 }
142 
143 
144 
147  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
148  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
149  // add items
150  // parameter
151  ret->mkItem("position [m]", false, myPosition);
152  ret->mkItem("lane", false, myDetector.getLane()->getID());
153  // values
154  ret->mkItem("passed vehicles [#]", true,
156  ret->mkItem("speed [m/s]", true,
158  ret->mkItem("occupancy [%]", true,
160  ret->mkItem("vehicle length [m]", true,
162  ret->mkItem("empty time [s]", true,
164  // close building
165  ret->closeBuilding();
166  return ret;
167 }
168 
169 
170 void
172  glPushName(getGlID());
173  SUMOReal width = (SUMOReal) 2.0 * s.scale;
174  glLineWidth(1.0);
175  // shape
176  glColor3d(1, 1, 0);
177  glPushMatrix();
178  glTranslated(0, 0, getType());
179  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
180  glRotated(myFGRotation, 0, 0, 1);
181  glScaled(s.addExaggeration, s.addExaggeration, 1);
182  glBegin(GL_QUADS);
183  glVertex2d(0 - 1.0, 2);
184  glVertex2d(-1.0, -2);
185  glVertex2d(1.0, -2);
186  glVertex2d(1.0, 2);
187  glEnd();
188  glTranslated(0, 0, .01);
189  glBegin(GL_LINES);
190  glVertex2d(0, 2 - .1);
191  glVertex2d(0, -2 + .1);
192  glEnd();
193 
194  // outline
195  if (width * s.addExaggeration > 1) {
196  glColor3d(1, 1, 1);
197  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
198  glBegin(GL_QUADS);
199  glVertex2f(0 - 1.0, 2);
200  glVertex2f(-1.0, -2);
201  glVertex2f(1.0, -2);
202  glVertex2f(1.0, 2);
203  glEnd();
204  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
205  }
206 
207  // position indicator
208  if (width * s.addExaggeration > 1) {
209  glRotated(90, 0, 0, -1);
210  glColor3d(1, 1, 1);
211  glBegin(GL_LINES);
212  glVertex2d(0, 1.7);
213  glVertex2d(0, -1.7);
214  glEnd();
215  }
216  glPopMatrix();
217  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
218  glPopName();
219 }
220 
221 
224  return myDetector;
225 }
226 
227 
228 
229 /****************************************************************************/
230