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-2016 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 #include "GNEInspectorFrame.h"
59 #include "GNESelectorFrame.h"
60 #include "GNEConnectorFrame.h"
61 #include "GNETLSEditorFrame.h"
62 #include "GNEAdditionalFrame.h"
63 
64 #ifdef CHECK_MEMORY_LEAKS
65 #include <foreign/nvwa/debug_new.h>
66 #endif // CHECK_MEMORY_LEAKS
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, FXMDIChild::ID_MDI_MENUCLOSE, GNEViewParent::onCmdClose),
79 };
80 
81 // Object implementation
82 FXIMPLEMENT(GNEViewParent, GUIGlChildWindow, GNEViewParentMap, ARRAYNUMBER(GNEViewParentMap))
83 
84 // ===========================================================================
85 // member method definitions
86 // ===========================================================================
88  FXMDIClient* p, FXMDIMenu* mdimenu,
89  const FXString& name,
90  GNEApplicationWindow* parentWindow,
91  FXGLCanvas* share, GNENet* net, GNEUndoList* undoList,
92  FXIcon* ic, FXuint opts,
93  FXint x, FXint y, FXint w, FXint h):
94  GUIGlChildWindow(p, parentWindow, mdimenu, name, ic, opts, x, y, w, h) {
95  // Add child to parent
96  myParent->addChild(this, false);
97 
98  // disable coloring and screenshot
99  //for (int i=5; i < myNavigationToolBar->numChildren(); i++) {
100  // myNavigationToolBar->childAtIndex(i)->hide();
101  //}
102 
103  // add undo/redo buttons
104  new FXButton(myNavigationToolBar,
105  "\tUndo\tUndo the last Change.",
106  GUIIconSubSys::getIcon(ICON_UNDO), parentWindow->getUndoList(), FXUndoList::ID_UNDO,
107  ICON_BEFORE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
108  new FXButton(myNavigationToolBar,
109  "\tRedo\tRedo the last Change.",
110  GUIIconSubSys::getIcon(ICON_REDO), parentWindow->getUndoList(), FXUndoList::ID_REDO,
111  ICON_BEFORE_TEXT | BUTTON_TOOLBAR | FRAME_RAISED | LAYOUT_TOP | LAYOUT_LEFT);
112 
113  // Create FXToolBarGrip
114  new FXToolBarGrip(myNavigationToolBar, NULL, 0, TOOLBARGRIP_SINGLE | FRAME_SUNKEN);
115 
116  // Create Frame Splitter
117  myFramesSplitter = new FXSplitter(myContentFrame, SPLITTER_HORIZONTAL | LAYOUT_FILL_X | LAYOUT_FILL_Y | SPLITTER_TRACKING | FRAME_RAISED | FRAME_THICK);
118 
119  // Create frames Area
120  myFramesArea = new FXHorizontalFrame(myFramesSplitter, FRAME_SUNKEN | LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
121 
122  // Set default width
123  myFramesArea->setWidth(200);
124 
125  // Create view area
126  myViewArea = new FXHorizontalFrame(myFramesSplitter, FRAME_SUNKEN | LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
127 
128  // Add the view to a temporary parent so that we can add items to myViewArea in the desired order
129  FXComposite* tmp = new FXComposite(this);
130 
131  // Create view net
132  GNEViewNet* viewNet = new GNEViewNet(tmp, myViewArea, *myParent, this, net, undoList, myParent->getGLVisual(), share, myNavigationToolBar);
133 
134  // Set pointer myView with the created view net
135  myView = viewNet;
136 
137  // creating order is important
138  myInspectorFrame = new GNEInspectorFrame(myFramesArea, viewNet);
139  mySelectorFrame = new GNESelectorFrame(myFramesArea, viewNet);
140  myConnectorFrame = new GNEConnectorFrame(myFramesArea, viewNet);
141  myTLSEditorFrame = new GNETLSEditorFrame(myFramesArea, viewNet);
142  myAdditionalFrame = new GNEAdditionalFrame(myFramesArea, viewNet);
143  myAdditionalFrame->hide();
144 
145  // Buld view toolBars
146  myView->buildViewToolBars(*this);
147 
148  // create windows
150 }
151 
152 
154  // Remove child before remove
155  myParent->removeChild(this);
156 }
157 
158 
159 
162  return myInspectorFrame;
163 }
164 
165 
168  return mySelectorFrame;
169 }
170 
171 
174  return myConnectorFrame;
175 }
176 
177 
180  return myTLSEditorFrame;
181 }
182 
183 
186  return myAdditionalFrame;
187 }
188 
189 
190 void
192  if (myInspectorFrame->shown() == true ||
193  mySelectorFrame->shown() == true ||
194  myConnectorFrame->shown() == true ||
195  myTLSEditorFrame->shown() == true ||
196  myAdditionalFrame->shown() == true) {
197  myFramesArea->show();
198  myFramesArea->recalc();
199  }
200 }
201 
202 
203 void
205  if (myInspectorFrame->shown() == false &&
206  mySelectorFrame->shown() == false &&
207  myConnectorFrame->shown() == false &&
208  myTLSEditorFrame->shown() == false &&
209  myAdditionalFrame->shown() == false) {
210  myFramesArea->hide();
211  myFramesArea->recalc();
212  }
213 }
214 
215 
216 int
218  std::cout << myFramesArea->getWidth() << std::endl;
219  return myFramesArea->getWidth();
220 }
221 
222 
223 long
224 GNEViewParent::onCmdMakeSnapshot(FXObject*, FXSelector, void*) {
225  // get the new file name
226  FXFileDialog opendialog(this, "Save Snapshot");
227  opendialog.setIcon(GUIIconSubSys::getIcon(ICON_EMPTY));
228  opendialog.setSelectMode(SELECTFILE_ANY);
229  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"
230  "GIF Image (*.gif)\nBMP Image (*.bmp)\nXPM Image (*.xpm)\nPCX Image (*.pcx)\nICO Image (*.ico)\n"
231  "RGB Image (*.rgb)\nXBM Image (*.xbm)\nTARGA Image (*.tga)\nPNG Image (*.png)\n"
232  "JPEG Image (*.jpg, *.jpeg)\nTIFF Image (*.tif, *.tiff)\n"
233  "Postscript (*.ps)\nEncapsulated Postscript (*.eps)\nPortable Document Format (*.pdf)\n"
234  "Scalable Vector Graphics (*.svg)\nLATEX text strings (*.tex)\nPortable LaTeX Graphics (*.pgf)\n"
235  "All Files (*)");
236  if (gCurrentFolder.length() != 0) {
237  opendialog.setDirectory(gCurrentFolder);
238  }
239  if (!opendialog.execute() || !MFXUtils::userPermitsOverwritingWhenFileExists(this, opendialog.getFilename())) {
240  return 1;
241  }
242  gCurrentFolder = opendialog.getDirectory();
243  std::string file = opendialog.getFilename().text();
244  std::string error = myView->makeSnapshot(file);
245  if (error != "") {
246  FXMessageBox::error(this, MBOX_OK, "Saving failed.", "%s", error.c_str());
247  }
248  return 1;
249 }
250 
251 
252 long
253 GNEViewParent::onCmdClose(FXObject*, FXSelector /* sel */, void*) {
254  myParent->handle(this, FXSEL(SEL_COMMAND, MID_CLOSE), 0);
255  return 1;
256 }
257 
258 
259 long
260 GNEViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
261  GNEViewNet* view = dynamic_cast<GNEViewNet*>(myView);
262  assert(view);
263  GUIGlObjectType type;
264  GUIIcon icon;
265  std::string title;
266  switch (FXSELID(sel)) {
267  case MID_LOCATEJUNCTION:
268  type = GLO_JUNCTION;
269  icon = ICON_LOCATEJUNCTION;
270  title = "Junction Chooser";
271  break;
272  case MID_LOCATEEDGE:
273  type = GLO_EDGE;
274  icon = ICON_LOCATEEDGE;
275  title = "Edge Chooser";
276  break;
277  case MID_LOCATETLS:
278  type = GLO_TLLOGIC;
279  icon = ICON_LOCATETLS;
280  title = "Traffic-Light-Junctions Chooser";
281  break;
282  default:
283  throw ProcessError("Unknown Message ID in onCmdLocate");
284  }
285  std::set<GUIGlID> idSet = view->getNet()->getGlIDs(type);
286  std::vector<GUIGlID> ids(idSet.begin(), idSet.end());
287  myLocatorPopup->popdown();
288  myLocatorButton->killFocus();
289  myLocatorPopup->update();
291  this, GUIIconSubSys::getIcon(icon), title.c_str(), ids, GUIGlObjectStorage::gIDStorage);
292  chooser->create();
293  chooser->show();
294  return 1;
295 }
296 
297 
298 bool
300  GUIGlObjectType type = o->getType();
301  if (gSelected.isSelected(type, o->getGlID())) {
302  return true;
303  } else if (type == GLO_EDGE) {
304  GNEEdge* edge = dynamic_cast<GNEEdge*>(o);
305  assert(edge);
306  const std::set<GUIGlID> laneIDs = edge->getLaneGlIDs();
307  for (std::set<GUIGlID>::const_iterator it = laneIDs.begin(); it != laneIDs.end(); it++) {
308  if (gSelected.isSelected(GLO_LANE, *it)) {
309  return true;
310  }
311  }
312  return false;
313  } else {
314  return false;
315  }
316 }
317 
318 
319 long
320 GNEViewParent::onKeyPress(FXObject* o, FXSelector sel, void* data) {
321  myView->onKeyPress(o, sel, data);
322  return 0;
323 }
324 
325 
326 long
327 GNEViewParent::onKeyRelease(FXObject* o, FXSelector sel, void* data) {
328  myView->onKeyRelease(o, sel, data);
329  return 0;
330 }
331 
332 /****************************************************************************/
333 
GNESelectorFrame * mySelectorFrame
the panel for GNE_MODE_SELECT
void show()
sets the focus after the window is created to work-around bug in libfox
Make snapshot - button.
Definition: GUIAppEnum.h:197
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
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
The main window of the Netedit.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
int getFramesAreaWidth()
get width of the Frames Area
Locate TLS - button.
Definition: GUIAppEnum.h:179
std::set< GUIGlID > getLaneGlIDs()
returns GLIDs of all lanes
Definition: GNEEdge.cpp:475
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
Definition: GNENet.cpp:838
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
GNETLSEditorFrame * myTLSEditorFrame
the panel for GNE_MODE_TLS
long onCmdLocate(FXObject *, FXSelector, void *)
locator-callback
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
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
FXString gCurrentFolder
The folder used as last.
FXPopup * myLocatorPopup
The locator menu.
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:69
GNETLSEditorFrame * getTLSEditorFrame() const
get frame for GNE_MODE_TLS
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
Locate edge - button.
Definition: GUIAppEnum.h:173
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
FXDEFMAP(GNEViewParent) GNEViewParentMap[]
bool isSelected(GUIGlObject *o) const
true if the object is selected (may include extra logic besides calling gSelected) ...
Locate junction - button.
Definition: GUIAppEnum.h:171
void removeChild(FXMDIChild *child)
removes the given child window from the list
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_MODE_SELECT
GNEAdditionalFrame * myAdditionalFrame
the panel for GNE_MODE_ADDITIONAL
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:55
long onCmdClose(FXObject *, FXSelector, void *)
Called when the user hits the close button (x)
FXMenuButton * myLocatorButton
GNEConnectorFrame * getConnectorFrame() const
get frame for GNE_MODE_CONNECT
an edge
GNEConnectorFrame * myConnectorFrame
the panel for GNE_MODE_CONNECT
GUISUMOAbstractView * myView
the view
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:912
GUIGlID getGlID() const
Returns the numerical id of the object.
virtual void buildViewToolBars(GUIGlChildWindow &)
builds the view toolbars
Definition: GNEViewNet.cpp:266
Close simulation - ID.
Definition: GUIAppEnum.h:85
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 *)
GNEInspectorFrame * myInspectorFrame
the panel for GNE_MODE_INSPECT
a junction