Fraxinus  22.09
An IGT application
cxTrainingWidget.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 "cxTrainingWidget.h"
13 #include <QtWidgets>
14 #include <QPushButton>
15 #include "boost/bind.hpp"
16 #include "boost/function.hpp"
17 #include "cxHelpEngine.h"
18 #include "cxHelpBrowser.h"
19 #include "cxLogger.h"
20 #include "cxApplication.h"
21 #include "cxPatientModelService.h"
22 #include "cxImage.h"
23 #include "cxMesh.h"
24 #include "cxRegServices.h"
25 
26 namespace cx {
27 
28 TrainingWidget::TrainingWidget(RegServicesPtr services, QString objectName, QString windowTitle, QWidget* parent) :
29  BaseWidget(parent, objectName, windowTitle),
30  mServices(services)
31 {
32  mEngine.reset(new HelpEngine);
33  mBrowser = new HelpBrowser(this, mEngine);
34 
35  this->createActions();
36 
37  QVBoxLayout* topLayout = new QVBoxLayout(this);
38  QHBoxLayout* buttonLayout = new QHBoxLayout;
39 
40  topLayout->addWidget(mBrowser);
41  topLayout->addLayout(buttonLayout);
42 
43  buttonLayout->addStretch(1);
44  this->addToolButtonFor(buttonLayout, mImportAction);
45  this->addToolButtonFor(buttonLayout, mPreviousAction);
46  CXToolButton* button = this->addToolButtonFor(buttonLayout, mCurrentAction);
47  button->setToolButtonStyle(Qt::ToolButtonIconOnly);
48 
49  this->addToolButtonFor(buttonLayout, mNextAction);
50 
51  connect(mImportAction, &QAction::triggered, this, &TrainingWidget::onImportSimulatedPatient);
52  connect(mPreviousAction, &QAction::triggered, boost::function<void()>(boost::bind(&TrainingWidget::onStep, this, -1)));
53  connect(mCurrentAction, &QAction::triggered, boost::function<void()>(boost::bind(&TrainingWidget::onStep, this, 0)));
54  connect(mNextAction, &QAction::triggered, boost::function<void()>(boost::bind(&TrainingWidget::onStep, this, +1)));
55 
56  //must always be the initial step
57  func_t welcome = boost::bind(&TrainingWidget::toWelcomeStep, this);
59 }
60 
62 {
63 }
64 
66 {
67  mCurrentStep = -1;
68  this->stepTo(0);
69 }
70 
72 {
73  mTransitions.push_back(transition);
74  int numberOfSteps = mTransitions.size();
75  this->createSteps(numberOfSteps);
76 }
77 
78 void TrainingWidget::createActions()
79 {
80  mImportAction = this->createAction2(this,
81  QIcon(":/icons/open_icon_library/document-open-7.png"),
82  "Import new training dataset", "Clear current data and import new training patient folder",
83  //SLOT(onImport()),
84  NULL);
85 
86  mPreviousAction = this->createAction2(this,
87  QIcon(":/icons/open_icon_library/arrow-left-3.png"),
88  "Previous", "Go to previous training step",
89  // SLOT(onPrevious()),
90  NULL);
91 
92  mCurrentAction = this->createAction2(this,
93  QIcon(":/icons/open_icon_library/button-green.png"),
94  "Reload", "Reload the current training step",
95  NULL);
96 
97  mNextAction = this->createAction2(this,
98  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
99  "Next", "Go to next training step",
100  // SLOT(onNext()),
101  NULL);
102 }
103 
104 void TrainingWidget::createSteps(unsigned numberOfSteps)
105 {
106 // CX_LOG_DEBUG() << "Creating " << numberOfSteps << " steps!";
107  mSessionIDs.clear();
108 
109  for (unsigned i=1; i<=numberOfSteps; ++i)
110  mSessionIDs << QString("org_custusx_training_sessionA_step%1").arg(i);
111 
112  this->resetSteps();
113 }
114 
115 CXToolButton* TrainingWidget::addToolButtonFor(QHBoxLayout* layout, QAction* action)
116 {
117  CXToolButton* button = new CXToolButton();
118  button->setDefaultAction(action);
119  button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
120  // button->setToolTip(action->toolTip());
121  layout->addWidget(button);
122  return button;
123 }
124 
125 void TrainingWidget::toWelcomeStep()
126 {
127 // std::cout << "toWelcomeStep" << std::endl;
128 }
129 
130 void TrainingWidget::onImportSimulatedPatient()
131 {
134 
135  //Transition to first step after welcome
136  this->stepTo(1);
137 }
138 
139 void TrainingWidget::onStep(int delta)
140 {
141  this->stepTo(mCurrentStep+delta);
142 }
143 
144 void TrainingWidget::stepTo(int step)
145 {
146 // CX_LOG_DEBUG() << "stepTo " << step;
147  step = std::min<int>(step, mSessionIDs.size()-1);
148  step = std::max<int>(step, 0);
149  mCurrentStep = step;
150 // CX_LOG_DEBUG() << "Current step is now " << mCurrentStep;
151 // CX_LOG_DEBUG() << "mSessionIDs.size(): " << mSessionIDs.size();
152 
153  mBrowser->showHelpForKeyword(mSessionIDs[mCurrentStep]);
154 
155  this->transitionToStep(step);
156 }
157 
158 void TrainingWidget::transitionToStep(int step)
159 {
160 // CX_LOG_DEBUG() << "Want to transition to step " << step;
161  int transitionNumber = step;
162  if(transitionNumber >= 0)
163  {
164 // CX_LOG_DEBUG() << "Going to execute transition number " << transitionNumber;
165  func_t transition = mTransitions.at(transitionNumber);
166  if(transition)
167  {
168 // CX_LOG_DEBUG() << "Transitioning";
169  transition();
170  }
171  }
172 
173 }
174 
176 {
177  std::map<QString, DataPtr> datas = mServices->patient()->getDatas();
178  std::map<QString, DataPtr>::iterator iter = datas.begin();
179 
180  for(; iter != datas.end(); ++iter)
181  {
182  DataPtr data = iter->second;
183  ImagePtr image = boost::dynamic_pointer_cast<Image>(data);
184 
185  if (image && image->getModality() == imUS)
186  return image->getUid();
187  }
188  return QString();
189 }
190 
192 {
193  std::map<QString, MeshPtr> datas = mServices->patient()->getDataOfType<Mesh>();
194  std::map<QString, MeshPtr>::iterator iter = datas.begin();
195  for(; iter != datas.end(); ++iter)
196  {
197  MeshPtr mesh = iter->second;
198  if(mesh && mesh->getUid().contains(uidPart))
199  return mesh;
200  }
201  return MeshPtr();
202 }
203 
204 void TrainingWidget::makeUnavailable(IMAGE_MODALITY modality, bool makeModalityUnavailable)
205 {
206  std::map<QString, DataPtr> datas = mServices->patient()->getDatas();
207  this->setAvailability(datas, false, modality, makeModalityUnavailable);
208 }
209 
210 
211 void TrainingWidget::makeAvailable(IMAGE_MODALITY modality, bool makeModalityUnavailable)
212 {
213  std::map<QString, DataPtr> datas = mServices->patient()->getDatas(PatientModelService::AllData);
214  this->setAvailability(datas, true, modality, makeModalityUnavailable);
215 }
216 
217 void TrainingWidget::setAvailability(std::map<QString, DataPtr> datas, bool available, IMAGE_MODALITY modality, bool makeModalityUnavailable)
218 {
219  std::map<QString, DataPtr>::iterator iter = datas.begin();
220 
221  for(; iter != datas.end(); ++iter)
222  {
223  DataPtr data = iter->second;
224  ImagePtr image = boost::dynamic_pointer_cast<Image>(data);
225 
226  if (makeModalityUnavailable && image && image->getModality() == modality)
227  mServices->patient()->makeAvailable(image->getUid(), available);
228 // else if (data && data->getUid().contains(uidPart))
229 // mServices->patient()->makeAvailable(data->getUid(), available);
230  }
231 }
232 
233 } /* namespace cx */
A mesh data set.
Definition: cxMesh.h:45
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
void registrateTransition(func_t transition)
void triggerMainWindowActionWithObjectName(QString actionName)
void makeAvailable(IMAGE_MODALITY modality, bool makeModalityUnavailable)
virtual QString getUid() const
Definition: cxData.cpp:64
MeshPtr getMesh(QString uidPart)
boost::shared_ptr< class Data > DataPtr
A volumetric data set.
Definition: cxImage.h:45
void showHelpForKeyword(const QString &id)
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
RegServicesPtr mServices
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
void makeUnavailable(IMAGE_MODALITY modality, bool makeModalityUnavailable=false)
imUS
TrainingWidget(RegServicesPtr services, QString objectName, QString windowTitle, QWidget *parent=NULL)
boost::function< void(void)> func_t
boost::shared_ptr< class Mesh > MeshPtr
QAction * createAction2(QObject *parent, QIcon iconName, QString text, QString tip, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:108
Namespace for all CustusX production code.