NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxClipperWidget.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 "boost/bind.hpp"
13 #include <QListWidget>
14 #include <QTableWidget>
15 #include <QGroupBox>
16 #include "cxClipperWidget.h"
19 #include "cxInteractiveClipper.h"
20 #include "cxVisServices.h"
21 #include "cxPatientModelService.h"
22 #include "cxImage.h"
23 #include "cxMesh.h"
24 #include "cxTrackedStream.h"
25 #include "cxLogger.h"
28 #include "cxTrackingService.h"
29 
30 namespace cx
31 {
32 
33 ClipperWidget::ClipperWidget(VisServicesPtr services, QWidget* parent) :
34  BaseWidget(parent, "ClipperWidget", "Clipper"),
35  mServices(services),
36  mInitializedWithClipper(false)
37 // planeSelector(NULL)
38 {
39  this->setEnabled(false);
40  this->setupDataStructures();
42 
44 }
45 
47 {
48  disconnect(mSelectAllData, &QCheckBox::clicked, this, &ClipperWidget::selectAllTableData);
49  disconnect(mShowImages, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
50  connect(mShowMeshes, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
51  connect(mShowMetrics, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
52  connect(mShowTrackedStreams, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
53  connect(mUseClipperCheckBox, &QCheckBox::toggled, this, &ClipperWidget::enable);
55 
57 }
58 
60 {
61  mLayout = new QVBoxLayout(this);
62  mUseClipperCheckBox = new QCheckBox("Enable");
63  mUseClipperCheckBox->setToolTip("Enable/disable interactive clipper.");
64  mUseClipperCheckBox->setChecked(true);
65 
66  mAttachedToTool = new QCheckBox("Attach to tool");
67  mAttachedToTool->setChecked(true);
68  mSelectAllData = new QCheckBox("Select all");
69  mInvertPlane = new QCheckBox("Invert plane");
70 
71  mShowImages = new QCheckBox("Images");
72  mShowMeshes = new QCheckBox("Meshes");
73  mShowMetrics = new QCheckBox("Metrics");
74  mShowTrackedStreams = new QCheckBox("TrackedStreams");
75  mShowImages->setChecked(true);
76  mShowMeshes->setChecked(true);
77 
79  mToolSelector->setValueName("Tool");
80  mToolSelector->provideActiveTool(true);
81  mToolSelector->setActiveTool();
82 
83  connect(mSelectAllData, &QCheckBox::clicked, this, &ClipperWidget::selectAllTableData);
84 
85  connect(mShowImages, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
86  connect(mShowMeshes, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
87  connect(mShowMetrics, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
88  connect(mShowTrackedStreams, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
89 
90  connect(mUseClipperCheckBox, &QCheckBox::toggled, this, &ClipperWidget::enable);
92  connect(mAttachedToTool, &QCheckBox::toggled, this, &ClipperWidget::onToolChanged);
94 
95  mDataTableWidget = new QTableWidget(this);
96 }
97 
99 {
101  return;
103 
104  mLayout->addLayout(this->planeLayout());
105  mLayout->addLayout(this->toolLayout());
106  mLayout->addWidget(this->dataTableWidget());
107  mLayout->addWidget(mUseClipperCheckBox);
108 
109  mLayout->addStretch();
110 
111  if(mClipper)
112  connect(mUseClipperCheckBox, &QCheckBox::toggled, this, &ClipperWidget::enable);
113 
114 }
115 
116 void ClipperWidget::enable(bool checked)
117 {
118  if(!mClipper)
119  return;
120  mClipper->useClipper(checked);
121 }
122 
124 {
125 // mPlaneAdapter = StringPropertyClipPlane::New(mClipper);
126 // planeSelector = new LabeledComboBoxWidget(this, mPlaneAdapter);
127 
128  QHBoxLayout *layout = new QHBoxLayout();
129 
130 // layout->addWidget(planeSelector);
131  layout->addWidget(mInvertPlane);
132  return layout;
133 }
134 
135 
137 {
138  LabeledComboBoxWidget* toolSelectorWidget = new LabeledComboBoxWidget(this, mToolSelector);
139 
140  QHBoxLayout *layout = new QHBoxLayout();
141  layout->addWidget(toolSelectorWidget);
142  layout->addWidget(mAttachedToTool);
143  return layout;
144 }
145 
146 
148 {
149  QGroupBox *groupBox = new QGroupBox("Structures to clip");
150  QVBoxLayout *layout = new QVBoxLayout();
151  QHBoxLayout *selectCheckBoxes = new QHBoxLayout();
152 
153  selectCheckBoxes->addWidget(mShowImages);
154  selectCheckBoxes->addWidget(mShowMeshes);
155  selectCheckBoxes->addWidget(mShowTrackedStreams);
156  selectCheckBoxes->addWidget(mShowMetrics);
157 
158  layout->addLayout(selectCheckBoxes);
159 
160  layout->addWidget(mDataTableWidget);
161  layout->addWidget(mSelectAllData);
162 
163  groupBox->setLayout(layout);
164 
165  return groupBox;
166 }
167 
169 {
170  if(mClipper)
171  {
172  mUseClipperCheckBox->setChecked(mClipper->getUseClipper());
173  mInvertPlane->setChecked(mClipper->getInvertPlane());
174  connect(mInvertPlane, &QCheckBox::toggled, mClipper.get(), &InteractiveClipper::invertPlane);
175 // if(planeSelector)
176 // {
177 // mPlaneAdapter->setClipper(mClipper);
178 // planeSelector->setModified();
179 // }
180  this->setEnabled(true);
181  this->setupUI();
182  this->setupDataSelectorUI();
183  }
184  else
185  this->setEnabled(false);
186 
187 }
188 
190 {
191  if(!mClipper)
192  return;
193  ToolPtr tool = mToolSelector->getTool();
194  if(!tool)
195  {
196  mClipper->useActiveTool(true);
197  tool = mServices->tracking()->getActiveTool();
198  }
199  else
200  mClipper->useActiveTool(false);
201  if(mAttachedToTool->isChecked())
202  mClipper->setTool(tool);
203  else
204  mClipper->setTool(ToolPtr());
205 }
206 
208 {
209  if(mClipper)
210  {
211  disconnect(mInvertPlane, &QCheckBox::toggled, mClipper.get(), &InteractiveClipper::invertPlane);
212  }
213 
214  mClipper = clipper;
215 
216  this->connectToNewClipper();
217 }
218 
220 {
221  if(this->getDatas().size() == mClipper->getDatas().size())
222  mSelectAllData->setChecked(true);
223  else
224  mSelectAllData->setChecked(false);
225 }
226 
227 void ClipperWidget::updateCheckBoxFromClipper(QCheckBox *checkbox, DataPtr data)
228 {
229  if(!mClipper)
230  return;
231  std::map<QString, DataPtr> datas = mClipper->getDatas();
232  bool checked = datas.count(data->getUid());
233  checkbox->setChecked(checked);
234 }
235 
237 {
238  std::map<QString, DataPtr> datas = this->getDatas();
239  std::map<QString, DataPtr>::iterator iter = datas.begin();
240 
241  int row = 0;
242 
243  for(; iter != datas.end(); ++iter)
244  {
245  DataPtr data = iter->second;
246  QCheckBox *checkbox = new QCheckBox();
247  checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
248  mDataTableWidget->setCellWidget(row, 0, checkbox);
249 
250  QTableWidgetItem *descriptionItem = new QTableWidgetItem(data->getName());
251  mDataTableWidget->setItem(row++, 1, descriptionItem);
252 
253  boost::function<void()> func = boost::bind(&ClipperWidget::dataSelectorClicked, this, checkbox, data);
254  connect(checkbox, &QCheckBox::clicked, this, func);
255  this->updateCheckBoxFromClipper(checkbox, data);
256  }
257 }
258 
260 {
261  if(!mClipper)
262  {
263  this->setEnabled(false);
264  return;
265  }
266 
267  std::map<QString, DataPtr> datas = this->getDatas();
268 
269  mDataTableWidget->setColumnCount(2);
270  mDataTableWidget->setRowCount(datas.size());
271 
272  QStringList horizontalHeaders;
273  horizontalHeaders << "Apply clipper" << "Object to be clipped";
274  mDataTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
275  mDataTableWidget->setColumnWidth(1, 300);
276 // mDataTableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);//test
277 
280 }
281 
283 {
284  QStringList dataTypes;
285  if(mShowImages->isChecked())
286  dataTypes << Image::getTypeName();
287  if(mShowMeshes->isChecked())
288  dataTypes << Mesh::getTypeName();
289  if(mShowTrackedStreams->isChecked())
290  dataTypes << TrackedStream::getTypeName();
291  if(mShowMetrics->isChecked())
292  dataTypes << ".*Metric$";
293  QString typeRegExp = dataTypes.join('|');
294 
295  return typeRegExp;
296 }
297 
298 std::map<QString, DataPtr> ClipperWidget::getDatas()
299 {
300  //TODO: Move SelectDataStringPropertyBase::filterOnType() to a utility file?
301  std::map<QString, DataPtr> datas = mServices->patient()->getDatas();
303  return datas;
304 }
305 
306 void ClipperWidget::dataSelectorClicked(QCheckBox *checkBox, DataPtr data)
307 {
308  bool checked = checkBox->isChecked();
309 
310  if(checked)
311  mClipper->addData(data);
312  else
313  mClipper->removeData(data);
314 }
315 
317 {
318  std::map<QString, DataPtr> datas = this->getDatas();
319  std::map<QString, DataPtr>::iterator iter = datas.begin();
320 
321  for(; iter != datas.end(); ++iter)
322  {
323  DataPtr data = iter->second;
324  if(checked)
325  mClipper->addData(data);
326  else
327  mClipper->removeData(data);
328  }
329  this->setModified();
330 }
331 
333 {
334  this->setModified();
335 }
336 
338 {
339  this->setupDataSelectorUI();
340 }
341 
342 }//cx
cx::LabeledComboBoxWidget
Composite widget for string selection.
Definition: cxLabeledComboBoxWidget.h:36
cx::ClipperWidget::mInitializedWithClipper
bool mInitializedWithClipper
Definition: cxClipperWidget.h:69
cx::ClipperWidget::mUseClipperCheckBox
QCheckBox * mUseClipperCheckBox
Definition: cxClipperWidget.h:55
cx::ClipperWidget::setClipper
void setClipper(InteractiveClipperPtr clipper)
Definition: cxClipperWidget.cpp:207
cxLogger.h
cx::ClipperWidget::createNewCheckboxesBasedOnData
void createNewCheckboxesBasedOnData()
Definition: cxClipperWidget.cpp:236
cxClipperWidget.h
cx::ClipperWidget::mToolSelector
StringPropertySelectToolPtr mToolSelector
Definition: cxClipperWidget.h:70
cx::ClipperWidget::~ClipperWidget
~ClipperWidget()
Definition: cxClipperWidget.cpp:46
cx::ClipperWidget::mShowMetrics
QCheckBox * mShowMetrics
Definition: cxClipperWidget.h:62
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
cx::InteractiveClipper::invertPlane
void invertPlane(bool on)
Definition: cxInteractiveClipper.cpp:146
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cxImage.h
cx::ClipperWidget::toolLayout
QLayout * toolLayout()
Definition: cxClipperWidget.cpp:136
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cxSelectDataStringPropertyBase.h
cx::ClipperWidget::mShowMeshes
QCheckBox * mShowMeshes
Definition: cxClipperWidget.h:61
cx::ClipperWidget::mDataTableWidget
QTableWidget * mDataTableWidget
Definition: cxClipperWidget.h:67
cx::ClipperWidget::planeLayout
QLayout * planeLayout()
Definition: cxClipperWidget.cpp:123
cx::ClipperWidget::mLayout
QVBoxLayout * mLayout
Definition: cxClipperWidget.h:54
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cxLabeledComboBoxWidget.h
cx::ClipperWidget::mClipper
InteractiveClipperPtr mClipper
Definition: cxClipperWidget.h:51
cx::TrackedStream::getTypeName
static QString getTypeName()
Definition: cxTrackedStream.cpp:160
cxInteractiveClipper.h
cxStringPropertySelectTool.h
cx::Mesh::getTypeName
static QString getTypeName()
Definition: cxMesh.h:67
cx::PatientModelService::dataAddedOrRemoved
void dataAddedOrRemoved()
cx::ClipperWidget::onToolChanged
void onToolChanged()
Definition: cxClipperWidget.cpp:189
cx::Image::getTypeName
static QString getTypeName()
Definition: cxImage.h:126
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::ClipperWidget::mServices
VisServicesPtr mServices
Definition: cxClipperWidget.h:65
cxPatientModelService.h
cx::ClipperWidget::dataTypeSelectorClicked
void dataTypeSelectorClicked(bool checked)
Definition: cxClipperWidget.cpp:332
cx::TrackingService::activeToolChanged
void activeToolChanged(const QString &uId)
cx::ClipperWidget::ClipperWidget
ClipperWidget(VisServicesPtr services, QWidget *parent)
Definition: cxClipperWidget.cpp:33
cx::ClipperWidget::dataTableWidget
QGroupBox * dataTableWidget()
Definition: cxClipperWidget.cpp:147
cx::ClipperWidget::updateSelectAllCheckbox
void updateSelectAllCheckbox()
Definition: cxClipperWidget.cpp:219
cx::SelectDataStringPropertyBase::filterOnType
static std::map< QString, DataPtr > filterOnType(std::map< QString, DataPtr > input, QString regexp)
Definition: cxSelectDataStringPropertyBase.cpp:35
cx::ClipperWidget::mInvertPlane
QCheckBox * mInvertPlane
Definition: cxClipperWidget.h:58
cx::ClipperWidget::getDatas
std::map< QString, DataPtr > getDatas()
Definition: cxClipperWidget.cpp:298
cx::ClipperWidget::mShowImages
QCheckBox * mShowImages
Definition: cxClipperWidget.h:60
cx::ClipperWidget::dataSelectorClicked
void dataSelectorClicked(QCheckBox *checkBox, DataPtr data)
Definition: cxClipperWidget.cpp:306
cx::ClipperWidget::mShowTrackedStreams
QCheckBox * mShowTrackedStreams
Definition: cxClipperWidget.h:63
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::InteractiveClipperPtr
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
Definition: cxForwardDeclarations.h:157
cxStringPropertyClipPlane.h
cx::ClipperWidget::prePaintEvent
virtual void prePaintEvent()
Definition: cxClipperWidget.cpp:337
cx::StringPropertySelectTool::New
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
Definition: cxStringPropertySelectTool.h:40
cx::ClipperWidget::getDataTypeRegExp
QString getDataTypeRegExp()
Definition: cxClipperWidget.cpp:282
cx::ClipperWidget::mSelectAllData
QCheckBox * mSelectAllData
Definition: cxClipperWidget.h:57
cx::ClipperWidget::connectToNewClipper
void connectToNewClipper()
Definition: cxClipperWidget.cpp:168
cx::ClipperWidget::mAttachedToTool
QCheckBox * mAttachedToTool
Definition: cxClipperWidget.h:56
cx::ClipperWidget::enable
void enable(bool checked)
Definition: cxClipperWidget.cpp:116
cx::ClipperWidget::setupDataSelectorUI
void setupDataSelectorUI()
Definition: cxClipperWidget.cpp:259
cxMesh.h
cx::ClipperWidget::setupUI
void setupUI()
Definition: cxClipperWidget.cpp:98
cxTrackingService.h
cx::ClipperWidget::selectAllTableData
void selectAllTableData(bool checked)
Definition: cxClipperWidget.cpp:316
cxTrackedStream.h
cx::ClipperWidget::setupDataStructures
void setupDataStructures()
Definition: cxClipperWidget.cpp:59
cxVisServices.h