Fraxinus  16.5.0-fx-rc3
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
41 //TODO: remove
42 #include "cxLegacySingletons.h"
43 
44 namespace cx {
45 
47  MetricBase(viewService, patientModelService),
48  mData(data)
49 {
50  mInternalUpdate = false;
51 // connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
52 // connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
53 // connect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
54 }
55 
57 {
58 // disconnect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
59 }
60 
62 {
63  this->initializeProperties();
64 
65  QWidget* widget = new QWidget;
66 
67  QVBoxLayout* topLayout = new QVBoxLayout(widget);
68  topLayout->setMargin(0);
69 
70  QHBoxLayout* hLayout2 = new QHBoxLayout;
71  hLayout2->setMargin(0);
72  topLayout->addLayout(hLayout2);
73 
74  QHBoxLayout* hLayout = new QHBoxLayout;
75  hLayout->setMargin(0);
76  topLayout->addLayout(hLayout);
77 
78  hLayout2->addWidget(createDataWidget(mViewService, mPatientModelService, widget, mToolNameSelector));
79  hLayout2->addWidget(createDataWidget(mViewService, mPatientModelService, widget, mToolOffsetSelector));
80 
81  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
82 
83  QPushButton* sampleButton = new QPushButton("Sample");
84  connect(sampleButton, SIGNAL(clicked()), this, SLOT(resampleMetric()));
85  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
86  hLayout->addWidget(sampleButton);
87 
88  mFrameWidget = new Transform3DWidget(widget);
89  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
90  topLayout->addWidget(mFrameWidget);
91 
92  this->addColorWidget(topLayout);
93 
94 // this->dataChangedSlot();
95 
96  return widget;
97 }
98 
99 void ToolMetricWrapper::initializeProperties()
100 {
101  mSpaceSelector = SpaceProperty::initialize("selectSpace",
102  "Space",
103  "Select coordinate system to store position in.");
104 
105  mSpaceSelector->setSpaceProvider(spaceProvider());
106  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
107 
108  mToolNameSelector = StringProperty::initialize("selectToolName",
109  "Tool Name",
110  "The name of the tool",
111  "",
112  QDomNode());
113  connect(mToolNameSelector.get(), SIGNAL(valueWasSet()), this, SLOT(toolNameSet()));
114 
115  mToolOffsetSelector = DoubleProperty::initialize("selectToolOffset",
116  "Tool Offset",
117  "Tool Offset",
118  0,
119  DoubleRange(0, 100, 1),
120  1);
121  connect(mToolOffsetSelector.get(), SIGNAL(valueWasSet()), this, SLOT(toolOffsetSet()));
122 }
123 
125 {
126  return prettyFormat(mData->getRefCoord(), 1, 3);
127 }
128 
130 {
131  return mData;
132 }
133 
135 {
136  return "tool";
137 }
138 
140 {
141  return mData->getSpace().toString();
142 }
143 
144 
145 void ToolMetricWrapper::resampleMetric()
146 {
147 // CoordinateSystem ref = CoordinateSystemHelpers::getR();
148  Transform3D qMt = spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
149  mData->setFrame(qMt);
150  mData->setToolName(trackingService()->getActiveTool()->getName());
151  mData->setToolOffset(trackingService()->getActiveTool()->getTooltipOffset());
152 }
153 
154 
155 void ToolMetricWrapper::spaceSelected()
156 {
157  if (mInternalUpdate)
158  return;
159  CoordinateSystem space = mSpaceSelector->getValue();
160  if (space.isValid())
161  mData->setSpace(space);
162 }
163 
164 void ToolMetricWrapper::toolNameSet()
165 {
166  if (mInternalUpdate)
167  return;
168  mData->setToolName(mToolNameSelector->getValue());
169 }
170 
171 void ToolMetricWrapper::toolOffsetSet()
172 {
173  if (mInternalUpdate)
174  return;
175  mData->setToolOffset(mToolOffsetSelector->getValue());
176 }
177 
178 //void ToolMetricWrapper::dataChangedSlot()
179 //{
180 //}
181 
183 {
184  mInternalUpdate = true;
185 
186  mSpaceSelector->setValue(mData->getSpace());
187  mFrameWidget->setMatrix(mData->getFrame());
188  mToolNameSelector->setValue(mData->getToolName());
189  mToolOffsetSelector->setValue(mData->getToolOffset());
190 
191  mInternalUpdate = false;
192 }
193 
194 
195 void ToolMetricWrapper::frameWidgetChangedSlot()
196 {
197  if (mInternalUpdate)
198  return;
199  Transform3D matrix = mFrameWidget->getMatrix();
200  mData->setFrame(matrix);
201 }
202 
203 
204 } //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
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:95
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
ToolMetricWrapper(ViewServicePtr viewService, PatientModelServicePtr patientModelService, cx::ToolMetricPtr data)
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:119
boost::shared_ptr< class ViewService > ViewServicePtr
ViewServicePtr mViewService
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
PatientModelServicePtr mPatientModelService
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
cxLogicManager_EXPORT ViewServicePtr viewService()
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Transform3D getMatrix() const
cxLogicManager_EXPORT TrackingServicePtr trackingService()
virtual DataMetricPtr getData() const