CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxClippingWidget.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 #include "cxClippingWidget.h"
33 
34 #include <QVBoxLayout>
35 #include <QPushButton>
36 #include <QCheckBox>
37 #include <QGroupBox>
38 #include "cxStringPropertyBase.h"
40 #include "cxDefinitionStrings.h"
41 #include "cxInteractiveClipper.h"
43 #include "cxImage.h"
44 #include "cxLegacySingletons.h"
45 #include "cxPatientModelService.h"
46 #include "cxLogicManager.h"
47 #include "cxViewService.h"
48 
49 namespace cx
50 {
51 
53  mInteractiveClipper(clipper)
54 {
55  connect(mInteractiveClipper.get(), SIGNAL(changed()), this, SIGNAL(changed()));
56 }
57 
59 {
60  return "Slice Plane";
61 }
62 bool StringPropertyClipPlane::setValue(const QString& value)
63 {
64  PLANE_TYPE plane = string2enum<PLANE_TYPE> (value);
65  if (plane == mInteractiveClipper->getSlicePlane())
66  return false;
67  mInteractiveClipper->setSlicePlane(plane);
68  return true;
69 }
71 {
72  return qstring_cast(mInteractiveClipper->getSlicePlane());
73 }
75 {
76  return "Chose the slice plane to clip with.";
77 }
79 {
80  std::vector<PLANE_TYPE> planes = mInteractiveClipper->getAvailableSlicePlanes();
81  QStringList retval;
82  //retval << ""; // removed this. No idea why we need an empty entry.
83  for (unsigned i = 0; i < planes.size(); ++i)
84  retval << qstring_cast(planes[i]);
85  return retval;
86 }
87 
91 
92 ClippingWidget::ClippingWidget(PatientModelServicePtr patientModelService, QWidget* parent) :
93  BaseWidget(parent, "ClippingWidget", "Clip"),
94  mPatientModelService(patientModelService)
95 {
96  connect(viewService().get(), &ViewService::activeLayoutChanged, this, &ClippingWidget::setupUI);
97  this->setupUI();
98 }
99 
100 void ClippingWidget::setupUI()
101 {
102  if (mInteractiveClipper)
103  return;
104 
105  mInteractiveClipper = viewService()->getClipper();
106 
107  if (!mInteractiveClipper)
108  return;
109 
110  connect(mInteractiveClipper.get(), SIGNAL(changed()), this, SLOT(clipperChangedSlot()));
111 
112  mImageAdapter = StringPropertySelectImage::New(mPatientModelService);
113  LabeledComboBoxWidget* imageCombo = new LabeledComboBoxWidget(this, mImageAdapter);
114  connect(mImageAdapter.get(), SIGNAL(changed()), this, SLOT(imageChangedSlot()));
115 
116  this->setToolTip("Interactive volume clipping");
117 
118  QVBoxLayout* layout = new QVBoxLayout(this);
119 
120  QGroupBox* activeClipGroupBox = new QGroupBox("Interactive clipper");
121  activeClipGroupBox->setToolTip(this->toolTip());
122  layout->addWidget(activeClipGroupBox);
123  QVBoxLayout* activeClipLayout = new QVBoxLayout(activeClipGroupBox);
124 
125  mPlaneAdapter = StringPropertyClipPlane::New(mInteractiveClipper);
126  LabeledComboBoxWidget* combo = new LabeledComboBoxWidget(this, mPlaneAdapter);
127 
128  mUseClipperCheckBox = new QCheckBox("Use Clipper");
129  mUseClipperCheckBox->setToolTip("Turn on interactive clipping for the selected volume.");
130  connect(mUseClipperCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(useClipper(bool)));
131  activeClipLayout->addWidget(mUseClipperCheckBox);
132  activeClipLayout->addWidget(imageCombo);
133  activeClipLayout->addWidget(combo);
134  mInvertPlaneCheckBox = new QCheckBox("Invert plane");
135  mInvertPlaneCheckBox->setToolTip("Use the inverse (mirror) of the selected slice plane.");
136  connect(mInvertPlaneCheckBox, SIGNAL(toggled(bool)), mInteractiveClipper.get(), SLOT(invertPlane(bool)));
137  activeClipLayout->addWidget(mInvertPlaneCheckBox);
138 
139  QPushButton* saveButton = new QPushButton("Save clip plane");
140  saveButton->setToolTip("Save the interactive plane as a clip plane in the selected volume.");
141  connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButtonClickedSlot()));
142  //saveButton->setEnabled(false);
143  QPushButton* clearButton = new QPushButton("Clear saved planes");
144  clearButton->setToolTip("Remove all saved clip planes from the selected volume");
145  connect(clearButton, SIGNAL(clicked()), this, SLOT(clearButtonClickedSlot()));
146  //clearButton->setEnabled(false);
147  activeClipLayout->addWidget(saveButton);
148  layout->addWidget(clearButton);
149 
150  layout->addStretch();
151 
152  this->clipperChangedSlot();
153 }
154 
155 void ClippingWidget::clipperChangedSlot()
156 {
157  mUseClipperCheckBox->setChecked(mInteractiveClipper->getUseClipper());
158  mInvertPlaneCheckBox->setChecked(mInteractiveClipper->getInvertPlane());
159  if (mInteractiveClipper->getImage())
160  mImageAdapter->setValue(mInteractiveClipper->getImage()->getUid());
161 }
162 
163 void ClippingWidget::imageChangedSlot()
164 {
165  mInteractiveClipper->setImage(mPatientModelService->getData<Image>(mImageAdapter->getValue()));
166 }
167 
168 void ClippingWidget::clearButtonClickedSlot()
169 {
170  mInteractiveClipper->clearClipPlanesInVolume();
171 }
172 
173 void ClippingWidget::saveButtonClickedSlot()
174 {
175  mInteractiveClipper->saveClipPlaneToVolume();
176 }
177 
178 }
QString qstring_cast(const T &val)
virtual QString getValue() const
get the data value.
static StringPropertyBasePtr New(InteractiveClipperPtr clipper)
void activeLayoutChanged()
emitted when the active layout changes
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual QStringList getValueRange() const
Composite widget for string selection.
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
InteractiveClipperPtr mInteractiveClipper
StringPropertyClipPlane(InteractiveClipperPtr clipper)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
ClippingWidget(cx::PatientModelServicePtr patientModelService, QWidget *parent)
cxLogicManager_EXPORT ViewServicePtr viewService()
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
virtual bool setValue(const QString &value)
set the data value.