GUIInductLoop.cpp

Go to the documentation of this file.
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 2001-2010 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/Position2DVector.h>
00033 #include "GUILaneWrapper.h"
00034 #include "GUIInductLoop.h"
00035 #include <utils/gui/div/GLHelper.h>
00036 #include <utils/geom/Line2D.h>
00037 #include <utils/gui/div/GUIParameterTableWindow.h>
00038 #include <microsim/logging/FuncBinding_IntParam.h>
00039 #include <microsim/logging/FunctionBinding.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  * GUIInductLoop-methods
00057  * ----------------------------------------------------------------------- */
00058 GUIInductLoop::GUIInductLoop(const std::string &id, MSLane * const lane,
00059                              SUMOReal position) throw()
00060         : MSInductLoop(id, lane, position) {}
00061 
00062 
00063 GUIInductLoop::~GUIInductLoop() throw() {}
00064 
00065 
00066 GUIDetectorWrapper *
00067 GUIInductLoop::buildDetectorWrapper(GUIGlObjectStorage &idStorage,
00068                                     GUILaneWrapper &wrapper) {
00069     return new MyWrapper(*this, idStorage, wrapper, myPosition);
00070 }
00071 
00072 
00073 /* -------------------------------------------------------------------------
00074  * GUIInductLoop::MyWrapper-methods
00075  * ----------------------------------------------------------------------- */
00076 GUIInductLoop::MyWrapper::MyWrapper(GUIInductLoop &detector,
00077                                     GUIGlObjectStorage &idStorage,
00078                                     GUILaneWrapper &wrapper, SUMOReal pos) throw()
00079         : GUIDetectorWrapper(idStorage, "induct loop:"+detector.getID()),
00080         myDetector(detector), myPosition(pos) {
00081     const Position2DVector &v = wrapper.getShape();
00082     myFGPosition = v.positionAtLengthPosition(pos);
00083     Line2D l(v.getBegin(), v.getEnd());
00084     SUMOReal sgPos = pos / v.length() * l.length();
00085     myBoundary.add(myFGPosition.x()+(SUMOReal) 5.5, myFGPosition.y()+(SUMOReal) 5.5);
00086     myBoundary.add(myFGPosition.x()-(SUMOReal) 5.5, myFGPosition.y()-(SUMOReal) 5.5);
00087     myFGRotation = -v.rotationDegreeAtLengthPosition(pos);
00088 }
00089 
00090 
00091 GUIInductLoop::MyWrapper::~MyWrapper() throw() {}
00092 
00093 
00094 Boundary
00095 GUIInductLoop::MyWrapper::getCenteringBoundary() const throw() {
00096     Boundary b(myBoundary);
00097     b.grow(20);
00098     return b;
00099 }
00100 
00101 
00102 
00103 GUIParameterTableWindow *
00104 GUIInductLoop::MyWrapper::getParameterWindow(GUIMainWindow &app,
00105         GUISUMOAbstractView &/*parent !!! recheck this - never needed?*/) throw() {
00106     GUIParameterTableWindow *ret = new GUIParameterTableWindow(app, *this, 7);
00107     // add items
00108     // parameter
00109     ret->mkItem("position [m]", false, myPosition);
00110     ret->mkItem("lane", false, myDetector.getLane()->getID());
00111     // values
00112     ret->mkItem("passed vehicles [#]", true,
00113                 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentPassedNumber));
00114     ret->mkItem("speed [m/s]", true,
00115                 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentSpeed));
00116     ret->mkItem("occupancy [%]", true,
00117                 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentOccupancy));
00118     ret->mkItem("vehicle length [m]", true,
00119                 new FunctionBinding<GUIInductLoop, SUMOReal>(&myDetector, &GUIInductLoop::getCurrentLength));
00120     ret->mkItem("empty time [s]", true,
00121                 new FunctionBinding<GUIInductLoop, SUMOReal>(&(getLoop()), &GUIInductLoop::getTimestepsSinceLastDetection));
00122     // close building
00123     ret->closeBuilding();
00124     return ret;
00125 }
00126 
00127 
00128 const std::string &
00129 GUIInductLoop::MyWrapper::getMicrosimID() const throw() {
00130     return myDetector.getID();
00131 }
00132 
00133 
00134 
00135 void
00136 GUIInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings &s) const throw() {
00137     // (optional) set id
00138     if (s.needsGlID) {
00139         glPushName(getGlID());
00140     }
00141     SUMOReal width = (SUMOReal) 2.0 * s.scale;
00142     glLineWidth(1.0);
00143     // shape
00144     glColor3d(1, 1, 0);
00145     glPushMatrix();
00146     glTranslated(0, 0, -.03);
00147     glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
00148     glRotated(myFGRotation, 0, 0, 1);
00149     glScaled(s.addExaggeration, s.addExaggeration, 1);
00150     glBegin(GL_QUADS);
00151     glVertex2d(0-1.0, 2);
00152     glVertex2d(-1.0, -2);
00153     glVertex2d(1.0, -2);
00154     glVertex2d(1.0, 2);
00155     glEnd();
00156     glTranslated(0, 0, -.01);
00157     glBegin(GL_LINES);
00158     glVertex2d(0, 2-.1);
00159     glVertex2d(0, -2+.1);
00160     glEnd();
00161 
00162     // outline
00163     if (width*s.addExaggeration>1) {
00164         glColor3d(1, 1, 1);
00165         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00166         glBegin(GL_QUADS);
00167         glVertex2f(0-1.0, 2);
00168         glVertex2f(-1.0, -2);
00169         glVertex2f(1.0, -2);
00170         glVertex2f(1.0, 2);
00171         glEnd();
00172         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00173     }
00174 
00175     // position indicator
00176     if (width*s.addExaggeration>1) {
00177         glRotated(90, 0, 0, -1);
00178         glColor3d(1, 1, 1);
00179         glBegin(GL_LINES);
00180         glVertex2d(0, 1.7);
00181         glVertex2d(0, -1.7);
00182         glEnd();
00183     }
00184     glPopMatrix();
00185     // (optional) draw name
00186     if (s.drawAddName) {
00187         drawGLName(getCenteringBoundary().getCenter(), getMicrosimID(), s.addNameSize / s.scale);
00188     }
00189     // (optional) clear id
00190     if (s.needsGlID) {
00191         glPopName();
00192     }
00193 }
00194 
00195 
00196 GUIInductLoop &
00197 GUIInductLoop::MyWrapper::getLoop() {
00198     return myDetector;
00199 }
00200 
00201 
00202 
00203 /****************************************************************************/
00204 

Generated on Wed May 5 00:06:30 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6