|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The gui-version of the MS_E2_ZS_Collector 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 <utils/gui/globjects/GUIGlObject.h> 00031 #include <utils/geom/PositionVector.h> 00032 #include "GUILaneWrapper.h" 00033 #include "GUI_E2_ZS_Collector.h" 00034 #include <utils/gui/div/GLHelper.h> 00035 #include <utils/geom/Line.h> 00036 #include <utils/geom/GeomHelper.h> 00037 #include <utils/gui/div/GUIParameterTableWindow.h> 00038 #include <microsim/logging/FunctionBinding.h> 00039 #include "GUIEdge.h" 00040 00041 #ifdef _WIN32 00042 #include <windows.h> 00043 #endif 00044 00045 #include <GL/gl.h> 00046 00047 #ifdef CHECK_MEMORY_LEAKS 00048 #include <foreign/nvwa/debug_new.h> 00049 #endif // CHECK_MEMORY_LEAKS 00050 00051 00052 // =========================================================================== 00053 // method definitions 00054 // =========================================================================== 00055 /* ------------------------------------------------------------------------- 00056 * GUI_E2_ZS_Collector-methods 00057 * ----------------------------------------------------------------------- */ 00058 GUI_E2_ZS_Collector::GUI_E2_ZS_Collector(const std::string& id, DetectorUsage usage, 00059 MSLane* const lane, SUMOReal startPos, SUMOReal detLength, 00060 SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold, 00061 SUMOReal jamDistThreshold) throw() 00062 : MSE2Collector(id, usage, lane, startPos, detLength, haltingTimeThreshold, 00063 haltingSpeedThreshold, jamDistThreshold) {} 00064 00065 00066 00067 GUI_E2_ZS_Collector::~GUI_E2_ZS_Collector() throw() {} 00068 00069 00070 GUIDetectorWrapper* 00071 GUI_E2_ZS_Collector::buildDetectorGUIRepresentation() { 00072 return new MyWrapper(*this); 00073 } 00074 00075 00076 00077 /* ------------------------------------------------------------------------- 00078 * GUI_E2_ZS_Collector::MyWrapper-methods 00079 * ----------------------------------------------------------------------- */ 00080 GUI_E2_ZS_Collector::MyWrapper::MyWrapper(GUI_E2_ZS_Collector& detector) throw() 00081 : GUIDetectorWrapper("E2 detector", detector.getID()), 00082 myDetector(detector) { 00083 GUILaneWrapper& lw = static_cast<GUIEdge&>(detector.getLane()->getEdge()).getLaneGeometry(detector.getLane()); 00084 const PositionVector& v = lw.getShape(); 00085 Line l(v.getBegin(), v.getEnd()); 00086 // build geometry 00087 myFullGeometry = v.getSubpart(detector.getStartPos(), detector.getEndPos()); 00088 // 00089 myShapeRotations.reserve(myFullGeometry.size()-1); 00090 myShapeLengths.reserve(myFullGeometry.size()-1); 00091 int e = (int) myFullGeometry.size() - 1; 00092 for (int i=0; i<e; ++i) { 00093 const Position& f = myFullGeometry[i]; 00094 const Position& s = myFullGeometry[i+1]; 00095 myShapeLengths.push_back(f.distanceTo(s)); 00096 myShapeRotations.push_back((SUMOReal) atan2((s.x()-f.x()), (f.y()-s.y()))*(SUMOReal) 180.0/(SUMOReal) PI); 00097 } 00098 // 00099 myBoundary = myFullGeometry.getBoxBoundary(); 00100 } 00101 00102 00103 GUI_E2_ZS_Collector::MyWrapper::~MyWrapper() throw() {} 00104 00105 00106 Boundary 00107 GUI_E2_ZS_Collector::MyWrapper::getCenteringBoundary() const throw() { 00108 Boundary b(myBoundary); 00109 b.grow(20); 00110 return b; 00111 } 00112 00113 00114 GUIParameterTableWindow* 00115 GUI_E2_ZS_Collector::MyWrapper::getParameterWindow(GUIMainWindow& app, 00116 GUISUMOAbstractView&) throw() { 00117 GUIParameterTableWindow* ret = 00118 new GUIParameterTableWindow(app, *this, 13); 00119 // add items 00120 // parameter 00121 ret->mkItem("length [m]", false, myDetector.getEndPos()-myDetector.getStartPos()); 00122 ret->mkItem("position [m]", false, myDetector.getStartPos()); 00123 ret->mkItem("lane", false, myDetector.getLane()->getID()); 00124 // values 00125 ret->mkItem("vehicles [#]", true, 00126 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentVehicleNumber)); 00127 ret->mkItem("occupancy [%]", true, 00128 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentOccupancy)); 00129 ret->mkItem("mean speed [m/s]", true, 00130 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentMeanSpeed)); 00131 ret->mkItem("mean vehicle length [m]", true, 00132 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentMeanLength)); 00133 ret->mkItem("jam number [#]", true, 00134 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentJamNumber)); 00135 ret->mkItem("max jam length [veh]", true, 00136 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentMaxJamLengthInVehicles)); 00137 ret->mkItem("max jam length [m]", true, 00138 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentMaxJamLengthInMeters)); 00139 ret->mkItem("jam length sum [veh]", true, 00140 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentJamLengthInVehicles)); 00141 ret->mkItem("jam length sum [m]", true, 00142 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentJamLengthInMeters)); 00143 ret->mkItem("started halts [#]", true, 00144 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentStartedHalts)); 00145 // close building 00146 ret->closeBuilding(); 00147 return ret; 00148 } 00149 00150 00151 void 00152 GUI_E2_ZS_Collector::MyWrapper::drawGL(const GUIVisualizationSettings& s) const throw() { 00153 glPushName(getGlID()); 00154 glPushMatrix(); 00155 glTranslated(0, 0, getType()); 00156 SUMOReal dwidth = 1; 00157 if (myDetector.getUsageType()==DU_TL_CONTROL) { 00158 dwidth = (SUMOReal) 0.3; 00159 glColor3d(0, (SUMOReal) .6, (SUMOReal) .8); 00160 } else { 00161 glColor3d(0, (SUMOReal) .8, (SUMOReal) .8); 00162 } 00163 SUMOReal width=2; // !!! 00164 if (width*s.addExaggeration>1.0) { 00165 glScaled(s.addExaggeration, s.addExaggeration, 1); 00166 GLHelper::drawBoxLines(myFullGeometry, myShapeRotations, myShapeLengths, dwidth); 00167 } else { 00168 int e = (int) myFullGeometry.size() - 1; 00169 for (int i=0; i<e; ++i) { 00170 GLHelper::drawLine(myFullGeometry[i], myShapeRotations[i], myShapeLengths[i]); 00171 } 00172 } 00173 glPopMatrix(); 00174 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName); 00175 glPopName(); 00176 } 00177 00178 00179 GUI_E2_ZS_Collector& 00180 GUI_E2_ZS_Collector::MyWrapper::getDetector() { 00181 return myDetector; 00182 } 00183 00184 00185 00186 /****************************************************************************/ 00187