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