MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkEndoDebugFromXmlFile.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include <itksys/SystemTools.hxx>
15#include <tinyxml2.h>
16#include <set>
17using namespace std;
18
19namespace mitk
20{
22 {
23 const std::string* m_FileName;
24
25 // private
28 };
29
31 const std::string* _FileName, EndoDebug* _EndoDebug )
33 {
34 d->m_FileName = _FileName;
35 d->m_EndoDebug = _EndoDebug;
36 d->m_FileModifiedTime = 0;
37 }
38
43
44 void StringExplode(string str, string separator, set<string>* results){
45 std::size_t found;
46 found = str.find_first_of(separator);
47 while(found != string::npos){
48 if(found != 0){
49 results->insert(str.substr(0,found));
50 }
51 str = str.substr(found+1);
52 found = str.find_first_of(separator);
53 }
54 if(!str.empty()){
55 results->insert(str);
56 }
57 }
58
59#ifdef _MSC_VER
60# pragma warning(push)
61# pragma warning(disable:4390)
62#endif
63
65 {
66 endodebug( __FUNCTION__ )
67
68 std::string _FileName = *d->m_FileName;
69 if( !itksys::SystemTools::FileExists( _FileName.c_str() ) )
70 {
71 endodebug(_FileName << " does not exist");
72 return;
73 }
74
75 long int _FileModifiedTime
76 = itksys::SystemTools::ModifiedTime( _FileName.c_str() );
77 // file has changed: we know an older version...
78 if( d->m_FileModifiedTime >= _FileModifiedTime )
79 {
80 endodebug("File not changed. No Update necessary.");
81 return;
82 }
83
84 // reread
85 endodebugvar(_FileName)
86 tinyxml2::XMLDocument doc;
87 doc.LoadFile(_FileName.c_str());
88 tinyxml2::XMLHandle docHandle(&doc);
89 auto* elem = docHandle.FirstChildElement().FirstChildElement( "EndoDebug" ).ToElement();
90
91 if(elem == nullptr)
92 {
93 endodebug("EndoDebug element not found");
94 return;
95 }
96
97 int _DebugEnabled = d->m_EndoDebug->GetDebugEnabled();
98 if( elem->QueryIntAttribute("DebugEnabled",&_DebugEnabled) != tinyxml2::XML_SUCCESS )
99 {
100 endodebug("DebugEnabled attribute not found");
101 }
102
103 int _ShowImagesInDebug = d->m_EndoDebug->GetShowImagesInDebug();
104 if( elem->QueryIntAttribute("ShowImagesInDebug",&_ShowImagesInDebug) != tinyxml2::XML_SUCCESS)
105 {
106 endodebug("ShowImagesInDebug attribute not found");
107 }
108
109 int _ShowImagesTimeOut = static_cast<int>(d->m_EndoDebug->GetShowImagesTimeOut());
110 if( elem->QueryIntAttribute("ShowImagesTimeOut",&_ShowImagesTimeOut) != tinyxml2::XML_SUCCESS)
111 {
112 endodebug("ShowImagesTimeOut attribute not found");
113 }
114
115 std::string _DebugImagesOutputDirectory;
116 const char* _DebugImagesOutputDirectoryC = elem->Attribute("DebugImagesOutputDirectory");
117 if(nullptr == _DebugImagesOutputDirectoryC)
118 {
119 _DebugImagesOutputDirectory = d->m_EndoDebug->GetDebugImagesOutputDirectory();
120 endodebug("DebugImagesOutputDirectory attribute not found");
121 }
122 else
123 {
124 _DebugImagesOutputDirectory = _DebugImagesOutputDirectoryC;
125 }
126
127 std::set<std::string> _FilesToDebug;
128 std::string _FilesToDebugString;
129 const char* _FilesToDebugStringC = elem->Attribute("FilesToDebug");
130 if(nullptr == _FilesToDebugStringC)
131 {
132 endodebug("FilesToDebug attribute not found");
133 }
134 else
135 {
136 _FilesToDebugString = _FilesToDebugStringC;
137 StringExplode( _FilesToDebugString, ";", &_FilesToDebug );
138 }
139
140 std::set<std::string> _SymbolsToDebug;
141 std::string _SymbolsToDebugString;
142 const char* _SymbolsToDebugStringC = elem->Attribute("SymbolsToDebug");
143 if( nullptr == _SymbolsToDebugStringC )
144 {
145 endodebug("SymbolsToDebug attribute not found");
146 }
147 else
148 {
149 _SymbolsToDebugString = _SymbolsToDebugStringC;
150 StringExplode( _SymbolsToDebugString, ";", &_SymbolsToDebug );
151 }
152
153 // save
154 mitk::EndoDebug::GetInstance().SetDebugEnabled( _DebugEnabled == 1? true: false );
155 mitk::EndoDebug::GetInstance().SetShowImagesInDebug( _ShowImagesInDebug == 1? true: false );
157 mitk::EndoDebug::GetInstance().SetDebugImagesOutputDirectory( _DebugImagesOutputDirectory );
160
161 // save that modified time
162 d->m_FileModifiedTime = _FileModifiedTime;
163 }
164
165#ifdef _MSC_VER
166# pragma warning(pop)
167#endif
168
169}
EndoDebugFromXmlFile(const std::string *_FileName, EndoDebug *_EndoDebug)
#define endodebugvar(var)
#define endodebug(msg)
IGT Exceptions.
void StringExplode(string str, string separator, set< string > *results)
void SetFilesToDebug(const std::set< std::string > &filesToDebug)
void SetSymbolsToDebug(const std::set< std::string > &symbolsToDebug)
void SetShowImagesInDebug(bool _ShowImagesInDebug)
void SetShowImagesTimeOut(size_t _ShowImagesTimeOut)
void SetDebugImagesOutputDirectory(const std::string &_DebugImagesOutputDirectory)
size_t GetShowImagesTimeOut()
static EndoDebug & GetInstance()
void SetDebugEnabled(bool _DebugEnabled)
std::string GetDebugImagesOutputDirectory() const