Fraxinus  17.12-rc4
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include <QLabel>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QGroupBox>
37 #include <QSlider>
38 #include <QSpinBox>
39 #include <QGridLayout>
40 #include <QLabel>
41 #include <QDial>
42 #include <QPushButton>
43 
44 #include "cxVBWidget.h"
46 #include "cxViewServiceProxy.h"
47 #include "cxDataSelectWidget.h"
48 #include "cxTrackingServiceProxy.h"
49 #include "cxView.h"
51 #include "cxPatientStorage.h"
52 #include "cxVisServices.h"
53 #include "cxLogger.h"
54 
55 
56 
57 namespace cx
58 {
59 
60 VBWidget::VBWidget(VisServicesPtr services, QWidget *parent) :
61  QWidget(parent),
62  mVerticalLayout(new QVBoxLayout(this)),
63  mControlsEnabled(false),
64  mStorage(new PatientStorage(services->session(), "VirtualBronchoscopy"))
65 {
66  this->setObjectName("virtual_bronchoscopy_widget");
67  this->setWindowTitle("Virtual Bronchoscopy");
68  this->setWhatsThis(this->defaultWhatsThis());
69 
70  this->setFocusPolicy(Qt::StrongFocus); // Widget needs focus to handle Key events
71 
72  mRouteToTarget = StringPropertySelectMesh::New(services->patient());
73  mRouteToTarget->setValueName("Route to target path: ");
74  mStorage->storeVariable("routeToTarget",
77 
78  // Selector for route to target
79  QVBoxLayout *inputVbox = new QVBoxLayout;
80  inputVbox->addWidget(new DataSelectWidget(services->view(), services->patient(), this,mRouteToTarget));
81  QGroupBox *inputBox = new QGroupBox(tr("Input"));
82  inputBox->setLayout(inputVbox);
83  mVerticalLayout->addWidget(inputBox);
84 
85  // Selectors for position along path and play/pause
86  QHBoxLayout *playbackHBox = new QHBoxLayout;
87  QGroupBox *playbackBox = new QGroupBox(tr("Playback"));
88  mPlaybackSlider = new QSlider(Qt::Horizontal);
89  QLabel *labelStart = new QLabel(tr("Start "));
90  QLabel *labelTarget = new QLabel(tr(" Target"));
91  playbackHBox->addWidget(labelStart);
92  playbackHBox->addWidget(mPlaybackSlider);
93  playbackHBox->addWidget(labelTarget);
94  playbackBox->setLayout(playbackHBox);
95  mVerticalLayout->addWidget(playbackBox);
96  mPlaybackSlider->setMinimum(0);
97  mPlaybackSlider->setMaximum(100);
98 
99  // Selectors for virtual endoscope control
100  QGroupBox *endoscopeBox = new QGroupBox(tr("Bronchoscope"));
101  QGridLayout *endoscopeControlLayout = new QGridLayout;
102  QLabel *labelRot = new QLabel(tr("Rotate (360 deg)"));
103  QLabel *labelView = new QLabel(tr("Left/right (+/- 60 deg)"));
104  mRotateDial = new QDial;
105  mRotateDial->setMinimum(-180);
106  mRotateDial->setMaximum(180);
107  mViewDial = new QDial;
108  mViewDial->setMinimum(-60);
109  mViewDial->setMaximum(60);
110  mResetEndoscopeButton = new QPushButton("Reset");
111 
112 
113  endoscopeControlLayout->addWidget(labelRot,0,0,Qt::AlignHCenter);
114  endoscopeControlLayout->addWidget(labelView,0,2,Qt::AlignHCenter);
115  endoscopeControlLayout->addWidget(mRotateDial,1,0);
116  endoscopeControlLayout->addWidget(mViewDial,1,2);
117  endoscopeControlLayout->addWidget(mResetEndoscopeButton,2,0);
118  endoscopeBox->setLayout(endoscopeControlLayout);
119  mVerticalLayout->addWidget(endoscopeBox);
120 
121  this->setLayout(mVerticalLayout);
122 
123 
124  this->enableControls(false);
125 
126  mCameraPath = new CXVBcameraPath(services->tracking(), services->patient(), services->view());
127 
129  this, &VBWidget::inputChangedSlot, Qt::UniqueConnection);
131  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
132  connect(mViewDial, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraViewAngleSlot);
133  connect(mRotateDial, &QDial::valueChanged, mCameraPath, &CXVBcameraPath::cameraRotateAngleSlot);
134  connect(mResetEndoscopeButton, &QPushButton::clicked, this, &VBWidget::resetEndoscopeSlot);
135 
136  mVerticalLayout->addStretch();
137 }
138 
140 {
141 }
142 
143 void VBWidget::setRouteToTarget(QString uid)
144 {
145  disconnect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged, this, &VBWidget::inputChangedSlot);
146  mRouteToTarget->setValue("");
147  connect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged, this, &VBWidget::inputChangedSlot, Qt::UniqueConnection);
148  mRouteToTarget->setValue(uid);
149 
150  disconnect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
151  mPlaybackSlider->setValue(1);
152  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot, Qt::UniqueConnection);
153  mPlaybackSlider->setValue(5);
154 }
155 
156 void VBWidget::enableControls(bool enable)
157 {
158  mPlaybackSlider->setEnabled(enable);
159  mRotateDial->setEnabled(enable);
160  mViewDial->setEnabled(enable);
161  mControlsEnabled = enable;
162 }
163 
164 void VBWidget::inputChangedSlot()
165 {
166  this->enableControls(true);
167  emit cameraPathChanged(mRouteToTarget->getMesh());
168 }
169 
170 void VBWidget::keyPressEvent(QKeyEvent* event)
171 {
172  if (event->key()==Qt::Key_Up || event->key()==Qt::Key_8)
173  {
174  if(mControlsEnabled) {
175  int currentPos = mPlaybackSlider->value();
176  mPlaybackSlider->setValue(currentPos+1);
177  return;
178  }
179  }
180 
181  if (event->key()==Qt::Key_Down || event->key()==Qt::Key_2)
182  {
183  if(mControlsEnabled) {
184  int currentPos = mPlaybackSlider->value();
185  mPlaybackSlider->setValue(currentPos-1);
186  return;
187  }
188  }
189 
190  if (event->key()==Qt::Key_Right || event->key()==Qt::Key_6)
191  {
192  if(mControlsEnabled) {
193  int currentPos = mRotateDial->value();
194  mRotateDial->setValue(currentPos+1);
195  return;
196  }
197  }
198 
199  if (event->key()==Qt::Key_Left || event->key()==Qt::Key_4)
200  {
201  if(mControlsEnabled) {
202  int currentPos = mRotateDial->value();
203  mRotateDial->setValue(currentPos-1);
204  return;
205  }
206  }
207 
208  if (event->key()==Qt::Key_PageUp || event->key()==Qt::Key_9)
209  {
210  if(mControlsEnabled) {
211  int currentPos = mViewDial->value();
212  mViewDial->setValue(currentPos+1);
213  return;
214  }
215  }
216 
217  if (event->key()==Qt::Key_PageDown || event->key()==Qt::Key_3)
218  {
219  if(mControlsEnabled) {
220  int currentPos = mViewDial->value();
221  mViewDial->setValue(currentPos-1);
222  return;
223  }
224  }
225 
226  if (event->key()==Qt::Key_5)
227  {
228  if(mControlsEnabled) {
229  this->resetEndoscopeSlot();
230  return;
231  }
232  }
233 
234  // Forward the keyPressevent if not processed
235  QWidget::keyPressEvent(event);
236 }
237 
238 void VBWidget::resetEndoscopeSlot()
239 {
240  mRotateDial->setValue(0);
241  mViewDial->setValue(0);
242 }
243 
245 {
246  return "<html>"
247  "<h3>Virtual Bronchoscopy.</h3>"
248  "<p>GUI for visualizing a route-to-target path</p>"
249  "</html>";
250 }
251 
252 
253 
254 } /* namespace cx */
virtual ~VBWidget()
Definition: cxVBWidget.cpp:139
void cameraRawPointsSlot(MeshPtr mesh)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
Helper class for storing variables in the patient file.
VBWidget(VisServicesPtr services, QWidget *parent=0)
Definition: cxVBWidget.cpp:60
QDial * mViewDial
Definition: cxVBWidget.h:78
PatientStoragePtr mStorage
Definition: cxVBWidget.h:87
void cameraRotateAngleSlot(int angle)
StringPropertySelectMeshPtr mRouteToTarget
Definition: cxVBWidget.h:81
virtual QString getValue() const
get the data value.
virtual void keyPressEvent(QKeyEvent *event)
Definition: cxVBWidget.cpp:170
QDial * mRotateDial
Definition: cxVBWidget.h:77
void setRouteToTarget(QString uid)
Definition: cxVBWidget.cpp:143
bool mControlsEnabled
Definition: cxVBWidget.h:83
QSlider * mPlaybackSlider
Definition: cxVBWidget.h:76
void cameraViewAngleSlot(int angle)
QString defaultWhatsThis() const
Definition: cxVBWidget.cpp:244
QVBoxLayout * mVerticalLayout
Definition: cxVBWidget.h:75
void enableControls(bool enable)
Definition: cxVBWidget.cpp:156
CXVBcameraPath * mCameraPath
Definition: cxVBWidget.h:82
void cameraPathPositionSlot(int pos)
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
QPushButton * mResetEndoscopeButton
Definition: cxVBWidget.h:79
virtual bool setValue(const QString &value)
set the data value.
void cameraPathChanged(MeshPtr pathMesh)
Namespace for all CustusX production code.