CustusX  15.3.3-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  ++it;
156  }
157  if(!passedApplicationFilter)
158  continue;
159 
160  //add if filters passed
161  retval << toolFilePath;
162  }
163 
164  return retval;
165 }
166 
167 IgstkTool::InternalStructure TrackerConfigurationImpl::getToolInternal(QString toolAbsoluteFilePath)
168 {
169  IgstkTool::InternalStructure retval;
170 
171  ToolFileParser parser(toolAbsoluteFilePath);
172  retval = parser.getTool();
173 
174  return retval;
175 }
176 
178 {
179  IgstkTool::InternalStructure internal = this->getToolInternal(uid);
180  return internal.verify();
181 }
182 
184 {
185  return profile()->getPath() + "/tool";
186 }
187 
189 {
190  QString path = this->getConfigurationApplicationsPath();
191  return cx::getAbsolutePathToXmlFiles(path);
192 
193 // QStringList retval;
194 
195 // QStringList configPaths = DataLocations::getRootConfigPaths();
196 
197 // for (int i=0; i< configPaths.size(); ++i)
198 // {
199 // QDir dir(configPaths[i]+"/tool/"+application);
200 // retval << cx::getAbsolutePathToXmlFiles(dir.absolutePath());
201 // }
202 // return retval;
203 }
204 
206 {
207  QStringList retval;
208  QStringList rootPaths = DataLocations::getRootConfigPaths();
209 
210  for (int i=0; i< rootPaths.size(); ++i)
211  {
212  QString configFilePath = rootPaths[i] + "/profiles";
213  foreach(QFileInfo dir, cx::getDirs(configFilePath))
214  {
215  retval << cx::getAbsolutePathToXmlFiles(dir.absoluteFilePath()+"/tool");
216  }
217  }
218  return retval;
219 }
220 
222 {
223  QStringList root = profile()->getAllRootConfigPaths();
224  QString suffix("/tool/Tools/");
225  QStringList retval;
226  bool includeSubDirs = true;
227  for (int i=0; i<root.size(); ++i)
228  {
229  QString toolPath = root[i]+suffix;
230  retval << getAbsolutePathToXmlFiles(toolPath, includeSubDirs);
231  }
232  return retval;
233 }
234 
236 {
237  QStringList retval;
239  return retval;
240 }
241 
242 
243 } // namespace cx
244 
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)