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