25 #include <QApplication>
26 #include <QMessageBox>
34 namespace Controller {
36 SessionController::SessionController(
QWidget* parent)
39 qRegisterMetaType< std::string >();
41 m_action_run =
new QAction(
"Run",
this);
42 m_action_run->setCheckable(
true);
43 m_action_run->setEnabled(
false);
44 m_action_run->setShortcut(QKeySequence(
"R"));
45 m_action_run->setShortcutContext(Qt::ApplicationShortcut);
46 connect(m_action_run, SIGNAL(toggled(
bool)),
this, SLOT(SLOT_ToggleRunning(
bool)));
48 m_action_single_step =
new QAction(
"Single Step",
this);
49 m_action_single_step->setEnabled(
false);
50 m_action_single_step->setShortcut(QKeySequence(
"S"));
51 m_action_single_step->setShortcutContext(Qt::ApplicationShortcut);
52 connect(m_action_single_step, SIGNAL(triggered()),
this, SLOT(SLOT_TimeStep()));
54 m_enabled_actions.Add(m_action_run);
55 m_enabled_actions.Add(m_action_single_step);
58 addAction(m_action_run);
59 addAction(m_action_single_step);
62 void SessionController::Disable()
65 m_action_run->setChecked(
false);
66 m_enabled_actions.Disable();
69 void SessionController::Enable(
const shared_ptr<Ws::IProject>& project)
73 if (m_project->IsOpened()) {
74 connect(&m_project->Session(),
75 SIGNAL(InfoMessage(
const std::string&,
const InfoMessageReason&)),
76 this, SLOT(SimulationInfo(
const std::string&,
const InfoMessageReason&)));
77 connect(&m_project->Session(),
78 SIGNAL(ErrorMessage(
const std::string&)),
79 this, SLOT(SimulationError(
const std::string&)));
80 m_enabled_actions.Enable();
84 QAction* SessionController::GetActionRun()
const
89 QAction* SessionController::GetActionSingleStep()
const
91 return m_action_single_step;
94 bool SessionController::IsEnabled()
const
96 return (
bool) m_project;
99 bool SessionController::IsRunning()
const
101 return m_action_run->isChecked();
104 void SessionController::SetRunning(
bool b)
106 if (m_action_run->isEnabled())
107 m_action_run->setChecked(b);
110 void SessionController::SimulationError(
const std::string& error)
112 std::cerr <<
"Exception> " + error << std::endl;
113 QString qmess = QString(
"Exception:\n%1\n").arg(error.c_str());
114 QMessageBox::information(0,
"Critical Error", qmess);
117 void SessionController::SimulationInfo(
const std::string& ,
118 const Session::ISession::InfoMessageReason& reason)
121 case Session::ISession::InfoMessageReason::Stopped:
124 case Session::ISession::InfoMessageReason::Terminated:
132 void SessionController::SLOT_ToggleRunning(
bool b)
134 m_action_single_step->setEnabled(!b);
137 if (m_project->IsOpened()) {
139 m_project->Session().StartSimulation();
141 m_project->Session().StopSimulation();
147 void SessionController::SLOT_TimeStep()
149 if (m_project->IsOpened()) {
150 m_project->Session().TimeStep();
Namespace for miscellaneous utilities.
SessionController header.
see the online Qt documentation
Header file for Exception class.
Namespace for generic graphical shell for simulators.