00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include "GUIE3Collector.h"
00031 #include "GUIEdge.h"
00032 #include <utils/geom/Line2D.h>
00033 #include <utils/gui/div/GUIParameterTableWindow.h>
00034 #include <utils/gui/images/GUITexturesHelper.h>
00035 #include <microsim/logging/FunctionBinding.h>
00036
00037 #ifdef _WIN32
00038 #include <windows.h>
00039 #endif
00040
00041 #include <GL/gl.h>
00042
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046
00047
00048
00049
00050
00051
00052
00053
00054 GUIE3Collector::MyWrapper::MyWrapper(GUIE3Collector &detector,
00055 GUIGlObjectStorage &idStorage) throw()
00056 : GUIDetectorWrapper(idStorage, "E3 detector:"+detector.getID()),
00057 myDetector(detector) {
00058 const CrossSectionVector &entries = detector.getEntries();
00059 const CrossSectionVector &exits = detector.getExits();
00060 CrossSectionVectorConstIt i;
00061 for (i=entries.begin(); i!=entries.end(); ++i) {
00062 SingleCrossingDefinition def = buildDefinition(*i);
00063 myBoundary.add(def.myFGPosition);
00064 myEntryDefinitions.push_back(def);
00065 }
00066 for (i=exits.begin(); i!=exits.end(); ++i) {
00067 SingleCrossingDefinition def = buildDefinition(*i);
00068 myBoundary.add(def.myFGPosition);
00069 myExitDefinitions.push_back(def);
00070 }
00071 }
00072
00073
00074 GUIE3Collector::MyWrapper::~MyWrapper() throw() {}
00075
00076
00077 GUIE3Collector::MyWrapper::SingleCrossingDefinition
00078 GUIE3Collector::MyWrapper::buildDefinition(const MSCrossSection §ion) {
00079 const MSLane *lane = section.myLane;
00080 SUMOReal pos = section.myPosition;
00081 const Position2DVector &v = lane->getShape();
00082 Line2D l(v.getBegin(), v.getEnd());
00083 SingleCrossingDefinition def;
00084 def.myFGPosition = v.positionAtLengthPosition(pos);
00085 def.myFGRotation = -v.rotationDegreeAtLengthPosition(pos);
00086 return def;
00087 }
00088
00089
00090 GUIParameterTableWindow *
00091 GUIE3Collector::MyWrapper::getParameterWindow(GUIMainWindow &app,
00092 GUISUMOAbstractView &) throw() {
00093 GUIParameterTableWindow *ret =
00094 new GUIParameterTableWindow(app, *this, 3);
00095
00096
00097 ret->mkItem("vehicles within [#]", true,
00098 new FunctionBinding<MSE3Collector, SUMOReal>(&myDetector, &MSE3Collector::getVehiclesWithin));
00099 ret->mkItem("mean speed [m/s]", true,
00100 new FunctionBinding<MSE3Collector, SUMOReal>(&myDetector, &MSE3Collector::getCurrentMeanSpeed));
00101 ret->mkItem("haltings [#]", true,
00102 new FunctionBinding<MSE3Collector, SUMOReal>(&myDetector, &MSE3Collector::getCurrentHaltingNumber));
00103
00104 ret->closeBuilding();
00105 return ret;
00106 }
00107
00108
00109 const std::string &
00110 GUIE3Collector::MyWrapper::getMicrosimID() const throw() {
00111 return myDetector.getID();
00112 }
00113
00114
00115 void
00116 GUIE3Collector::MyWrapper::drawGL(const GUIVisualizationSettings &s) const throw() {
00117
00118 if (s.needsGlID) {
00119 glPushName(getGlID());
00120 }
00121 glTranslated(0, 0, -.03);
00122 typedef std::vector<SingleCrossingDefinition> CrossingDefinitions;
00123 CrossingDefinitions::const_iterator i;
00124 glColor3d(0, .8, 0);
00125 for (i=myEntryDefinitions.begin(); i!=myEntryDefinitions.end(); ++i) {
00126 drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, s.addExaggeration);
00127 }
00128 glColor3d(.8, 0, 0);
00129 for (i=myExitDefinitions.begin(); i!=myExitDefinitions.end(); ++i) {
00130 drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, s.addExaggeration);
00131 }
00132 glTranslated(0, 0, .03);
00133
00134 if (s.drawAddName) {
00135 drawGLName(getCenteringBoundary().getCenter(), getMicrosimID(), s.addNameSize / s.scale);
00136 }
00137
00138 if (s.needsGlID) {
00139 glPopName();
00140 }
00141 }
00142
00143
00144 void
00145 GUIE3Collector::MyWrapper::drawSingleCrossing(const Position2D &pos,
00146 SUMOReal rot, SUMOReal upscale) const {
00147 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00148 glPushMatrix();
00149 glScaled(upscale, upscale, 1);
00150 glTranslated(pos.x(), pos.y(), 0);
00151 glRotated(rot, 0, 0, 1);
00152 glBegin(GL_LINES);
00153 glVertex2d(1.7, 0);
00154 glVertex2d(-1.7, 0);
00155 glEnd();
00156 glBegin(GL_QUADS);
00157 glVertex2d(-1.7, .5);
00158 glVertex2d(-1.7, -.5);
00159 glVertex2d(1.7, -.5);
00160 glVertex2d(1.7, .5);
00161 glEnd();
00162
00163 glTranslated(1.5, 0, 0);
00164 GUITexturesHelper::drawDirectionArrow(TEXTURE_LINKDIR_STRAIGHT, 1.0);
00165 glTranslated(-3, 0, 0);
00166 GUITexturesHelper::drawDirectionArrow(TEXTURE_LINKDIR_STRAIGHT, 1.0);
00167 glPopMatrix();
00168 }
00169
00170
00171 Boundary
00172 GUIE3Collector::MyWrapper::getCenteringBoundary() const throw() {
00173 Boundary b(myBoundary);
00174 b.grow(20);
00175 return b;
00176 }
00177
00178
00179 GUIE3Collector &
00180 GUIE3Collector::MyWrapper::getDetector() {
00181 return myDetector;
00182 }
00183
00184
00185
00186
00187
00188 GUIE3Collector::GUIE3Collector(const std::string &id,
00189 const CrossSectionVector &entries, const CrossSectionVector &exits,
00190 MetersPerSecond haltingSpeedThreshold,
00191 SUMOTime haltingTimeThreshold) throw()
00192 : MSE3Collector(id, entries, exits, haltingSpeedThreshold, haltingTimeThreshold) {}
00193
00194
00195 GUIE3Collector::~GUIE3Collector() throw() {}
00196
00197
00198 const CrossSectionVector &
00199 GUIE3Collector::getEntries() const {
00200 return myEntries;
00201 }
00202
00203
00204 const CrossSectionVector &
00205 GUIE3Collector::getExits() const {
00206 return myExits;
00207 }
00208
00209
00210
00211 GUIDetectorWrapper *
00212 GUIE3Collector::buildDetectorWrapper(GUIGlObjectStorage &idStorage) {
00213 return new MyWrapper(*this, idStorage);
00214 }
00215
00216
00217
00218
00219