|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A single child window which contains a view of the simulation area 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 <string> 00031 #include <vector> 00032 #include <guisim/GUIShapeContainer.h> 00033 #include <utils/common/UtilExceptions.h> 00034 #include <utils/geom/Position.h> 00035 #include <utils/geom/Boundary.h> 00036 #include <utils/foxtools/MFXUtils.h> 00037 #include <utils/foxtools/MFXCheckableButton.h> 00038 #include <utils/foxtools/MFXImageHelper.h> 00039 #include <utils/gui/globjects/GUIGlObjectTypes.h> 00040 #include <utils/gui/globjects/GUIGlObjectStorage.h> 00041 #include <utils/gui/images/GUIIcons.h> 00042 #include <utils/gui/images/GUIIconSubSys.h> 00043 #include <utils/gui/div/GUIGlobalSelection.h> 00044 #include <utils/gui/div/GUIIOGlobals.h> 00045 #include <utils/gui/windows/GUIAppEnum.h> 00046 #include <utils/gui/windows/GUIDialog_GLObjChooser.h> 00047 #include <guisim/GUIVehicle.h> 00048 #include <guisim/GUIEdge.h> 00049 #include <guisim/GUINet.h> 00050 #include <guisim/GUIVehicleControl.h> 00051 #include <guisim/GUINet.h> 00052 #include <microsim/MSJunction.h> 00053 #include "GUIGlobals.h" 00054 #include "GUIViewTraffic.h" 00055 #include "GUIApplicationWindow.h" 00056 #include "GUISUMOViewParent.h" 00057 00058 #ifdef CHECK_MEMORY_LEAKS 00059 #include <foreign/nvwa/debug_new.h> 00060 #endif // CHECK_MEMORY_LEAKS 00061 00062 00063 // =========================================================================== 00064 // FOX callback mapping 00065 // =========================================================================== 00066 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[]= { 00067 FXMAPFUNC(SEL_COMMAND, MID_MAKESNAPSHOT, GUISUMOViewParent::onCmdMakeSnapshot), 00068 // FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GUISUMOViewParent::onCmdAllowRotation), 00069 FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocate), 00070 FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocate), 00071 FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocate), 00072 FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocate), 00073 FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocate), 00074 FXMAPFUNC(SEL_COMMAND, MID_LOCATESHAPE, GUISUMOViewParent::onCmdLocate), 00075 FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep), 00076 00077 }; 00078 00079 // Object implementation 00080 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap)) 00081 00082 00083 // =========================================================================== 00084 // member method definitions 00085 // =========================================================================== 00086 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu* mdimenu, 00087 const FXString& name, 00088 GUIMainWindow* parentWindow, 00089 FXIcon* ic, FXuint opts, 00090 FXint x, FXint y, FXint w, FXint h) 00091 : GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) { 00092 myParent->addChild(this, false); 00093 } 00094 00095 00096 GUISUMOAbstractView* 00097 GUISUMOViewParent::init(FXGLCanvas* share, GUINet& net) { 00098 myView = new GUIViewTraffic(myContentFrame, *myParent, this, net, 00099 myParent->getGLVisual(), share); 00100 myView->buildViewToolBars(*this); 00101 if (myParent->isGaming()) { 00102 myNavigationToolBar->hide(); 00103 } 00104 return myView; 00105 } 00106 00107 00108 GUISUMOViewParent::~GUISUMOViewParent() { 00109 myParent->removeChild(this); 00110 } 00111 00112 00113 long 00114 GUISUMOViewParent::onCmdMakeSnapshot(FXObject*,FXSelector,void*) { 00115 // get the new file name 00116 FXFileDialog opendialog(this, "Save Snapshot"); 00117 opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY)); 00118 opendialog.setSelectMode(SELECTFILE_ANY); 00119 opendialog.setPatternList("All Image Files (*.gif, *.bmp, *.xpm, *.pcx, *.ico, *.rgb, *.xbm, *.tga, *.png, *.jpg, *.jpeg, *.tif, *.tiff, *.ps, *.eps, *.pdf, *.svg, *.tex, *.pgf)\n" 00120 "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n" 00121 "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n" 00122 "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n" 00123 "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n" 00124 "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n" 00125 "All Files (*)"); 00126 if (gCurrentFolder.length()!=0) { 00127 opendialog.setDirectory(gCurrentFolder); 00128 } 00129 if (!opendialog.execute()||!MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) { 00130 return 1; 00131 } 00132 gCurrentFolder = opendialog.getDirectory(); 00133 std::string file = opendialog.getFilename().text(); 00134 std::string error = myView->makeSnapshot(file); 00135 if (error!="") { 00136 FXMessageBox::error(this, MBOX_OK, "Saving failed.", error.c_str()); 00137 } 00138 return 1; 00139 } 00140 00141 00142 long 00143 GUISUMOViewParent::onCmdLocate(FXObject*,FXSelector sel,void*) { 00144 GUIGlObjectType type; 00145 std::vector<GUIGlID> ids; 00146 GUIIcon icon; 00147 std::string title; 00148 switch (FXSELID(sel)) { 00149 case MID_LOCATEJUNCTION: 00150 type = GLO_JUNCTION; 00151 ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal()); 00152 icon = ICON_LOCATEJUNCTION; 00153 title = "Junction Chooser"; 00154 break; 00155 case MID_LOCATEEDGE: 00156 type = GLO_EDGE; 00157 ids = GUIEdge::getIDs(myParent->listInternal()); 00158 icon = ICON_LOCATEEDGE; 00159 title = "Edge Chooser"; 00160 break; 00161 case MID_LOCATEVEHICLE: 00162 type = GLO_VEHICLE; 00163 static_cast<GUIVehicleControl&>(MSNet::getInstance()->getVehicleControl()).insertVehicleIDs(ids); 00164 icon = ICON_LOCATEVEHICLE; 00165 title = "Vehicle Chooser"; 00166 break; 00167 case MID_LOCATETLS: 00168 type = GLO_TLLOGIC; 00169 ids = static_cast<GUINet*>(GUINet::getInstance())->getTLSIDs(); 00170 icon = ICON_LOCATETLS; 00171 title = "Traffic Lights Chooser"; 00172 break; 00173 case MID_LOCATEADD: 00174 type = GLO_ADDITIONAL; 00175 ids = GUIGlObject_AbstractAdd::getIDList(); 00176 icon = ICON_LOCATEADD; 00177 title = "Additional Objects Chooser"; 00178 break; 00179 case MID_LOCATESHAPE: 00180 type = GLO_SHAPE; 00181 ids = static_cast<GUIShapeContainer&>(GUINet::getInstance()->getShapeContainer()).getShapeIDs(); 00182 icon = ICON_LOCATESHAPE; 00183 title = "Shape Chooser"; 00184 break; 00185 default: 00186 throw ProcessError("Unknown Message ID in onCmdLocate"); 00187 } 00188 myLocatorPopup->popdown(); 00189 myLocatorButton->killFocus(); 00190 myLocatorPopup->update(); 00191 GUIDialog_GLObjChooser* chooser = new GUIDialog_GLObjChooser( 00192 this, GUIIconSubSys::getIcon(icon), title.c_str(), type, ids, GUIGlObjectStorage::gIDStorage); 00193 chooser->create(); 00194 chooser->show(); 00195 return 1; 00196 } 00197 00198 00199 long 00200 GUISUMOViewParent::onSimStep(FXObject*,FXSelector,void*) { 00201 myView->update(); 00202 myView->checkSnapshots(); 00203 return 1; 00204 } 00205 00206 00207 bool 00208 GUISUMOViewParent::isSelected(GUIGlObject* o) const { 00209 GUIGlObjectType type = o->getType(); 00210 if (gSelected.isSelected(type, o->getGlID())) { 00211 return true; 00212 } else if (type == GLO_EDGE) { 00213 GUIEdge* edge = dynamic_cast<GUIEdge*>(o); 00214 assert(edge); 00215 size_t noLanes = edge->getLanes().size(); 00216 for (size_t j=0; j<noLanes; ++j) { 00217 const GUILaneWrapper& l = edge->getLaneGeometry(j); 00218 if (gSelected.isSelected(GLO_LANE, l.getGlID())) { 00219 return true; 00220 } 00221 } 00222 return false; 00223 } else { 00224 return false; 00225 } 00226 } 00227 00228 00229 /****************************************************************************/ 00230