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