1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GUIApplicationWindow.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Christian Roessel
14 /// @author  Michael Behrisch
15 /// @date    Sept 2002
16 /// @version $Id$
17 ///
18 // The main window of the SUMO-gui.
19 /****************************************************************************/
20 #ifndef GUIApplicationWindow_h
21 #define GUIApplicationWindow_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <vector>
31 #include <iostream>
32 #include <fx.h>
33 #include <utils/foxtools/FXSynchQue.h>
34 #include <utils/foxtools/FXThreadEvent.h>
35 #include <utils/foxtools/MFXInterThreadEventClient.h>
36 #include <utils/foxtools/FXLCDLabel.h>
37 #include <utils/gui/windows/GUIMainWindow.h>
38 #include <utils/common/ValueRetriever.h>
39 #include <utils/common/ValueSource.h>
40 #include <utils/distribution/RandomDistributor.h>
41 #include "GUISUMOViewParent.h"
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class GUILoadThread;
48 class GUIRunThread;
49 class GUIMessageWindow;
50 class GUIEvent;
51 class GUIParameterTracker;
52 class GUIParameterTableWindow;
53 
54 
55 // ===========================================================================
56 // class definition
57 // ===========================================================================
58 /**
59  * @class GUIApplicationWindow
60  * @brief The main window of the SUMO-gui.
61  *
62  * Beside views on the simulation, shown within a MDI-window, the main window
63  * may also have some further views (children) assigned which are stored
64  * within a separate list.
65  */
66 class GUIApplicationWindow :
67     public GUIMainWindow, public MFXInterThreadEventClient {
68     // FOX-declarations
69     FXDECLARE(GUIApplicationWindow)
70 public:
71 
72     /** @brief Constructor
73      * @param[in] a The FOX application
74      * @param[in] configPattern The pattern used for loading configurations
75      */
76     GUIApplicationWindow(FXApp* a, const std::string& configPattern);
77 
78 
79     /// @brief Destructor
80     virtual ~GUIApplicationWindow();
81 
82 
83     /// @name FOX-interactions
84     /// {
85 
86     /// @brief Creates the main window (required by FOX)
87     virtual void create();
88 
89     /// @brief Detaches the tool/menu bar
90     virtual void detach();
91     /// @}
92 
93     void loadOnStartup();
94 
95 
96     void dependentBuild();
97 
98     void setStatusBarText(const std::string& text);
99 
100     void addRecentFile(const FX::FXString& f, const bool isNet);
101 
102     FXGLCanvas* getBuildGLCanvas() const;
103     SUMOTime getCurrentSimTime() const;
104     double getTrackerInterval() const;
105 
106     FXCursor* getDefaultCursor();
107 
108 
109 
110 
111     /// @name Inter-thread event handling
112     /// @{
113 
114     virtual void eventOccurred();
115     void handleEvent_SimulationLoaded(GUIEvent* e);
116     void handleEvent_SimulationStep(GUIEvent* e);
117     void handleEvent_Message(GUIEvent* e);
118     void handleEvent_SimulationEnded(GUIEvent* e);
119     /// @}
120 
121 
122 
123     /// @name FOX-callbacks
124     /// @{
125 
126     /// @brief Called on menu File->Open Configuration
127     long onCmdOpenConfiguration(FXObject*, FXSelector, void*);
128 
129     /// @brief Called on menu File->Open Network
130     long onCmdOpenNetwork(FXObject*, FXSelector, void*);
131 
132     /// @brief Called on menu File->Load Shapes
133     long onCmdOpenShapes(FXObject*, FXSelector, void*);
134 
135     /// @brief Called on menu File->Load EdgeData
136     long onCmdOpenEdgeData(FXObject*, FXSelector, void*);
137 
138     /// @brief Called on reload
139     long onCmdReload(FXObject*, FXSelector, void*);
140 
141     /// @brief Called on opening a recent file
142     long onCmdOpenRecent(FXObject*, FXSelector, void*);
143 
144     /// @brief Called on menu File->Close
145     long onCmdClose(FXObject*, FXSelector, void*);
146 
147     /** @brief Called by FOX if the application shall be closed
148      *
149      * Called either by FileMenu->Quit, the normal close-menu or SIGINT */
150     long onCmdQuit(FXObject*, FXSelector, void*);
151 
152     /// @brief Called on menu Edit->Edit Chosen
153     long onCmdEditChosen(FXObject*, FXSelector, void*);
154 
155     /// @brief Called on menu Edit->Edit Breakpoints
156     long onCmdEditBreakpoints(FXObject*, FXSelector, void*);
157 
158     /// @brief Called on menu Edit->Visualization
159     long onCmdEditViewScheme(FXObject*, FXSelector, void*);
160 
161     /// @brief Called on menu Edit->Viewport
162     long onCmdEditViewport(FXObject*, FXSelector, void*);
163 
164     /// @brief called if the user selects help->Documentation
165     long onCmdHelp(FXObject* sender, FXSelector sel, void* ptr);
166 
167     /// @brief Called on menu Edit->Netedit
168     long onCmdNetedit(FXObject*, FXSelector, void*);
169 
170     /// @brief Opens the application settings menu (Settings->Application Settings...)
171     long onCmdAppSettings(FXObject*, FXSelector, void*);
172 
173     /// @brief Toggle gaming mode
174     long onCmdGaming(FXObject*, FXSelector, void*);
175 
176     /// @brief Toggle full screen mode
177     long onCmdFullScreen(FXObject*, FXSelector, void*);
178 
179     /// @brief Toggle listing of internal structures
180     long onCmdListInternal(FXObject*, FXSelector, void*);
181 
182     /// @brief Toggle listing of parking vehicles
183     long onCmdListParking(FXObject*, FXSelector, void*);
184 
185     /// @brief Toggle listing of teleporting vehicles
186     long onCmdListTeleporting(FXObject*, FXSelector, void*);
187 
188     /// @brief Shows the about dialog
189     long onCmdAbout(FXObject*, FXSelector, void*);
190 
191     /// @brief Called on "play"
192     long onCmdStart(FXObject*, FXSelector, void*);
193 
194     /// @brief Called on "stop"
195     long onCmdStop(FXObject*, FXSelector, void*);
196 
197     /// @brief Called on "step"
198     long onCmdStep(FXObject*, FXSelector, void*);
199 
200     /// @brief Called on "save state"
201     long onCmdSaveState(FXObject*, FXSelector, void*);
202 
203     /// @brief Called on "time toggle"
204     long onCmdTimeToggle(FXObject*, FXSelector, void*);
205 
206     /// @brief Called on "delay toggle"
207     long onCmdDelayToggle(FXObject*, FXSelector, void*);
208 
209     /// @brief Called on "demand scale"
210     long onCmdDemandScale(FXObject*, FXSelector, void*);
211 
212     /// @brief Called if a new view shall be opened (2D view)
213     long onCmdNewView(FXObject*, FXSelector, void*);
214 
215 #ifdef HAVE_OSG
216     /// @brief Called if a new 3D view shall be opened
217     long onCmdNewOSG(FXObject*, FXSelector, void*);
218 #endif
219 
220     /// @brief Determines whether opening is enabled
221     long onUpdOpen(FXObject*, FXSelector, void*);
222 
223     /// @brief Determines whether reloading is enabled
224     long onUpdReload(FXObject*, FXSelector, void*);
225 
226     /// @brief Determines whether opening a recent file is enabled
227     long onUpdOpenRecent(FXObject*, FXSelector, void*);
228 
229     /// @brief Determines whether adding a view is enabled
230     long onUpdAddView(FXObject*, FXSelector, void*);
231 
232     /// @brief Determines whether "play" is enabled
233     long onUpdStart(FXObject* sender, FXSelector, void* ptr);
234 
235     /// @brief Determines whether "stop" is enabled
236     long onUpdStop(FXObject*, FXSelector, void*);
237 
238     /// @brief Determines whether "step" is enabled
239     long onUpdStep(FXObject*, FXSelector, void*);
240 
241     /// @brief Determines whether some buttons which require an active simulation may be shown
242     long onUpdNeedsSimulation(FXObject*, FXSelector, void*);
243 
244     /// @brief Determines whether traci is active
245     long onUpdTraCIStatus(FXObject*, FXSelector, void*);
246 
247     /// @brief Called if the message window shall be cleared
248     long onCmdClearMsgWindow(FXObject*, FXSelector, void*);
249 
250     /// @brief Called on menu commands from the Locator menu
251     long onCmdLocate(FXObject*, FXSelector, void*);
252 
253     /// @brief Called on commands from the statistic buttons
254     long onCmdShowStats(FXObject*, FXSelector, void*);
255 
256     /// @brief Called on an event from the loading thread
257     long onLoadThreadEvent(FXObject*, FXSelector, void*);
258 
259     /// @brief Called on an event from the simulation thread
260     long onRunThreadEvent(FXObject*, FXSelector, void*);
261 
262     /// @brief Somebody wants our clipped text
263     long onClipboardRequest(FXObject* sender, FXSelector sel, void* ptr);
264 
265     /// @brief handle keys
266     long onKeyPress(FXObject* o, FXSelector sel, void* data);
267     long onKeyRelease(FXObject* o, FXSelector sel, void* data);
268     /// @}
269 
270 
271     /** @brief Returns the simulation delay
272      * @return delay in milliseconds
273      */
getDelay()274     virtual double getDelay() const {
275         return mySimDelay;
276     }
277 
278     /** @brief Sets the delay of the parent application
279      * @param delay the new delay in milliseconds
280      */
setDelay(double delay)281     virtual void setDelay(double delay) {
282         mySimDelay = delay;
283     }
284 
285     /** @brief Sets the breakpoints of the parent application
286      */
287     virtual void setBreakpoints(const std::vector<SUMOTime>& breakpoints);
288 
289     /** @brief Sends an event from the application thread to the GUI and waits until it is handled
290      * @param event the event to send
291      */
292     virtual void sendBlockingEvent(GUIEvent* event);
293 
294     const std::vector<SUMOTime> retrieveBreakpoints() const;
295 
296 protected:
addToWindowsMenu(FXMenuPane *)297     virtual void addToWindowsMenu(FXMenuPane*) { }
298 
299 private:
300     /** starts to load a simulation */
301     void loadConfigOrNet(const std::string& file, bool isNet);
302 
303     /** this method closes all windows and deletes the current simulation */
304     void closeAllWindows();
305 
306     /// @brief updates the simulation time display
307     void updateTimeLCD(SUMOTime time);
308 
309     /** opens a new simulation display */
310     GUISUMOAbstractView* openNewView(GUISUMOViewParent::ViewType vt = GUISUMOViewParent::VIEW_2D_OPENGL);
311 
312     /// @brief handles additional game-related events
313     void checkGamingEvents();
314     void checkGamingEventsDRT();
315 
316 protected:
317     /// FOX needs this for static members
GUIApplicationWindow()318     GUIApplicationWindow() { }
319 
320 protected:
321     /// Builds the menu bar
322     virtual void fillMenuBar();
323 
324     /// Builds the tool bar
325     virtual void buildToolBars();
326 
327 protected:
328     /// @brief  the name of the simulation
329     std::string myName;
330 
331     /// @brief  the thread that loads simulations
332     GUILoadThread* myLoadThread;
333 
334     /// @brief  the thread that runs simulations
335     GUIRunThread* myRunThread;
336 
337     /// @brief  the information whether the simulation was started before
338     bool myWasStarted;
339 
340     /// @brief The current view number
341     int myViewNumber;
342 
343     /// @brief information whether the gui is currently loading and the load-options shall be greyed out
344     bool myAmLoading;
345 
346     /// @brief the submenus
347     FXMenuPane* myFileMenu, *myEditMenu, *mySelectByPermissions, *mySettingsMenu,
348                 *myLocatorMenu, *myControlMenu,
349                 *myWindowsMenu, *myHelpMenu;
350 
351     /// @brief the menu cascades
352     FXMenuCascade* mySelectLanesMenuCascade;
353 
354     /// @brief Buttons showing and running values and triggering statistic windows
355     std::vector<FXButton*> myStatButtons;
356 
357     /// @brief A window to display messages, warnings and error in
358     GUIMessageWindow* myMessageWindow;
359 
360     /// @brief The splitter that divides the main window into vies and the log window
361     FXSplitter* myMainSplitter;
362 
363     /// @brief for some menu detaching fun
364     FXToolBarShell* myToolBarDrag1, *myToolBarDrag2, *myToolBarDrag3,
365                     *myToolBarDrag4, *myToolBarDrag5, *myMenuBarDrag,
366                     *myToolBarDrag8;
367 
368     /// @brief the simulation delay in milliseconds
369     double mySimDelay;
370     FXDataTarget* mySimDelayTarget;
371     FXRealSpinner* mySimDelaySpinner;
372     FXSlider* mySimDelaySlider;
373 
374     /// @brief the demand scale
375     FXRealSpinner* myDemandScaleSpinner;
376 
377     /// @brief The alternate simulation delay in milliseconds for toggling
378     double myAlternateSimDelay;
379 
380     /// @brief List of got requests
381     FXSynchQue<GUIEvent*> myEvents;
382 
383     /// @brief The menu used for the MDI-windows
384     FXMDIMenu* myMDIMenu;
385 
386     /// @brief The application menu bar
387     FXMenuBar* myMenuBar;
388 
389     /// @brief The application tool bar
390     FXToolBar* myToolBar1, *myToolBar2, *myToolBar3, *myToolBar4, *myToolBar5, *myToolBar8;
391 
392     /// @brief the simulation step display
393     FXEX::FXLCDLabel* myLCDLabel;
394 
395     /// @brief io-event with the load-thread
396     FXEX::FXThreadEvent myLoadThreadEvent;
397 
398     /// @brief io-event with the run-thread
399     FXEX::FXThreadEvent myRunThreadEvent;
400 
401     /// @brief List of recent config files
402     FXRecentFiles myRecentConfigs;
403 
404     /// @brief List of recent nets
405     FXRecentFiles myRecentNets;
406 
407     /// @brief Input file pattern
408     std::string myConfigPattern;
409 
410     bool hadDependentBuild;
411 
412     /// @brief whether to show time as hour:minute:second
413     bool myShowTimeAsHMS;
414 
415     /// @brief whether the simulation end was already announced
416     bool myHaveNotifiedAboutSimEnd;
417 
418     /// @brief the mutex for the waiting semaphore
419     FXMutex myEventMutex;
420 
421     /// @brief the semaphore when waiting for event completion
422     FXCondition myEventCondition;
423 
424     /// @name game related things
425     /// {
426     RandomDistributor<std::string> myJamSounds;
427     RandomDistributor<std::string> myCollisionSounds;
428     /// @brief waiting time after which vehicles trigger jam sounds
429     double myJamSoundTime;
430     /// @brief A random number generator used to choose a gaming sound
431     static std::mt19937 myGamingRNG;
432     int myPreviousCollisionNumber;
433     /// @brief current game mode
434     bool myTLSGame;
435 
436     /// @brief performance indicators
437     FXEX::FXLCDLabel* myWaitingTimeLabel;
438     FXEX::FXLCDLabel* myTimeLossLabel;
439     FXEX::FXLCDLabel* myTotalDistanceLabel;
440     SUMOTime myWaitingTime;
441     SUMOTime myTimeLoss;
442     double myTotalDistance;
443     FXToolBar* myToolBar6, *myToolBar7, *myToolBar9;
444     FXToolBarShell* myToolBarDrag6, *myToolBarDrag7, *myToolBarDrag9;
445     ////}
446 
447 };
448 
449 
450 #endif
451 
452 /****************************************************************************/
453 
454