CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxMeshInfoWidget.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 #include "cxMeshInfoWidget.h"
33 
34 #include <QVBoxLayout>
35 #include "cxImage.h"
36 
40 #include "cxMeshHelpers.h"
41 #include "cxHelperWidgets.h"
42 #include "cxColorProperty.h"
43 #include "cxDataLocations.h"
44 #include "cxDataInterface.h"
45 #include "cxDataSelectWidget.h"
47 
48 #include "cxPatientModelService.h"
49 #include "cxLogger.h"
50 #include "cxProfile.h"
51 
52 namespace cx
53 {
54 
55 
56 MeshInfoWidget::MeshInfoWidget(PatientModelServicePtr patientModelService, VisualizationServicePtr visualizationService, QWidget* parent) :
57  InfoWidget(parent, "MeshInfoWidget", "Mesh Properties"),
58  mPatientModelService(patientModelService),
59  mVisualizationService(visualizationService)
60 {
61  this->addWidgets(patientModelService);
62  this->meshSelectedSlot();
63 }
64 
66 {}
67 
69 {
70  if(!mMesh)
71  return;
72  // Implement like TransferFunctionColorWidget::setColorSlot()
73  // to prevent crash problems
74  QTimer::singleShot(1, this, SLOT(setColorSlotDelayed()));
75 }
76 
78 {
79  mMesh->setColor(mColorAdapter->getValue());
80 }
81 
83 {
84  if (mMesh == mSelectMeshWidget->getMesh())
85  return;
86 
87  if(mMesh)
88  {
89  disconnect(mBackfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setBackfaceCullingSlot(bool)));
90  disconnect(mFrontfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setFrontfaceCullingSlot(bool)));
91  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
92  }
93 
94  mMesh = mSelectMeshWidget->getMesh();
95 
96  if (!mMesh)
97  {
98  mParentFrameAdapter->setData(mMesh);
99  mNameAdapter->setData(mMesh);
100  mUidAdapter->setData(mMesh);
101  return;
102  }
103 
104  mBackfaceCullingCheckBox->setChecked(mMesh->getBackfaceCulling());
105  mFrontfaceCullingCheckBox->setChecked(mMesh->getFrontfaceCulling());
106  connect(mBackfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setBackfaceCullingSlot(bool)));
107  connect(mFrontfaceCullingCheckBox, SIGNAL(toggled(bool)), mMesh.get(), SLOT(setFrontfaceCullingSlot(bool)));
108  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
109 
110  mParentFrameAdapter->setData(mMesh);
111  mNameAdapter->setData(mMesh);
112  mUidAdapter->setData(mMesh);
113  mColorAdapter->setValue(mMesh->getColor());
114 
115  std::map<std::string, std::string> info = getDisplayFriendlyInfo(mMesh);
116  this->populateTableWidget(info);
117 }
118 
120 {
121  if(!mMesh)
122  return;
123  DataPtr parent = mPatientModelService->getData(mMesh->getParentSpace());
124  if (!parent)
125  return;
126  mMesh->get_rMd_History()->setRegistration(parent->get_rMd());
127  report("Assigned rMd from volume [" + parent->getName() + "] to surface [" + mMesh->getName() + "]");
128 }
129 
131 {
132  mBackfaceCullingCheckBox->setChecked(mMesh->getBackfaceCulling());
133  mFrontfaceCullingCheckBox->setChecked(mMesh->getFrontfaceCulling());
134  mColorAdapter->setValue(mMesh->getColor());
135 }
136 
137 void MeshInfoWidget::showEvent(QShowEvent* event)
138 {
139  QWidget::showEvent(event);
140 }
141 
142 void MeshInfoWidget::hideEvent(QCloseEvent* event)
143 {
144  QWidget::closeEvent(event);
145 }
146 
147 void MeshInfoWidget::addWidgets(PatientModelServicePtr patientModelService)
148 {
149  mSelectMeshWidget = StringPropertySelectMesh::New(patientModelService);
150  mSelectMeshWidget->setValueName("Surface: ");
151  connect(mSelectMeshWidget.get(), &Property::changed, this, &MeshInfoWidget::meshSelectedSlot);
152 
153  XmlOptionFile options = profile()->getXmlSettings().descend("MeshInfoWidget");
154  QString uid("Color");
155  QString name("");
156  QString help("Color of the mesh.");
157  QColor color("red");
158 
159  if(mSelectMeshWidget->getMesh())
160  color = mSelectMeshWidget->getMesh()->getColor();
161 
162  mColorAdapter = ColorProperty::initialize(uid, name, help, color, options.getElement());
163  connect(mColorAdapter.get(), SIGNAL(changed()), this, SLOT(setColorSlot()));
164 
165  QPushButton* importTransformButton = new QPushButton("Import Transform from Parent", this);
166  importTransformButton->setToolTip("Replace data transform with that of the parent data.");
167  connect(importTransformButton, SIGNAL(clicked()), this, SLOT(importTransformSlot()));
168 
169  mUidAdapter = StringPropertyDataUidEditable::New();
170  mNameAdapter = StringPropertyDataNameEditable::New();
171  mParentFrameAdapter = StringPropertyParentFrame::New(mPatientModelService);
172 
173  QWidget* optionsWidget = new QWidget(this);
174  QHBoxLayout* optionsLayout = new QHBoxLayout(optionsWidget);
175  mBackfaceCullingCheckBox = new QCheckBox("Backface culling");
176  mBackfaceCullingCheckBox->setToolTip("Set backface culling on. This makes transparent meshes work, but only draws outside mesh walls (eg. navigating inside meshes will not work).");
177  optionsLayout->addWidget(mBackfaceCullingCheckBox);
178  mFrontfaceCullingCheckBox = new QCheckBox("Frontface culling");
179  mFrontfaceCullingCheckBox->setToolTip("Set frontface culling on. Can be used to make transparent meshes work from inside the meshes.");
180  optionsLayout->addWidget(mFrontfaceCullingCheckBox);
181  optionsLayout->addWidget(sscCreateDataWidget(this, mColorAdapter));
182  optionsLayout->addStretch(1);
183 
184  int gridLayoutRow = 1;
185 
186  gridLayout->addWidget(new DataSelectWidget(mVisualizationService, mPatientModelService, this, mSelectMeshWidget), gridLayoutRow++, 0, 1, 2);
187  new LabeledLineEditWidget(this, mUidAdapter, gridLayout, gridLayoutRow++);
188  new LabeledLineEditWidget(this, mNameAdapter, gridLayout, gridLayoutRow++);
189  new LabeledComboBoxWidget(this, mParentFrameAdapter, gridLayout, gridLayoutRow++);
190  gridLayout->addWidget(optionsWidget, gridLayoutRow++, 0, 1, 2);
191  gridLayout->addWidget(mTableWidget, gridLayoutRow++, 0, 1, 2);
192  gridLayout->addWidget(importTransformButton, gridLayoutRow++, 0, 1, 2);
193 
194  this->addStretch();
195 }
196 
197 }//end namespace cx
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:169
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
static StringPropertyParentFramePtr New(PatientModelServicePtr patientModelService)
QTableWidget * mTableWidget
Definition: cxInfoWidget.h:69
virtual void hideEvent(QCloseEvent *event)
disconnects stuff
void populateTableWidget(std::map< std::string, std::string > &info)
Composite widget for string selection.
static StringPropertyDataUidEditablePtr New()
QGridLayout * gridLayout
Definition: cxInfoWidget.h:68
Composite widget for string edit.
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class VisualizationService > VisualizationServicePtr
Definition: cxRegServices.h:43
static StringPropertyDataNameEditablePtr New()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
void report(QString msg)
Definition: cxLogger.cpp:90
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
Helper class for xml files used to store ssc/cx data.