SUMO - Simulation of Urban MObility
GNEViewParent.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A single child window which contains a view of the edited network (adapted
18 // from GUISUMOViewParent)
19 // While we don't actually need MDI for netedit it is easier to adapt existing
20 // structures than to write everything from scratch.
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <vector>
39 #include <utils/geom/Position.h>
40 #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 #include "GNEPolygonFrame.h"
67 
68 
69 // ===========================================================================
70 // FOX callback mapping
71 // ===========================================================================
72 FXDEFMAP(GNEViewParent) GNEViewParentMap[] = {
73  FXMAPFUNC(SEL_COMMAND, MID_MAKESNAPSHOT, GNEViewParent::onCmdMakeSnapshot),
74  //FXMAPFUNC(SEL_COMMAND, MID_ALLOWROTATION, GNEViewParent::onCmdAllowRotation),
75  FXMAPFUNC(SEL_COMMAND, MID_LOCATEJUNCTION, GNEViewParent::onCmdLocate),
76  FXMAPFUNC(SEL_COMMAND, MID_LOCATEEDGE, GNEViewParent::onCmdLocate),
77  FXMAPFUNC(SEL_COMMAND, MID_LOCATETLS, GNEViewParent::onCmdLocate),
78  FXMAPFUNC(SEL_COMMAND, MID_LOCATEADD, GNEViewParent::onCmdLocate),
79  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOI, GNEViewParent::onCmdLocate),
80  FXMAPFUNC(SEL_COMMAND, MID_LOCATEPOLY, GNEViewParent::onCmdLocate),
81  FXMAPFUNC(SEL_COMMAND, FXMDIChild::ID_MDI_MENUCLOSE, GNEViewParent::onCmdClose),
83 };
84 
85 // Object implementation
86 FXIMPLEMENT(GNEViewParent, GUIGlChildWindow, GNEViewParentMap, ARRAYNUMBER(GNEViewParentMap))
87 
88 // ===========================================================================
89 // member method definitions
90 // ===========================================================================
92  FXMDIClient* p, FXMDIMenu* mdimenu,
93  const FXString& name,
94  GNEApplicationWindow* parentWindow,
95  FXGLCanvas* share, GNENet* net, GNEUndoList* undoList,
96  FXIcon* ic, FXuint opts,
97  FXint x, FXint y, FXint w, FXint h):
98  GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h),
99  myGNEAppWindows(parentWindow) {
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_VIEWPARENT_FRAMEAREAWIDTH, 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_SETMODE_INSPECT] = new GNEInspectorFrame(myFramesArea, viewNet);
138  myGNEFrames[MID_GNE_SETMODE_SELECT] = new GNESelectorFrame(myFramesArea, viewNet);
139  myGNEFrames[MID_GNE_SETMODE_CONNECT] = new GNEConnectorFrame(myFramesArea, viewNet);
140  myGNEFrames[MID_GNE_SETMODE_TLS] = new GNETLSEditorFrame(myFramesArea, viewNet);
141  myGNEFrames[MID_GNE_SETMODE_ADDITIONAL] = new GNEAdditionalFrame(myFramesArea, viewNet);
142  myGNEFrames[MID_GNE_SETMODE_CROSSING] = new GNECrossingFrame(myFramesArea, viewNet);
143  myGNEFrames[MID_GNE_SETMODE_DELETE] = new GNEDeleteFrame(myFramesArea, viewNet);
144  myGNEFrames[MID_GNE_SETMODE_POLYGON] = new GNEPolygonFrame(myFramesArea, viewNet);
145 
146  // Update frame areas after creation
147  onCmdUpdateFrameAreaWidth(0, 0, 0);
148 
149  // Hidde all Frames Area
150  hideFramesArea();
151 
152  // Buld view toolBars
153  myView->buildViewToolBars(*this);
154 
155  // create windows
157 }
158 
159 
161  // Remove child before remove
162  myParent->removeChild(this);
163 }
164 
165 
166 void
168  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
169  i->second->hide();
170  }
171 }
172 
175  return dynamic_cast<GNEInspectorFrame*>(myGNEFrames.at(MID_GNE_SETMODE_INSPECT));
176 }
177 
178 
181  return dynamic_cast<GNESelectorFrame*>(myGNEFrames.at(MID_GNE_SETMODE_SELECT));
182 }
183 
184 
187  return dynamic_cast<GNEConnectorFrame*>(myGNEFrames.at(MID_GNE_SETMODE_CONNECT));
188 }
189 
190 
193  return dynamic_cast<GNETLSEditorFrame*>(myGNEFrames.at(MID_GNE_SETMODE_TLS));
194 }
195 
196 
199  return dynamic_cast<GNEAdditionalFrame*>(myGNEFrames.at(MID_GNE_SETMODE_ADDITIONAL));
200 }
201 
202 
205  return dynamic_cast<GNECrossingFrame*>(myGNEFrames.at(MID_GNE_SETMODE_CROSSING));
206 }
207 
208 
211  return dynamic_cast<GNEDeleteFrame*>(myGNEFrames.at(MID_GNE_SETMODE_DELETE));
212 }
213 
214 
217  return dynamic_cast<GNEPolygonFrame*>(myGNEFrames.at(MID_GNE_SETMODE_POLYGON));
218 }
219 
220 void
222  bool showFlag = false;
223  // Iterate over GNEFrames
224  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
225  // if at least one frame is shown, change showFlag
226  if (i->second->shown()) {
227  showFlag = true;
228  }
229  }
230  // show and recalc framesArea if showFlag is enabled
231  if (showFlag) {
232  myFramesArea->recalc();
233  myFramesArea->show();
234  }
235 }
236 
237 
238 void
240  bool hideFlag = true;
241  // Iterate over frames
242  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
243  // if at least one frame is shown, change hideflag
244  if (i->second->shown()) {
245  hideFlag = false;
246  }
247  }
248  // hide and recalc frames Area if hideFlag is enabled
249  if (hideFlag) {
250  myFramesArea->hide();
251  myFramesArea->recalc();
252  }
253 }
254 
255 
258  return myParent;
259 }
260 
261 
264  return myGNEAppWindows;
265 }
266 
267 
268 long
269 GNEViewParent::onCmdMakeSnapshot(FXObject*, FXSelector, void*) {
270  // get the new file name
271  FXFileDialog opendialog(this, "Save Snapshot");
272  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
273  opendialog.setSelectMode(SELECTFILE_ANY);
274  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"
275  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
276  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
277  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
278  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
279  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
280  "All Files (*)");
281  if (gCurrentFolder.length() != 0) {
282  opendialog.setDirectory(gCurrentFolder);
283  }
284  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
285  return 1;
286  }
287  gCurrentFolder = opendialog.getDirectory();
288  std::string file = opendialog.getFilename().text();
289  std::string error = myView->makeSnapshot(file);
290  if (error != "") {
291  // write warning if netedit is running in testing mode
292  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
293  WRITE_WARNING("Opening FXMessageBox 'error saving snapshot'");
294  }
295  // open message box
296  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
297  // write warning if netedit is running in testing mode
298  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
299  WRITE_WARNING("Closed FXMessageBox 'error saving snapshot' with 'OK'");
300  }
301  }
302  return 1;
303 }
304 
305 
306 long
307 GNEViewParent::onCmdClose(FXObject*, FXSelector /* sel */, void*) {
308  myParent->handle(this, FXSEL(SEL_COMMAND, MID_CLOSE), 0);
309  return 1;
310 }
311 
312 
313 long
314 GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
315  GNEViewNet* view = dynamic_cast<GNEViewNet*>(myView);
316  assert(view);
317  GUIGlObjectType type;
318  GUIIcon icon;
319  std::string dialogtitle;
320  switch (FXSELID(sel)) {
321  case MID_LOCATEJUNCTION:
322  type = GLO_JUNCTION;
323  icon = ICON_LOCATEJUNCTION;
324  dialogtitle = "Junction Chooser";
325  break;
326  case MID_LOCATEEDGE:
327  type = GLO_EDGE;
328  icon = ICON_LOCATEEDGE;
329  dialogtitle = "Edge Chooser";
330  break;
331  case MID_LOCATETLS:
332  type = GLO_TLLOGIC;
333  icon = ICON_LOCATETLS;
334  dialogtitle = "Traffic-Light-Junctions Chooser";
335  break;
336  case MID_LOCATEADD:
337  type = GLO_ADDITIONAL;
338  icon = ICON_LOCATEADD;
339  title = "Additional Objects Chooser";
340  break;
341  case MID_LOCATEPOI:
342  type = GLO_POI;
343  icon = ICON_LOCATEPOI;
344  title = "POI Chooser";
345  break;
346  case MID_LOCATEPOLY:
347  type = GLO_POLYGON;
348  icon = ICON_LOCATEPOLY;
349  title = "Polygon Chooser";
350  break;
351  default:
352  throw ProcessError("Unknown Message ID in onCmdLocate");
353  }
354  std::set<GUIGlID> idSet = view->getNet()->getGlIDs(type);
355  std::vector<GUIGlID> ids(idSet.begin(), idSet.end());
356  myLocatorPopup->popdown();
357  myLocatorButton->killFocus();
358  myLocatorPopup->update();
360  this, GUIIconSubSys::getIcon(icon), dialogtitle.c_str(), ids, GUIGlObjectStorage::gIDStorage);
361  chooser->create();
362  chooser->show();
363  return 1;
364 }
365 
366 
367 bool
369  GUIGlObjectType type = o->getType();
370  if (gSelected.isSelected(type, o->getGlID())) {
371  return true;
372  } else if (type == GLO_EDGE) {
373  GNEEdge* edge = dynamic_cast<GNEEdge*>(o);
374  assert(edge);
375  const std::set<GUIGlID> laneIDs = edge->getLaneGlIDs();
376  for (std::set<GUIGlID>::const_iterator it = laneIDs.begin(); it != laneIDs.end(); it++) {
377  if (gSelected.isSelected(GLO_LANE, *it)) {
378  return true;
379  }
380  }
381  return false;
382  } else {
383  return false;
384  }
385 }
386 
387 
388 long
389 GNEViewParent::onKeyPress(FXObject* o, FXSelector sel, void* eventData) {
390  myView->onKeyPress(o, sel, eventData);
391  return 0;
392 }
393 
394 
395 long
396 GNEViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* eventData) {
397  myView->onKeyRelease(o, sel, eventData);
398  return 0;
399 }
400 
401 
402 long
403 GNEViewParent::onCmdUpdateFrameAreaWidth(FXObject*, FXSelector, void*) {
404  for (auto i = myGNEFrames.begin(); i != myGNEFrames.end(); i++) {
405  // update size of all GNEFrame
406  i->second->setFrameWidth(myFramesArea->getWidth());
407  }
408  return 0;
409 }
410 
411 /****************************************************************************/
412 
void show()
sets the focus after the window is created to work-around bug in libfox
mode for selecting objects
Definition: GUIAppEnum.h:477
Locate poi - button.
Definition: GUIAppEnum.h:184
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
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
~GNEViewParent()
Destructor.
a polygon
mode for creating polygons
Definition: GUIAppEnum.h:487
GUIGlObjectType
The main window of the Netedit.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:42
#define GUIDesignVerticalSeparator
vertical separator
Definition: GUIDesigns.h:286
std::set< GUIGlID > getLaneGlIDs()
returns GLIDs of all lanes
Definition: GNEEdge.cpp:643
#define GUIDesignButtonToolbar
little button with icon placed in navigation toolbar
Definition: GUIDesigns.h:81
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
get ids of currently active objects
Definition: GNENet.cpp:1138
Locate junction - button.
Definition: GUIAppEnum.h:172
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:47
void showFramesArea()
show frames area if at least a GNEFrame is showed
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
#define GUIDesignSplitter
Definition: GUIDesigns.h:293
long onKeyRelease(FXObject *o, FXSelector sel, void *data)
Called when user releases a key.
mode for deleting things
Definition: GUIAppEnum.h:473
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:91
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:234
#define GUIDesignViewnArea
design for viewn area
Definition: GUIDesigns.h:237
GNEPolygonFrame * getPolygonFrame() const
get frame for GNE_MODE_POLYGON
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
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:64
GNEAdditionalFrame * getAdditionalFrame() const
get frame for GNE_MODE_ADDITIONAL
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 editing tls
Definition: GUIAppEnum.h:481
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
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
Locate polygons - button.
Definition: GUIAppEnum.h:186
mode for editing crossing
Definition: GUIAppEnum.h:485
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
FXHorizontalFrame * myFramesArea
frame to hold GNEFrames
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:56
long onCmdClose(FXObject *, FXSelector, void *)
Called when the user hits the close button (x)
compound additional
FXMenuButton * myLocatorButton
GUIMainWindow * getApp() const
get App (GUIMainWindow)
GNEConnectorFrame * getConnectorFrame() const
get frame for GNE_MODE_CONNECT
Locate addtional structure - button.
Definition: GUIAppEnum.h:182
an edge
GNECrossingFrame * getCrossingFrame() const
get frame for GNE_MODE_CROSSING
GUISUMOAbstractView * myView
the view
Size of frame area updated.
Definition: GUIAppEnum.h:495
GNEDeleteFrame * getDeleteFrame() const
get frame for GNE_MODE_DELETE
Close simulation - ID.
Definition: GUIAppEnum.h:84
GNENet * getNet() const
get the net object
Make snapshot - button.
Definition: GUIAppEnum.h:194
GUIGlID getGlID() const
Returns the numerical id of the object.
void hideAllFrames()
hide all frames
Locate edge - button.
Definition: GUIAppEnum.h:174
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Definition: GNEViewNet.cpp:220
Locate TLS - button.
Definition: GUIAppEnum.h:180
mode for connecting lanes
Definition: GUIAppEnum.h:479
mode for editing additional
Definition: GUIAppEnum.h:483
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 *)
mode for inspecting object attributes
Definition: GUIAppEnum.h:475
a junction