Fraxinus  18.10
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 "cxLogger.h"
27 #include "cxTrackingService.h"
28 
29 namespace cx
30 {
31 
32 ClipperWidget::ClipperWidget(VisServicesPtr services, QWidget* parent) :
33  BaseWidget(parent, "ClipperWidget", "Clipper"),
34  mServices(services),
35  mInitializedWithClipper(false)
36 // planeSelector(NULL)
37 {
38  this->setEnabled(false);
39  this->setupDataStructures();
41 
43 }
44 
46 {
47  disconnect(mSelectAllData, &QCheckBox::clicked, this, &ClipperWidget::selectAllTableData);
48  disconnect(mShowImages, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
49  connect(mShowMeshes, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
50  connect(mShowMetrics, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
51  connect(mShowTrackedStreams, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
52  connect(mUseClipperCheckBox, &QCheckBox::toggled, this, &ClipperWidget::enable);
54 
56 }
57 
59 {
60  mLayout = new QVBoxLayout(this);
61  mUseClipperCheckBox = new QCheckBox("Enable");
62  mUseClipperCheckBox->setToolTip("Enable/disable interactive clipper.");
63  mUseClipperCheckBox->setChecked(true);
64 
65  mAttachedToTool = new QCheckBox("Attach to tool");
66  mAttachedToTool->setChecked(true);
67  mSelectAllData = new QCheckBox("Select all");
68  mInvertPlane = new QCheckBox("Invert plane");
69 
70  mShowImages = new QCheckBox("Images");
71  mShowMeshes = new QCheckBox("Meshes");
72  mShowMetrics = new QCheckBox("Metrics");
73  mShowTrackedStreams = new QCheckBox("TrackedStreams");
74  mShowImages->setChecked(true);
75  mShowMeshes->setChecked(true);
76 
78  mToolSelector->setValueName("Tool");
79  mToolSelector->provideActiveTool(true);
80  mToolSelector->setActiveTool();
81 
82  connect(mSelectAllData, &QCheckBox::clicked, this, &ClipperWidget::selectAllTableData);
83 
84  connect(mShowImages, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
85  connect(mShowMeshes, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
86  connect(mShowMetrics, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
87  connect(mShowTrackedStreams, &QCheckBox::clicked, this, &ClipperWidget::dataTypeSelectorClicked);
88 
89  connect(mUseClipperCheckBox, &QCheckBox::toggled, this, &ClipperWidget::enable);
91  connect(mAttachedToTool, &QCheckBox::toggled, this, &ClipperWidget::onToolChanged);
93 
94  mDataTableWidget = new QTableWidget(this);
95 }
96 
98 {
100  return;
102 
103  mLayout->addLayout(this->planeLayout());
104  mLayout->addLayout(this->toolLayout());
105  mLayout->addWidget(this->dataTableWidget());
106  mLayout->addWidget(mUseClipperCheckBox);
107 
108  mLayout->addStretch();
109 
110  if(mClipper)
111  connect(mUseClipperCheckBox, &QCheckBox::toggled, this, &ClipperWidget::enable);
112 
113 }
114 
115 void ClipperWidget::enable(bool checked)
116 {
117  if(!mClipper)
118  return;
119  mClipper->useClipper(checked);
120 }
121 
123 {
124 // mPlaneAdapter = StringPropertyClipPlane::New(mClipper);
125 // planeSelector = new LabeledComboBoxWidget(this, mPlaneAdapter);
126 
127  QHBoxLayout *layout = new QHBoxLayout();
128 
129 // layout->addWidget(planeSelector);
130  layout->addWidget(mInvertPlane);
131  return layout;
132 }
133 
134 
136 {
137  LabeledComboBoxWidget* toolSelectorWidget = new LabeledComboBoxWidget(this, mToolSelector);
138 
139  QHBoxLayout *layout = new QHBoxLayout();
140  layout->addWidget(toolSelectorWidget);
141  layout->addWidget(mAttachedToTool);
142  return layout;
143 }
144 
145 
147 {
148  QGroupBox *groupBox = new QGroupBox("Structures to clip");
149  QVBoxLayout *layout = new QVBoxLayout();
150  QHBoxLayout *selectCheckBoxes = new QHBoxLayout();
151 
152  selectCheckBoxes->addWidget(mShowImages);
153  selectCheckBoxes->addWidget(mShowMeshes);
154  selectCheckBoxes->addWidget(mShowTrackedStreams);
155  selectCheckBoxes->addWidget(mShowMetrics);
156 
157  layout->addLayout(selectCheckBoxes);
158 
159  layout->addWidget(mDataTableWidget);
160  layout->addWidget(mSelectAllData);
161 
162  groupBox->setLayout(layout);
163 
164  return groupBox;
165 }
166 
168 {
169  if(mClipper)
170  {
171  mUseClipperCheckBox->setChecked(mClipper->getUseClipper());
172  mInvertPlane->setChecked(mClipper->getInvertPlane());
173  connect(mInvertPlane, &QCheckBox::toggled, mClipper.get(), &InteractiveClipper::invertPlane);
174 // if(planeSelector)
175 // {
176 // mPlaneAdapter->setClipper(mClipper);
177 // planeSelector->setModified();
178 // }
179  this->setEnabled(true);
180  this->setupUI();
181  this->setupDataSelectorUI();
182  }
183  else
184  this->setEnabled(false);
185 
186 }
187 
189 {
190  if(!mClipper)
191  return;
192  ToolPtr tool = mToolSelector->getTool();
193  if(!tool)
194  {
195  mClipper->useActiveTool(true);
196  tool = mServices->tracking()->getActiveTool();
197  }
198  else
199  mClipper->useActiveTool(false);
200  if(mAttachedToTool->isChecked())
201  mClipper->setTool(tool);
202  else
203  mClipper->setTool(ToolPtr());
204 }
205 
207 {
208  if(mClipper)
209  {
210  disconnect(mInvertPlane, &QCheckBox::toggled, mClipper.get(), &InteractiveClipper::invertPlane);
211  }
212 
213  mClipper = clipper;
214 
215  this->connectToNewClipper();
216 }
217 
219 {
220  if(this->getDatas().size() == mClipper->getDatas().size())
221  mSelectAllData->setChecked(true);
222  else
223  mSelectAllData->setChecked(false);
224 }
225 
226 void ClipperWidget::updateCheckBoxFromClipper(QCheckBox *checkbox, DataPtr data)
227 {
228  if(!mClipper)
229  return;
230  std::map<QString, DataPtr> datas = mClipper->getDatas();
231  bool checked = datas.count(data->getUid());
232  checkbox->setChecked(checked);
233 }
234 
236 {
237  std::map<QString, DataPtr> datas = this->getDatas();
238  std::map<QString, DataPtr>::iterator iter = datas.begin();
239 
240  int row = 0;
241 
242  for(; iter != datas.end(); ++iter)
243  {
244  DataPtr data = iter->second;
245  QCheckBox *checkbox = new QCheckBox();
246  checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
247  mDataTableWidget->setCellWidget(row, 0, checkbox);
248 
249  QTableWidgetItem *descriptionItem = new QTableWidgetItem(data->getName());
250  mDataTableWidget->setItem(row++, 1, descriptionItem);
251 
252  boost::function<void()> func = boost::bind(&ClipperWidget::dataSelectorClicked, this, checkbox, data);
253  connect(checkbox, &QCheckBox::clicked, this, func);
254  this->updateCheckBoxFromClipper(checkbox, data);
255  }
256 }
257 
259 {
260  if(!mClipper)
261  {
262  this->setEnabled(false);
263  return;
264  }
265 
266  std::map<QString, DataPtr> datas = this->getDatas();
267 
268  mDataTableWidget->setColumnCount(2);
269  mDataTableWidget->setRowCount(datas.size());
270 
271  QStringList horizontalHeaders;
272  horizontalHeaders << "Apply clipper" << "Object to be clipped";
273  mDataTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
274  mDataTableWidget->setColumnWidth(1, 300);
275 // mDataTableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);//test
276 
279 }
280 
282 {
283  QStringList dataTypes;
284  if(mShowImages->isChecked())
285  dataTypes << "image";
286  if(mShowMeshes->isChecked())
287  dataTypes << "mesh";
288  if(mShowTrackedStreams->isChecked())
289  dataTypes << "trackedStream";
290  if(mShowMetrics->isChecked())
291  dataTypes << ".*Metric$";
292  QString typeRegExp = dataTypes.join('|');
293 
294  return typeRegExp;
295 }
296 
297 std::map<QString, DataPtr> ClipperWidget::getDatas()
298 {
299  //TODO: Move SelectDataStringPropertyBase::filterOnType() to a utility file?
300  std::map<QString, DataPtr> datas = mServices->patient()->getDatas();
302  return datas;
303 }
304 
305 void ClipperWidget::dataSelectorClicked(QCheckBox *checkBox, DataPtr data)
306 {
307  bool checked = checkBox->isChecked();
308 
309  if(checked)
310  mClipper->addData(data);
311  else
312  mClipper->removeData(data);
313 }
314 
316 {
317  std::map<QString, DataPtr> datas = this->getDatas();
318  std::map<QString, DataPtr>::iterator iter = datas.begin();
319 
320  for(; iter != datas.end(); ++iter)
321  {
322  DataPtr data = iter->second;
323  if(checked)
324  mClipper->addData(data);
325  else
326  mClipper->removeData(data);
327  }
328  this->setModified();
329 }
330 
332 {
333  this->setModified();
334 }
335 
337 {
338  this->setupDataSelectorUI();
339 }
340 
341 }//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)
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
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
QCheckBox * mInvertPlane
StringPropertySelectToolPtr mToolSelector
void enable(bool checked)
QCheckBox * mShowImages
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
QCheckBox * mSelectAllData