CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 "cxFrameMetricWrapper.h"
34 
35 #include <QHBoxLayout>
37 #include "cxLegacySingletons.h"
38 #include "cxSpaceProvider.h"
39 #include "cxPatientModelService.h"
40 #include "cxSpaceEditWidget.h"
41 
42 namespace cx {
43 
45  MetricBase(viewService, patientModelService),
46  mData(data)
47 {
48  mInternalUpdate = false;
49 // connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
50 // connect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
51 }
52 
54 {
55 // disconnect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
56 }
57 
59 {
60  QWidget* widget = this->newWidget("frame_metric");
61  QVBoxLayout* topLayout = new QVBoxLayout(widget);
62  QHBoxLayout* hLayout = new QHBoxLayout;
63  hLayout->setMargin(0);
64  topLayout->setMargin(0);
65  topLayout->addLayout(hLayout);
66 
67  mSpaceSelector = SpaceProperty::initialize("selectSpace",
68  "Space",
69  "Select coordinate system to store position in.");
70  mSpaceSelector->setSpaceProvider(spaceProvider());
71  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
72 
73  mFrameWidget = new Transform3DWidget(widget);
74  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
75  topLayout->addWidget(mFrameWidget);
76 
77  QPushButton* sampleButton = new QPushButton("Sample");
78  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
79  hLayout->addWidget(sampleButton);
80 
81  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
82  connect(sampleButton, SIGNAL(clicked()), this, SLOT(moveToToolPosition()));
83 
84  this->addColorWidget(topLayout);
85 
86  return widget;
87 }
88 
90 {
91  return prettyFormat(mData->getRefCoord(), 1, 3);
92 }
93 
95 {
96  return mData;
97 }
98 
100 {
101  return "frame";
102 }
103 
105 {
106  return mData->getSpace().toString();
107 }
108 
109 
110 void FrameMetricWrapper::moveToToolPosition()
111 {
112 // CoordinateSystem ref = CoordinateSystem::reference()
113  Transform3D qMt = spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
114  mData->setFrame(qMt);
115 }
116 
117 void FrameMetricWrapper::spaceSelected()
118 {
119  if (mInternalUpdate)
120  return;
121  CoordinateSystem space = mSpaceSelector->getValue();
122  if (space.isValid())
123  mData->setSpace(space);
124 }
125 
126 //void FrameMetricWrapper::dataChangedSlot()
127 //{
128 //}
129 
130 void FrameMetricWrapper::frameWidgetChangedSlot()
131 {
132  if (mInternalUpdate)
133  return;
134  Transform3D matrix = mFrameWidget->getMatrix();
135  mData->setFrame(matrix);
136 }
137 
139 {
140  mInternalUpdate = true;
141  mSpaceSelector->setValue(mData->getSpace());
142  mFrameWidget->setMatrix(mData->getFrame());
143  mInternalUpdate = false;
144 }
145 
146 
147 
148 } //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:44
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:96
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:119
boost::shared_ptr< class ViewService > ViewServicePtr
FrameMetricWrapper(ViewServicePtr viewService, PatientModelServicePtr patientModelService, cx::FrameMetricPtr data)
void setMatrix(const Transform3D &M)
virtual QString getType() const
virtual DataMetricPtr getData() const
virtual QString getArguments() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual QWidget * createWidget()
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
virtual QString getValue() const
cxLogicManager_EXPORT ViewServicePtr viewService()
Transform3D getMatrix() const
QWidget * newWidget(QString objectName)