Fraxinus  2023.01.05-dev+develop.0da12
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
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:24
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
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:32
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:98
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.