Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSelectClippersForDataWidget.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 
34 #include "boost/bind.hpp"
35 #include <QTableWidget>
36 #include <QLabel>
37 #include <QCheckBox>
38 #include "cxVisServices.h"
39 #include "cxViewService.h"
40 #include "cxPatientModelService.h"
41 #include "cxClippers.h"
42 #include "cxLogger.h"
43 #include "cxInteractiveClipper.h"
44 #include "cxActiveData.h"
46 #include "cxDataSelectWidget.h"
47 
48 namespace cx
49 {
51  BaseWidget(parent, "SelectClippersForImageWidget", "Select Clippers")
52 {
53  StringPropertyActiveImagePtr activeImageProperty = StringPropertyActiveImage::New(services->patient());
54 
55  QVBoxLayout *mLayout = new QVBoxLayout(this);
56 
57  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
58  selectClippersWidget->setActiveDataProperty(activeImageProperty);
59 
60  mLayout->addWidget(selectClippersWidget);
61 }
62 
64 
66  BaseWidget(parent, "SelectClippersForMeshWidget", "Select Clippers")
67 {
68  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), "mesh");
69 
70  QVBoxLayout *mLayout = new QVBoxLayout(this);
71 
72  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
73  selectClippersWidget->setActiveDataProperty(activeMeshProperty);
74 
75  mLayout->addWidget(selectClippersWidget);
76 }
77 
79 
81  BaseWidget(parent, "SelectClippersForDataWidget", "Select Clippers"),
82  mServices(services),
83  mActiveDataProperty(StringPropertyActiveData::New(services->patient()))
84 {
85  this->initUI();
86 
87  ClippersPtr clippers = mServices->view()->getClippers();
88  connect(clippers.get(), &Clippers::changed, this, &SelectClippersForDataWidget::setModified);
90 }
91 
93 {
95  mActiveDataProperty = property;
96  connect(mActiveDataProperty.get(), &Property::changed, this, &SelectClippersForDataWidget::setModified);
97 }
98 
100 {
101  mClipperTableWidget = new QTableWidget(this);
102 
103  mHeading = new QLabel("Active clippers");
104 
105  mLayout = new QVBoxLayout(this);
106  mLayout->addWidget(mHeading);
107  mLayout->addWidget(mClipperTableWidget);
108 
109  this->setupClipperSelectorUI();
111 }
112 
114 {
115  ClippersPtr clippers = mServices->view()->getClippers();
116  mClipperTableWidget->setColumnCount(3);
117  mClipperTableWidget->setRowCount(clippers->size());
118  QStringList horizontalHeaders;
119  horizontalHeaders << "Clip data" << "Clipper" << "Invert";
120  mClipperTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
121 }
122 
124 {
125  ClippersPtr clippers = mServices->view()->getClippers();
126  QStringList clipperNames = clippers->getClipperNames();
127 
128  int row = 0;
129  for(int i = 0; i < clipperNames.size(); ++i)
130  {
131  QString clipperName = clipperNames.at(i);
132  this->createDataCheckBox(row, clipperName);
133 
134  QTableWidgetItem *descriptionItem = new QTableWidgetItem(clipperName);
135  mClipperTableWidget->setItem(row++, 1, descriptionItem);
136  }
137 }
138 
139 void SelectClippersForDataWidget::createDataCheckBox(int row, QString clipperName)
140 {
141  QCheckBox *dataCheckBox = this->createCheckBox(clipperName);
142  QCheckBox *invertCheckbox = this->createCheckBox(clipperName);
143  mClipperTableWidget->setCellWidget(row, 0, dataCheckBox);
144  mClipperTableWidget->setCellWidget(row, 2, invertCheckbox);
145 
146  boost::function<void()> func = boost::bind(&SelectClippersForDataWidget::clipDataClicked, this, dataCheckBox, clipperName);
147  connect(dataCheckBox, &QCheckBox::clicked, this, func);
148 
149  boost::function<void()> invertFunc = boost::bind(&SelectClippersForDataWidget::invertClicked, this, invertCheckbox, clipperName);
150  connect(invertCheckbox, &QCheckBox::clicked, this, invertFunc);
151 
152  this->updateCheckBoxesFromClipper(dataCheckBox, invertCheckbox, clipperName);
153 }
154 
155 void SelectClippersForDataWidget::updateCheckBoxesFromClipper(QCheckBox *dataCheckBox, QCheckBox *invertCheckBox, QString clipperName)
156 {
157  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
158  DataPtr activeData = mActiveDataProperty->getData();
159 
160  bool checkData = clipper->exists(activeData);
161  dataCheckBox->setChecked(checkData);
162 
163  bool checkInvert = clipper->getInvertPlane();
164  invertCheckBox->setChecked(checkInvert);
165 }
166 
167 QCheckBox *SelectClippersForDataWidget::createCheckBox(QString clipperName)
168 {
169  QCheckBox *checkbox = new QCheckBox();
170  checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
171  return checkbox;
172 }
173 
174 cx::InteractiveClipperPtr SelectClippersForDataWidget::getClipper(QString clipperName)
175 {
176  ClippersPtr clippers = mServices->view()->getClippers();
177  cx::InteractiveClipperPtr clipper = clippers->getClipper(clipperName);
178  return clipper;
179 }
180 
181 void SelectClippersForDataWidget::clipDataClicked(QCheckBox *checkBox, QString clipperName)
182 {
183  DataPtr activeData = mActiveDataProperty->getData();
184  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
185  bool checked = checkBox->isChecked();
186 
187  if(checked)
188  clipper->addData(activeData);
189  else
190  clipper->removeData(activeData);
191 }
192 
193 void SelectClippersForDataWidget::invertClicked(QCheckBox *checkBox, QString clipperName)
194 {
195  bool checked = checkBox->isChecked();
196  this->getClipper(clipperName)->invertPlane(checked);
197 }
198 
200 {
202 }
203 
204 
205 }//cx
206 
void changed()
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
boost::shared_ptr< class StringPropertyActiveImage > StringPropertyActiveImagePtr
Turn clippers on/off for a spesific data structure.
SelectClippersForMeshWidget(VisServicesPtr services, QWidget *parent)
SelectClippersForImageWidget(VisServicesPtr services, QWidget *parent)
SelectDataStringPropertyBasePtr mActiveDataProperty
void invertClicked(QCheckBox *checkBox, QString clipperName)
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
static StringPropertyActiveImagePtr New(PatientModelServicePtr patientModelService)
void setActiveDataProperty(SelectDataStringPropertyBasePtr property)
void clipDataClicked(QCheckBox *checkBox, QString clipperName)
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
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
boost::shared_ptr< class Clippers > ClippersPtr
SelectClippersForDataWidget(VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr