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-2017 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>
52 
53 #include "GNENet.h"
54 #include "GNEEdge.h"
55 #include "GNEViewNet.h"
56 #include "GNEViewParent.h"
57 #include "GNEUndoList.h"
58 #include "GNEApplicationWindow.h"
59 #include "GNEInspectorFrame.h"
60 #include "GNESelectorFrame.h"
61 #include "GNEConnectorFrame.h"
62 #include "GNETLSEditorFrame.h"
63 #include "GNEAdditionalFrame.h"
64 #include "GNECrossingFrame.h"
65 #include "GNEDeleteFrame.h"
66 
67 
68 #ifdef CHECK_MEMORY_LEAKS
69 #include <foreign/nvwa/debug_new.h>
70 #endif // CHECK_MEMORY_LEAKS
71 
72 
73 // ===========================================================================
74 // FOX callback mapping
75 // ===========================================================================
76 FXDEFMAP(GNEViewParent) GNEViewParentMap[] = {
77  FXMAPFUNC(SEL_COMMAND, MID_MAKESNAPSHOT, GNEViewParent::onCmdMakeSnapshot),
78  //FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GNEViewParent::onCmdAllowRotation),
79  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GNEViewParent::onCmdLocate),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GNEViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GNEViewParent::onCmdLocate),
82  FXMAPFUNC(SEL_COMMAND, FXMDIChild::ID_MDI_MENUCLOSE, GNEViewParent::onCmdClose),
84 };
85 
86 // Object implementation
87 FXIMPLEMENT(GNEViewParent, GUIGlChildWindow, GNEViewParentMap, ARRAYNUMBER(GNEViewParentMap))
88 
89 // ===========================================================================
90 // member method definitions
91 // ===========================================================================
93  FXMDIClient* p, FXMDIMenu* mdimenu,
94  const FXString& name,
95  GNEApplicationWindow* parentWindow,
96  FXGLCanvas* share, GNENet* net, GNEUndoList* undoList,
97  FXIcon* ic, FXuint opts,
98  FXint x, FXint y, FXint w, FXint h):
99  GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
100  // Add child to parent
101  myParent->addChild(this, false);
102 
103  // disable coloring and screenshot
104  //for (int i=5; i < myNavigationToolBar->numChildren(); i++) {
105  // myNavigationToolBar->childAtIndex(i)->hide();
106  //}
107 
108  // add undo/redo buttons
109  new FXButton(myNavigationToolBar, "\tUndo\tUndo the last Change.", GUIIconSubSys::getIcon(ICON_UNDO), parentWindow->getUndoList(), FXUndoList::ID_UNDO, GUIDesignButtonToolbar);
110  new FXButton(myNavigationToolBar, "\tRedo\tRedo the last Change.", GUIIconSubSys::getIcon(ICON_REDO), parentWindow->getUndoList(), FXUndoList::ID_REDO, GUIDesignButtonToolbar);
111 
112  // Create Vertical separator
113  new FXVerticalSeparator(myNavigationToolBar, GUIDesignVerticalSeparator);
114 
115  // Create Frame Splitter
116  myFramesSplitter = new FXSplitter(myContentFrame, this, MID_GNE_SIZEOF_FRAMEAREAWIDTH_UPDATED, GUIDesignSplitter | SPLITTER_HORIZONTAL);
117 
118  // Create frames Area
119  myFramesArea = new FXHorizontalFrame(myFramesSplitter, GUIDesignFrameArea);
120 
121  // Set default width of frames area
122  myFramesArea->setWidth(220);
123 
124  // Create view area
125  myViewArea = new FXHorizontalFrame(myFramesSplitter, GUIDesignViewnArea);
126 
127  // Add the view to a temporary parent so that we can add items to myViewArea in the desired order
128  FXComposite* tmp = new FXComposite(this);
129 
130  // Create view net
131  GNEViewNet* viewNet = new GNEViewNet(tmp, myViewArea, *myParent, this, net, undoList, myParent->getGLVisual(), share, myNavigationToolBar);
132 
133  // Set pointer myView with the created view net
134  myView = viewNet;
135 
136  // Create frames
137  myGNEFrames[MID_GNE_MODE_INSPECT] = new GNEInspectorFrame(myFramesArea, viewNet);
138  myGNEFrames[MID_GNE_MODE_SELECT] = new GNESelectorFrame(myFramesArea, viewNet);
139  myGNEFrames[MID_GNE_MODE_CONNECT] = new GNEConnectorFrame(myFramesArea, viewNet);
140  myGNEFrames[MID_GNE_MODE_TLS] = new GNETLSEditorFrame(myFramesArea, viewNet);
141  myGNEFrames[MID_GNE_MODE_ADDITIONAL] = new GNEAdditionalFrame(myFramesArea, viewNet);
142  myGNEFrames[MID_GNE_MODE_CROSSING] = new GNECrossingFrame(myFramesArea, viewNet);
143  myGNEFrames[MID_GNE_MODE_DELETE] = new GNEDeleteFrame(myFramesArea, viewNet);
144 
145  // Update frame areas after creation
146  onCmdUpdateFrameAreaWidth(0, 0, 0);
147 
148  // Hidde all Frames Area
149  hideFramesArea();
150 
151  // Buld view toolBars
152  myView->buildViewToolBars(*this);
153 
154  // create windows
156 }
157 
158 
160  // Remove child before remove
161  myParent->removeChild(this);
162 }
163 
164 
165 void
167  for (std::map<int, GNEFrame*>::iterator i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
168  i->second->hide();
169  }
170 }
171 
174  return dynamic_cast<GNEInspectorFrame*>(myGNEFrames.at(MID_GNE_MODE_INSPECT));
175 }
176 
177 
180  return dynamic_cast<GNESelectorFrame*>(myGNEFrames.at(MID_GNE_MODE_SELECT));
181 }
182 
183 
186  return dynamic_cast<GNEConnectorFrame*>(myGNEFrames.at(MID_GNE_MODE_CONNECT));
187 }
188 
189 
192  return dynamic_cast<GNETLSEditorFrame*>(myGNEFrames.at(MID_GNE_MODE_TLS));
193 }
194 
195 
198  return dynamic_cast<GNEAdditionalFrame*>(myGNEFrames.at(MID_GNE_MODE_ADDITIONAL));
199 }
200 
201 
204  return dynamic_cast<GNECrossingFrame*>(myGNEFrames.at(MID_GNE_MODE_CROSSING));
205 }
206 
207 
210  return dynamic_cast<GNEDeleteFrame*>(myGNEFrames.at(MID_GNE_MODE_DELETE));
211 }
212 
213 
214 void
216  bool showFlag = false;
217  // Iterate over GNEFrames
218  for (std::map<int, GNEFrame*>::iterator i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
219  // if at least one frame is shown, change showFlag
220  if (i->second->shown() == true) {
221  showFlag = true;
222  }
223  }
224  // show and recalc framesArea if showFlag is enabled
225  if (showFlag) {
226  myFramesArea->recalc();
227  myFramesArea->show();
228  }
229 }
230 
231 
232 void
234  bool hideFlag = true;
235  // Iterate over frames
236  for (std::map<int, GNEFrame*>::iterator i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
237  // if at least one frame is shown, change hideflag
238  if (i->second->shown() == true) {
239  hideFlag = false;
240  }
241  }
242  // hide and recalc frames Area if hideFlag is enabled
243  if (hideFlag) {
244  myFramesArea->hide();
245  myFramesArea->recalc();
246  }
247 }
248 
249 
252  return myParent;
253 }
254 
255 
256 long
257 GNEViewParent::onCmdMakeSnapshot(FXObject*, FXSelector, void*) {
258  // get the new file name
259  FXFileDialog opendialog(this, "Save Snapshot");
260  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
261  opendialog.setSelectMode(SELECTFILE_ANY);
262  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"
263  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
264  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
265  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
266  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
267  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
268  "All Files (*)");
269  if (gCurrentFolder.length() != 0) {
270  opendialog.setDirectory(gCurrentFolder);
271  }
272  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
273  return 1;
274  }
275  gCurrentFolder = opendialog.getDirectory();
276  std::string file = opendialog.getFilename().text();
277  std::string error = myView->makeSnapshot(file);
278  if (error != "") {
279  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
280  }
281  return 1;
282 }
283 
284 
285 long
286 GNEViewParent::onCmdClose(FXObject*, FXSelector /* sel */, void*) {
287  myParent->handle(this, FXSEL(SEL_COMMAND, MID_CLOSE), 0);
288  return 1;
289 }
290 
291 
292 long
293 GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
294  GNEViewNet* view = dynamic_cast<GNEViewNet*>(myView);
295  assert(view);
296  GUIGlObjectType type;
297  GUIIcon icon;
298  std::string title;
299  switch (FXSELID(sel)) {
300  case MID_LOCATEJUNCTION:
301  type = GLO_JUNCTION;
302  icon = ICON_LOCATEJUNCTION;
303  title = "Junction Chooser";
304  break;
305  case MID_LOCATEEDGE:
306  type = GLO_EDGE;
307  icon = ICON_LOCATEEDGE;
308  title = "Edge Chooser";
309  break;
310  case MID_LOCATETLS:
311  type = GLO_TLLOGIC;
312  icon = ICON_LOCATETLS;
313  title = "Traffic-Light-Junctions Chooser";
314  break;
315  default:
316  throw ProcessError("Unknown Message ID in onCmdLocate");
317  }
318  std::set<GUIGlID> idSet = view->getNet()->getGlIDs(type);
319  std::vector<GUIGlID> ids(idSet.begin(), idSet.end());
320  myLocatorPopup->popdown();
321  myLocatorButton->killFocus();
322  myLocatorPopup->update();
324  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
325  chooser->create();
326  chooser->show();
327  return 1;
328 }
329 
330 
331 bool
333  GUIGlObjectType type = o->getType();
334  if (gSelected.isSelected(type, o->getGlID())) {
335  return true;
336  } else if (type == GLO_EDGE) {
337  GNEEdge* edge = dynamic_cast<GNEEdge*>(o);
338  assert(edge);
339  const std::set<GUIGlID> laneIDs = edge->getLaneGlIDs();
340  for (std::set<GUIGlID>::const_iterator it = laneIDs.begin(); it != laneIDs.end(); it++) {
341  if (gSelected.isSelected(GLO_LANE, *it)) {
342  return true;
343  }
344  }
345  return false;
346  } else {
347  return false;
348  }
349 }
350 
351 
352 long
353 GNEViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
354  myView->onKeyPress(o, sel, data);
355  return 0;
356 }
357 
358 
359 long
360 GNEViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
361  myView->onKeyRelease(o, sel, data);
362  return 0;
363 }
364 
365 
366 long
367 GNEViewParent::onCmdUpdateFrameAreaWidth(FXObject*, FXSelector, void*) {
368  for (std::map<int, GNEFrame*>::iterator i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
369  // update size of all GNEFrame
370  i->second->setFrameWidth(myFramesArea->getWidth());
371  }
372  return 0;
373 }
374 
375 /****************************************************************************/
376 
void show()
sets the focus after the window is created to work-around bug in libfox
long onKeyPress(FXObject *o, FXSelector sel, void *data)
Called when user press a key.
void hideFramesArea()
hide frames area if all GNEFrames are hidden
~GNEViewParent()
Destructor.
GUIGlObjectType
GNEDeleteFrame * getDeleteFrame() const
get frame for GNE_MODE_DELETE
The main window of the Netedit.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:269
std::set< GUIGlID > getLaneGlIDs()
returns GLIDs of all lanes
Definition: GNEEdge.cpp:469
#define GUIDesignButtonToolbar
little button with icon placed in navigation toolbar
Definition: GUIDesigns.h:89
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
Definition: GNENet.cpp:864
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
void showFramesArea()
show frames area if at least a GNEFrame is showed
GNEAdditionalFrame * getAdditionalFrame() const
get frame for GNE_MODE_ADDITIONAL
Locate TLS - button.
Definition: GUIAppEnum.h:181
mode for editing crossing
Definition: GUIAppEnum.h:450
Make snapshot - button.
Definition: GUIAppEnum.h:199
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
#define GUIDesignSplitter
Definition: GUIDesigns.h:276
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
Called when user releases a key.
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:87
mode for editing tls
Definition: GUIAppEnum.h:446
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
FXString gCurrentFolder
The folder used as last.
FXPopup * myLocatorPopup
The locator menu.
#define GUIDesignFrameArea
Definition: GUIDesigns.h:214
Close simulation - ID.
Definition: GUIAppEnum.h:85
#define GUIDesignViewnArea
design for viewn area
Definition: GUIDesigns.h:217
Locate junction - button.
Definition: GUIAppEnum.h:173
GUIGlID getGlID() const
Returns the numerical id of the object.
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:72
GUIMainWindow * myParent
The parent window.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
keyboard functions
long onCmdUpdateFrameAreaWidth(FXObject *, FXSelector, void *)
Called when user change the splitter between FrameArea and ViewNet.
mode for inspecting object attributes
Definition: GUIAppEnum.h:440
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
std::map< int, GNEFrame * > myGNEFrames
map with the Frames
FXDEFMAP(GNEViewParent) GNEViewParentMap[]
GNECrossingFrame * getCrossingFrame() const
get frame for GNE_MODE_CROSSING
void removeChild(FXMDIChild *child)
removes the given child window from the list
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
GNEConnectorFrame * getConnectorFrame() const
get frame for GNE_MODE_CONNECT
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
mode for connecting lanes
Definition: GUIAppEnum.h:444
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected) ...
FXHorizontalFrame * myFramesArea
frame to hold GNEFrames
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
long onCmdClose(FXObject *, FXSelector, void *)
Called when the user hits the close button (x)
mode for editing additional
Definition: GUIAppEnum.h:448
FXMenuButton * myLocatorButton
GUIMainWindow * getApp() const
get App (GUIMainWindow)
mode for selecting objects
Definition: GUIAppEnum.h:442
an edge
GUISUMOAbstractView * myView
the view
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:989
mode for deleting things
Definition: GUIAppEnum.h:438
void hideAllFrames()
hide all frames
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Definition: GNEViewNet.cpp:295
Locate edge - button.
Definition: GUIAppEnum.h:175
GNETLSEditorFrame * getTLSEditorFrame() const
get frame for GNE_MODE_TLS
virtual void create()
Size of frame area updated.
Definition: GUIAppEnum.h:661
GUISelectedStorage gSelected
A global holder of selected objects.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
long onCmdMakeSnapshot(FXObject *sender, FXSelector, void *)
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_MODE_SELECT
a junction