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 #include "GNEPolygonFrame.h"
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  myGNEAppWindows(parentWindow) {
98  // Add child to parent
99  myParent->addChild(this, false);
100 
101  // disable coloring and screenshot
102  //for (int i=5; i < myNavigationToolBar->numChildren(); i++) {
103  // myNavigationToolBar->childAtIndex(i)->hide();
104  //}
105 
106  // add undo/redo buttons
107  new FXButton(myNavigationToolBar, "\tUndo\tUndo the last Change.", GUIIconSubSys::getIcon(ICON_UNDO), parentWindow->getUndoList(), FXUndoList::ID_UNDO, GUIDesignButtonToolbar);
108  new FXButton(myNavigationToolBar, "\tRedo\tRedo the last Change.", GUIIconSubSys::getIcon(ICON_REDO), parentWindow->getUndoList(), FXUndoList::ID_REDO, GUIDesignButtonToolbar);
109 
110  // Create Vertical separator
111  new FXVerticalSeparator(myNavigationToolBar, GUIDesignVerticalSeparator);
112 
113  // Create Frame Splitter
114  myFramesSplitter = new FXSplitter(myContentFrame, this, MID_GNE_SIZEOF_FRAMEAREAWIDTH_UPDATED, GUIDesignSplitter | SPLITTER_HORIZONTAL);
115 
116  // Create frames Area
117  myFramesArea = new FXHorizontalFrame(myFramesSplitter, GUIDesignFrameArea);
118 
119  // Set default width of frames area
120  myFramesArea->setWidth(220);
121 
122  // Create view area
123  myViewArea = new FXHorizontalFrame(myFramesSplitter, GUIDesignViewnArea);
124 
125  // Add the view to a temporary parent so that we can add items to myViewArea in the desired order
126  FXComposite* tmp = new FXComposite(this);
127 
128  // Create view net
129  GNEViewNet* viewNet = new GNEViewNet(tmp, myViewArea, *myParent, this, net, undoList, myParent->getGLVisual(), share, myNavigationToolBar);
130 
131  // Set pointer myView with the created view net
132  myView = viewNet;
133 
134  // Create frames
135  myGNEFrames[MID_GNE_MODE_INSPECT] = new GNEInspectorFrame(myFramesArea, viewNet);
136  myGNEFrames[MID_GNE_MODE_SELECT] = new GNESelectorFrame(myFramesArea, viewNet);
137  myGNEFrames[MID_GNE_MODE_CONNECT] = new GNEConnectorFrame(myFramesArea, viewNet);
138  myGNEFrames[MID_GNE_MODE_TLS] = new GNETLSEditorFrame(myFramesArea, viewNet);
139  myGNEFrames[MID_GNE_MODE_ADDITIONAL] = new GNEAdditionalFrame(myFramesArea, viewNet);
140  myGNEFrames[MID_GNE_MODE_CROSSING] = new GNECrossingFrame(myFramesArea, viewNet);
141  myGNEFrames[MID_GNE_MODE_DELETE] = new GNEDeleteFrame(myFramesArea, viewNet);
142  myGNEFrames[MID_GNE_MODE_POLYGON] = new GNEPolygonFrame(myFramesArea, viewNet);
143 
144  // Update frame areas after creation
145  onCmdUpdateFrameAreaWidth(0, 0, 0);
146 
147  // Hidde all Frames Area
148  hideFramesArea();
149 
150  // Buld view toolBars
151  myView->buildViewToolBars(*this);
152 
153  // create windows
155 }
156 
157 
159  // Remove child before remove
160  myParent->removeChild(this);
161 }
162 
163 
164 void
166  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
167  i->second->hide();
168  }
169 }
170 
173  return dynamic_cast<GNEInspectorFrame*>(myGNEFrames.at(MID_GNE_MODE_INSPECT));
174 }
175 
176 
179  return dynamic_cast<GNESelectorFrame*>(myGNEFrames.at(MID_GNE_MODE_SELECT));
180 }
181 
182 
185  return dynamic_cast<GNEConnectorFrame*>(myGNEFrames.at(MID_GNE_MODE_CONNECT));
186 }
187 
188 
191  return dynamic_cast<GNETLSEditorFrame*>(myGNEFrames.at(MID_GNE_MODE_TLS));
192 }
193 
194 
197  return dynamic_cast<GNEAdditionalFrame*>(myGNEFrames.at(MID_GNE_MODE_ADDITIONAL));
198 }
199 
200 
203  return dynamic_cast<GNECrossingFrame*>(myGNEFrames.at(MID_GNE_MODE_CROSSING));
204 }
205 
206 
209  return dynamic_cast<GNEDeleteFrame*>(myGNEFrames.at(MID_GNE_MODE_DELETE));
210 }
211 
212 
215  return dynamic_cast<GNEPolygonFrame*>(myGNEFrames.at(MID_GNE_MODE_POLYGON));
216 }
217 
218 void
220  bool showFlag = false;
221  // Iterate over GNEFrames
222  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
223  // if at least one frame is shown, change showFlag
224  if (i->second->shown()) {
225  showFlag = true;
226  }
227  }
228  // show and recalc framesArea if showFlag is enabled
229  if (showFlag) {
230  myFramesArea->recalc();
231  myFramesArea->show();
232  }
233 }
234 
235 
236 void
238  bool hideFlag = true;
239  // Iterate over frames
240  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
241  // if at least one frame is shown, change hideflag
242  if (i->second->shown()) {
243  hideFlag = false;
244  }
245  }
246  // hide and recalc frames Area if hideFlag is enabled
247  if (hideFlag) {
248  myFramesArea->hide();
249  myFramesArea->recalc();
250  }
251 }
252 
253 
256  return myParent;
257 }
258 
259 
262  return myGNEAppWindows;
263 }
264 
265 
266 long
267 GNEViewParent::onCmdMakeSnapshot(FXObject*, FXSelector, void*) {
268  // get the new file name
269  FXFileDialog opendialog(this, "Save Snapshot");
270  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
271  opendialog.setSelectMode(SELECTFILE_ANY);
272  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"
273  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
274  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
275  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
276  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
277  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
278  "All Files (*)");
279  if (gCurrentFolder.length() != 0) {
280  opendialog.setDirectory(gCurrentFolder);
281  }
282  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
283  return 1;
284  }
285  gCurrentFolder = opendialog.getDirectory();
286  std::string file = opendialog.getFilename().text();
287  std::string error = myView->makeSnapshot(file);
288  if (error != "") {
289  // write warning if netedit is running in testing mode
290  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
291  WRITE_WARNING("Opening FXMessageBox 'error saving snapshot'");
292  }
293  // open message box
294  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
295  // write warning if netedit is running in testing mode
296  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
297  WRITE_WARNING("Closed FXMessageBox 'error saving snapshot' with 'OK'");
298  }
299  }
300  return 1;
301 }
302 
303 
304 long
305 GNEViewParent::onCmdClose(FXObject*, FXSelector /* sel */, void*) {
306  myParent->handle(this, FXSEL(SEL_COMMAND, MID_CLOSE), 0);
307  return 1;
308 }
309 
310 
311 long
312 GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
313  GNEViewNet* view = dynamic_cast<GNEViewNet*>(myView);
314  assert(view);
315  GUIGlObjectType type;
316  GUIIcon icon;
317  std::string dialogtitle;
318  switch (FXSELID(sel)) {
319  case MID_LOCATEJUNCTION:
320  type = GLO_JUNCTION;
321  icon = ICON_LOCATEJUNCTION;
322  dialogtitle = "Junction Chooser";
323  break;
324  case MID_LOCATEEDGE:
325  type = GLO_EDGE;
326  icon = ICON_LOCATEEDGE;
327  dialogtitle = "Edge Chooser";
328  break;
329  case MID_LOCATETLS:
330  type = GLO_TLLOGIC;
331  icon = ICON_LOCATETLS;
332  dialogtitle = "Traffic-Light-Junctions Chooser";
333  break;
334  default:
335  throw ProcessError("Unknown Message ID in onCmdLocate");
336  }
337  std::set<GUIGlID> idSet = view->getNet()->getGlIDs(type);
338  std::vector<GUIGlID> ids(idSet.begin(), idSet.end());
339  myLocatorPopup->popdown();
340  myLocatorButton->killFocus();
341  myLocatorPopup->update();
343  this, GUIIconSubSys::getIcon(icon), dialogtitle.c_str(), ids, GUIGlObjectStorage::gIDStorage);
344  chooser->create();
345  chooser->show();
346  return 1;
347 }
348 
349 
350 bool
352  GUIGlObjectType type = o->getType();
353  if (gSelected.isSelected(type, o->getGlID())) {
354  return true;
355  } else if (type == GLO_EDGE) {
356  GNEEdge* edge = dynamic_cast<GNEEdge*>(o);
357  assert(edge);
358  const std::set<GUIGlID> laneIDs = edge->getLaneGlIDs();
359  for (std::set<GUIGlID>::const_iterator it = laneIDs.begin(); it != laneIDs.end(); it++) {
360  if (gSelected.isSelected(GLO_LANE, *it)) {
361  return true;
362  }
363  }
364  return false;
365  } else {
366  return false;
367  }
368 }
369 
370 
371 long
372 GNEViewParent::onKeyPress(FXObject* o, FXSelector sel, void* eventData) {
373  myView->onKeyPress(o, sel, eventData);
374  return 0;
375 }
376 
377 
378 long
379 GNEViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* eventData) {
380  myView->onKeyRelease(o, sel, eventData);
381  return 0;
382 }
383 
384 
385 long
386 GNEViewParent::onCmdUpdateFrameAreaWidth(FXObject*, FXSelector, void*) {
387  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
388  // update size of all GNEFrame
389  i->second->setFrameWidth(myFramesArea->getWidth());
390  }
391  return 0;
392 }
393 
394 /****************************************************************************/
395 
void show()
sets the focus after the window is created to work-around bug in libfox
Make snapshot - button.
Definition: GUIAppEnum.h:199
GNEApplicationWindow * myGNEAppWindows
pointer to GNEApplicationWindow
long onKeyPress(FXObject *o, FXSelector sel, void *data)
Called when user press a key.
void hideFramesArea()
hide frames area if all GNEFrames are hidden
mode for inspecting object attributes
Definition: GUIAppEnum.h:442
~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
Locate TLS - button.
Definition: GUIAppEnum.h:181
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:284
std::set< GUIGlID > getLaneGlIDs()
returns GLIDs of all lanes
Definition: GNEEdge.cpp:589
#define GUIDesignButtonToolbar
little button with icon placed in navigation toolbar
Definition: GUIDesigns.h:82
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
get ids of currently active objects
Definition: GNENet.cpp:1070
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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
GNEAdditionalFrame * getAdditionalFrame() const
get frame for GNE_MODE_ADDITIONAL
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:92
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:232
#define GUIDesignViewnArea
design for viewn area
Definition: GUIDesigns.h:235
GUIGlID getGlID() const
Returns the numerical id of the object.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:73
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
GUIMainWindow * myParent
The parent window.
mode for editing additional
Definition: GUIAppEnum.h:450
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
mode for creating polygons
Definition: GUIAppEnum.h:454
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.
Locate edge - button.
Definition: GUIAppEnum.h:175
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
Locate junction - button.
Definition: GUIAppEnum.h:173
mode for selecting objects
Definition: GUIAppEnum.h:444
void removeChild(FXMDIChild *child)
removes the given child window from the list
mode for editing crossing
Definition: GUIAppEnum.h:452
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.
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected) ...
Size of frame area updated.
Definition: GUIAppEnum.h:706
FXHorizontalFrame * myFramesArea
frame to hold GNEFrames
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:58
long onCmdClose(FXObject *, FXSelector, void *)
Called when the user hits the close button (x)
FXMenuButton * myLocatorButton
mode for editing tls
Definition: GUIAppEnum.h:448
GUIMainWindow * getApp() const
get App (GUIMainWindow)
an edge
GUISUMOAbstractView * myView
the view
GNENet * getNet() const
get the net object
mode for deleting things
Definition: GUIAppEnum.h:440
void hideAllFrames()
hide all frames
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Definition: GNEViewNet.cpp:206
Close simulation - ID.
Definition: GUIAppEnum.h:85
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
GNETLSEditorFrame * getTLSEditorFrame() const
get frame for GNE_MODE_TLS
virtual void create()
GUISelectedStorage gSelected
A global holder of selected objects.
GNEPolygonFrame * getPolygonFrame() const
get frame for GNE_MODE_POLYGON
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
mode for connecting lanes
Definition: GUIAppEnum.h:446
long onCmdMakeSnapshot(FXObject *sender, FXSelector, void *)
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_MODE_SELECT
a junction