CustusX  2023.01.05-dev+develop.0da12
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 
16 #include "cxFileHelpers.h"
17 #include "cxProfile.h"
18 #include "cxTracker.h"
19 #include "cxLogger.h"
20 #include "cxEnumConversion.h"
21 
22 namespace cx
23 {
24 
26 {
28  data.mFileName = config.mUid;
29  data.mClinical_app = config.mClinicalApplication;
31  data.mApplyRefToTools = config.mApplyRefToTools;
32 
33  QStringList selectedTools = config.mTools;
34  QString referencePath = config.mReferenceTool;
35 
36  TRACKING_SYSTEM selectedTracker = string2enum<TRACKING_SYSTEM>(config.mTrackingSystemName);
37 
39 // QFile configFile(data.mFileName);
40 // QFileInfo info(configFile);
41 // QDir dir = info.dir();
42  foreach(QString absoluteToolPath, selectedTools)
43  {
44 // QString relativeToolFilePath = dir.relativeFilePath(absoluteToolPath);
46  tool.mAbsoluteToolFilePath = absoluteToolPath;
47  tool.mReference = (absoluteToolPath == referencePath);
48 
49  for (unsigned i = 0; i < config.mToolList.size(); ++i)
50  {
51  if(tool.mAbsoluteToolFilePath == config.mToolList[i].mAbsoluteToolFilePath)
52  {
53  tool.mOpenIGTLinkImageId = config.mToolList[i].mOpenIGTLinkImageId;
54  tool.mOpenIGTLinkTransformId = config.mToolList[i].mOpenIGTLinkTransformId;
55  }
56  }
57 
58  toolStructureVector.push_back(tool);
59  }
60 
61  data.mTrackersAndTools[selectedTracker] = toolStructureVector;
62 
64 }
65 
67 {
68  ConfigurationFileParser parser(uid);
69 
70  Configuration retval;
71  retval.mUid = uid;
72  retval.mName = QFileInfo(uid).completeBaseName();
73 
75 
76  std::vector<ToolFileParser::TrackerInternalStructure> trackers = parser.getTrackers();
77  for (unsigned i = 0; i < trackers.size(); ++i)
78  {
79  retval.mTrackingSystemName = enum2string(trackers[i].mType);
80  // only one trackingsystem is returned. (backed supports more than is needed.)
81  }
82 
83  std::vector<QString> tools = parser.getAbsoluteToolFilePaths();
84  for (unsigned i = 0; i < tools.size(); ++i)
85  {
86  retval.mTools << tools[i];
87  }
88 
91  retval.mApplyRefToTools = parser.getApplyRefToTools();
92  retval.mToolList = parser.getToolListWithMetaInformation();
93 
94  return retval;
95 }
96 
97 QStringList TrackerConfigurationImpl::getToolsGivenFilter(QStringList applicationsFilter,
98  QStringList trackingsystemsFilter)
99 {
100  QStringList allTools = this->getAllTools();
101  QStringList filteredTools = this->filter(allTools, applicationsFilter, trackingsystemsFilter);
102  return filteredTools;
103 }
104 
106 {
107  Tool retval;
108  retval.mUid = uid;
109 
110  QString absoluteFilePath = uid;
111  QFile file(absoluteFilePath);
112  QFileInfo info(file);
113  retval.mName = info.dir().dirName();
114 
115  ToolFileParser parser(absoluteFilePath);
117 
118  retval.mTrackingSystemName = enum2string(internal->mTrackerType);
119  retval.mIsReference = internal->mIsReference;
120  retval.mPictureFilename = internal->mPictureFileName;
121  retval.mPortNumber = internal->mPortNumber;
122 
123  return retval;
124 }
125 
127 {
128  QStringList allTools = this->getAllTools();
129  QStringList retval;
130 
131  foreach(QString path, allTools)
132  {
133  //get internal tool
134  ToolFileParser::ToolInternalStructurePtr internal = this->getToolInternal(path);
135  for (unsigned i=0; i<internal->mClinicalApplications.size(); ++i)
136  retval << internal->mClinicalApplications[i];
137  }
138 
139  retval.removeDuplicates();
140  return retval;
141 }
142 
144 {
146 }
147 
148 void TrackerConfigurationImpl::setTrackingSystemImplementation(QString trackingSystemImplementation)
149 {
150  mTrackingSystemImplementation = trackingSystemImplementation;
151 }
152 
153 QStringList TrackerConfigurationImpl::filter(QStringList toolsToFilter, QStringList applicationsFilter,
154  QStringList trackingsystemsFilter)
155 {
156  QStringList retval;
157 
158  foreach(QString toolFilePath, toolsToFilter)
159  {
160  //get internal tool
161  ToolFileParser::ToolInternalStructurePtr internal = this->getToolInternal(toolFilePath);
162 
163  //check tracking systems
164  QString trackerName = enum2string(internal->mTrackerType);
165  if(!trackingsystemsFilter.contains(trackerName, Qt::CaseInsensitive))
166  continue;
167 
168  //check applications
169  bool passedApplicationFilter = false;
170  std::vector<QString>::iterator it = internal->mClinicalApplications.begin();
171  while(it != internal->mClinicalApplications.end() && !passedApplicationFilter)
172  {
173  QString applicationName = *it;
174  if(applicationsFilter.contains(applicationName, Qt::CaseInsensitive))
175  {
176  passedApplicationFilter = true;
177  }
178  if(applicationsFilter.contains("all", Qt::CaseInsensitive))
179  {
180  passedApplicationFilter = true;
181  }
182  if(applicationsFilter.contains("default", Qt::CaseInsensitive))
183  {
184  passedApplicationFilter = true;
185  }
186  ++it;
187  }
188  if(!passedApplicationFilter)
189  continue;
190 
191  //add if filters passed
192  retval << toolFilePath;
193  }
194 
195  return retval;
196 }
197 
198 ToolFileParser::ToolInternalStructurePtr TrackerConfigurationImpl::getToolInternal(QString toolAbsoluteFilePath)
199 {
201 
202  ToolFileParser parser(toolAbsoluteFilePath);
203  retval = parser.getTool();
204 
205  return retval;
206 }
207 
209 {
210  ToolFileParser::ToolInternalStructurePtr internal = this->getToolInternal(uid);
211  return internal->verify();
212 }
213 
215 {
216  return profile()->getPath() + "/tool";
217 }
218 
220 {
221  QString path = this->getConfigurationApplicationsPath();
222  return cx::getAbsolutePathToXmlFiles(path);
223 
224 // QStringList retval;
225 
226 // QStringList configPaths = DataLocations::getRootConfigPaths();
227 
228 // for (int i=0; i< configPaths.size(); ++i)
229 // {
230 // QDir dir(configPaths[i]+"/tool/"+application);
231 // retval << cx::getAbsolutePathToXmlFiles(dir.absolutePath());
232 // }
233 // return retval;
234 }
235 
237 {
238  QStringList retval;
239  QStringList rootPaths = DataLocations::getRootConfigPaths();
240 
241  for (int i=0; i< rootPaths.size(); ++i)
242  {
243  QString configFilePath = rootPaths[i] + "/profiles";
244  foreach(QFileInfo dir, cx::getDirs(configFilePath))
245  {
246  retval << cx::getAbsolutePathToXmlFiles(dir.absoluteFilePath()+"/tool");
247  }
248  }
249  return retval;
250 }
251 
253 {
254  QStringList root = profile()->getAllRootConfigPaths();
255  QString suffix("/tool/Tools/");
256  QStringList retval;
257  bool includeSubDirs = true;
258  for (int i=0; i<root.size(); ++i)
259  {
260  QString toolPath = root[i]+suffix;
261  retval << getAbsolutePathToXmlFiles(toolPath, includeSubDirs);
262  }
263  return retval;
264 }
265 
267 {
268  QStringList retval;
270  return retval;
271 }
272 
273 
274 } // namespace cx
275 
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.