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