Fraxinus  17.12
An IGT application
cxToolTreeNode.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 #include "cxToolTreeNode.h"
33 #include "cxTreeRepository.h"
34 #include "cxLogger.h"
35 #include "cxTrackingService.h"
36 #include "cxVisServices.h"
37 #include <QIcon>
38 #include <QFont>
39 #include <QLabel>
40 #include "cxToolPropertiesWidget.h"
42 
43 namespace cx
44 {
45 
46 
48  TreeNodeImpl(repo), mTool(tool)
49 {
50  connect(mTool.get(), &Tool::toolVisible, this, &TreeNode::changed);
51 
52 }
53 
55 {
56 }
57 
58 QString ToolTreeNode::getUid() const
59 {
60  return mTool->getUid();
61 }
62 
63 QString ToolTreeNode::getName() const
64 {
65  return mTool->getName();
66 }
67 
69 {
70  if (this->repo()->getMode()=="flat")
71  return this->repo()->getNodeForGroup("tool");
72 
73  if (mTool->getUid() == this->getServices()->tracking()->getManualTool()->getUid())
74  return this->repo()->getNode(CoordinateSystem(csPATIENTREF).toString());
75 
76  if (mTool->hasType(Tool::TOOL_REFERENCE))
77  return this->repo()->getNode(CoordinateSystem(csPATIENTREF).toString());
78 
79  ToolPtr ref = this->getServices()->tracking()->getReferenceTool();
80  if (ref)
81  return this->repo()->getNode(ref->getUid());
82 
83  return this->repo()->getNode(CoordinateSystem(csPATIENTREF).toString());
84 }
85 
87 {
88  this->getServices()->tracking()->setActiveTool(mTool->getUid());
89 }
90 
91 QString ToolTreeNode::getType() const
92 {
93  return "tool";
94 }
95 
96 QIcon ToolTreeNode::getIcon() const
97 {
98  if (mTool->hasType(Tool::TOOL_US_PROBE))
99  return QIcon(":icons/tool_us_probe.png");
100  if (mTool->hasType(Tool::TOOL_POINTER))
101  return QIcon(":icons/tool_pointer.png");
102  if (mTool->hasType(Tool::TOOL_REFERENCE))
103  return QIcon(":icons/tool_reference.png");
104  if (mTool->hasType(Tool::TOOL_MANUAL))
105  return QIcon(":icons/tool_manual.png");
106  return QIcon(":icons/tool_pointer.png");
107 }
108 
109 QVariant ToolTreeNode::getColor() const
110 {
111  if (!mTool->isInitialized())
112  return QColor("darkgray");
113  if (mTool->getVisible())
114  return QColor("green");
115  else
116  return QColor("red");
117 }
118 
119 QVariant ToolTreeNode::getFont() const
120 {
121  if (this->getServices()->tracking()->getActiveTool()==mTool)
122  {
123  QFont font;
124  font.setBold(true);
125  return font;
126  }
127  return QVariant();
128 }
129 
130 boost::shared_ptr<QWidget> ToolTreeNode::createPropertiesWidget() const
131 {
133  selector->setValue(mTool->getUid());
134  return boost::shared_ptr<QWidget>(new ToolPropertiesWidget(selector,
135  this->getServices()->tracking(),
136  this->getServices()->spaceProvider(),
137  NULL));
138 
139 // return new ToolPropertiesWidget(NULL);
140 // return new QLabel(QString("Tool widget %1 ").arg(mTool->getName()));
141 }
142 
143 
144 } // namespace cx
boost::shared_ptr< TreeNode > TreeNodePtr
void changed()
virtual QVariant getColor() const
virtual TreeNodePtr getParent() const
VisServicesPtr getServices() const
virtual QIcon getIcon() const
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:755
boost::shared_ptr< class StringPropertySelectTool > StringPropertySelectToolPtr
virtual void activate()
boost::weak_ptr< class TreeRepository > TreeRepositoryWeakPtr
Definition: cxTreeNode.h:51
TreeRepositoryPtr repo()
Reference tool.
Definition: cxTool.h:105
csPATIENTREF
the patient/tool reference space (pr)
void toolVisible(bool visible)
ToolTreeNode(TreeRepositoryWeakPtr repo, ToolPtr tool)
Identification of a Coordinate system.
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:106
virtual QString getName() const
virtual QVariant getFont() const
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
virtual ~ToolTreeNode()
virtual boost::shared_ptr< QWidget > createPropertiesWidget() const
virtual QString getUid() const
virtual QString getType() const
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:108
Navigation pointer. Pointing functionality such as tool offset.
Definition: cxTool.h:107
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr