Fraxinus  18.10
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include "cxDataLocations.h"
14 
15 #include "cxDefinitionStrings.h"
17 #include "cxFileHelpers.h"
18 #include "cxProfile.h"
19 #include "cxTracker.h"
20 #include "cxLogger.h"
21 
22 namespace cx
23 {
24 
26 {
28  data.mFileName = config.mUid;
29  data.mClinical_app = config.mClinicalApplication;
31 
32  QStringList selectedTools = config.mTools;
33  QString referencePath = config.mReferenceTool;
34 
35  TRACKING_SYSTEM selectedTracker = string2enum<TRACKING_SYSTEM>(config.mTrackingSystemName);
36 
38 // QFile configFile(data.mFileName);
39 // QFileInfo info(configFile);
40 // QDir dir = info.dir();
41  foreach(QString absoluteToolPath, selectedTools)
42  {
43 // QString relativeToolFilePath = dir.relativeFilePath(absoluteToolPath);
45  tool.mAbsoluteToolFilePath = absoluteToolPath;
46  tool.mReference = (absoluteToolPath == referencePath);
47 
48  for (unsigned i = 0; i < config.mToolList.size(); ++i)
49  {
50  if(tool.mAbsoluteToolFilePath == config.mToolList[i].mAbsoluteToolFilePath)
51  {
52  tool.mOpenIGTLinkImageId = config.mToolList[i].mOpenIGTLinkImageId;
53  tool.mOpenIGTLinkTransformId = config.mToolList[i].mOpenIGTLinkTransformId;
54  }
55  }
56 
57  toolStructureVector.push_back(tool);
58  }
59 
60  data.mTrackersAndTools[selectedTracker] = toolStructureVector;
61 
63 }
64 
66 {
67  ConfigurationFileParser parser(uid);
68 
69  Configuration retval;
70  retval.mUid = uid;
71  retval.mName = QFileInfo(uid).completeBaseName();
72 
74 
75  std::vector<ToolFileParser::TrackerInternalStructure> trackers = parser.getTrackers();
76  for (unsigned i = 0; i < trackers.size(); ++i)
77  {
78  retval.mTrackingSystemName = enum2string(trackers[i].mType);
79  // only one trackingsystem is returned. (backed supports more than is needed.)
80  }
81 
82  std::vector<QString> tools = parser.getAbsoluteToolFilePaths();
83  for (unsigned i = 0; i < tools.size(); ++i)
84  {
85  retval.mTools << tools[i];
86  }
87 
90  retval.mToolList = parser.getToolListWithMetaInformation();
91 
92  return retval;
93 }
94 
95 QStringList TrackerConfigurationImpl::getToolsGivenFilter(QStringList applicationsFilter,
96  QStringList trackingsystemsFilter)
97 {
98  QStringList allTools = this->getAllTools();
99  QStringList filteredTools = this->filter(allTools, applicationsFilter, trackingsystemsFilter);
100  return filteredTools;
101 }
102 
104 {
105  Tool retval;
106  retval.mUid = uid;
107 
108  QString absoluteFilePath = uid;
109  QFile file(absoluteFilePath);
110  QFileInfo info(file);
111  retval.mName = info.dir().dirName();
112 
113  ToolFileParser parser(absoluteFilePath);
115 
116  retval.mTrackingSystemName = enum2string(internal->mTrackerType);
117  retval.mIsReference = internal->mIsReference;
118  retval.mPictureFilename = internal->mPictureFileName;
119 
120  return retval;
121 }
122 
124 {
125  QStringList allTools = this->getAllTools();
126  QStringList retval;
127 
128  foreach(QString path, allTools)
129  {
130  //get internal tool
131  ToolFileParser::ToolInternalStructurePtr internal = this->getToolInternal(path);
132  for (unsigned i=0; i<internal->mClinicalApplications.size(); ++i)
133  retval << internal->mClinicalApplications[i];
134  }
135 
136  retval.removeDuplicates();
137  return retval;
138 }
139 
141 {
143 }
144 
145 void TrackerConfigurationImpl::setTrackingSystemImplementation(QString trackingSystemImplementation)
146 {
147  mTrackingSystemImplementation = trackingSystemImplementation;
148 }
149 
150 QStringList TrackerConfigurationImpl::filter(QStringList toolsToFilter, QStringList applicationsFilter,
151  QStringList trackingsystemsFilter)
152 {
153  QStringList retval;
154 
155  foreach(QString toolFilePath, toolsToFilter)
156  {
157  //get internal tool
158  ToolFileParser::ToolInternalStructurePtr internal = this->getToolInternal(toolFilePath);
159 
160  //check tracking systems
161  QString trackerName = enum2string(internal->mTrackerType);
162  if(!trackingsystemsFilter.contains(trackerName, Qt::CaseInsensitive))
163  continue;
164 
165  //check applications
166  bool passedApplicationFilter = false;
167  std::vector<QString>::iterator it = internal->mClinicalApplications.begin();
168  while(it != internal->mClinicalApplications.end() && !passedApplicationFilter)
169  {
170  QString applicationName = *it;
171  if(applicationsFilter.contains(applicationName, Qt::CaseInsensitive))
172  {
173  passedApplicationFilter = true;
174  }
175  if(applicationsFilter.contains("all", Qt::CaseInsensitive))
176  {
177  passedApplicationFilter = true;
178  }
179  if(applicationsFilter.contains("default", Qt::CaseInsensitive))
180  {
181  passedApplicationFilter = true;
182  }
183  ++it;
184  }
185  if(!passedApplicationFilter)
186  continue;
187 
188  //add if filters passed
189  retval << toolFilePath;
190  }
191 
192  return retval;
193 }
194 
195 ToolFileParser::ToolInternalStructurePtr TrackerConfigurationImpl::getToolInternal(QString toolAbsoluteFilePath)
196 {
198 
199  ToolFileParser parser(toolAbsoluteFilePath);
200  retval = parser.getTool();
201 
202  return retval;
203 }
204 
206 {
207  ToolFileParser::ToolInternalStructurePtr internal = this->getToolInternal(uid);
208  return internal->verify();
209 }
210 
212 {
213  return profile()->getPath() + "/tool";
214 }
215 
217 {
218  QString path = this->getConfigurationApplicationsPath();
219  return cx::getAbsolutePathToXmlFiles(path);
220 
221 // QStringList retval;
222 
223 // QStringList configPaths = DataLocations::getRootConfigPaths();
224 
225 // for (int i=0; i< configPaths.size(); ++i)
226 // {
227 // QDir dir(configPaths[i]+"/tool/"+application);
228 // retval << cx::getAbsolutePathToXmlFiles(dir.absolutePath());
229 // }
230 // return retval;
231 }
232 
234 {
235  QStringList retval;
236  QStringList rootPaths = DataLocations::getRootConfigPaths();
237 
238  for (int i=0; i< rootPaths.size(); ++i)
239  {
240  QString configFilePath = rootPaths[i] + "/profiles";
241  foreach(QFileInfo dir, cx::getDirs(configFilePath))
242  {
243  retval << cx::getAbsolutePathToXmlFiles(dir.absoluteFilePath()+"/tool");
244  }
245  }
246  return retval;
247 }
248 
250 {
251  QStringList root = profile()->getAllRootConfigPaths();
252  QString suffix("/tool/Tools/");
253  QStringList retval;
254  bool includeSubDirs = true;
255  for (int i=0; i<root.size(); ++i)
256  {
257  QString toolPath = root[i]+suffix;
258  retval << getAbsolutePathToXmlFiles(toolPath, includeSubDirs);
259  }
260  return retval;
261 }
262 
264 {
265  QStringList retval;
267  return retval;
268 }
269 
270 
271 } // namespace cx
272 
TrackersAndToolsMap mTrackersAndTools
the trackers and tools (relative path) that should be used in the config
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
virtual QStringList getConfigurationsGivenApplication()
boost::shared_ptr< ToolInternalStructure > ToolInternalStructurePtr
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()
std::vector< ToolStructure > ToolStructureVector
virtual void setTrackingSystemImplementation(QString trackingSystemImplementation)
QFileInfoList getDirs(QString path)
virtual ToolInternalStructurePtr getTool()
virtual QStringList getToolsGivenFilter(QStringList applicationsFilter, QStringList trackingsystemsFilter)
std::vector< cx::ConfigurationFileParser::ToolStructure > mToolList
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::vector< QString > getAbsoluteToolFilePaths()
QString mClinical_app
the clinical application this config is made for
std::vector< ToolFileParser::TrackerInternalStructure > getTrackers()
Class for reading the files defining a CustusX tool.
QString enum2string(const ENUM &val)
std::vector< ConfigurationFileParser::ToolStructure > getToolListWithMetaInformation()
virtual Configuration getConfiguration(QString uid)
Namespace for all CustusX production code.