Fraxinus  17.12
An IGT application
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, "select_clippers_for_image_widget", "Select Clippers")
52 {
53  StringPropertyActiveImagePtr activeImageProperty = StringPropertyActiveImage::New(services->patient());
54 
55  QVBoxLayout *mLayout = new QVBoxLayout(this);
56  mLayout->setMargin(0);
57 
58  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
59  selectClippersWidget->setActiveDataProperty(activeImageProperty);
60 
61  mLayout->addWidget(selectClippersWidget);
62 }
63 
65 
67  BaseWidget(parent, "select_clippers_for_mesh_widget", "Select Clippers")
68 {
69  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), "mesh");
70 
71  QVBoxLayout *mLayout = new QVBoxLayout(this);
72  mLayout->setMargin(0);
73 
74  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
75  selectClippersWidget->setActiveDataProperty(activeMeshProperty);
76 
77  mLayout->addWidget(selectClippersWidget);
78 }
79 
81 
83  BaseWidget(parent, "select_clippers_for_data_widget", "Select Clippers"),
84  mServices(services),
85  mActiveDataProperty(StringPropertyActiveData::New(services->patient()))
86 {
87  this->initUI();
88 
89  ClippersPtr clippers = mServices->view()->getClippers();
90  connect(clippers.get(), &Clippers::changed, this, &SelectClippersForDataWidget::setModified);
92 }
93 
95 {
97  mActiveDataProperty = property;
98  connect(mActiveDataProperty.get(), &Property::changed, this, &SelectClippersForDataWidget::setModified);
99 }
100 
102 {
103  mClipperTableWidget = new QTableWidget(this);
104 
105  mHeading = new QLabel("Active clippers");
106 
107  mLayout = new QVBoxLayout(this);
108  mLayout->setMargin(0);
109  mLayout->addWidget(mHeading);
110  mLayout->addWidget(mClipperTableWidget);
111 
112  this->setupClipperSelectorUI();
114 }
115 
117 {
118  ClippersPtr clippers = mServices->view()->getClippers();
119  mClipperTableWidget->setColumnCount(3);
120  mClipperTableWidget->setRowCount(clippers->size());
121  QStringList horizontalHeaders;
122  horizontalHeaders << "Clip data" << "Clipper" << "Invert";
123  mClipperTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
124 }
125 
127 {
128  ClippersPtr clippers = mServices->view()->getClippers();
129  QStringList clipperNames = clippers->getClipperNames();
130 
131  int row = 0;
132  for(int i = 0; i < clipperNames.size(); ++i)
133  {
134  QString clipperName = clipperNames.at(i);
135  this->createDataCheckBox(row, clipperName);
136 
137  QTableWidgetItem *descriptionItem = new QTableWidgetItem(clipperName);
138  mClipperTableWidget->setItem(row++, 1, descriptionItem);
139  }
140 }
141 
142 void SelectClippersForDataWidget::createDataCheckBox(int row, QString clipperName)
143 {
144  QCheckBox *dataCheckBox = this->createCheckBox(clipperName);
145  QCheckBox *invertCheckbox = this->createCheckBox(clipperName);
146  mClipperTableWidget->setCellWidget(row, 0, dataCheckBox);
147  mClipperTableWidget->setCellWidget(row, 2, invertCheckbox);
148 
149  boost::function<void()> func = boost::bind(&SelectClippersForDataWidget::clipDataClicked, this, dataCheckBox, clipperName);
150  connect(dataCheckBox, &QCheckBox::clicked, this, func);
151 
152  boost::function<void()> invertFunc = boost::bind(&SelectClippersForDataWidget::invertClicked, this, invertCheckbox, clipperName);
153  connect(invertCheckbox, &QCheckBox::clicked, this, invertFunc);
154 
155  this->updateCheckBoxesFromClipper(dataCheckBox, invertCheckbox, clipperName);
156 }
157 
158 void SelectClippersForDataWidget::updateCheckBoxesFromClipper(QCheckBox *dataCheckBox, QCheckBox *invertCheckBox, QString clipperName)
159 {
160  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
161  DataPtr activeData = mActiveDataProperty->getData();
162 
163  bool checkData = clipper->exists(activeData);
164  dataCheckBox->setChecked(checkData);
165 
166  bool checkInvert = clipper->getInvertPlane();
167  invertCheckBox->setChecked(checkInvert);
168 }
169 
170 QCheckBox *SelectClippersForDataWidget::createCheckBox(QString clipperName)
171 {
172  QCheckBox *checkbox = new QCheckBox();
173  checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
174  return checkbox;
175 }
176 
177 cx::InteractiveClipperPtr SelectClippersForDataWidget::getClipper(QString clipperName)
178 {
179  ClippersPtr clippers = mServices->view()->getClippers();
180  cx::InteractiveClipperPtr clipper = clippers->getClipper(clipperName);
181  return clipper;
182 }
183 
184 void SelectClippersForDataWidget::clipDataClicked(QCheckBox *checkBox, QString clipperName)
185 {
186  DataPtr activeData = mActiveDataProperty->getData();
187  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
188  bool checked = checkBox->isChecked();
189 
190  if(checked)
191  clipper->addData(activeData);
192  else
193  clipper->removeData(activeData);
194 }
195 
196 void SelectClippersForDataWidget::invertClicked(QCheckBox *checkBox, QString clipperName)
197 {
198  bool checked = checkBox->isChecked();
199  this->getClipper(clipperName)->invertPlane(checked);
200 }
201 
203 {
205 }
206 
207 
208 }//cx
209 
void changed()
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
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)
boost::shared_ptr< class Clippers > ClippersPtr
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:109
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
SelectClippersForDataWidget(VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr
Namespace for all CustusX production code.