Eclipse SUMO - Simulation of Urban MObility
GUIRunThread.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // The thread that runs the simulation
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <string>
26 #include <vector>
27 #include <set>
28 #include <iostream>
33 #include <utils/common/SUMOTime.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class GUINet;
40 class GUIEvent;
41 class OutputDevice;
42 
43 // ===========================================================================
44 // class definition
45 // ===========================================================================
54 
55 public:
58  double& simDelay, MFXSynchQue<GUIEvent*>& eq,
60 
62  virtual ~GUIRunThread();
63 
65  virtual bool init(GUINet* net, SUMOTime start, SUMOTime end);
66 
68  virtual FXint run();
69 
72  void resume();
73 
76  void singleStep();
77 
79  virtual void begin();
80 
82  void stop();
83 
85  bool networkAvailable() const;
86 
88  virtual bool simulationIsStartable() const;
89 
91  virtual bool simulationIsStopable() const;
92 
94  virtual bool simulationIsStepable() const;
95 
97  virtual void deleteSim();
98 
100  GUINet& getNet() const;
101 
103  void prepareDestruction();
104 
106  void retrieveMessage(const MsgHandler::MsgType type, const std::string& msg);
107 
110  return mySimStartTime;
111  }
112 
115  return mySimEndTime;
116  }
117 
119  std::vector<SUMOTime>& getBreakpoints() {
120  return myBreakpoints;
121  }
122 
124  FXMutex& getBreakpointLock() {
125  return myBreakpointLock;
126  }
127 
129  void enableLibsumo() {
130  myAmLibsumo = true;
131  }
132 
134  void tryStep();
135 
136 protected:
138  void makeStep();
139 
141  void waitForSnapshots(const SUMOTime snapshotTime);
142 
143 protected:
146 
149 
151  bool myHalting;
152 
155  bool myQuit;
156 
160 
162  bool myOk;
163 
165  bool mySingle;
166 
169 
173 
175  double& mySimDelay;
176 
179 
182 
185 
187  std::vector<SUMOTime> myBreakpoints;
188 
191 
194 
197 
200 };
long long int SUMOTime
Definition: GUI.h:35
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:82
double & mySimDelay
simulation delay
Definition: GUIRunThread.h:175
void singleStep()
called when the user presses the "single step"-button
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations.
Definition: GUIRunThread.h:172
GUINet * myNet
the loaded simulation network
Definition: GUIRunThread.h:145
SUMOTime mySimEndTime
Definition: GUIRunThread.h:148
FXMutex & getBreakpointLock()
get breakpoint lock
Definition: GUIRunThread.h:124
FXMutex myBreakpointLock
Lock for modifying the list of breakpoints.
Definition: GUIRunThread.h:190
GUINet & getNet() const
returns the loaded network
std::vector< SUMOTime > myBreakpoints
List of breakpoints.
Definition: GUIRunThread.h:187
virtual FXint run()
starts the execution
virtual void begin()
starts the simulation (execution of one step after another)
SUMOTime getSimBegin()
get simulation begin time
Definition: GUIRunThread.h:109
std::vector< SUMOTime > & getBreakpoints()
get list of breakpoints
Definition: GUIRunThread.h:119
void resume()
called when the user presses the "resume"-button
FXEX::MFXThreadEvent & myEventThrow
thrower events
Definition: GUIRunThread.h:181
virtual bool simulationIsStartable() const
check if simulation is startable
bool networkAvailable() const
returns the information whether a network has been loaded
bool myOk
flag to check if all is ok
Definition: GUIRunThread.h:162
virtual bool simulationIsStepable() const
check if simulation is stepable
bool mySimulationInProgress
information whether a simulation step is being performed
Definition: GUIRunThread.h:159
virtual bool init(GUINet *net, SUMOTime start, SUMOTime end)
initialises the thread with the new simulation
void makeStep()
make simulation step
bool myHalting
information whether the simulation is halting (is not being executed)
Definition: GUIRunThread.h:151
SUMOTime getSimEndTime() const
get simulation end time
Definition: GUIRunThread.h:114
virtual ~GUIRunThread()
destructor
void tryStep()
try simulation step
virtual bool simulationIsStopable() const
check if simulation is stopableo
void enableLibsumo()
enable lib SUMO
Definition: GUIRunThread.h:129
OutputDevice * myMessageRetriever
Definition: GUIRunThread.h:172
long myLastEndMillis
end of the last simulation step
Definition: GUIRunThread.h:193
bool mySingle
information whether the thread is running in single step mode
Definition: GUIRunThread.h:165
OutputDevice * myWarningRetriever
Definition: GUIRunThread.h:172
virtual void deleteSim()
deletes the existing simulation
void retrieveMessage(const MsgHandler::MsgType type, const std::string &msg)
Retrieves messages from the loading module.
void waitForSnapshots(const SUMOTime snapshotTime)
wait for snapshots
SUMOTime mySimStartTime
the times the simulation starts and ends with
Definition: GUIRunThread.h:148
bool myQuit
information whether the thread shall be stopped
Definition: GUIRunThread.h:155
void stop()
halts the simulation execution
bool myAmLibsumo
whether we are running in libsumo
Definition: GUIRunThread.h:199
void prepareDestruction()
halts the thread before it shall be deleted
long myLastBreakMillis
last time the simulation took a microsecond break for the fox event loop to catch up (#9028)
Definition: GUIRunThread.h:196
MFXSynchQue< GUIEvent * > & myEventQue
event queue
Definition: GUIRunThread.h:178
FXMutex mySimulationLock
mutex for lock simulation
Definition: GUIRunThread.h:184
GUIRunThread(FXApp *app, MFXInterThreadEventClient *mw, double &simDelay, MFXSynchQue< GUIEvent * > &eq, FXEX::MFXThreadEvent &ev)
constructor
bool myHaveSignaledEnd
whether the simulation already ended
Definition: GUIRunThread.h:168
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61