CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxToolPropertiesWidget.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 "cxToolPropertiesWidget.h"
34 
35 #include <QTreeWidget>
36 #include <QTreeWidgetItem>
37 #include <QStringList>
38 #include <QVBoxLayout>
39 #include <QGroupBox>
40 #include <QCheckBox>
41 
42 
43 #include "cxTrackingService.h"
45 #include "cxTypeConversions.h"
46 //#include "UsConfigGui.h"
47 #include "cxDataInterface.h"
48 #include "cxTrackingService.h"
49 #include "cxTool.h"
50 #include "cxToolProperty.h"
51 #include "cxActiveToolWidget.h"
52 #include "cxManualTool.h"
53 #include "cxLegacySingletons.h"
54 #include "cxSpaceProvider.h"
55 #include "cxSpaceEditWidget.h"
56 #include "cxLegacySingletons.h"
57 
58 namespace cx
59 {
60 
61 ToolPropertiesWidget::ToolPropertiesWidget(QWidget* parent) :
62  BaseWidget(parent, "ToolPropertiesWidget", "Tool Properties")
63 {
64  //layout
65  mToptopLayout = new QVBoxLayout(this);
66  //toptopLayout->setMargin(0);
67 
68  mToptopLayout->addWidget(new ActiveToolWidget(trackingService(), this));
69 
70  QHBoxLayout* generalLayout = new QHBoxLayout;
71  mReferenceStatusLabel = new QLabel("Reference frame <undefined>", this);
72  generalLayout->addWidget(mReferenceStatusLabel);
73  mTrackingSystemStatusLabel = new QLabel("Tracking <undefined>", this);
74  generalLayout->addWidget(mTrackingSystemStatusLabel);
75 
76  mToptopLayout->addLayout(generalLayout);
77 
78  QGroupBox* activeGroup = new QGroupBox(this);
79  activeGroup->setTitle("Active Tool");
80  mToptopLayout->addWidget(activeGroup);
81  QVBoxLayout* activeGroupLayout = new QVBoxLayout;
82  activeGroup->setLayout(activeGroupLayout);
83 
84  QHBoxLayout* activeToolLayout = new QHBoxLayout;
85  activeToolLayout->addWidget(new QLabel("Name:", this));
86  mToolNameLabel = new QLabel(this);
87  activeToolLayout->addWidget(mToolNameLabel);
88  mActiveToolVisibleLabel = new QLabel("Visible: NA");
89  activeToolLayout->addWidget(mActiveToolVisibleLabel);
90  activeGroupLayout->addLayout(activeToolLayout);
91 
92  QGroupBox* manualGroup = new QGroupBox(this);
93  manualGroup->setTitle("Manual Tool");
94  mToptopLayout->addWidget(manualGroup);
95  QVBoxLayout* manualGroupLayout = new QVBoxLayout;
96  mManualGroup = manualGroup;
97  manualGroup->setLayout(manualGroupLayout);
98  manualGroupLayout->setMargin(0);
99  mManualToolWidget = new Transform3DWidget(manualGroup);
100  manualGroupLayout->addWidget(mManualToolWidget);
101  connect(trackingService()->getManualTool().get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(manualToolChanged()));
102  connect(trackingService()->getManualTool().get(), SIGNAL(toolVisible(bool)), this, SLOT(manualToolChanged()));
103  connect(mManualToolWidget, SIGNAL(changed()), this, SLOT(manualToolWidgetChanged()));
104 
105  mSpaceSelector = SpaceProperty::initialize("selectSpace",
106  "Space",
107  "Select coordinate system to store position in.");
108  mSpaceSelector->setSpaceProvider(spaceProvider());
109  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::spacesChangedSlot);
110  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::setModified);
111  mSpaceSelector->setValue(spaceProvider()->getPr());
112  manualGroupLayout->addWidget(new SpaceEditWidget(this, mSpaceSelector));
113 
115  mUSSectorConfigBox = new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(ts));
116  mToptopLayout->addWidget(mUSSectorConfigBox);
117  mUSSectorConfigBox->hide();
118 
119  QGridLayout* gridLayout = new QGridLayout;
120  activeGroupLayout->addLayout(gridLayout);
121 
123 
124  mToptopLayout->addStretch();
125 
127 
128  connect(trackingService().get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(activeToolChangedSlot()));
129 
131  connect(trackingService().get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(updateSlot()));
132 
133  this->activeToolChangedSlot();
134  this->referenceToolChangedSlot();
135  this->updateSlot();
136  this->manualToolChanged();
137  this->spacesChangedSlot();
138 }
139 
141 {
142 }
143 
145 {
146  return "<html>"
147  "<h3>Tool Properties</h3>"
148  "<p>TODO.</p>"
149  "<p><i></i></p>"
150  "</html>";
151 }
152 
154 {
155  if (!trackingService()->getManualTool())
156  return;
157  mManualGroup->setVisible(trackingService()->getManualTool()->getVisible());
158  mManualToolWidget->blockSignals(true);
159 
160  Transform3D prMt = trackingService()->getManualTool()->get_prMt();
161  CoordinateSystem space_q = mSpaceSelector->getValue();
162  CoordinateSystem space_mt = spaceProvider()->getTO(trackingService()->getManualTool());
163  Transform3D qMt = spaceProvider()->get_toMfrom(space_mt, space_q);
164 
165  mManualToolWidget->setMatrix(qMt);
166  mManualToolWidget->blockSignals(false);
167 }
168 
170 {
171  Transform3D qMt = mManualToolWidget->getMatrix();
172  CoordinateSystem space_q = mSpaceSelector->getValue();
173  CoordinateSystem space_mt = spaceProvider()->getTO(trackingService()->getManualTool());
174  CoordinateSystem space_pr = spaceProvider()->getPr();
175  Transform3D qMpr = spaceProvider()->get_toMfrom(space_pr, space_q);
176  Transform3D prMt = qMpr.inv() * qMt;
177 
178  trackingService()->getManualTool()->set_prMt(prMt);
179 }
180 
182 {
183  CoordinateSystem space = mSpaceSelector->getValue();
184 
185 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
186  mSpaceSelector->setValue(space);
187  mSpaceSelector->setHelp(QString("The space q to display tool position in,\n"
188  "qMt"));
189  this->setModified();
190  this->manualToolChanged();
191 }
192 
194 {
195  if (mActiveTool)
196  disconnect(mActiveTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
197 
198  mActiveTool = trackingService()->getActiveTool();
199 
200  if(mActiveTool && mActiveTool->hasType(Tool::TOOL_US_PROBE))
201  {
202  mUSSectorConfigBox->show();
203  mToptopLayout->update();
204  }
205  else
206  {
207  mUSSectorConfigBox->hide();
208  mToptopLayout->update();
209  }
210 
211  if (mActiveTool)
212  connect(mActiveTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
213 }
214 
216 {
217  if (mReferenceTool)
218  disconnect(mReferenceTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
219 
220  mReferenceTool = trackingService()->getReferenceTool();
221 
222  if (mReferenceTool)
223  connect(mReferenceTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
224 }
225 
227 {
228  if (mActiveTool)
229  {
230  mToolNameLabel->setText(qstring_cast(mActiveTool->getName()));
231  QString text = mActiveTool->getVisible() ? "Visible" : "Not Visible";
232  mActiveToolVisibleLabel->setText(text);
233  }
234  else
235  {
236  mToolNameLabel->setText("none");
237  mActiveToolVisibleLabel->setText("");
238  }
239 
240  if (mReferenceTool)
241  {
242  QString text = mReferenceTool->getVisible() ? "visible" : "not visible";
243  mReferenceStatusLabel->setText("Reference " + text);
244  }
245  else
246  {
247  mReferenceStatusLabel->setText("Reference is the tracker");
248  }
249 
250  QString status = "Unconfigured";
251  if (trackingService()->getState()==Tool::tsCONFIGURED)
252  status = "Configured";
253  if (trackingService()->getState()==Tool::tsINITIALIZED)
254  status = "Initialized";
255  if (trackingService()->getState()==Tool::tsTRACKING)
256  status = "Tracking";
257  mTrackingSystemStatusLabel->setText("Tracking status: " + status);
258 }
259 
260 void ToolPropertiesWidget::showEvent(QShowEvent* event)
261 {
262  QWidget::showEvent(event);
263 }
264 
265 void ToolPropertiesWidget::hideEvent(QCloseEvent* event)
266 {
267  QWidget::closeEvent(event);
268 }
269 
270 
271 }//end namespace cx
QString qstring_cast(const T &val)
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix...
Composite widget for string selection.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class TrackingService > TrackingServicePtr
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
static StringPropertyActiveProbeConfigurationPtr New(TrackingServicePtr trackingService)
Composite widget for string selection.
configured with basic info
Definition: cxTool.h:81
Interface to the tool offset of the active tool.
virtual void hideEvent(QCloseEvent *event)
disconnects stuff
void setMatrix(const Transform3D &M)
Composite widget for scalar data manipulation.
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
Widget that contains a select active tool combo box.
Identification of a Coordinate system.
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
connected to hardware, if any, ready to use
Definition: cxTool.h:82
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
Transform3D getMatrix() const
emitting tracking data
Definition: cxTool.h:83
cxLogicManager_EXPORT TrackingServicePtr trackingService()
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:93