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