CustusX  15.4.0-beta
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 
130 QStringList TrackerConfigurationImpl::filter(QStringList toolsToFilter, QStringList applicationsFilter,
131  QStringList trackingsystemsFilter)
132 {
133  QStringList retval;
134 
135  foreach(QString toolFilePath, toolsToFilter)
136  {
137  //get internal tool
138  IgstkTool::InternalStructure internal = this->getToolInternal(toolFilePath);
139 
140  //check tracking systems
141  QString trackerName = enum2string(internal.mTrackerType);
142  if(!trackingsystemsFilter.contains(trackerName, Qt::CaseInsensitive))
143  continue;
144 
145  //check applications
146  bool passedApplicationFilter = false;
147  std::vector<QString>::iterator it = internal.mClinicalApplications.begin();
148  while(it != internal.mClinicalApplications.end() && !passedApplicationFilter)
149  {
150  QString applicationName = *it;
151  if(applicationsFilter.contains(applicationName, Qt::CaseInsensitive))
152  {
153  passedApplicationFilter = true;
154  }
155  if(applicationsFilter.contains("all", Qt::CaseInsensitive))
156  {
157  passedApplicationFilter = true;
158  }
159  if(applicationsFilter.contains("default", Qt::CaseInsensitive))
160  {
161  passedApplicationFilter = true;
162  }
163  ++it;
164  }
165  if(!passedApplicationFilter)
166  continue;
167 
168  //add if filters passed
169  retval << toolFilePath;
170  }
171 
172  return retval;
173 }
174 
175 IgstkTool::InternalStructure TrackerConfigurationImpl::getToolInternal(QString toolAbsoluteFilePath)
176 {
177  IgstkTool::InternalStructure retval;
178 
179  ToolFileParser parser(toolAbsoluteFilePath);
180  retval = parser.getTool();
181 
182  return retval;
183 }
184 
186 {
187  IgstkTool::InternalStructure internal = this->getToolInternal(uid);
188  return internal.verify();
189 }
190 
192 {
193  return profile()->getPath() + "/tool";
194 }
195 
197 {
198  QString path = this->getConfigurationApplicationsPath();
199  return cx::getAbsolutePathToXmlFiles(path);
200 
201 // QStringList retval;
202 
203 // QStringList configPaths = DataLocations::getRootConfigPaths();
204 
205 // for (int i=0; i< configPaths.size(); ++i)
206 // {
207 // QDir dir(configPaths[i]+"/tool/"+application);
208 // retval << cx::getAbsolutePathToXmlFiles(dir.absolutePath());
209 // }
210 // return retval;
211 }
212 
214 {
215  QStringList retval;
216  QStringList rootPaths = DataLocations::getRootConfigPaths();
217 
218  for (int i=0; i< rootPaths.size(); ++i)
219  {
220  QString configFilePath = rootPaths[i] + "/profiles";
221  foreach(QFileInfo dir, cx::getDirs(configFilePath))
222  {
223  retval << cx::getAbsolutePathToXmlFiles(dir.absoluteFilePath()+"/tool");
224  }
225  }
226  return retval;
227 }
228 
230 {
231  QStringList root = profile()->getAllRootConfigPaths();
232  QString suffix("/tool/Tools/");
233  QStringList retval;
234  bool includeSubDirs = true;
235  for (int i=0; i<root.size(); ++i)
236  {
237  QString toolPath = root[i]+suffix;
238  retval << getAbsolutePathToXmlFiles(toolPath, includeSubDirs);
239  }
240  return retval;
241 }
242 
244 {
245  QStringList retval;
247  return retval;
248 }
249 
250 
251 } // namespace cx
252 
TrackersAndToolsMap mTrackersAndTools
the trackers and tools (relative path) that should be used in the config
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:142
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)