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