|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The gui-version of the MSInductLoop, together with the according 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <microsim/output/MSInductLoop.h> 00031 #include <utils/gui/globjects/GUIGlObject.h> 00032 #include <utils/geom/PositionVector.h> 00033 #include "GUILaneWrapper.h" 00034 #include "GUIInductLoop.h" 00035 #include <utils/gui/div/GLHelper.h> 00036 #include <utils/geom/Line.h> 00037 #include <utils/gui/div/GUIParameterTableWindow.h> 00038 #include <microsim/logging/FuncBinding_IntParam.h> 00039 #include <microsim/logging/FunctionBinding.h> 00040 #include <microsim/MSLane.h> 00041 #include "GUIEdge.h" 00042 00043 #ifdef _WIN32 00044 #include <windows.h> 00045 #endif 00046 00047 #include <GL/gl.h> 00048 00049 #ifdef CHECK_MEMORY_LEAKS 00050 #include <foreign/nvwa/debug_new.h> 00051 #endif // CHECK_MEMORY_LEAKS 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 /* ------------------------------------------------------------------------- 00058 * GUIInductLoop-methods 00059 * ----------------------------------------------------------------------- */ 00060 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane, 00061 SUMOReal position, bool splitByType) throw() 00062 : MSInductLoop(id, lane, position, splitByType) {} 00063 00064 00065 GUIInductLoop::~GUIInductLoop() throw() {} 00066 00067 00068 GUIDetectorWrapper* 00069 GUIInductLoop::buildDetectorGUIRepresentation() { 00070 return new MyWrapper(*this, static_cast<GUIEdge&>(getLane()->getEdge()).getLaneGeometry(getLane()), myPosition); 00071 } 00072 00073 00074 void 00075 GUIInductLoop::reset() throw() { 00076 myLock.lock(); 00077 MSInductLoop::reset(); 00078 myLock.unlock(); 00079 } 00080 00081 00082 void 00083 GUIInductLoop::enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep) throw() { 00084 myLock.lock(); 00085 MSInductLoop::enterDetectorByMove(veh, entryTimestep); 00086 myLock.unlock(); 00087 } 00088 00089 void 00090 GUIInductLoop::leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep) throw() { 00091 myLock.lock(); 00092 MSInductLoop::leaveDetectorByMove(veh, leaveTimestep); 00093 myLock.unlock(); 00094 } 00095 00096 void 00097 GUIInductLoop::leaveDetectorByLaneChange(SUMOVehicle& veh) throw() { 00098 myLock.lock(); 00099 MSInductLoop::leaveDetectorByLaneChange(veh); 00100 myLock.unlock(); 00101 } 00102 00103 00104 std::vector<MSInductLoop::VehicleData> 00105 GUIInductLoop::collectVehiclesOnDet(SUMOTime t) const throw() { 00106 myLock.lock(); 00107 std::vector<VehicleData> ret = MSInductLoop::collectVehiclesOnDet(t); 00108 myLock.unlock(); 00109 return ret; 00110 } 00111 00112 00113 /* ------------------------------------------------------------------------- 00114 * GUIInductLoop::MyWrapper-methods 00115 * ----------------------------------------------------------------------- */ 00116 GUIInductLoop::MyWrapper::MyWrapper(GUIInductLoop& detector, 00117 GUILaneWrapper& wrapper, SUMOReal pos) throw() 00118 : GUIDetectorWrapper("induct loop", detector.getID()), 00119 myDetector(detector), myPosition(pos) { 00120 const PositionVector& v = wrapper.getShape(); 00121 myFGPosition = v.positionAtLengthPosition(pos); 00122 Line l(v.getBegin(), v.getEnd()); 00123 SUMOReal sgPos = pos / v.length() * l.length(); 00124 myBoundary.add(myFGPosition.x()+(SUMOReal) 5.5, myFGPosition.y()+(SUMOReal) 5.5); 00125 myBoundary.add(myFGPosition.x()-(SUMOReal) 5.5, myFGPosition.y()-(SUMOReal) 5.5); 00126 myFGRotation = -v.rotationDegreeAtLengthPosition(pos); 00127 } 00128 00129 00130 GUIInductLoop::MyWrapper::~MyWrapper() throw() {} 00131 00132 00133 Boundary 00134 GUIInductLoop::MyWrapper::getCenteringBoundary() const throw() { 00135 Boundary b(myBoundary); 00136 b.grow(20); 00137 return b; 00138 } 00139 00140 00141 00142 GUIParameterTableWindow* 00143 GUIInductLoop::MyWrapper::getParameterWindow(GUIMainWindow& app, 00144 GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) throw() { 00145 GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7); 00146 // add items 00147 // parameter 00148 ret->mkItem("position [m]", false, myPosition); 00149 ret->mkItem("lane", false, myDetector.getLane()->getID()); 00150 // values 00151 ret->mkItem("passed vehicles [#]", true, 00152 new FunctionBinding<GUIInductLoop, unsigned int>(&myDetector, &GUIInductLoop::getCurrentPassedNumber)); 00153 ret->mkItem("speed [m/s]", true, 00154 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentSpeed)); 00155 ret->mkItem("occupancy [%]", true, 00156 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentOccupancy)); 00157 ret->mkItem("vehicle length [m]", true, 00158 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentLength)); 00159 ret->mkItem("empty time [s]", true, 00160 new FunctionBinding<GUIInductLoop, SUMOReal>(&(getLoop()), &GUIInductLoop::getTimestepsSinceLastDetection)); 00161 // close building 00162 ret->closeBuilding(); 00163 return ret; 00164 } 00165 00166 00167 void 00168 GUIInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const throw() { 00169 glPushName(getGlID()); 00170 SUMOReal width = (SUMOReal) 2.0 * s.scale; 00171 glLineWidth(1.0); 00172 // shape 00173 glColor3d(1, 1, 0); 00174 glPushMatrix(); 00175 glTranslated(0, 0, getType()); 00176 glTranslated(myFGPosition.x(), myFGPosition.y(), 0); 00177 glRotated(myFGRotation, 0, 0, 1); 00178 glScaled(s.addExaggeration, s.addExaggeration, 1); 00179 glBegin(GL_QUADS); 00180 glVertex2d(0-1.0, 2); 00181 glVertex2d(-1.0, -2); 00182 glVertex2d(1.0, -2); 00183 glVertex2d(1.0, 2); 00184 glEnd(); 00185 glTranslated(0, 0, .01); 00186 glBegin(GL_LINES); 00187 glVertex2d(0, 2-.1); 00188 glVertex2d(0, -2+.1); 00189 glEnd(); 00190 00191 // outline 00192 if (width*s.addExaggeration>1) { 00193 glColor3d(1, 1, 1); 00194 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 00195 glBegin(GL_QUADS); 00196 glVertex2f(0-1.0, 2); 00197 glVertex2f(-1.0, -2); 00198 glVertex2f(1.0, -2); 00199 glVertex2f(1.0, 2); 00200 glEnd(); 00201 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00202 } 00203 00204 // position indicator 00205 if (width*s.addExaggeration>1) { 00206 glRotated(90, 0, 0, -1); 00207 glColor3d(1, 1, 1); 00208 glBegin(GL_LINES); 00209 glVertex2d(0, 1.7); 00210 glVertex2d(0, -1.7); 00211 glEnd(); 00212 } 00213 glPopMatrix(); 00214 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName); 00215 glPopName(); 00216 } 00217 00218 00219 GUIInductLoop& 00220 GUIInductLoop::MyWrapper::getLoop() { 00221 return myDetector; 00222 } 00223 00224 00225 00226 /****************************************************************************/ 00227