Fraxinus  22.09
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
void createNewCheckboxesBasedOnData()
QCheckBox * mShowMeshes
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
virtual void prePaintEvent()
QCheckBox * mShowMetrics
ClipperWidget(VisServicesPtr services, QWidget *parent)
std::map< QString, DataPtr > getDatas()
void setClipper(InteractiveClipperPtr clipper)
Composite widget for string selection.
QCheckBox * mShowTrackedStreams
QGroupBox * dataTableWidget()
QCheckBox * mUseClipperCheckBox
static std::map< QString, DataPtr > filterOnType(std::map< QString, DataPtr > input, QString regexp)
boost::shared_ptr< class Data > DataPtr
VisServicesPtr mServices
void activeToolChanged(const QString &uId)
void dataTypeSelectorClicked(bool checked)
static QString getTypeName()
Definition: cxImage.h:126
void dataSelectorClicked(QCheckBox *checkBox, DataPtr data)
InteractiveClipperPtr mClipper
QCheckBox * mAttachedToTool
void selectAllTableData(bool checked)
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:88
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
QTableWidget * mDataTableWidget
QVBoxLayout * mLayout
static QString getTypeName()
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
QCheckBox * mInvertPlane
static QString getTypeName()
Definition: cxMesh.h:67
StringPropertySelectToolPtr mToolSelector
void enable(bool checked)
QCheckBox * mShowImages
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
QCheckBox * mSelectAllData