Fraxinus  16.5.0-fx-rc9
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 "cxSpaceProvider.h"
54 #include "cxSpaceEditWidget.h"
55 #include "cxToolProperty.h"
56 #include "cxSpaceProvider.h"
57 #include "cxLogger.h"
58 
59 namespace cx
60 {
61 
62 
64  BaseWidget(parent, "ToolPropertiesWidget", "Tool Properties")
65 {
66 
67  QVBoxLayout* layout = new QVBoxLayout(this);
68  layout->setMargin(0);
69  ActiveToolWidget* activeToolWidget = new ActiveToolWidget(trackingService, this);
70  layout->addWidget(activeToolWidget);
71 
72  StringPropertyBasePtr selector = activeToolWidget->getSelector();
73 
74  ToolPropertiesWidget* info = new ToolPropertiesWidget(selector, trackingService, spaceProvider, this);
75  info->layout()->setMargin(0);
76  layout->addWidget(info);
77 }
78 
80 {}
81 
82 //---------------------------------------------------------
83 //---------------------------------------------------------
84 //---------------------------------------------------------
85 
86 ToolPropertiesWidget::ToolPropertiesWidget(StringPropertyBasePtr toolSelector,
89  QWidget* parent) :
90  BaseWidget(parent, "ToolCorePropertiesWidget", "Tool Properties"),
91  mSelector(toolSelector),
92  mTrackingService(trackingService),
93  mSpaceProvider(spaceProvider),
94  mManualToolWidget(NULL)
95 {
96  mToptopLayout = new QVBoxLayout(this);
97  this->setModified();
98 }
99 
101 {
102 }
103 
105 {
106  if (mManualToolWidget) // already created
107  return;
108 
109  this->setToolTip("Tool properties");
110  //layout
111  //toptopLayout->setMargin(0);
112 
113  QHBoxLayout* generalLayout = new QHBoxLayout;
114  mReferenceStatusLabel = new QLabel("Reference frame <undefined>", this);
115  generalLayout->addWidget(mReferenceStatusLabel);
116  mTrackingSystemStatusLabel = new QLabel("Tracking <undefined>", this);
117  generalLayout->addWidget(mTrackingSystemStatusLabel);
118 
119  mToptopLayout->addLayout(generalLayout);
120 
121  QGroupBox* activeGroup = new QGroupBox(this);
122  activeGroup->setTitle("Tool");
123  mToptopLayout->addWidget(activeGroup);
124  QVBoxLayout* activeGroupLayout = new QVBoxLayout;
125  activeGroup->setLayout(activeGroupLayout);
126 
127  QHBoxLayout* activeToolLayout = new QHBoxLayout;
128  activeToolLayout->addWidget(new QLabel("Name:", this));
129  mToolNameLabel = new QLabel(this);
130  activeToolLayout->addWidget(mToolNameLabel);
131  mActiveToolVisibleLabel = new QLabel("Visible: NA");
132  activeToolLayout->addWidget(mActiveToolVisibleLabel);
133  activeGroupLayout->addLayout(activeToolLayout);
134 
135  QGroupBox* manualGroup = new QGroupBox(this);
136  manualGroup->setTitle("Manual Tool");
137  mToptopLayout->addWidget(manualGroup);
138  QVBoxLayout* manualGroupLayout = new QVBoxLayout;
139  mManualGroup = manualGroup;
140  manualGroup->setLayout(manualGroupLayout);
141  manualGroupLayout->setMargin(0);
142  mManualToolWidget = new Transform3DWidget(manualGroup);
143  manualGroupLayout->addWidget(mManualToolWidget);
144  connect(mManualToolWidget, SIGNAL(changed()), this, SLOT(manualToolWidgetChanged()));
145 
146  mSpaceSelector = SpaceProperty::initialize("selectSpace",
147  "Space",
148  "Select coordinate system to store position in.");
149  mSpaceSelector->setSpaceProvider(mSpaceProvider);
150  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::spacesChangedSlot);
151  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::setModified);
152  mSpaceSelector->setValue(mSpaceProvider->getPr());
153  manualGroupLayout->addWidget(new SpaceEditWidget(this, mSpaceSelector));
154 
155  TrackingServicePtr ts = mTrackingService;
156  mUSSectorConfigBox = new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(ts));
157  mToptopLayout->addWidget(mUSSectorConfigBox);
158  mUSSectorConfigBox->hide();
159 
160  QGridLayout* gridLayout = new QGridLayout;
161  activeGroupLayout->addLayout(gridLayout);
162 
163  mToolOffset = DoublePropertyToolOffset::create(mTool);
164  gridLayout->addWidget(new SpinBoxAndSliderGroupWidget(this, mToolOffset));
165 
166  mMetadataLabel = new QTextEdit;
167  mToptopLayout->addWidget(mMetadataLabel);
168 
169  connect(ts.get(), &TrackingService::stateChanged, this, &ToolPropertiesWidget::reconnectTools);
172 
173  this->reconnectTools();
174  this->activeToolChangedSlot();
175  this->spacesChangedSlot();
176 }
177 
179 {
180  this->setupUI();
181  this->updateFrontend();
182  this->toolPositionChanged();
183 }
184 
185 void ToolPropertiesWidget::toolPositionChanged()
186 {
187  if (!mTool)
188  return;
189 
190  mManualGroup->setVisible(mTool->getVisible());
191  mManualToolWidget->blockSignals(true);
192 
193  Transform3D prMt = mTool->get_prMt();
194  CoordinateSystem space_q = mSpaceSelector->getValue();
195  CoordinateSystem space_mt = mSpaceProvider->getTO(mTool);
196  Transform3D qMt = mSpaceProvider->get_toMfrom(space_mt, space_q);
197 
198  mManualToolWidget->setMatrix(qMt);
199  mManualToolWidget->blockSignals(false);
200 
201  this->updateBrowser();
202 }
203 
204 QString ToolPropertiesWidget::createDescriptionForTool(ToolPtr current)
205 {
206  QString meta = current->getMetadata().toString();
207  return QString("Tool=%1: visible=%2\n%3\n")
208  .arg(current->getName())
209  .arg(current->getVisible())
210  .arg(meta);
211 }
212 
213 void ToolPropertiesWidget::updateBrowser()
214 {
215  QString text;
216 
217  for (TrackingService::ToolMap::iterator i=mTools.begin(); i!=mTools.end(); ++i)
218  {
219  text += this->createDescriptionForTool(i->second) + "\n";
220  }
221 
222  int sstart = mMetadataLabel->textCursor().selectionStart();
223  int send = mMetadataLabel->textCursor().selectionEnd();
224  int textPos = mMetadataLabel->textCursor().position();
225 
226  mMetadataLabel->setPlainText(text);
227  QTextCursor cursor = mMetadataLabel->textCursor();
228 
229  cursor.setPosition(sstart, QTextCursor::MoveAnchor);
230  cursor.setPosition(send, QTextCursor::KeepAnchor);
231 
232  mMetadataLabel->setTextCursor(cursor);
233 }
234 
236 {
237  if (!mTool)
238  return;
239 
240  Transform3D qMt = mManualToolWidget->getMatrix();
241  CoordinateSystem space_q = mSpaceSelector->getValue();
242  CoordinateSystem space_mt = mSpaceProvider->getTO(mTool);
243  CoordinateSystem space_pr = mSpaceProvider->getPr();
244  Transform3D qMpr = mSpaceProvider->get_toMfrom(space_pr, space_q);
245  Transform3D prMt = qMpr.inv() * qMt;
246 
247  mTool->set_prMt(prMt);
248 }
249 
251 {
252  CoordinateSystem space = mSpaceSelector->getValue();
253 
254 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
255  mSpaceSelector->setValue(space);
256  mSpaceSelector->setHelp(QString("The space q to display tool position in,\n"
257  "qMt"));
258  this->setModified();
259 // this->toolPositionChanged();
260 }
261 
262 void ToolPropertiesWidget::reconnectTools()
263 {
264  for (TrackingService::ToolMap::iterator i=mTools.begin(); i!=mTools.end(); ++i)
265  {
266  disconnect(i->second.get(), &Tool::toolVisible, this, &ToolPropertiesWidget::setModified);
267  disconnect(i->second.get(), &Tool::toolTransformAndTimestamp, this, &ToolPropertiesWidget::setModified);
268  }
269  mTools = mTrackingService->getTools();
270  for (TrackingService::ToolMap::iterator i=mTools.begin(); i!=mTools.end(); ++i)
271  {
272  connect(i->second.get(), &Tool::toolVisible, this, &ToolPropertiesWidget::setModified);
273  connect(i->second.get(), &Tool::toolTransformAndTimestamp, this, &ToolPropertiesWidget::setModified);
274  }
275 }
276 
278 {
279  mTool = mTrackingService->getTool(mSelector->getValue());
280 
281  mToolOffset->setTool(mTool);
282  mUSSectorConfigBox->setVisible(mTool && mTool->hasType(Tool::TOOL_US_PROBE));
283  mToptopLayout->update();
284 
285  this->setModified();
286 }
287 
288 void ToolPropertiesWidget::updateFrontend()
289 {
290  if (mTool)
291  {
292  mToolNameLabel->setText(qstring_cast(mTool->getName()));
293  QString text = mTool->getVisible() ? "Visible" : "Not Visible";
294  mActiveToolVisibleLabel->setText(text);
295  }
296  else
297  {
298  mToolNameLabel->setText("none");
299  mActiveToolVisibleLabel->setText("");
300  }
301 
302  ToolPtr reference = mTrackingService->getReferenceTool();
303  if (reference)
304  {
305  QString text = reference->getVisible() ? "Visible" : "Not Visible";
306  mReferenceStatusLabel->setText("Reference " + text);
307  }
308  else
309  {
310  mReferenceStatusLabel->setText("Reference is the tracker");
311  }
312 
313  QString status = "Unconfigured";
314  if (mTrackingService->getState()==Tool::tsCONFIGURED)
315  status = "Configured";
316  if (mTrackingService->getState()==Tool::tsINITIALIZED)
317  status = "Initialized";
318  if (mTrackingService->getState()==Tool::tsTRACKING)
319  status = "Tracking";
320  mTrackingSystemStatusLabel->setText("Tracking status: " + status);
321 }
322 
323 }//end namespace cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
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())
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
static StringPropertyActiveProbeConfigurationPtr New(TrackingServicePtr trackingService)
Composite widget for string selection.
configured with basic info
Definition: cxTool.h:96
void setMatrix(const Transform3D &M)
Composite widget for scalar data manipulation.
static boost::shared_ptr< DoublePropertyToolOffset > create(ToolPtr tool)
void toolVisible(bool visible)
StringPropertyBasePtr getSelector()
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
Widget that contains a select active tool combo box.
Identification of a Coordinate system.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
connected to hardware, if any, ready to use
Definition: cxTool.h:97
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
Transform3D getMatrix() const
ActiveToolPropertiesWidget(TrackingServicePtr trackingService, SpaceProviderPtr spaceProvider, QWidget *parent)
emitting tracking data
Definition: cxTool.h:98
cxLogicManager_EXPORT TrackingServicePtr trackingService()
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:108
boost::shared_ptr< class Tool > ToolPtr