CustusX  22.04-rc5
An IGT application
cxFrameMetricWrapper.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 "cxFrameMetricWrapper.h"
13 
14 #include <QHBoxLayout>
16 #include "cxSpaceProvider.h"
17 #include "cxSpaceEditWidget.h"
18 #include "cxVisServices.h"
19 
20 namespace cx {
21 
23  MetricBase(services),
24  mData(data)
25 {
26  mInternalUpdate = false;
27 }
28 
30 {
31 }
32 
34 {
35  QWidget* widget = this->newWidget("frame_metric");
36  QVBoxLayout* topLayout = new QVBoxLayout(widget);
37  QHBoxLayout* hLayout = new QHBoxLayout;
38  hLayout->setMargin(0);
39  topLayout->setMargin(0);
40  topLayout->addLayout(hLayout);
41 
42  mSpaceSelector = SpaceProperty::initialize("selectSpace",
43  "Space",
44  "Select coordinate system to store position in.");
45  mSpaceSelector->setSpaceProvider(mServices->spaceProvider());
46  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
47 
48  mFrameWidget = new Transform3DWidget(widget);
49  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
50  topLayout->addWidget(mFrameWidget);
51 
52  QPushButton* sampleButton = new QPushButton("Sample");
53  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
54  hLayout->addWidget(sampleButton);
55 
56  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
57  connect(sampleButton, SIGNAL(clicked()), this, SLOT(moveToToolPosition()));
58 
59  this->addColorWidget(topLayout);
60 
61  return widget;
62 }
63 
65 {
66  return prettyFormat(mData->getRefCoord(), 1, 3);
67 }
68 
70 {
71  return mData;
72 }
73 
75 {
76  return "frame";
77 }
78 
80 {
81  return mData->getSpace().toString();
82 }
83 
84 
85 void FrameMetricWrapper::moveToToolPosition()
86 {
87 // CoordinateSystem ref = CoordinateSystem::reference()
88  Transform3D qMt = mServices->spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
89  mData->setFrame(qMt);
90 }
91 
92 void FrameMetricWrapper::spaceSelected()
93 {
94  if (mInternalUpdate)
95  return;
96  CoordinateSystem space = mSpaceSelector->getValue();
97  if (space.isValid())
98  mData->setSpace(space);
99 }
100 
101 void FrameMetricWrapper::frameWidgetChangedSlot()
102 {
103  if (mInternalUpdate)
104  return;
105  Transform3D matrix = mFrameWidget->getMatrix();
106  mData->setFrame(matrix);
107 }
108 
110 {
111  mInternalUpdate = true;
112  mSpaceSelector->setValue(mData->getSpace());
113  mFrameWidget->setMatrix(mData->getFrame());
114  mInternalUpdate = false;
115 }
116 
117 
118 
119 } //namespace cx
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix...
Composite widget for string selection.
boost::shared_ptr< class FrameMetric > FrameMetricPtr
Definition: cxFrameMetric.h:23
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())
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:98
FrameMetricWrapper(VisServicesPtr services, FrameMetricPtr data)
void setMatrix(const Transform3D &M)
virtual QString getType() const
virtual DataMetricPtr getData() const
virtual QString getArguments() const
virtual QWidget * createWidget()
Identification of a Coordinate system.
virtual QString getValue() const
VisServicesPtr mServices
Transform3D getMatrix() const
QWidget * newWidget(QString objectName)
Namespace for all CustusX production code.