NorMIT-nav  22.09
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 
cx::TrackerConfigurationImpl::setTrackingSystemImplementation
virtual void setTrackingSystemImplementation(QString trackingSystemImplementation)
Definition: cxTrackerConfigurationImpl.cpp:148
cx::ConfigurationFileParser::getTrackingSystemImplementation
QString getTrackingSystemImplementation()
Definition: cxToolConfigurationParser.cpp:63
cx::TrackerConfigurationImpl::saveConfiguration
virtual void saveConfiguration(const Configuration &config)
Definition: cxTrackerConfigurationImpl.cpp:25
cxLogger.h
cx::TrackerConfiguration::Configuration::mApplyRefToTools
bool mApplyRefToTools
Definition: cxTrackerConfiguration.h:45
cx::TrackerConfiguration::Configuration::mReferenceTool
QString mReferenceTool
Definition: cxTrackerConfiguration.h:43
cx::ToolFileParser
Class for reading the files defining a CustusX tool.
Definition: cxToolFileParser.h:33
cx::TrackerConfigurationImpl::getTrackingSystemImplementation
virtual QString getTrackingSystemImplementation()
Definition: cxTrackerConfigurationImpl.cpp:143
cx::ConfigurationFileParser::getToolListWithMetaInformation
std::vector< ConfigurationFileParser::ToolStructure > getToolListWithMetaInformation()
Definition: cxToolConfigurationParser.cpp:157
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::TrackerConfigurationImpl::getSupportedTrackingSystems
virtual QStringList getSupportedTrackingSystems()
Definition: cxTrackerConfigurationImpl.cpp:266
cx::TrackerConfigurationImpl::verifyTool
virtual bool verifyTool(QString uid)
Definition: cxTrackerConfigurationImpl.cpp:208
cx::ConfigurationFileParser::ToolStructure::mOpenIGTLinkTransformId
QString mOpenIGTLinkTransformId
Definition: cxToolConfigurationParser.h:41
cx::TrackerConfiguration::Tool::mTrackingSystemName
QString mTrackingSystemName
Definition: cxTrackerConfiguration.h:52
cx::TrackerConfiguration::mTrackingSystemImplementation
QString mTrackingSystemImplementation
Definition: cxTrackerConfiguration.h:83
cx::TrackerConfiguration::Tool::mUid
QString mUid
Definition: cxTrackerConfiguration.h:50
cx::TrackerConfiguration::Configuration::mName
QString mName
Definition: cxTrackerConfiguration.h:39
cx::getDirs
QFileInfoList getDirs(QString path)
Definition: cxFileHelpers.cpp:93
cx::ConfigurationFileParser::getApplicationapplication
QString getApplicationapplication()
Definition: cxToolConfigurationParser.cpp:53
cx::ConfigurationFileParser::saveConfiguration
static void saveConfiguration(Configuration &config)
Definition: cxToolConfigurationParser.cpp:235
cx::ConfigurationFileParser::Configuration::mClinical_app
QString mClinical_app
the clinical application this config is made for
Definition: cxToolConfigurationParser.h:60
cxTrackerConfigurationImpl.h
cxTracker.h
cx::ToolFileParser::getTool
virtual ToolInternalStructurePtr getTool()
Definition: cxToolFileParser.cpp:159
cx::ConfigurationFileParser::ToolStructure
Definition: cxToolConfigurationParser.h:38
cx::TrackerConfiguration::Configuration::mToolList
std::vector< cx::ConfigurationFileParser::ToolStructure > mToolList
Definition: cxTrackerConfiguration.h:46
cx::ConfigurationFileParser::ToolStructure::mAbsoluteToolFilePath
QString mAbsoluteToolFilePath
Definition: cxToolConfigurationParser.h:40
cx::DataLocations::getRootConfigPaths
static QStringList getRootConfigPaths()
Definition: cxDataLocations.cpp:179
cx::TrackerConfigurationImpl::getAllTools
virtual QStringList getAllTools()
Definition: cxTrackerConfigurationImpl.cpp:252
cx::TrackerConfiguration::Tool::mPortNumber
int mPortNumber
Definition: cxTrackerConfiguration.h:55
cx::TrackerConfiguration::Configuration::mTrackingSystemName
QString mTrackingSystemName
Definition: cxTrackerConfiguration.h:41
cx::ConfigurationFileParser::Configuration::mFileName
QString mFileName
absolute path and filename for the new config file
Definition: cxToolConfigurationParser.h:59
cx::TrackerConfiguration::Configuration::mTrackingSystemImplementation
QString mTrackingSystemImplementation
Definition: cxTrackerConfiguration.h:44
cx::TrackerConfigurationImpl::getToolsGivenFilter
virtual QStringList getToolsGivenFilter(QStringList applicationsFilter, QStringList trackingsystemsFilter)
Definition: cxTrackerConfigurationImpl.cpp:97
cx::Tracker::getSupportedTrackingSystems
static QStringList getSupportedTrackingSystems()
Definition: cxTracker.cpp:14
cx::ConfigurationFileParser::Configuration
Definition: cxToolConfigurationParser.h:57
cx::TrackerConfiguration::Configuration::mClinicalApplication
QString mClinicalApplication
Definition: cxTrackerConfiguration.h:40
cx::TrackerConfigurationImpl::getAllApplications
virtual QStringList getAllApplications()
Definition: cxTrackerConfigurationImpl.cpp:126
cx::ConfigurationFileParser::Configuration::mApplyRefToTools
bool mApplyRefToTools
Definition: cxToolConfigurationParser.h:63
cx::TrackerConfigurationImpl::getConfigurationsGivenApplication
virtual QStringList getConfigurationsGivenApplication()
Definition: cxTrackerConfigurationImpl.cpp:219
cxProfile.h
cx::ConfigurationFileParser::ToolStructureVector
std::vector< ToolStructure > ToolStructureVector
Definition: cxToolConfigurationParser.h:55
cx::TrackerConfiguration::Tool::mPictureFilename
QString mPictureFilename
Definition: cxTrackerConfiguration.h:53
cx::ConfigurationFileParser::getAbsoluteReferenceFilePath
QString getAbsoluteReferenceFilePath()
Definition: cxToolConfigurationParser.cpp:133
cx::ConfigurationFileParser::getTrackers
std::vector< ToolFileParser::TrackerInternalStructure > getTrackers()
Definition: cxToolConfigurationParser.cpp:87
cx::TrackerConfigurationImpl::getConfigurationApplicationsPath
virtual QString getConfigurationApplicationsPath()
Definition: cxTrackerConfigurationImpl.cpp:214
cx::TrackerConfigurationImpl::getAllConfigurations
virtual QStringList getAllConfigurations()
Definition: cxTrackerConfigurationImpl.cpp:236
cx::ConfigurationFileParser::getAbsoluteToolFilePaths
std::vector< QString > getAbsoluteToolFilePaths()
Definition: cxToolConfigurationParser.cpp:113
cx::TrackerConfiguration::Tool::mName
QString mName
Definition: cxTrackerConfiguration.h:51
cx::getAbsolutePathToXmlFiles
QStringList getAbsolutePathToXmlFiles(QString path, bool includeSubDirs)
Definition: cxFileHelpers.cpp:118
cx::TrackerConfiguration::Tool::mIsReference
bool mIsReference
Definition: cxTrackerConfiguration.h:54
cx::TrackerConfiguration::Configuration::mTools
QStringList mTools
Definition: cxTrackerConfiguration.h:42
cx::TrackerConfigurationImpl::getConfiguration
virtual Configuration getConfiguration(QString uid)
Definition: cxTrackerConfigurationImpl.cpp:66
cx::profile
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
cx::ConfigurationFileParser::Configuration::mTrackingSystemImplementation
QString mTrackingSystemImplementation
Definition: cxToolConfigurationParser.h:61
cxFileHelpers.h
cx::TrackerConfiguration::Tool
Definition: cxTrackerConfiguration.h:48
cx::ConfigurationFileParser::Configuration::mTrackersAndTools
TrackersAndToolsMap mTrackersAndTools
the trackers and tools (relative path) that should be used in the config
Definition: cxToolConfigurationParser.h:62
cxDataLocations.h
cx::TrackerConfiguration::Configuration::mUid
QString mUid
absolute path and filename for the new config file
Definition: cxTrackerConfiguration.h:38
enum2string
QString enum2string(const ENUM &val)
cx::ConfigurationFileParser::getApplyRefToTools
bool getApplyRefToTools()
Definition: cxToolConfigurationParser.cpp:190
cx::TrackerConfigurationImpl::getTool
virtual Tool getTool(QString uid)
Definition: cxTrackerConfigurationImpl.cpp:105
cxEnumConversion.h
cxToolConfigurationParser.h
cx::TrackerConfiguration::Configuration
Definition: cxTrackerConfiguration.h:36
cx::ConfigurationFileParser::ToolStructure::mOpenIGTLinkImageId
QString mOpenIGTLinkImageId
Definition: cxToolConfigurationParser.h:42
cx::ConfigurationFileParser::ToolStructure::mReference
bool mReference
Definition: cxToolConfigurationParser.h:43
cx::ConfigurationFileParser
Class for reading the files defining a CustusX tool.
Definition: cxToolConfigurationParser.h:34
cx::ToolFileParser::ToolInternalStructurePtr
boost::shared_ptr< ToolInternalStructure > ToolInternalStructurePtr
Definition: cxToolFileParser.h:99