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