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