Fraxinus  17.12
An IGT application
cxToolMetricWrapper.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 "cxToolMetricWrapper.h"
34 #include <QHBoxLayout>
35 #include "cxSpaceEditWidget.h"
36 #include "cxHelperWidgets.h"
37 #include "cxTrackingService.h"
38 #include "cxSpaceProvider.h"
39 #include "cxPatientModelService.h"
40 #include "cxVisServices.h"
41 
42 namespace cx {
43 
45  MetricBase(services),
46  mData(data)
47 {
48  mInternalUpdate = false;
49 // connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
50 // connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
51 // connect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
52 }
53 
55 {
56 // disconnect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
57 }
58 
60 {
61  this->initializeProperties();
62 
63  QWidget* widget = this->newWidget("tool_metric");
64 
65  QVBoxLayout* topLayout = new QVBoxLayout(widget);
66  topLayout->setMargin(0);
67 
68  QHBoxLayout* hLayout2 = new QHBoxLayout;
69  hLayout2->setMargin(0);
70  topLayout->addLayout(hLayout2);
71 
72  QHBoxLayout* hLayout = new QHBoxLayout;
73  hLayout->setMargin(0);
74  topLayout->addLayout(hLayout);
75 
76  hLayout2->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mToolNameSelector));
77  hLayout2->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mToolOffsetSelector));
78 
79  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
80 
81  QPushButton* sampleButton = new QPushButton("Sample");
82  connect(sampleButton, SIGNAL(clicked()), this, SLOT(resampleMetric()));
83  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
84  hLayout->addWidget(sampleButton);
85 
86  mFrameWidget = new Transform3DWidget(widget);
87  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
88  topLayout->addWidget(mFrameWidget);
89 
90  this->addColorWidget(topLayout);
91 
92 // this->dataChangedSlot();
93 
94  return widget;
95 }
96 
97 void ToolMetricWrapper::initializeProperties()
98 {
99  mSpaceSelector = SpaceProperty::initialize("selectSpace",
100  "Space",
101  "Select coordinate system to store position in.");
102 
103  mSpaceSelector->setSpaceProvider(mServices->spaceProvider());
104  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
105 
106  mToolNameSelector = StringProperty::initialize("selectToolName",
107  "Tool Name",
108  "The name of the tool",
109  "",
110  QDomNode());
111  connect(mToolNameSelector.get(), SIGNAL(valueWasSet()), this, SLOT(toolNameSet()));
112 
113  mToolOffsetSelector = DoubleProperty::initialize("selectToolOffset",
114  "Tool Offset",
115  "Tool Offset",
116  0,
117  DoubleRange(0, 100, 1),
118  1);
119  connect(mToolOffsetSelector.get(), SIGNAL(valueWasSet()), this, SLOT(toolOffsetSet()));
120 }
121 
123 {
124  return prettyFormat(mData->getRefCoord(), 1, 3);
125 }
126 
128 {
129  return mData;
130 }
131 
133 {
134  return "tool";
135 }
136 
138 {
139  return mData->getSpace().toString();
140 }
141 
142 
143 void ToolMetricWrapper::resampleMetric()
144 {
145 // CoordinateSystem ref = CoordinateSystemHelpers::getR();
146  Transform3D qMt = mServices->spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
147  mData->setFrame(qMt);
148  mData->setToolName(mServices->tracking()->getActiveTool()->getName());
149  mData->setToolOffset(mServices->tracking()->getActiveTool()->getTooltipOffset());
150 }
151 
152 
153 void ToolMetricWrapper::spaceSelected()
154 {
155  if (mInternalUpdate)
156  return;
157  CoordinateSystem space = mSpaceSelector->getValue();
158  if (space.isValid())
159  mData->setSpace(space);
160 }
161 
162 void ToolMetricWrapper::toolNameSet()
163 {
164  if (mInternalUpdate)
165  return;
166  mData->setToolName(mToolNameSelector->getValue());
167 }
168 
169 void ToolMetricWrapper::toolOffsetSet()
170 {
171  if (mInternalUpdate)
172  return;
173  mData->setToolOffset(mToolOffsetSelector->getValue());
174 }
175 
176 //void ToolMetricWrapper::dataChangedSlot()
177 //{
178 //}
179 
181 {
182  mInternalUpdate = true;
183 
184  mSpaceSelector->setValue(mData->getSpace());
185  mFrameWidget->setMatrix(mData->getFrame());
186  mToolNameSelector->setValue(mData->getToolName());
187  mToolOffsetSelector->setValue(mData->getToolOffset());
188 
189  mInternalUpdate = false;
190 }
191 
192 
193 void ToolMetricWrapper::frameWidgetChangedSlot()
194 {
195  if (mInternalUpdate)
196  return;
197  Transform3D matrix = mFrameWidget->getMatrix();
198  mData->setFrame(matrix);
199 }
200 
201 
202 } //namespace cx
virtual QString getValue() const
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix...
virtual QWidget * createWidget()
Composite widget for string selection.
boost::shared_ptr< class ToolMetric > ToolMetricPtr
Definition: cxToolMetric.h:45
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:94
void addColorWidget(QVBoxLayout *layout)
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:119
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
void setMatrix(const Transform3D &M)
virtual QString getArguments() const
virtual QString getType() const
Identification of a Coordinate system.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
VisServicesPtr mServices
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Transform3D getMatrix() const
QWidget * newWidget(QString objectName)
ToolMetricWrapper(VisServicesPtr services, cx::ToolMetricPtr data)
virtual DataMetricPtr getData() const
Namespace for all CustusX production code.