00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <utils/geom/Position2D.h>
00031 #include <utils/geom/Boundary.h>
00032 #include <guisim/GUIVehicle.h>
00033 #include <microsim/MSJunction.h>
00034 #include <guisim/GUIEdge.h>
00035 #include <guisim/GUINet.h>
00036
00037 #include <string>
00038 #include <vector>
00039 #include "GUIGlobals.h"
00040 #include "dialogs/GUIDialog_GLObjChooser.h"
00041 #include "GUIViewTraffic.h"
00042 #include "GUIApplicationWindow.h"
00043 #include "GUISUMOViewParent.h"
00044 #include <utils/gui/globjects/GUIGlObjectTypes.h>
00045 #include <utils/gui/globjects/GUIGlObjectStorage.h>
00046 #include <utils/gui/windows/GUIAppEnum.h>
00047 #include <utils/gui/images/GUIIcons.h>
00048 #include <utils/gui/images/GUIIconSubSys.h>
00049 #include <utils/foxtools/MFXUtils.h>
00050 #include <utils/foxtools/MFXCheckableButton.h>
00051 #include <utils/gui/div/GUIGlobalSelection.h>
00052 #include <utils/gui/globjects/GUIGlObjectStorage.h>
00053 #include <utils/gui/div/GUIIOGlobals.h>
00054 #include <utils/foxtools/MFXImageHelper.h>
00055 #include <utils/common/UtilExceptions.h>
00056
00057 #ifdef CHECK_MEMORY_LEAKS
00058 #include <foreign/nvwa/debug_new.h>
00059 #endif // CHECK_MEMORY_LEAKS
00060
00061
00062
00063
00064
00065 FXDEFMAP(GUISUMOViewParent) GUISUMOViewParentMap[]= {
00066 FXMAPFUNC(SEL_COMMAND, MID_MAKESNAPSHOT, GUISUMOViewParent::onCmdMakeSnapshot),
00067
00068 FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GUISUMOViewParent::onCmdLocateJunction),
00069 FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GUISUMOViewParent::onCmdLocateEdge),
00070 FXMAPFUNC(SEL_COMMAND, MID_LOCATEVEHICLE, GUISUMOViewParent::onCmdLocateVehicle),
00071 FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GUISUMOViewParent::onCmdLocateTLS),
00072 FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GUISUMOViewParent::onCmdLocateAdd),
00073 FXMAPFUNC(SEL_COMMAND, MID_LOCATESHAPE, GUISUMOViewParent::onCmdLocateShape),
00074 FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUISUMOViewParent::onSimStep),
00075
00076 };
00077
00078
00079 FXIMPLEMENT(GUISUMOViewParent, GUIGlChildWindow, GUISUMOViewParentMap, ARRAYNUMBER(GUISUMOViewParentMap))
00080
00081
00082
00083
00084
00085 GUISUMOViewParent::GUISUMOViewParent(FXMDIClient* p, FXMDIMenu *mdimenu,
00086 const FXString& name,
00087 GUIMainWindow *parentWindow,
00088 FXIcon* ic, FXuint opts,
00089 FXint x, FXint y, FXint w, FXint h)
00090 : GUIGlChildWindow(p, mdimenu, name, ic, opts, x, y, w, h),
00091 myParent(parentWindow)
00092
00093 {
00094 myParent->addChild(this, false);
00095 }
00096
00097
00098 GUISUMOAbstractView*
00099 GUISUMOViewParent::init(FXGLCanvas *share, GUINet &net) {
00100 myView = new GUIViewTraffic(myContentFrame, *myParent, this, net,
00101 myParent->getGLVisual(), share);
00102 myView->buildViewToolBars(*this);
00103 return myView;
00104 }
00105
00106
00107 GUISUMOViewParent::~GUISUMOViewParent() {
00108 myParent->removeChild(this);
00109 }
00110
00111
00112 long
00113 GUISUMOViewParent::onCmdMakeSnapshot(FXObject*,FXSelector,void*) {
00114
00115 FXFileDialog opendialog(this, "Save Snapshot");
00116 opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
00117 opendialog.setSelectMode(SELECTFILE_ANY);
00118 opendialog.setPatternList("All Image Files (*.gif, *.bmp, *.xpm, *.pcx, *.ico, *.rgb, *.xbm, *.tga, *.png, *.jpg, *.jpeg, *.tif, *.tiff)\n"
00119 "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
00120 "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
00121 "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\nAll Files (*)");
00122 if (gCurrentFolder.length()!=0) {
00123 opendialog.setDirectory(gCurrentFolder);
00124 }
00125 if (!opendialog.execute()||!MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
00126 return 1;
00127 }
00128 gCurrentFolder = opendialog.getDirectory();
00129 std::string file = opendialog.getFilename().text();
00130 FXColor *buf = myView->getSnapshot();
00131
00132 try {
00133 MFXImageHelper::saveImage(file, myView->getWidth(), myView->getHeight(), buf);
00134 } catch (InvalidArgument e) {
00135 std::string msg = "Could not save '" + file + "'.\n" + e.what();
00136 FXMessageBox::error(this, MBOX_OK, "Saving failed.", msg.c_str());
00137 }
00138 FXFREE(&buf);
00139 return 1;
00140 }
00141
00142
00143 void
00144 GUISUMOViewParent::showLocator(GUIGlObjectType type, FXIcon *icon, FXString title) {
00145 myLocatorPopup->popdown();
00146 myLocatorButton->killFocus();
00147 myLocatorPopup->update();
00148 GUIDialog_GLObjChooser *chooser = new GUIDialog_GLObjChooser(this, icon, title, type, GUIGlObjectStorage::gIDStorage);
00149 chooser->create();
00150 chooser->show();
00151 }
00152
00153
00154 long
00155 GUISUMOViewParent::onCmdLocateJunction(FXObject *,FXSelector,void*) {
00156 showLocator(GLO_JUNCTION, GUIIconSubSys::getIcon(ICON_LOCATEJUNCTION), "Junction Chooser");
00157 return 1;
00158 }
00159
00160
00161 long
00162 GUISUMOViewParent::onCmdLocateEdge(FXObject *,FXSelector,void*) {
00163 showLocator(GLO_EDGE, GUIIconSubSys::getIcon(ICON_LOCATEEDGE), "Edge Chooser");
00164 return 1;
00165 }
00166
00167
00168 long
00169 GUISUMOViewParent::onCmdLocateVehicle(FXObject *,FXSelector,void*) {
00170 showLocator(GLO_VEHICLE, GUIIconSubSys::getIcon(ICON_LOCATEVEHICLE), "Vehicle Chooser");
00171 return 1;
00172 }
00173
00174
00175 long
00176 GUISUMOViewParent::onCmdLocateTLS(FXObject *,FXSelector,void*) {
00177 showLocator(GLO_TLLOGIC, GUIIconSubSys::getIcon(ICON_LOCATETLS), "Traffic Lights Chooser");
00178 return 1;
00179 }
00180
00181
00182 long
00183 GUISUMOViewParent::onCmdLocateAdd(FXObject *,FXSelector,void*) {
00184 showLocator(GLO_ADDITIONAL, GUIIconSubSys::getIcon(ICON_LOCATEADD), "Additional Objects Chooser");
00185 return 1;
00186 }
00187
00188
00189 long
00190 GUISUMOViewParent::onCmdLocateShape(FXObject *sender,FXSelector,void*) {
00191 showLocator(GLO_SHAPE, GUIIconSubSys::getIcon(ICON_LOCATESHAPE), "Shape Chooser");
00192 return 1;
00193 }
00194
00195
00196 void
00197 GUISUMOViewParent::setView(const GUIGlObject * const o) throw() {
00198 myView->centerTo(o);
00199 }
00200
00201
00202 long
00203 GUISUMOViewParent::onSimStep(FXObject*,FXSelector,void*) {
00204 myView->update();
00205 myView->checkSnapshots();
00206 return 1;
00207 }
00208
00209
00210
00211
00212