SUMO - Simulation of Urban MObility
GNEViewParent.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A single child window which contains a view of the edited network (adapted
8 // from GUISUMOViewParent)
9 // While we don't actually need MDI for netedit it is easier to adapt existing
10 // structures than to write everything from scratch.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
40 #include <utils/geom/Position.h>
41 #include <utils/geom/Boundary.h>
51 
52 #include "GNENet.h"
53 #include "GNEEdge.h"
54 #include "GNEViewNet.h"
55 #include "GNEViewParent.h"
56 #include "GNEUndoList.h"
57 #include "GNEApplicationWindow.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 
64 // ===========================================================================
65 // FOX callback mapping
66 // ===========================================================================
67 FXDEFMAP(GNEViewParent) GNEViewParentMap[] = {
68  FXMAPFUNC(SEL_COMMAND, MID_MAKESNAPSHOT, GNEViewParent::onCmdMakeSnapshot),
69  //FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GNEViewParent::onCmdAllowRotation),
70  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GNEViewParent::onCmdLocate),
71  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GNEViewParent::onCmdLocate),
72  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GNEViewParent::onCmdLocate),
73  FXMAPFUNC(SEL_COMMAND, FXMDIChild::ID_MDI_MENUCLOSE, GNEViewParent::onCmdClose),
74 };
75 
76 // Object implementation
77 FXIMPLEMENT(GNEViewParent, GUIGlChildWindow, GNEViewParentMap, ARRAYNUMBER(GNEViewParentMap))
78 
79 // ===========================================================================
80 // member method definitions
81 // ===========================================================================
83  FXMDIClient* p, FXMDIMenu* mdimenu,
84  const FXString& name,
85  GNEApplicationWindow* parentWindow,
86  FXGLCanvas* share, GNENet* net,
87  FXIcon* ic, FXuint opts,
88  FXint x, FXint y, FXint w, FXint h):
89  GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
90  myParent->addChild(this, false);
91 
92  // disable coloring and screenshot
93  //for (int i=5; i < myNavigationToolBar->numChildren(); i++) {
94  // myNavigationToolBar->childAtIndex(i)->hide();
95  //}
96 
97  // add undo/redo buttons
98  new FXButton(myNavigationToolBar,
99  "\tUndo\tUndo the last Change.",
100  GUIIconSubSys::getIcon(ICON_UNDO), parentWindow->getUndoList(), FXUndoList::ID_UNDO,
101  ICON_BEFORE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
102  new FXButton(myNavigationToolBar,
103  "\tRedo\tRedo the last Change.",
104  GUIIconSubSys::getIcon(ICON_REDO), parentWindow->getUndoList(), FXUndoList::ID_REDO,
105  ICON_BEFORE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
106  new FXToolBarGrip(myNavigationToolBar, NULL, 0, TOOLBARGRIP_SINGLE | FRAME_SUNKEN);
107 
108  myViewArea = new FXHorizontalFrame(myContentFrame,
109  FRAME_SUNKEN | LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y,
110  0, 0, 0, 0, 0, 0, 0, 0);
111  // we add the view to a temporary parent so that we can add items to
112  // myViewArea in the desired order
113  FXComposite* tmp = new FXComposite(this);
114  myView = new GNEViewNet(tmp, myViewArea,
115  *myParent, this, net,
116  myParent->getGLVisual(), share,
117  myNavigationToolBar);
118 
119  myView->buildViewToolBars(*this);
120 
121  // create
123 }
124 
125 
127  myParent->removeChild(this);
128 }
129 
130 
131 long
132 GNEViewParent::onCmdMakeSnapshot(FXObject*, FXSelector, void*) {
133  // get the new file name
134  FXFileDialog opendialog(this, "Save Snapshot");
135  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
136  opendialog.setSelectMode(SELECTFILE_ANY);
137  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"
138  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
139  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
140  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
141  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
142  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
143  "All Files (*)");
144  if (gCurrentFolder.length() != 0) {
145  opendialog.setDirectory(gCurrentFolder);
146  }
147  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
148  return 1;
149  }
150  gCurrentFolder = opendialog.getDirectory();
151  std::string file = opendialog.getFilename().text();
152  std::string error = myView->makeSnapshot(file);
153  if (error != "") {
154  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
155  }
156  return 1;
157 }
158 
159 
160 long
161 GNEViewParent::onCmdClose(FXObject*, FXSelector /* sel */, void*) {
162  myParent->handle(this, FXSEL(SEL_COMMAND, MID_CLOSE), 0);
163  return 1;
164 }
165 
166 
167 long
168 GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
169  GNEViewNet* view = dynamic_cast<GNEViewNet*>(myView);
170  assert(view);
171  GUIGlObjectType type;
172  GUIIcon icon;
173  std::string title;
174  switch (FXSELID(sel)) {
175  case MID_LOCATEJUNCTION:
176  type = GLO_JUNCTION;
177  icon = ICON_LOCATEJUNCTION;
178  title = "Junction Chooser";
179  break;
180  case MID_LOCATEEDGE:
181  type = GLO_EDGE;
182  icon = ICON_LOCATEEDGE;
183  title = "Edge Chooser";
184  break;
185  case MID_LOCATETLS:
186  type = GLO_TLLOGIC;
187  icon = ICON_LOCATETLS;
188  title = "Traffic-Light-Junctions Chooser";
189  break;
190  default:
191  throw ProcessError("Unknown Message ID in onCmdLocate");
192  }
193  std::set<GUIGlID> idSet = view->getNet()->getGlIDs(type);
194  std::vector<GUIGlID> ids(idSet.begin(), idSet.end());
195  myLocatorPopup->popdown();
196  myLocatorButton->killFocus();
197  myLocatorPopup->update();
199  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
200  chooser->create();
201  chooser->show();
202  return 1;
203 }
204 
205 
206 bool
208  GUIGlObjectType type = o->getType();
209  if (gSelected.isSelected(type, o->getGlID())) {
210  return true;
211  } else if (type == GLO_EDGE) {
212  GNEEdge* edge = dynamic_cast<GNEEdge*>(o);
213  assert(edge);
214  const std::set<GUIGlID> laneIDs = edge->getLaneGlIDs();
215  for (std::set<GUIGlID>::const_iterator it = laneIDs.begin(); it != laneIDs.end(); it++) {
216  if (gSelected.isSelected(GLO_LANE, *it)) {
217  return true;
218  }
219  }
220  return false;
221  } else {
222  return false;
223  }
224 }
225 
226 
227 long
228 GNEViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
229  myView->onKeyPress(o, sel, data);
230  return 0;
231 }
232 
233 
234 long
235 GNEViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
236  myView->onKeyRelease(o, sel, data);
237  return 0;
238 }
239 
240 /****************************************************************************/
241 
void show()
sets the focus after the window is created to work-around bug in libfox
Make snapshot - button.
Definition: GUIAppEnum.h:185
long onKeyPress(FXObject *o, FXSelector sel, void *data)
handle keys
~GNEViewParent()
Destructor.
GUIGlObjectType
The main window of the Netedit.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
Locate TLS - button.
Definition: GUIAppEnum.h:171
std::set< GUIGlID > getLaneGlIDs()
Definition: GNEEdge.cpp:391
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
Definition: GNENet.cpp:635
static FXbool userPermitsOverwritingWhenFileExists(FXWindow *const parent, const FXString &file)
Returns true if either the file given by its name does not exist or the user allows overwriting it...
Definition: MFXUtils.cpp:52
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:77
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
FXString gCurrentFolder
The folder used as last.
GNENet * getNet()
Definition: GNEViewNet.h:176
FXPopup * myLocatorPopup
The locator menu.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:123
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:65
GUIMainWindow * myParent
The parent window.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:167
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
Locate edge - button.
Definition: GUIAppEnum.h:165
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
FXDEFMAP(GNEViewParent) GNEViewParentMap[]
Locate junction - button.
Definition: GUIAppEnum.h:163
void removeChild(FXMDIChild *child)
removes the given child window from the list
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected) ...
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:61
long onCmdClose(FXObject *, FXSelector, void *)
Called when the user hits the close button (x)
FXMenuButton * myLocatorButton
an edge
GUISUMOAbstractView * myView
the view
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Definition: GNEViewNet.cpp:260
Close simulation - ID.
Definition: GUIAppEnum.h:83
virtual void create()
GUISelectedStorage gSelected
A global holder of selected objects.
static FXIcon * getIcon(GUIIcon which)
long onCmdMakeSnapshot(FXObject *sender, FXSelector, void *)
Called if the user wants to make a snapshot (screenshot)
a junction