NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
51 }
52 
53 QString ToolTreeNode::getUid() const
54 {
55  return mTool->getUid();
56 }
57 
58 QString ToolTreeNode::getName() const
59 {
60  return mTool->getName();
61 }
62 
64 {
65  if (this->repo()->getMode()=="flat")
66  return this->repo()->getNodeForGroup("tool");
67 
68  if (mTool->getUid() == this->getServices()->tracking()->getManualTool()->getUid())
69  return this->repo()->getNode(CoordinateSystem(csPATIENTREF).toString());
70 
71  if (mTool->hasType(Tool::TOOL_REFERENCE))
72  return this->repo()->getNode(CoordinateSystem(csPATIENTREF).toString());
73 
74  ToolPtr ref = this->getServices()->tracking()->getReferenceTool();
75  if (ref)
76  return this->repo()->getNode(ref->getUid());
77 
78  return this->repo()->getNode(CoordinateSystem(csPATIENTREF).toString());
79 }
80 
82 {
83  this->getServices()->tracking()->setActiveTool(mTool->getUid());
84 }
85 
86 QString ToolTreeNode::getType() const
87 {
88  return "tool";
89 }
90 
91 QIcon ToolTreeNode::getIcon() const
92 {
93  if (mTool->hasType(Tool::TOOL_US_PROBE))
94  return QIcon(":icons/tool_us_probe.png");
95  if (mTool->hasType(Tool::TOOL_POINTER))
96  return QIcon(":icons/tool_pointer.png");
97  if (mTool->hasType(Tool::TOOL_REFERENCE))
98  return QIcon(":icons/tool_reference.png");
99  if (mTool->hasType(Tool::TOOL_MANUAL))
100  return QIcon(":icons/tool_manual.png");
101  return QIcon(":icons/tool_pointer.png");
102 }
103 
104 QVariant ToolTreeNode::getColor() const
105 {
106  if (!mTool->isInitialized())
107  return QColor("darkgray");
108  if (mTool->getVisible())
109  return QColor("green");
110  else
111  return QColor("red");
112 
113  CX_LOG_CHANNEL_DEBUG("CA") << "tool " << mTool->getName() << ": init=" << mTool->isInitialized() << ", v=" << mTool->getVisible();
114 }
115 
116 QVariant ToolTreeNode::getFont() const
117 {
118  if (this->getServices()->tracking()->getActiveTool()==mTool)
119  {
120  QFont font;
121  font.setBold(true);
122  return font;
123  }
124  return QVariant();
125 }
126 
128 {
130  selector->setValue(mTool->getUid());
131  return new ToolPropertiesWidget(selector,
132  this->getServices()->tracking(),
133  this->getServices()->spaceProvider(),
134  NULL);
135 
136 // return new ToolPropertiesWidget(NULL);
137 // return new QLabel(QString("Tool widget %1 ").arg(mTool->getName()));
138 }
139 
140 
141 } // namespace cx
boost::shared_ptr< TreeNode > TreeNodePtr
virtual QVariant getColor() const
virtual TreeNodePtr getParent() const
VisServicesPtr getServices() const
virtual QIcon getIcon() const
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)
ToolTreeNode(TreeRepositoryWeakPtr repo, ToolPtr tool)
#define CX_LOG_CHANNEL_DEBUG(channel)
Definition: cxLogger.h:122
Identification of a Coordinate system.
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:106
virtual QString getName() const
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
virtual QVariant getFont() const
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
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
QWidget * createPropertiesWidget() const
Navigation pointer. Pointing functionality such as tool offset.
Definition: cxTool.h:107
boost::shared_ptr< class Tool > ToolPtr