CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxToolProperty.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 "cxToolProperty.h"
34 
35 #include "cxTypeConversions.h"
36 #include "cxTrackingService.h"
37 #include "cxTool.h"
38 
39 namespace cx
40 {
41 
42 
44 {
45  mTrackingService = trackingService;
46  connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SIGNAL(changed()));
47  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &StringPropertyActiveTool::changed);
48 }
49 
51 {
52  return "Active Tool";
53 }
54 
55 bool StringPropertyActiveTool::setValue(const QString& value)
56 {
57  ToolPtr newTool = mTrackingService->getTool(value);
58  if (!newTool)
59  return false;
60  if(newTool == mTrackingService->getActiveTool())
61  return false;
62  mTrackingService->setActiveTool(newTool->getUid());
63  return true;
64 }
65 
67 {
68  if (!mTrackingService->getActiveTool())
69  return "";
70  return qstring_cast(mTrackingService->getActiveTool()->getUid());
71 }
72 
74 {
75  return "select the active tool";
76 }
77 
79 {
80  TrackingService::ToolMap tools = mTrackingService->getTools();
81 
82  QStringList retval;
83  for (TrackingService::ToolMap::iterator iter=tools.begin(); iter!=tools.end(); ++iter)
84  retval << iter->second->getUid();
85  return retval;
86 }
87 
89 {
90  ToolPtr tool = mTrackingService->getTool(internal);
91  if (!tool)
92  return "<no tool>";
93  return qstring_cast(tool->getName());
94 }
95 
99 
100 
101 
105 
106 
108 {
109  mTrackingService = trackingService;
110  connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(activeToolChanged()));
111  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &StringPropertyActiveProbeConfiguration::activeToolChanged);
112  this->activeToolChanged();
113 }
114 
115 void StringPropertyActiveProbeConfiguration::activeToolChanged()
116 {
117  // ignore tool changes to something non-probeish.
118  // This gives the user a chance to use the widget without having to show the probe.
119  ToolPtr newTool = mTrackingService->getFirstProbe();
120  if (!newTool || !newTool->getProbe())
121  return;
122 
123  if (mTool)
124  disconnect(mTool->getProbe().get(), SIGNAL(sectorChanged()), this, SIGNAL(changed()));
125 
126  mTool = newTool;
127 
128  if (mTool)
129  connect(mTool->getProbe().get(), SIGNAL(sectorChanged()), this, SIGNAL(changed()));
130 
131  emit changed();
132 }
133 
135 {
136  return "Probe Config";
137 }
138 
140 {
141  if (!mTool)
142  return false;
143  mTool->getProbe()->applyNewConfigurationWithId(value);
144  return true;
145 }
146 
148 {
149  if (!mTool)
150  return "";
151  return mTool->getProbe()->getConfigId();
152 }
153 
155 {
156  return "Select a probe configuration for the active probe.";
157 }
158 
160 {
161  if (!mTool)
162  return QStringList();
163  return mTool->getProbe()->getConfigIdList();
164 }
165 
167 {
168  if (!mTool)
169  return "<no tool>";
170  return mTool->getProbe()->getConfigName(internal);
171 }
172 
173 
174 }
StringPropertyActiveTool(TrackingServicePtr trackingService)
QString qstring_cast(const T &val)
virtual QStringList getValueRange() const
virtual QString getValue() const
get the data value.
virtual QStringList getValueRange() const
boost::shared_ptr< class TrackingService > TrackingServicePtr
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual bool setValue(const QString &value)
set the data value.
virtual bool setValue(const QString &value)
set the data value.
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
std::map< QString, ToolPtr > ToolMap
StringPropertyActiveProbeConfiguration(TrackingServicePtr trackingService)
virtual QString getValue() const
get the data value.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
cxLogicManager_EXPORT TrackingServicePtr trackingService()
boost::shared_ptr< class Tool > ToolPtr