VPTissue Reference Manual
SimSession.h
Go to the documentation of this file.
1 #ifndef SIMPT_SESSION_SIM_SESSION_H_INCLUDED
2 #define SIMPT_SESSION_SIM_SESSION_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "ISimSession.h"
24 
25 #include <boost/property_tree/ptree.hpp>
26 #include <functional>
27 #include <memory>
28 #include <mutex>
29 #include <thread>
30 
31 
32 namespace SimShell { namespace Ws { class MergedPreferences; } }
33 namespace SimPT_Sim { class Sim; }
34 class QMainWindow;
35 class QTimer;
36 
37 namespace SimPT_Shell {
38 namespace Session {
39 
40 class SimWorker;
41 
42 using boost::property_tree::ptree;
43 using namespace SimShell;
44 using namespace SimShell::Session;
45 using namespace SimShell::Ws;
46 
51 class SimSession : public ISimSession,
52  public std::enable_shared_from_this<SimSession>
53 {
54  Q_OBJECT
55 public:
57  SimSession(const std::shared_ptr<MergedPreferences>& prefs, const ptree& sim);
58 
60  SimSession(const std::shared_ptr<MergedPreferences>& prefs, const SimPT_Sim::SimState& sim);
61 
63  virtual ~SimSession();
64 
66  virtual std::shared_ptr<RootViewerType>
67  CreateRootViewer(SimShell::Gui::Controller::AppController* parent = nullptr);
68 
70  virtual std::shared_ptr<SimPT_Sim::Sim> GetSim();
71 
73  virtual ExportersType GetExporters();
74 
76  virtual const ptree& GetParameters() const;
77 
79  virtual std::string GetStatusMessage() const;
80 
82  virtual Timings GetTimings() const;
83 
85  virtual void ForceExport();
86 
88  virtual void SetParameters(const ptree&);
89 
91  virtual void StartSimulation(int steps = -1);
92 
94  virtual void StopSimulation();
95 
96 public slots:
98  virtual void TimeStep();
99 
100 private slots:
101  virtual void ExecuteViewUnit(QString);
102 
103 signals:
104  void ExecuteWorkUnit();
105 
106 private:
107  std::shared_ptr<SimPT_Sim::Sim> m_sim;
108  std::mutex m_parameters_mutex;
109  std::mutex m_viewers_mutex;
110  Timings m_timings;
111  std::shared_ptr<MergedPreferences> m_preferences;
112 
113  QThread* m_sim_thread;
114  bool m_running;
115 
116  int m_steps_limit;
117 
118  struct {
119  bool updated;
120  ptree pt;
121  } m_parameter_buffer;
122 };
123 
124 } // namespace
125 } // namespace
126 
127 #endif // end_of_include_guard
Collection of instances associated with an opened/running project.
Definition: SimSession.h:51
ptree pt
Ptree containing parameters.
Definition: SimSession.h:120
AppController header.
Interface for sessions.
Namespace for SimPT shell package.
Definition: Client.cpp:50
Interface for handling an opened/running simulation.
Definition: ISimSession.h:31
Wrapper around workspace to have read and write access to merged (workspace + project) preferences...
bool updated
Whether parameters were updated and need saving to disk.
Definition: SimSession.h:119
Namespace for the core simulator.
Namespace for session classes.
Definition: ISession.h:42
Namespace for generic workspace classes.
Definition: SimSession.h:32
Contains the state of the whole Simulator at a given simulation step.
Definition: SimState.h:33
see the online Qt documentation
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
see the online C++11 documentation