NorMIT-nav  18.04
An IGT application
cxVBWidget.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 <QLabel>
13 #include <QHBoxLayout>
14 #include <QVBoxLayout>
15 #include <QGroupBox>
16 #include <QSlider>
17 #include <QSpinBox>
18 #include <QGridLayout>
19 #include <QLabel>
20 #include <QDial>
21 #include <QPushButton>
22 
23 #include "cxVBWidget.h"
25 #include "cxViewServiceProxy.h"
26 #include "cxDataSelectWidget.h"
27 #include "cxTrackingServiceProxy.h"
28 #include "cxView.h"
30 #include "cxPatientStorage.h"
31 #include "cxVisServices.h"
32 #include "cxLogger.h"
33 
34 
35 
36 namespace cx
37 {
38 
39 VBWidget::VBWidget(VisServicesPtr services, QWidget *parent) :
40  QWidget(parent),
41  mVerticalLayout(new QVBoxLayout(this)),
42  mControlsEnabled(false),
43  mStorage(new PatientStorage(services->session(), "VirtualBronchoscopy"))
44 {
45  this->setObjectName("virtual_bronchoscopy_widget");
46  this->setWindowTitle("Virtual Bronchoscopy");
47  this->setWhatsThis(this->defaultWhatsThis());
48 
49  this->setFocusPolicy(Qt::StrongFocus); // Widget needs focus to handle Key events
50 
51  mRouteToTarget = StringPropertySelectMesh::New(services->patient());
52  mRouteToTarget->setValueName("Route to target path: ");
53  mStorage->storeVariable("routeToTarget",
56 
57  // Selector for route to target
58  QVBoxLayout *inputVbox = new QVBoxLayout;
59  inputVbox->addWidget(new DataSelectWidget(services->view(), services->patient(), this,mRouteToTarget));
60  QGroupBox *inputBox = new QGroupBox(tr("Input"));
61  inputBox->setLayout(inputVbox);
62  mVerticalLayout->addWidget(inputBox);
63 
64  // Selectors for position along path and play/pause
65  QHBoxLayout *playbackHBox = new QHBoxLayout;
66  QGroupBox *playbackBox = new QGroupBox(tr("Playback"));
67  mPlaybackSlider = new QSlider(Qt::Horizontal);
68  QLabel *labelStart = new QLabel(tr("Start "));
69  QLabel *labelTarget = new QLabel(tr(" Target"));
70  playbackHBox->addWidget(labelStart);
71  playbackHBox->addWidget(mPlaybackSlider);
72  playbackHBox->addWidget(labelTarget);
73  playbackBox->setLayout(playbackHBox);
74  mVerticalLayout->addWidget(playbackBox);
75  mPlaybackSlider->setMinimum(0);
76  mPlaybackSlider->setMaximum(100);
77 
78  // Selectors for virtual endoscope control
79  QGroupBox *endoscopeBox = new QGroupBox(tr("Bronchoscope"));
80  QGridLayout *endoscopeControlLayout = new QGridLayout;
81  QLabel *labelRot = new QLabel(tr("Rotate (360 deg)"));
82  QLabel *labelView = new QLabel(tr("Left/right (+/- 60 deg)"));
83  mRotateDial = new QDial;
84  mRotateDial->setMinimum(-180);
85  mRotateDial->setMaximum(180);
86  mViewDial = new QDial;
87  mViewDial->setMinimum(-60);
88  mViewDial->setMaximum(60);
89  mResetEndoscopeButton = new QPushButton("Reset");
90 
91 
92  endoscopeControlLayout->addWidget(labelRot,0,0,Qt::AlignHCenter);
93  endoscopeControlLayout->addWidget(labelView,0,2,Qt::AlignHCenter);
94  endoscopeControlLayout->addWidget(mRotateDial,1,0);
95  endoscopeControlLayout->addWidget(mViewDial,1,2);
96  endoscopeControlLayout->addWidget(mResetEndoscopeButton,2,0);
97  endoscopeBox->setLayout(endoscopeControlLayout);
98  mVerticalLayout->addWidget(endoscopeBox);
99 
100  this->setLayout(mVerticalLayout);
101 
102 
103  this->enableControls(false);
104 
105  mCameraPath = new CXVBcameraPath(services->tracking(), services->patient(), services->view());
106 
108  this, &VBWidget::inputChangedSlot, Qt::UniqueConnection);
110  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
111  connect(mViewDial, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraViewAngleSlot);
112  connect(mRotateDial, &QDial::valueChanged, mCameraPath, &CXVBcameraPath::cameraRotateAngleSlot);
113  connect(mResetEndoscopeButton, &QPushButton::clicked, this, &VBWidget::resetEndoscopeSlot);
114 
115  mVerticalLayout->addStretch();
116 }
117 
119 {
120 }
121 
122 void VBWidget::setRouteToTarget(QString uid)
123 {
124  disconnect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged, this, &VBWidget::inputChangedSlot);
125  mRouteToTarget->setValue("");
126  connect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged, this, &VBWidget::inputChangedSlot, Qt::UniqueConnection);
127  mRouteToTarget->setValue(uid);
128 
129  disconnect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
130  mPlaybackSlider->setValue(1);
131  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot, Qt::UniqueConnection);
132  mPlaybackSlider->setValue(5);
133 }
134 
135 void VBWidget::enableControls(bool enable)
136 {
137  mPlaybackSlider->setEnabled(enable);
138  mRotateDial->setEnabled(enable);
139  mViewDial->setEnabled(enable);
140  mControlsEnabled = enable;
141 }
142 
143 void VBWidget::inputChangedSlot()
144 {
145  this->enableControls(true);
146  emit cameraPathChanged(mRouteToTarget->getMesh());
147 }
148 
149 void VBWidget::keyPressEvent(QKeyEvent* event)
150 {
151  if (event->key()==Qt::Key_Up || event->key()==Qt::Key_8)
152  {
153  if(mControlsEnabled) {
154  int currentPos = mPlaybackSlider->value();
155  mPlaybackSlider->setValue(currentPos+1);
156  return;
157  }
158  }
159 
160  if (event->key()==Qt::Key_Down || event->key()==Qt::Key_2)
161  {
162  if(mControlsEnabled) {
163  int currentPos = mPlaybackSlider->value();
164  mPlaybackSlider->setValue(currentPos-1);
165  return;
166  }
167  }
168 
169  if (event->key()==Qt::Key_Right || event->key()==Qt::Key_6)
170  {
171  if(mControlsEnabled) {
172  int currentPos = mRotateDial->value();
173  mRotateDial->setValue(currentPos+1);
174  return;
175  }
176  }
177 
178  if (event->key()==Qt::Key_Left || event->key()==Qt::Key_4)
179  {
180  if(mControlsEnabled) {
181  int currentPos = mRotateDial->value();
182  mRotateDial->setValue(currentPos-1);
183  return;
184  }
185  }
186 
187  if (event->key()==Qt::Key_PageUp || event->key()==Qt::Key_9)
188  {
189  if(mControlsEnabled) {
190  int currentPos = mViewDial->value();
191  mViewDial->setValue(currentPos+1);
192  return;
193  }
194  }
195 
196  if (event->key()==Qt::Key_PageDown || event->key()==Qt::Key_3)
197  {
198  if(mControlsEnabled) {
199  int currentPos = mViewDial->value();
200  mViewDial->setValue(currentPos-1);
201  return;
202  }
203  }
204 
205  if (event->key()==Qt::Key_5)
206  {
207  if(mControlsEnabled) {
208  this->resetEndoscopeSlot();
209  return;
210  }
211  }
212 
213  // Forward the keyPressevent if not processed
214  QWidget::keyPressEvent(event);
215 }
216 
217 void VBWidget::resetEndoscopeSlot()
218 {
219  mRotateDial->setValue(0);
220  mViewDial->setValue(0);
221 }
222 
224 {
225  return "<html>"
226  "<h3>Virtual Bronchoscopy.</h3>"
227  "<p>GUI for visualizing a route-to-target path</p>"
228  "</html>";
229 }
230 
231 
232 
233 } /* namespace cx */
virtual ~VBWidget()
Definition: cxVBWidget.cpp:118
void cameraRawPointsSlot(MeshPtr mesh)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Helper class for storing variables in the patient file.
VBWidget(VisServicesPtr services, QWidget *parent=0)
Definition: cxVBWidget.cpp:39
QDial * mViewDial
Definition: cxVBWidget.h:57
PatientStoragePtr mStorage
Definition: cxVBWidget.h:66
void cameraRotateAngleSlot(int angle)
StringPropertySelectMeshPtr mRouteToTarget
Definition: cxVBWidget.h:60
virtual QString getValue() const
get the data value.
virtual void keyPressEvent(QKeyEvent *event)
Definition: cxVBWidget.cpp:149
QDial * mRotateDial
Definition: cxVBWidget.h:56
void setRouteToTarget(QString uid)
Definition: cxVBWidget.cpp:122
bool mControlsEnabled
Definition: cxVBWidget.h:62
QSlider * mPlaybackSlider
Definition: cxVBWidget.h:55
void cameraViewAngleSlot(int angle)
QString defaultWhatsThis() const
Definition: cxVBWidget.cpp:223
QVBoxLayout * mVerticalLayout
Definition: cxVBWidget.h:54
void enableControls(bool enable)
Definition: cxVBWidget.cpp:135
CXVBcameraPath * mCameraPath
Definition: cxVBWidget.h:61
void cameraPathPositionSlot(int pos)
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
QPushButton * mResetEndoscopeButton
Definition: cxVBWidget.h:58
virtual bool setValue(const QString &value)
set the data value.
void cameraPathChanged(MeshPtr pathMesh)
Namespace for all CustusX production code.