CustusX  15.8
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  this->setToolTip("Tool properties");
65  //layout
66  mToptopLayout = new QVBoxLayout(this);
67  //toptopLayout->setMargin(0);
68 
69  mToptopLayout->addWidget(new ActiveToolWidget(trackingService(), this));
70 
71  QHBoxLayout* generalLayout = new QHBoxLayout;
72  mReferenceStatusLabel = new QLabel("Reference frame <undefined>", this);
73  generalLayout->addWidget(mReferenceStatusLabel);
74  mTrackingSystemStatusLabel = new QLabel("Tracking <undefined>", this);
75  generalLayout->addWidget(mTrackingSystemStatusLabel);
76 
77  mToptopLayout->addLayout(generalLayout);
78 
79  QGroupBox* activeGroup = new QGroupBox(this);
80  activeGroup->setTitle("Active Tool");
81  mToptopLayout->addWidget(activeGroup);
82  QVBoxLayout* activeGroupLayout = new QVBoxLayout;
83  activeGroup->setLayout(activeGroupLayout);
84 
85  QHBoxLayout* activeToolLayout = new QHBoxLayout;
86  activeToolLayout->addWidget(new QLabel("Name:", this));
87  mToolNameLabel = new QLabel(this);
88  activeToolLayout->addWidget(mToolNameLabel);
89  mActiveToolVisibleLabel = new QLabel("Visible: NA");
90  activeToolLayout->addWidget(mActiveToolVisibleLabel);
91  activeGroupLayout->addLayout(activeToolLayout);
92 
93  QGroupBox* manualGroup = new QGroupBox(this);
94  manualGroup->setTitle("Manual Tool");
95  mToptopLayout->addWidget(manualGroup);
96  QVBoxLayout* manualGroupLayout = new QVBoxLayout;
97  mManualGroup = manualGroup;
98  manualGroup->setLayout(manualGroupLayout);
99  manualGroupLayout->setMargin(0);
100  mManualToolWidget = new Transform3DWidget(manualGroup);
101  manualGroupLayout->addWidget(mManualToolWidget);
102  connect(trackingService()->getManualTool().get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(manualToolChanged()));
103  connect(trackingService()->getManualTool().get(), SIGNAL(toolVisible(bool)), this, SLOT(manualToolChanged()));
104  connect(mManualToolWidget, SIGNAL(changed()), this, SLOT(manualToolWidgetChanged()));
105 
106  mSpaceSelector = SpaceProperty::initialize("selectSpace",
107  "Space",
108  "Select coordinate system to store position in.");
109  mSpaceSelector->setSpaceProvider(spaceProvider());
110  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::spacesChangedSlot);
111  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::setModified);
112  mSpaceSelector->setValue(spaceProvider()->getPr());
113  manualGroupLayout->addWidget(new SpaceEditWidget(this, mSpaceSelector));
114 
116  mUSSectorConfigBox = new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(ts));
117  mToptopLayout->addWidget(mUSSectorConfigBox);
118  mUSSectorConfigBox->hide();
119 
120  QGridLayout* gridLayout = new QGridLayout;
121  activeGroupLayout->addLayout(gridLayout);
122 
124 
125  mToptopLayout->addStretch();
126 
128 
129  connect(trackingService().get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(activeToolChangedSlot()));
130 
132  connect(trackingService().get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(updateSlot()));
133 
134  this->activeToolChangedSlot();
135  this->referenceToolChangedSlot();
136  this->updateSlot();
137  this->manualToolChanged();
138  this->spacesChangedSlot();
139 }
140 
142 {
143 }
144 
146 {
147  if (!trackingService()->getManualTool())
148  return;
149  mManualGroup->setVisible(trackingService()->getManualTool()->getVisible());
150  mManualToolWidget->blockSignals(true);
151 
152  Transform3D prMt = trackingService()->getManualTool()->get_prMt();
153  CoordinateSystem space_q = mSpaceSelector->getValue();
154  CoordinateSystem space_mt = spaceProvider()->getTO(trackingService()->getManualTool());
155  Transform3D qMt = spaceProvider()->get_toMfrom(space_mt, space_q);
156 
157  mManualToolWidget->setMatrix(qMt);
158  mManualToolWidget->blockSignals(false);
159 }
160 
162 {
163  Transform3D qMt = mManualToolWidget->getMatrix();
164  CoordinateSystem space_q = mSpaceSelector->getValue();
165  CoordinateSystem space_mt = spaceProvider()->getTO(trackingService()->getManualTool());
166  CoordinateSystem space_pr = spaceProvider()->getPr();
167  Transform3D qMpr = spaceProvider()->get_toMfrom(space_pr, space_q);
168  Transform3D prMt = qMpr.inv() * qMt;
169 
170  trackingService()->getManualTool()->set_prMt(prMt);
171 }
172 
174 {
175  CoordinateSystem space = mSpaceSelector->getValue();
176 
177 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
178  mSpaceSelector->setValue(space);
179  mSpaceSelector->setHelp(QString("The space q to display tool position in,\n"
180  "qMt"));
181  this->setModified();
182  this->manualToolChanged();
183 }
184 
186 {
187  if (mActiveTool)
188  disconnect(mActiveTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
189 
190  mActiveTool = trackingService()->getActiveTool();
191 
192  if(mActiveTool && mActiveTool->hasType(Tool::TOOL_US_PROBE))
193  {
194  mUSSectorConfigBox->show();
195  mToptopLayout->update();
196  }
197  else
198  {
199  mUSSectorConfigBox->hide();
200  mToptopLayout->update();
201  }
202 
203  if (mActiveTool)
204  connect(mActiveTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
205 }
206 
208 {
209  if (mReferenceTool)
210  disconnect(mReferenceTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
211 
212  mReferenceTool = trackingService()->getReferenceTool();
213 
214  if (mReferenceTool)
215  connect(mReferenceTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateSlot()));
216 }
217 
219 {
220  if (mActiveTool)
221  {
222  mToolNameLabel->setText(qstring_cast(mActiveTool->getName()));
223  QString text = mActiveTool->getVisible() ? "Visible" : "Not Visible";
224  mActiveToolVisibleLabel->setText(text);
225  }
226  else
227  {
228  mToolNameLabel->setText("none");
229  mActiveToolVisibleLabel->setText("");
230  }
231 
232  if (mReferenceTool)
233  {
234  QString text = mReferenceTool->getVisible() ? "visible" : "not visible";
235  mReferenceStatusLabel->setText("Reference " + text);
236  }
237  else
238  {
239  mReferenceStatusLabel->setText("Reference is the tracker");
240  }
241 
242  QString status = "Unconfigured";
243  if (trackingService()->getState()==Tool::tsCONFIGURED)
244  status = "Configured";
245  if (trackingService()->getState()==Tool::tsINITIALIZED)
246  status = "Initialized";
247  if (trackingService()->getState()==Tool::tsTRACKING)
248  status = "Tracking";
249  mTrackingSystemStatusLabel->setText("Tracking status: " + status);
250 }
251 
252 void ToolPropertiesWidget::showEvent(QShowEvent* event)
253 {
254  QWidget::showEvent(event);
255 }
256 
257 void ToolPropertiesWidget::hideEvent(QCloseEvent* event)
258 {
259  QWidget::closeEvent(event);
260 }
261 
262 
263 }//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.
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