Fraxinus  22.04-rc3
An IGT application
cxWorkflowState.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxWorkflowState.h"
13 #include "cxStateService.h"
14 #include "cxSettings.h"
15 #include "cxTrackingService.h"
16 #include "cxTool.h"
17 #include "cxVideoService.h"
18 #include "cxPatientModelService.h"
19 #include "cxLogger.h"
20 #include "cxCoreServices.h"
21 
22 namespace cx
23 {
24 
25 void WorkflowState::onEntry(QEvent * event)
26 {
27  report("Workflow change to [" + mName + "]");
28  if (mAction)
29  mAction->setChecked(true);
30 }
31 
32 void WorkflowState::onExit(QEvent * event)
33 {
34  emit aboutToExit();
35 }
36 
37 std::vector<WorkflowState*> WorkflowState::getChildStates()
38 {
39  QObjectList childrenList = this->children();
40  std::vector<WorkflowState*> retval;
41  for (int i = 0; i < childrenList.size(); ++i)
42  {
43  WorkflowState* state = dynamic_cast<WorkflowState*>(childrenList[i]);
44  if (state)
45  retval.push_back(state);
46  }
47  return retval;
48 }
49 
50 QAction* WorkflowState::createAction(QActionGroup* group)
51 {
52  if (mAction)
53  return mAction;
54 
55  mAction = new QAction(this->getName(), group);
56  mAction->setIcon(this->getIcon());
57  mAction->setStatusTip(this->getName());
58  mAction->setCheckable(true);
59  mAction->setData(QVariant(this->getUid()));
60  this->canEnterSlot();
61 
62  connect(mAction, SIGNAL(triggered()), this, SLOT(setActionSlot()));
63 
64  this->enableAction(mEnableAction);
65  return mAction;
66 }
67 
69 {
70  if (mAction)
71  mAction->setEnabled(this->canEnter());
72 }
73 
75 {
76  this->machine()->postEvent(new RequestEnterStateEvent(this->getUid()));
77 }
78 
79 
81 {
82  if (settings()->value("Automation/autoStartTracking").toBool())
83  mServices->tracking()->setState(Tool::tsTRACKING);
84  if (settings()->value("Automation/autoStartStreaming").toBool())
85  mServices->video()->openConnection();
86 }
87 
88 void WorkflowState::enableAction(bool enable)
89 {
90  mEnableAction = enable;
91  if(mAction)
92  mAction->setEnabled(enable);
93 }
94 
95 } //namespace cx
96 
virtual void onEntry(QEvent *event)
virtual QString getName() const
virtual void enableAction(bool enable)
CoreServicesPtr mServices
virtual QString getUid() const
Utility class for StateService states.
std::vector< WorkflowState * > getChildStates()
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
QAction * createAction(QActionGroup *group)
void report(QString msg)
Definition: cxLogger.cpp:69
State in a WorkflowStateMachine.
virtual void onExit(QEvent *event)
emitting tracking data
Definition: cxTool.h:77
virtual bool canEnter() const =0
Namespace for all CustusX production code.
virtual QIcon getIcon() const =0