NorMIT-nav  16.5
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 
96 //--------------------------------------------------------
97 //--------------------------------------------------------
98 //--------------------------------------------------------
99 
101 {
102  mTrackingService = trackingService;
103  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &StringPropertyActiveProbeConfiguration::activeToolChanged);
104  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &StringPropertyActiveProbeConfiguration::activeToolChanged);
105  this->activeToolChanged();
106 }
107 
108 void StringPropertyActiveProbeConfiguration::activeToolChanged()
109 {
110  // ignore tool changes to something non-probeish.
111  // This gives the user a chance to use the widget without having to show the probe.
112  ToolPtr newTool = mTrackingService->getFirstProbe();
113  if (!newTool || !newTool->getProbe())
114  return;
115 
116  if (mTool)
117  disconnect(mTool->getProbe().get(), &Probe::sectorChanged, this, &StringPropertyActiveProbeConfiguration::changed);
118 
119  mTool = newTool;
120 
121  if (mTool)
122  connect(mTool->getProbe().get(), &Probe::sectorChanged, this, &StringPropertyActiveProbeConfiguration::changed);
123 
124  emit changed();
125 }
126 
128 {
129  return "Probe Config";
130 }
131 
133 {
134  if (!mTool)
135  return false;
136  mTool->getProbe()->applyNewConfigurationWithId(value);
137  return true;
138 }
139 
141 {
142  if (!mTool)
143  return "";
144  return mTool->getProbe()->getConfigId();
145 }
146 
148 {
149  return "Select a probe configuration for the active probe.";
150 }
151 
153 {
154  if (!mTool)
155  return QStringList();
156  return mTool->getProbe()->getConfigIdList();
157 }
158 
160 {
161  if (!mTool)
162  return "<no tool>";
163  return mTool->getProbe()->getConfigName(internal);
164 }
165 
166 
167 }
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 activeToolChanged(const QString &uId)
void sectorChanged()
< Return a ProbeSectorPtr for the given uid. Use 'active' to get the default.
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