CustusX  2023.01.05-dev+develop.0da12
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) 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 
13 #include "boost/bind.hpp"
14 #include <QTableWidget>
15 #include <QLabel>
16 #include <QCheckBox>
17 #include "cxVisServices.h"
18 #include "cxViewService.h"
19 #include "cxPatientModelService.h"
20 #include "cxClippers.h"
21 #include "cxLogger.h"
22 #include "cxInteractiveClipper.h"
23 #include "cxActiveData.h"
25 #include "cxDataSelectWidget.h"
26 #include "cxMesh.h"
27 
28 namespace cx
29 {
31  BaseWidget(parent, "select_clippers_for_image_widget", "Select Clippers")
32 {
33  StringPropertyActiveImagePtr activeImageProperty = StringPropertyActiveImage::New(services->patient());
34 
35  QVBoxLayout *mLayout = new QVBoxLayout(this);
36  mLayout->setMargin(0);
37 
38  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
39  selectClippersWidget->setActiveDataProperty(activeImageProperty);
40 
41  mLayout->addWidget(selectClippersWidget);
42 }
43 
45 
47  BaseWidget(parent, "select_clippers_for_mesh_widget", "Select Clippers")
48 {
49  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), Mesh::getTypeName());
50 
51  QVBoxLayout *mLayout = new QVBoxLayout(this);
52  mLayout->setMargin(0);
53 
54  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
55  selectClippersWidget->setActiveDataProperty(activeMeshProperty);
56 
57  mLayout->addWidget(selectClippersWidget);
58 }
59 
61 
63  BaseWidget(parent, "select_clippers_for_data_widget", "Select Clippers"),
64  mServices(services),
65  mActiveDataProperty(StringPropertyActiveData::New(services->patient()))
66 {
67  this->initUI();
68 
69  ClippersPtr clippers = mServices->view()->getClippers();
70  connect(clippers.get(), &Clippers::changed, this, &SelectClippersForDataWidget::setModified);
72 }
73 
75 {
77  mActiveDataProperty = property;
78  connect(mActiveDataProperty.get(), &Property::changed, this, &SelectClippersForDataWidget::setModified);
79 }
80 
82 {
83  mClipperTableWidget = new QTableWidget(this);
84 
85  mHeading = new QLabel("Active clippers");
86 
87  mLayout = new QVBoxLayout(this);
88  mLayout->setMargin(0);
89  mLayout->addWidget(mHeading);
90  mLayout->addWidget(mClipperTableWidget);
91 
92  this->setupClipperSelectorUI();
94 }
95 
97 {
98  ClippersPtr clippers = mServices->view()->getClippers();
99  mClipperTableWidget->setColumnCount(3);
100  mClipperTableWidget->setRowCount(clippers->size());
101  QStringList horizontalHeaders;
102  horizontalHeaders << "Clip data" << "Clipper" << "Invert";
103  mClipperTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
104 }
105 
107 {
108  ClippersPtr clippers = mServices->view()->getClippers();
109  QStringList clipperNames = clippers->getClipperNames();
110 
111  int row = 0;
112  for(int i = 0; i < clipperNames.size(); ++i)
113  {
114  QString clipperName = clipperNames.at(i);
115  this->createDataCheckBox(row, clipperName);
116 
117  QTableWidgetItem *descriptionItem = new QTableWidgetItem(clipperName);
118  mClipperTableWidget->setItem(row++, 1, descriptionItem);
119  }
120 }
121 
122 void SelectClippersForDataWidget::createDataCheckBox(int row, QString clipperName)
123 {
124  QCheckBox *dataCheckBox = this->createCheckBox(clipperName);
125  QCheckBox *invertCheckbox = this->createCheckBox(clipperName);
126  mClipperTableWidget->setCellWidget(row, 0, dataCheckBox);
127  mClipperTableWidget->setCellWidget(row, 2, invertCheckbox);
128 
129  boost::function<void()> func = boost::bind(&SelectClippersForDataWidget::clipDataClicked, this, dataCheckBox, clipperName);
130  connect(dataCheckBox, &QCheckBox::clicked, this, func);
131 
132  boost::function<void()> invertFunc = boost::bind(&SelectClippersForDataWidget::invertClicked, this, invertCheckbox, clipperName);
133  connect(invertCheckbox, &QCheckBox::clicked, this, invertFunc);
134 
135  this->updateCheckBoxesFromClipper(dataCheckBox, invertCheckbox, clipperName);
136 }
137 
138 void SelectClippersForDataWidget::updateCheckBoxesFromClipper(QCheckBox *dataCheckBox, QCheckBox *invertCheckBox, QString clipperName)
139 {
140  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
141  DataPtr activeData = mActiveDataProperty->getData();
142 
143  bool checkData = clipper->exists(activeData);
144  dataCheckBox->setChecked(checkData);
145 
146  bool checkInvert = clipper->getInvertPlane();
147  invertCheckBox->setChecked(checkInvert);
148 }
149 
150 QCheckBox *SelectClippersForDataWidget::createCheckBox(QString clipperName)
151 {
152  QCheckBox *checkbox = new QCheckBox();
153  checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
154  return checkbox;
155 }
156 
157 cx::InteractiveClipperPtr SelectClippersForDataWidget::getClipper(QString clipperName)
158 {
159  ClippersPtr clippers = mServices->view()->getClippers();
160  cx::InteractiveClipperPtr clipper = clippers->getClipper(clipperName);
161  return clipper;
162 }
163 
164 void SelectClippersForDataWidget::clipDataClicked(QCheckBox *checkBox, QString clipperName)
165 {
166  DataPtr activeData = mActiveDataProperty->getData();
167  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
168  bool checked = checkBox->isChecked();
169 
170  if(checked)
171  clipper->addData(activeData);
172  else
173  clipper->removeData(activeData);
174 }
175 
176 void SelectClippersForDataWidget::invertClicked(QCheckBox *checkBox, QString clipperName)
177 {
178  bool checked = checkBox->isChecked();
179  this->getClipper(clipperName)->invertPlane(checked);
180 }
181 
183 {
185 }
186 
187 
188 }//cx
189 
void changed()
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
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:88
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
static QString getTypeName()
Definition: cxMesh.h:67
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
SelectClippersForDataWidget(VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr
Namespace for all CustusX production code.