|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 // A view on the simulation; this view is a microscopic one 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 /****************************************************************************/ 00016 // 00017 // This file is part of SUMO. 00018 // SUMO is free software: you can redistribute it and/or modify 00019 // it under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation, either version 3 of the License, or 00021 // (at your option) any later version. 00022 // 00023 /****************************************************************************/ 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <iostream> 00036 #include <utility> 00037 #include <cmath> 00038 #include <limits> 00039 #include <guisim/GUINet.h> 00040 #include <guisim/GUIEdge.h> 00041 #include <guisim/GUILane.h> 00042 #include <guisim/GUIVehicle.h> 00043 #include <microsim/MSEdge.h> 00044 #include <microsim/MSLane.h> 00045 #include <microsim/MSJunctionControl.h> 00046 #include <microsim/traffic_lights/MSTLLogicControl.h> 00047 #include <utils/common/RGBColor.h> 00048 #include <utils/geom/PositionVector.h> 00049 #include <utils/shapes/Polygon.h> 00050 #include "GUISUMOViewParent.h" 00051 #include "GUIViewTraffic.h" 00052 #include <utils/gui/windows/GUISUMOAbstractView.h> 00053 #include <utils/gui/windows/GUIPerspectiveChanger.h> 00054 #include <utils/gui/windows/GUIAppEnum.h> 00055 #include <utils/foxtools/MFXCheckableButton.h> 00056 #include <utils/gui/images/GUIIconSubSys.h> 00057 #include <gui/GUIApplicationWindow.h> 00058 #include <foreign/polyfonts/polyfonts.h> 00059 #include <utils/gui/windows/GUIDialog_ViewSettings.h> 00060 #include <utils/gui/settings/GUICompleteSchemeStorage.h> 00061 #include <utils/gui/images/GUITexturesHelper.h> 00062 #include <utils/foxtools/MFXImageHelper.h> 00063 #include <utils/gui/globjects/GUIGlObjectStorage.h> 00064 #include <foreign/rtree/SUMORTree.h> 00065 #include <utils/gui/div/GLHelper.h> 00066 00067 #ifdef _WIN32 00068 #include <windows.h> 00069 #endif 00070 00071 #include <GL/gl.h> 00072 #include <GL/glu.h> 00073 00074 #ifdef CHECK_MEMORY_LEAKS 00075 #include <foreign/nvwa/debug_new.h> 00076 #endif // CHECK_MEMORY_LEAKS 00077 00078 00079 // =========================================================================== 00080 // member method definitions 00081 // =========================================================================== 00082 GUIViewTraffic::GUIViewTraffic( 00083 FXComposite* p, 00084 GUIMainWindow& app, 00085 GUISUMOViewParent* parent, 00086 GUINet& net, FXGLVisual* glVis, 00087 FXGLCanvas* share) : 00088 GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share), 00089 myTrackedID(-1) {} 00090 00091 00092 GUIViewTraffic::~GUIViewTraffic() { 00093 } 00094 00095 00096 void 00097 GUIViewTraffic::buildViewToolBars(GUIGlChildWindow& v) { 00098 // build coloring tools 00099 { 00100 const std::vector<std::string> &names = gSchemeStorage.getNames(); 00101 for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) { 00102 v.getColoringSchemesCombo().appendItem((*i).c_str()); 00103 if ((*i) == myVisualizationSettings->name) { 00104 v.getColoringSchemesCombo().setCurrentItem(v.getColoringSchemesCombo().getNumItems() - 1); 00105 } 00106 } 00107 v.getColoringSchemesCombo().setNumVisible(5); 00108 } 00109 // for junctions 00110 new FXButton(v.getLocatorPopup(), 00111 "\tLocate Junction\tLocate a junction within the network.", 00112 GUIIconSubSys::getIcon(ICON_LOCATEJUNCTION), &v, MID_LOCATEJUNCTION, 00113 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED); 00114 // for edges 00115 new FXButton(v.getLocatorPopup(), 00116 "\tLocate Street\tLocate a street within the network.", 00117 GUIIconSubSys::getIcon(ICON_LOCATEEDGE), &v, MID_LOCATEEDGE, 00118 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED); 00119 // for vehicles 00120 new FXButton(v.getLocatorPopup(), 00121 "\tLocate Vehicle\tLocate a vehicle within the network.", 00122 GUIIconSubSys::getIcon(ICON_LOCATEVEHICLE), &v, MID_LOCATEVEHICLE, 00123 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED); 00124 // for tls 00125 new FXButton(v.getLocatorPopup(), 00126 "\tLocate TLS\tLocate a tls within the network.", 00127 GUIIconSubSys::getIcon(ICON_LOCATETLS), &v, MID_LOCATETLS, 00128 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED); 00129 // for additional stuff 00130 new FXButton(v.getLocatorPopup(), 00131 "\tLocate Additional\tLocate an additional structure within the network.", 00132 GUIIconSubSys::getIcon(ICON_LOCATEADD), &v, MID_LOCATEADD, 00133 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED); 00134 // for shapes 00135 new FXButton(v.getLocatorPopup(), 00136 "\tLocate Shape\tLocate a shape within the network.", 00137 GUIIconSubSys::getIcon(ICON_LOCATESHAPE), &v, MID_LOCATESHAPE, 00138 ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED); 00139 } 00140 00141 00142 bool 00143 GUIViewTraffic::setColorScheme(const std::string& name) { 00144 if (!gSchemeStorage.contains(name)) { 00145 return false; 00146 } 00147 if (myVisualizationChanger != 0) { 00148 if (myVisualizationChanger->getCurrentScheme() != name) { 00149 myVisualizationChanger->setCurrentScheme(name); 00150 } 00151 } 00152 myVisualizationSettings = &gSchemeStorage.get(name.c_str()); 00153 myVisualizationSettings->gaming = myApp->isGaming(); 00154 update(); 00155 return true; 00156 } 00157 00158 00159 int 00160 GUIViewTraffic::doPaintGL(int mode, const Boundary& bound) { 00161 // init view settings 00162 glRenderMode(mode); 00163 glMatrixMode(GL_MODELVIEW); 00164 glPushMatrix(); 00165 glDisable(GL_TEXTURE_2D); 00166 glDisable(GL_ALPHA_TEST); 00167 glDisable(GL_BLEND); 00168 glEnable(GL_DEPTH_TEST); 00169 00170 // draw decals (if not in grabbing mode) 00171 if (!myUseToolTips) { 00172 drawDecals(); 00173 if (myVisualizationSettings->showGrid) { 00174 paintGLGrid(); 00175 } 00176 } 00177 00178 glLineWidth(1); 00179 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00180 float minB[2]; 00181 float maxB[2]; 00182 minB[0] = bound.xmin(); 00183 minB[1] = bound.ymin(); 00184 maxB[0] = bound.xmax(); 00185 maxB[1] = bound.ymax(); 00186 myVisualizationSettings->scale = m2p(SUMO_const_laneWidth); 00187 glEnable(GL_POLYGON_OFFSET_FILL); 00188 glEnable(GL_POLYGON_OFFSET_LINE); 00189 int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings); 00190 // 00191 glTranslated(0, 0, -.01); 00192 for (std::map<GUIGlObject*, int>::iterator i = myAdditionallyDrawn.begin(); i != myAdditionallyDrawn.end(); ++i) { 00193 (i->first)->drawGLAdditional(this, *myVisualizationSettings); 00194 } 00195 glTranslated(0, 0, .01); 00196 glPopMatrix(); 00197 /* 00198 // draw legends 00199 glMatrixMode(GL_MODELVIEW); 00200 glLoadIdentity(); 00201 glTranslated(1.-.2, 1.-.5, 0.); 00202 glScaled(.2, .5, 1.); 00203 GUIColoringSchemesMap<GUILaneWrapper> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!! 00204 sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend(); 00205 */ 00206 return hits2; 00207 } 00208 00209 00210 void 00211 GUIViewTraffic::startTrack(int id) { 00212 myTrackedID = id; 00213 } 00214 00215 00216 void 00217 GUIViewTraffic::stopTrack() { 00218 myTrackedID = -1; 00219 } 00220 00221 00222 int 00223 GUIViewTraffic::getTrackedID() const { 00224 return myTrackedID; 00225 } 00226 00227 00228 void 00229 GUIViewTraffic::showViewschemeEditor() { 00230 if (myVisualizationChanger == 0) { 00231 myVisualizationChanger = 00232 new GUIDialog_ViewSettings( 00233 this, myVisualizationSettings, 00234 &myDecals, &myDecalsLock); 00235 myVisualizationChanger->create(); 00236 } else { 00237 myVisualizationChanger->setCurrent(myVisualizationSettings); 00238 } 00239 myVisualizationChanger->show(); 00240 } 00241 00242 00243 void 00244 GUIViewTraffic::onGamingClick(Position pos) { 00245 MSTLLogicControl& tlsControl = MSNet::getInstance()->getTLSControl(); 00246 const std::vector<MSTrafficLightLogic*> &logics = tlsControl.getAllLogics(); 00247 MSTrafficLightLogic* minTll = 0; 00248 SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity(); 00249 for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) { 00250 // get the logic 00251 MSTrafficLightLogic* tll = (*i); 00252 if (tlsControl.isActive(tll)) { 00253 // get the links 00254 const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0); 00255 if (lanes.size() > 0) { 00256 const Position& endPos = lanes[0]->getShape().getEnd(); 00257 if (endPos.distanceTo(pos) < minDist) { 00258 minDist = endPos.distanceTo(pos); 00259 minTll = tll; 00260 } 00261 } 00262 } 00263 } 00264 if (minTll != 0) { 00265 const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID()); 00266 const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics(); 00267 if (logics.size() > 1) { 00268 MSSimpleTrafficLightLogic* l = (MSSimpleTrafficLightLogic*) logics[0]; 00269 for (unsigned int i = 0; i < logics.size() - 1; i++) { 00270 if (minTll->getProgramID() == logics[i]->getProgramID()) { 00271 l = (MSSimpleTrafficLightLogic*) logics[i + 1]; 00272 tlsControl.switchTo(minTll->getID(), l->getProgramID()); 00273 } 00274 } 00275 if (l == logics[0]) { 00276 tlsControl.switchTo(minTll->getID(), l->getProgramID()); 00277 } 00278 l->changeStepAndDuration(tlsControl, MSNet::getInstance()->getCurrentTimeStep(), 0, l->getPhase(0).duration); 00279 update(); 00280 } 00281 } 00282 } 00283 00284 00285 SUMOTime 00286 GUIViewTraffic::getCurrentTimeStep() const { 00287 return MSNet::getInstance()->getCurrentTimeStep(); 00288 } 00289 /****************************************************************************/