|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The gui-version of the MSInstantInductLoop 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 <microsim/output/MSInstantInductLoop.h> 00031 #include <utils/gui/globjects/GUIGlObject.h> 00032 #include <utils/geom/PositionVector.h> 00033 #include "GUILaneWrapper.h" 00034 #include "GUIInstantInductLoop.h" 00035 #include <utils/gui/div/GLHelper.h> 00036 #include <utils/geom/Line.h> 00037 #include <utils/gui/div/GUIParameterTableWindow.h> 00038 #include <microsim/logging/FuncBinding_IntParam.h> 00039 #include <microsim/logging/FunctionBinding.h> 00040 #include <microsim/MSLane.h> 00041 #include "GUIEdge.h" 00042 00043 #ifdef _WIN32 00044 #include <windows.h> 00045 #endif 00046 00047 #include <GL/gl.h> 00048 00049 #ifdef CHECK_MEMORY_LEAKS 00050 #include <foreign/nvwa/debug_new.h> 00051 #endif // CHECK_MEMORY_LEAKS 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 /* ------------------------------------------------------------------------- 00058 * GUIInstantInductLoop-methods 00059 * ----------------------------------------------------------------------- */ 00060 GUIInstantInductLoop::GUIInstantInductLoop(const std::string& id, OutputDevice& od, 00061 MSLane* const lane, SUMOReal positionInMeters) throw() 00062 : MSInstantInductLoop(id, od, lane, positionInMeters) {} 00063 00064 00065 GUIInstantInductLoop::~GUIInstantInductLoop() throw() {} 00066 00067 00068 GUIDetectorWrapper* 00069 GUIInstantInductLoop::buildDetectorGUIRepresentation() { 00070 return new MyWrapper(*this, static_cast<GUIEdge&>(getLane()->getEdge()).getLaneGeometry(getLane()), myPosition); 00071 } 00072 00073 00074 /* ------------------------------------------------------------------------- 00075 * GUIInstantInductLoop::MyWrapper-methods 00076 * ----------------------------------------------------------------------- */ 00077 GUIInstantInductLoop::MyWrapper::MyWrapper(GUIInstantInductLoop& detector, 00078 GUILaneWrapper& wrapper, SUMOReal pos) throw() 00079 : GUIDetectorWrapper("instant induct loop", detector.getID()), 00080 myDetector(detector), myPosition(pos) { 00081 const PositionVector& v = wrapper.getShape(); 00082 myFGPosition = v.positionAtLengthPosition(pos); 00083 Line 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 GUIInstantInductLoop::MyWrapper::~MyWrapper() throw() {} 00092 00093 00094 Boundary 00095 GUIInstantInductLoop::MyWrapper::getCenteringBoundary() const throw() { 00096 Boundary b(myBoundary); 00097 b.grow(20); 00098 return b; 00099 } 00100 00101 00102 00103 GUIParameterTableWindow* 00104 GUIInstantInductLoop::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 // close building 00113 ret->closeBuilding(); 00114 return ret; 00115 } 00116 00117 00118 void 00119 GUIInstantInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const throw() { 00120 glPushName(getGlID()); 00121 SUMOReal width = (SUMOReal) 2.0 * s.scale; 00122 glLineWidth(1.0); 00123 // shape 00124 glColor3d(1, 0, 1); 00125 glPushMatrix(); 00126 glTranslated(0, 0, getType()); 00127 glTranslated(myFGPosition.x(), myFGPosition.y(), 0); 00128 glRotated(myFGRotation, 0, 0, 1); 00129 glScaled(s.addExaggeration, s.addExaggeration, 1); 00130 glBegin(GL_QUADS); 00131 glVertex2d(0-1.0, 2); 00132 glVertex2d(-1.0, -2); 00133 glVertex2d(1.0, -2); 00134 glVertex2d(1.0, 2); 00135 glEnd(); 00136 glTranslated(0, 0, .01); 00137 glBegin(GL_LINES); 00138 glVertex2d(0, 2-.1); 00139 glVertex2d(0, -2+.1); 00140 glEnd(); 00141 00142 // outline 00143 if (width*s.addExaggeration>1) { 00144 glColor3d(1, 1, 1); 00145 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 00146 glBegin(GL_QUADS); 00147 glVertex2f(0-1.0, 2); 00148 glVertex2f(-1.0, -2); 00149 glVertex2f(1.0, -2); 00150 glVertex2f(1.0, 2); 00151 glEnd(); 00152 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00153 } 00154 00155 // position indicator 00156 if (width*s.addExaggeration>1) { 00157 glRotated(90, 0, 0, -1); 00158 glColor3d(1, 1, 1); 00159 glBegin(GL_LINES); 00160 glVertex2d(0, 1.7); 00161 glVertex2d(0, -1.7); 00162 glEnd(); 00163 } 00164 glPopMatrix(); 00165 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName); 00166 glPopName(); 00167 } 00168 00169 00170 GUIInstantInductLoop& 00171 GUIInstantInductLoop::MyWrapper::getLoop() { 00172 return myDetector; 00173 } 00174 00175 00176 00177 /****************************************************************************/ 00178