Fraxinus  16.5.0-fx-rc7
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 = new QWidget;
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(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
75 // connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
76  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
77  topLayout->addWidget(mFrameWidget);
78 
79  QPushButton* sampleButton = new QPushButton("Sample");
80  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
81  hLayout->addWidget(sampleButton);
82 
83  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
84  connect(sampleButton, SIGNAL(clicked()), this, SLOT(moveToToolPosition()));
85 
86  this->addColorWidget(topLayout);
87 
88 // this->dataChangedSlot();
89 
90  return widget;
91 }
92 
94 {
95  return prettyFormat(mData->getRefCoord(), 1, 3);
96 }
97 
99 {
100  return mData;
101 }
102 
104 {
105  return "frame";
106 }
107 
109 {
110  return mData->getSpace().toString();
111 }
112 
113 
114 void FrameMetricWrapper::moveToToolPosition()
115 {
116 // CoordinateSystem ref = CoordinateSystem::reference()
117  Transform3D qMt = spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
118  mData->setFrame(qMt);
119 }
120 
121 void FrameMetricWrapper::spaceSelected()
122 {
123  if (mInternalUpdate)
124  return;
125  CoordinateSystem space = mSpaceSelector->getValue();
126  if (space.isValid())
127  mData->setSpace(space);
128 }
129 
130 //void FrameMetricWrapper::dataChangedSlot()
131 //{
132 //}
133 
134 void FrameMetricWrapper::frameWidgetChangedSlot()
135 {
136  if (mInternalUpdate)
137  return;
138  Transform3D matrix = mFrameWidget->getMatrix();
139  mData->setFrame(matrix);
140 }
141 
143 {
144  mInternalUpdate = true;
145  mSpaceSelector->setValue(mData->getSpace());
146  mFrameWidget->setMatrix(mData->getFrame());
147  mInternalUpdate = false;
148 }
149 
150 
151 
152 } //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: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())
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