CustusX  2023.01.05-dev+develop.0da12
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxToolPropertiesWidget.h"
13 
14 #include <QTreeWidget>
15 #include <QTreeWidgetItem>
16 #include <QStringList>
17 #include <QVBoxLayout>
18 #include <QGroupBox>
19 #include <QCheckBox>
20 
21 
22 #include "cxTrackingService.h"
24 #include "cxTypeConversions.h"
25 //#include "UsConfigGui.h"
26 #include "cxDataInterface.h"
27 #include "cxTrackingService.h"
28 #include "cxTool.h"
29 #include "cxToolProperty.h"
30 #include "cxActiveToolWidget.h"
31 #include "cxManualTool.h"
32 #include "cxSpaceProvider.h"
33 #include "cxSpaceEditWidget.h"
34 #include "cxToolProperty.h"
35 #include "cxSpaceProvider.h"
36 #include "cxLogger.h"
37 
38 namespace cx
39 {
40 
41 
43  BaseWidget(parent, "tool_properties_widget", "Tool Properties")
44 {
45 
46  QVBoxLayout* layout = new QVBoxLayout(this);
47  layout->setMargin(0);
48  ActiveToolWidget* activeToolWidget = new ActiveToolWidget(trackingService, this);
49  layout->addWidget(activeToolWidget);
50 
51  StringPropertyBasePtr selector = activeToolWidget->getSelector();
52 
53  ToolPropertiesWidget* info = new ToolPropertiesWidget(selector, trackingService, spaceProvider, this);
54  info->layout()->setMargin(0);
55  layout->addWidget(info);
56 }
57 
59 {}
60 
61 //---------------------------------------------------------
62 //---------------------------------------------------------
63 //---------------------------------------------------------
64 
65 ToolPropertiesWidget::ToolPropertiesWidget(StringPropertyBasePtr toolSelector,
66  TrackingServicePtr trackingService,
67  SpaceProviderPtr spaceProvider,
68  QWidget* parent) :
69  BaseWidget(parent, "ToolCorePropertiesWidget", "Tool Properties"),
70  mSelector(toolSelector),
71  mTrackingService(trackingService),
72  mSpaceProvider(spaceProvider),
73  mManualToolWidget(NULL)
74 {
75  mToptopLayout = new QVBoxLayout(this);
76  this->setModified();
77 }
78 
80 {
81 }
82 
84 {
85  if (mManualToolWidget) // already created
86  return;
87 
88  this->setToolTip("Tool properties");
89  //layout
90  //toptopLayout->setMargin(0);
91 
92  QHBoxLayout* generalLayout = new QHBoxLayout;
93  mReferenceStatusLabel = new QLabel("Reference frame <undefined>", this);
94  generalLayout->addWidget(mReferenceStatusLabel);
95  mTrackingSystemStatusLabel = new QLabel("Tracking <undefined>", this);
96  generalLayout->addWidget(mTrackingSystemStatusLabel);
97 
98  mToptopLayout->addLayout(generalLayout);
99 
100  QGroupBox* activeGroup = new QGroupBox(this);
101  activeGroup->setTitle("Tool");
102  mToptopLayout->addWidget(activeGroup);
103  QVBoxLayout* activeGroupLayout = new QVBoxLayout;
104  activeGroup->setLayout(activeGroupLayout);
105 
106  QHBoxLayout* activeToolLayout = new QHBoxLayout;
107  activeToolLayout->addWidget(new QLabel("Name:", this));
108  mToolNameLabel = new QLabel(this);
109  activeToolLayout->addWidget(mToolNameLabel);
110  mActiveToolVisibleLabel = new QLabel("Visible: NA");
111  activeToolLayout->addWidget(mActiveToolVisibleLabel);
112  activeGroupLayout->addLayout(activeToolLayout);
113 
114  QGroupBox* manualGroup = new QGroupBox(this);
115  manualGroup->setTitle("Manual Tool");
116  mToptopLayout->addWidget(manualGroup);
117  QVBoxLayout* manualGroupLayout = new QVBoxLayout;
118  mManualGroup = manualGroup;
119  manualGroup->setLayout(manualGroupLayout);
120  manualGroupLayout->setMargin(0);
121  mManualToolWidget = new Transform3DWidget(manualGroup);
122  manualGroupLayout->addWidget(mManualToolWidget);
123  connect(mManualToolWidget, SIGNAL(changed()), this, SLOT(manualToolWidgetChanged()));
124 
125  mSpaceSelector = SpaceProperty::initialize("selectSpace",
126  "Space",
127  "Select coordinate system to store position in.");
128  mSpaceSelector->setSpaceProvider(mSpaceProvider);
129  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::spacesChangedSlot);
130  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &ToolPropertiesWidget::setModified);
131  mSpaceSelector->setValue(mSpaceProvider->getPr());
132  manualGroupLayout->addWidget(new SpaceEditWidget(this, mSpaceSelector));
133 
134  TrackingServicePtr ts = mTrackingService;
135  mUSSectorConfigBox = new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(ts));
136  mToptopLayout->addWidget(mUSSectorConfigBox);
137  mUSSectorConfigBox->hide();
138 
139  QGridLayout* gridLayout = new QGridLayout;
140  activeGroupLayout->addLayout(gridLayout);
141 
142  mToolOffset = DoublePropertyToolOffset::create(mTool);
143  gridLayout->addWidget(new SpinBoxAndSliderGroupWidget(this, mToolOffset));
144 
145  mMetadataLabel = new QTextEdit;
146  mToptopLayout->addWidget(mMetadataLabel);
147 
148  connect(ts.get(), &TrackingService::stateChanged, this, &ToolPropertiesWidget::reconnectTools);
151 
152  this->reconnectTools();
153  this->activeToolChangedSlot();
154  this->spacesChangedSlot();
155 }
156 
158 {
159  this->setupUI();
160  this->updateFrontend();
161  this->toolPositionChanged();
162 }
163 
164 void ToolPropertiesWidget::toolPositionChanged()
165 {
166  if (!mTool)
167  return;
168 
169  mManualGroup->setVisible(mTool->getVisible());
170  mManualToolWidget->blockSignals(true);
171 
172  Transform3D prMt = mTool->get_prMt();
173  CoordinateSystem space_q = mSpaceSelector->getValue();
174  CoordinateSystem space_mt = mSpaceProvider->getT(mTool);
175  Transform3D qMt = mSpaceProvider->get_toMfrom(space_mt, space_q);
176 
177  mManualToolWidget->setMatrix(qMt);
178  mManualToolWidget->blockSignals(false);
179 
180  this->updateBrowser();
181 }
182 
183 QString ToolPropertiesWidget::createDescriptionForTool(ToolPtr current)
184 {
185  bool hasProbe = false;
186  if(current->getProbe())
187  hasProbe=true;
188  QString meta = current->getMetadata().toString();
189  return QString("Tool=%1: visible=%2 has_probe=%3\n%4\n")
190  .arg(current->getName())
191  .arg(current->getVisible())
192  .arg(hasProbe)
193  .arg(meta);
194 }
195 
196 void ToolPropertiesWidget::updateBrowser()
197 {
198  QString text;
199 
200  for (TrackingService::ToolMap::iterator i=mTools.begin(); i!=mTools.end(); ++i)
201  {
202  text += this->createDescriptionForTool(i->second) + "\n";
203  }
204 
205  int sstart = mMetadataLabel->textCursor().selectionStart();
206  int send = mMetadataLabel->textCursor().selectionEnd();
207  int textPos = mMetadataLabel->textCursor().position();
208 
209  mMetadataLabel->setPlainText(text);
210  QTextCursor cursor = mMetadataLabel->textCursor();
211 
212  cursor.setPosition(sstart, QTextCursor::MoveAnchor);
213  cursor.setPosition(send, QTextCursor::KeepAnchor);
214 
215  mMetadataLabel->setTextCursor(cursor);
216 }
217 
219 {
220  if (!mTool)
221  return;
222 
223  Transform3D qMt = mManualToolWidget->getMatrix();
224  CoordinateSystem space_q = mSpaceSelector->getValue();
225 // CoordinateSystem space_mt = mSpaceProvider->getTO(mTool);
226  CoordinateSystem space_pr = mSpaceProvider->getPr();
227  Transform3D qMpr = mSpaceProvider->get_toMfrom(space_pr, space_q);
228  Transform3D prMt = qMpr.inv() * qMt;
229 
230  mTool->set_prMt(prMt);
231 }
232 
234 {
235  CoordinateSystem space = mSpaceSelector->getValue();
236 
237 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
238  mSpaceSelector->setValue(space);
239  mSpaceSelector->setHelp(QString("The space q to display tool position in,\n"
240  "qMt"));
241  this->setModified();
242 // this->toolPositionChanged();
243 }
244 
245 void ToolPropertiesWidget::reconnectTools()
246 {
247  for (TrackingService::ToolMap::iterator i=mTools.begin(); i!=mTools.end(); ++i)
248  {
249  disconnect(i->second.get(), &Tool::toolVisible, this, &ToolPropertiesWidget::setModified);
250  disconnect(i->second.get(), &Tool::toolTransformAndTimestamp, this, &ToolPropertiesWidget::setModified);
251  }
252  mTools = mTrackingService->getTools();
253  for (TrackingService::ToolMap::iterator i=mTools.begin(); i!=mTools.end(); ++i)
254  {
255  connect(i->second.get(), &Tool::toolVisible, this, &ToolPropertiesWidget::setModified);
256  connect(i->second.get(), &Tool::toolTransformAndTimestamp, this, &ToolPropertiesWidget::setModified);
257  }
258 }
259 
261 {
262  mTool = mTrackingService->getTool(mSelector->getValue());
263 
264  mToolOffset->setTool(mTool);
265  mUSSectorConfigBox->setVisible(mTool && mTool->hasType(Tool::TOOL_US_PROBE));
266  mToptopLayout->update();
267 
268  this->setModified();
269 }
270 
271 void ToolPropertiesWidget::updateFrontend()
272 {
273  if (mTool)
274  {
275  mToolNameLabel->setText(qstring_cast(mTool->getName()));
276  QString text = mTool->getVisible() ? "Visible" : "Not Visible";
277  mActiveToolVisibleLabel->setText(text);
278  }
279  else
280  {
281  mToolNameLabel->setText("none");
282  mActiveToolVisibleLabel->setText("");
283  }
284 
285  ToolPtr reference = mTrackingService->getReferenceTool();
286  if (reference)
287  {
288  QString text = reference->getVisible() ? "Visible" : "Not Visible";
289  mReferenceStatusLabel->setText("Reference " + text);
290  }
291  else
292  {
293  mReferenceStatusLabel->setText("Reference is the tracker");
294  }
295 
296  QString status = "Unconfigured";
297  if (mTrackingService->getState()==Tool::tsCONFIGURED)
298  status = "Configured";
299  if (mTrackingService->getState()==Tool::tsINITIALIZED)
300  status = "Initialized";
301  if (mTrackingService->getState()==Tool::tsTRACKING)
302  status = "Tracking";
303  mTrackingSystemStatusLabel->setText("Tracking status: " + status);
304 }
305 
306 }//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:75
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.
connected to hardware, if any, ready to use
Definition: cxTool.h:76
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
Transform3D getMatrix() const
ActiveToolPropertiesWidget(TrackingServicePtr trackingService, SpaceProviderPtr spaceProvider, QWidget *parent)
emitting tracking data
Definition: cxTool.h:77
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:87
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr