NorMIT-nav  22.09
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 
cxLogger.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::WorkflowState::setActionSlot
void setActionSlot()
Definition: cxWorkflowState.cpp:74
cx::WorkflowState::canEnter
virtual bool canEnter() const =0
cx::WorkflowState
State in a WorkflowStateMachine.
Definition: cxWorkflowState.h:42
cx::report
void report(QString msg)
Definition: cxLogger.cpp:69
cxWorkflowState.h
cx::WorkflowState::onExit
virtual void onExit(QEvent *event)
Definition: cxWorkflowState.cpp:32
cx::WorkflowState::getIcon
virtual QIcon getIcon() const =0
cx::RequestEnterStateEvent
Utility class for StateService states.
Definition: cxRequestEnterStateTransition.h:31
cx::WorkflowState::mName
QString mName
Definition: cxWorkflowState.h:83
cx::WorkflowState::getUid
virtual QString getUid() const
Definition: cxWorkflowState.h:61
cxVideoService.h
cxTool.h
cxPatientModelService.h
cx::WorkflowState::getChildStates
std::vector< WorkflowState * > getChildStates()
Definition: cxWorkflowState.cpp:37
cxSettings.h
cxStateService.h
cx::WorkflowState::mServices
CoreServicesPtr mServices
Definition: cxWorkflowState.h:85
cx::WorkflowState::autoStartHardware
void autoStartHardware()
Definition: cxWorkflowState.cpp:80
cxCoreServices.h
cx::WorkflowState::aboutToExit
void aboutToExit()
cx::WorkflowState::canEnterSlot
void canEnterSlot()
Definition: cxWorkflowState.cpp:68
cx::WorkflowState::onEntry
virtual void onEntry(QEvent *event)
Definition: cxWorkflowState.cpp:25
cx::WorkflowState::getName
virtual QString getName() const
Definition: cxWorkflowState.h:62
cx::WorkflowState::enableAction
virtual void enableAction(bool enable)
Definition: cxWorkflowState.cpp:88
cx::WorkflowState::createAction
QAction * createAction(QActionGroup *group)
Definition: cxWorkflowState.cpp:50
cx::WorkflowState::mAction
QAction * mAction
Definition: cxWorkflowState.h:84
cx::Tool::tsTRACKING
@ tsTRACKING
emitting tracking data
Definition: cxTool.h:77
cxTrackingService.h
cx::settings
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21