CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxTrackerConfigurationImpl.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 
34 #include "cxDataLocations.h"
35 
36 #include "cxDefinitionStrings.h"
38 #include "cxFileHelpers.h"
39 #include "cxProfile.h"
40 
41 namespace cx
42 {
43 
45 {
47  data.mFileName = config.mUid;
48  data.mClinical_app = config.mClinicalApplication;
49 
50  QStringList selectedTools = config.mTools;
51  QString referencePath = config.mReferenceTool;
52 
53  TRACKING_SYSTEM selectedTracker = string2enum<TRACKING_SYSTEM>(config.mTrackingSystem);
54 
56 // QFile configFile(data.mFileName);
57 // QFileInfo info(configFile);
58 // QDir dir = info.dir();
59  foreach(QString absoluteToolPath, selectedTools)
60  {
61 // QString relativeToolFilePath = dir.relativeFilePath(absoluteToolPath);
63 // tool.first = relativeToolFilePath;
64  tool.first = absoluteToolPath;
65  tool.second = (absoluteToolPath == referencePath);
66  toolfilesAndRefVector.push_back(tool);
67  }
68 
69  data.mTrackersAndTools[selectedTracker] = toolfilesAndRefVector;
70 
72 }
73 
75 {
76  ConfigurationFileParser parser(uid);
77 
78  Configuration retval;
79  retval.mUid = uid;
80  retval.mName = QFileInfo(uid).completeBaseName();
81 
83 
84  std::vector<IgstkTracker::InternalStructure> trackers = parser.getTrackers();
85  for (unsigned i = 0; i < trackers.size(); ++i)
86  {
87  retval.mTrackingSystem = enum2string(trackers[i].mType);
88  // only one trackingsystem is returned. (backed supports more than is needed.)
89  }
90 
91  std::vector<QString> tools = parser.getAbsoluteToolFilePaths();
92  for (unsigned i = 0; i < tools.size(); ++i)
93  {
94  retval.mTools << tools[i];
95  }
96 
98 
99  return retval;
100 }
101 
102 QStringList TrackerConfigurationImpl::getToolsGivenFilter(QStringList applicationsFilter,
103  QStringList trackingsystemsFilter)
104 {
105  QStringList allTools = this->getAllTools();
106  QStringList filteredTools = this->filter(allTools, applicationsFilter, trackingsystemsFilter);
107  return filteredTools;
108 }
109 
111 {
112  Tool retval;
113  retval.mUid = uid;
114 
115  QString absoluteFilePath = uid;
116  QFile file(absoluteFilePath);
117  QFileInfo info(file);
118  retval.mName = info.dir().dirName();
119 
120  ToolFileParser parser(absoluteFilePath);
121  IgstkTool::InternalStructure internal = parser.getTool();
122 
123  retval.mTrackingSystem = enum2string(internal.mTrackerType);
124  retval.mIsReference = internal.mIsReference;
125  retval.mPictureFilename = internal.mPictureFileName;
126 
127  return retval;
128 }
129 
131 {
132  QStringList allTools = this->getAllTools();
133  QStringList retval;
134 
135  foreach(QString path, allTools)
136  {
137  //get internal tool
138  IgstkTool::InternalStructure internal = this->getToolInternal(path);
139  for (unsigned i=0; i<internal.mClinicalApplications.size(); ++i)
140  retval << internal.mClinicalApplications[i];
141  }
142 
143  retval.removeDuplicates();
144  return retval;
145 }
146 
147 QStringList TrackerConfigurationImpl::filter(QStringList toolsToFilter, QStringList applicationsFilter,
148  QStringList trackingsystemsFilter)
149 {
150  QStringList retval;
151 
152  foreach(QString toolFilePath, toolsToFilter)
153  {
154  //get internal tool
155  IgstkTool::InternalStructure internal = this->getToolInternal(toolFilePath);
156 
157  //check tracking systems
158  QString trackerName = enum2string(internal.mTrackerType);
159  if(!trackingsystemsFilter.contains(trackerName, Qt::CaseInsensitive))
160  continue;
161 
162  //check applications
163  bool passedApplicationFilter = false;
164  std::vector<QString>::iterator it = internal.mClinicalApplications.begin();
165  while(it != internal.mClinicalApplications.end() && !passedApplicationFilter)
166  {
167  QString applicationName = *it;
168  if(applicationsFilter.contains(applicationName, Qt::CaseInsensitive))
169  {
170  passedApplicationFilter = true;
171  }
172  if(applicationsFilter.contains("all", Qt::CaseInsensitive))
173  {
174  passedApplicationFilter = true;
175  }
176  if(applicationsFilter.contains("default", Qt::CaseInsensitive))
177  {
178  passedApplicationFilter = true;
179  }
180  ++it;
181  }
182  if(!passedApplicationFilter)
183  continue;
184 
185  //add if filters passed
186  retval << toolFilePath;
187  }
188 
189  return retval;
190 }
191 
192 IgstkTool::InternalStructure TrackerConfigurationImpl::getToolInternal(QString toolAbsoluteFilePath)
193 {
194  IgstkTool::InternalStructure retval;
195 
196  ToolFileParser parser(toolAbsoluteFilePath);
197  retval = parser.getTool();
198 
199  return retval;
200 }
201 
203 {
204  IgstkTool::InternalStructure internal = this->getToolInternal(uid);
205  return internal.verify();
206 }
207 
209 {
210  return profile()->getPath() + "/tool";
211 }
212 
214 {
215  QString path = this->getConfigurationApplicationsPath();
216  return cx::getAbsolutePathToXmlFiles(path);
217 
218 // QStringList retval;
219 
220 // QStringList configPaths = DataLocations::getRootConfigPaths();
221 
222 // for (int i=0; i< configPaths.size(); ++i)
223 // {
224 // QDir dir(configPaths[i]+"/tool/"+application);
225 // retval << cx::getAbsolutePathToXmlFiles(dir.absolutePath());
226 // }
227 // return retval;
228 }
229 
231 {
232  QStringList retval;
233  QStringList rootPaths = DataLocations::getRootConfigPaths();
234 
235  for (int i=0; i< rootPaths.size(); ++i)
236  {
237  QString configFilePath = rootPaths[i] + "/profiles";
238  foreach(QFileInfo dir, cx::getDirs(configFilePath))
239  {
240  retval << cx::getAbsolutePathToXmlFiles(dir.absoluteFilePath()+"/tool");
241  }
242  }
243  return retval;
244 }
245 
247 {
248  QStringList root = profile()->getAllRootConfigPaths();
249  QString suffix("/tool/Tools/");
250  QStringList retval;
251  bool includeSubDirs = true;
252  for (int i=0; i<root.size(); ++i)
253  {
254  QString toolPath = root[i]+suffix;
255  retval << getAbsolutePathToXmlFiles(toolPath, includeSubDirs);
256  }
257  return retval;
258 }
259 
261 {
262  QStringList retval;
264  return retval;
265 }
266 
267 
268 } // namespace cx
269 
TrackersAndToolsMap mTrackersAndTools
the trackers and tools (relative path) that should be used in the config
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:169
virtual Configuration getConfiguration(QString uid)
virtual QStringList getConfigurationsGivenApplication()
std::vector< ToolFileAndReference > ToolFilesAndReferenceVector
static QStringList getRootConfigPaths()
QString mFileName
absolute path and filename for the new config file
static void saveConfiguration(Configuration &config)
virtual QStringList getSupportedTrackingSystems()
QFileInfoList getDirs(QString path)
virtual QStringList getToolsGivenFilter(QStringList applicationsFilter, QStringList trackingsystemsFilter)
std::vector< IgstkTracker::InternalStructure > getTrackers()
Class for reading the files defining a CustusX tool.
A tools internal structure.
Definition: cxIgstkTool.h:80
virtual void saveConfiguration(const Configuration &config)
QStringList getAbsolutePathToXmlFiles(QString path, bool includeSubDirs)
QString mUid
absolute path and filename for the new config file
static QStringList getSupportedTrackingSystems()
std::pair< QString, bool > ToolFileAndReference
std::vector< QString > getAbsoluteToolFilePaths()
IgstkTool::InternalStructure getTool()
QString mClinical_app
the clinical application this config is made for
Class for reading the files defining a CustusX tool.
QString enum2string(const ENUM &val)