Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkEndoDebugFromXmlFile.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include <itksys/SystemTools.hxx>
15 #include <tinyxml.h>
16 #include <set>
17 using namespace std;
18 
19 namespace mitk
20 {
21  struct EndoDebugFromXmlFileData
22  {
23  const std::string* m_FileName;
24 
25  // private
26  EndoDebug* m_EndoDebug;
27  long int m_FileModifiedTime;
28  };
29 
30  EndoDebugFromXmlFile::EndoDebugFromXmlFile(
31  const std::string* _FileName, EndoDebug* _EndoDebug )
32  : d( new EndoDebugFromXmlFileData )
33  {
34  d->m_FileName = _FileName;
35  d->m_EndoDebug = _EndoDebug;
36  d->m_FileModifiedTime = 0;
37  }
38 
40  {
41  delete d;
42  }
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  TiXmlDocument doc( _FileName );
87  doc.LoadFile();
88  TiXmlHandle docHandle( &doc );
89  TiXmlElement* 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) != TIXML_SUCCESS )
99  {
100  endodebug("DebugEnabled attribute not found");
101  }
102 
103  int _ShowImagesInDebug = d->m_EndoDebug->GetShowImagesInDebug();
104  if( elem->QueryIntAttribute("ShowImagesInDebug",&_ShowImagesInDebug) != TIXML_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) != TIXML_SUCCESS )
111  {
112  endodebug("ShowImagesTimeOut attribute not found");
113  }
114 
115  std::string _DebugImagesOutputDirectory = d->m_EndoDebug->GetDebugImagesOutputDirectory();
116  if( elem->QueryStringAttribute("DebugImagesOutputDirectory",&_DebugImagesOutputDirectory) != TIXML_SUCCESS )
117  {
118  endodebug("DebugImagesOutputDirectory attribute not found");
119  }
120 
121  std::set<std::string> _FilesToDebug;
122  std::string _FilesToDebugString;
123  if( elem->QueryStringAttribute("FilesToDebug",&_FilesToDebugString) != TIXML_SUCCESS )
124  {
125  endodebug("FilesToDebug attribute not found");
126  }
127  else
128  {
129  StringExplode( _FilesToDebugString, ";", &_FilesToDebug );
130  }
131 
132  std::set<std::string> _SymbolsToDebug;
133  std::string _SymbolsToDebugString;
134  if( elem->QueryStringAttribute("SymbolsToDebug",&_SymbolsToDebugString) != TIXML_SUCCESS )
135  {
136  endodebug("SymbolsToDebug attribute not found");
137  }
138  else
139  {
140  StringExplode( _SymbolsToDebugString, ";", &_SymbolsToDebug );
141  }
142 
143  // save
144  mitk::EndoDebug::GetInstance().SetDebugEnabled( _DebugEnabled == 1? true: false );
145  mitk::EndoDebug::GetInstance().SetShowImagesInDebug( _ShowImagesInDebug == 1? true: false );
146  mitk::EndoDebug::GetInstance().SetShowImagesTimeOut( _ShowImagesTimeOut );
147  mitk::EndoDebug::GetInstance().SetDebugImagesOutputDirectory( _DebugImagesOutputDirectory );
150 
151  // save that modified time
152  d->m_FileModifiedTime = _FileModifiedTime;
153  }
154 
155 #ifdef _MSC_VER
156 # pragma warning(pop)
157 #endif
158 
159 }
static EndoDebug & GetInstance()
void SetSymbolsToDebug(const std::set< std::string > &symbolsToDebug)
void SetShowImagesInDebug(bool _ShowImagesInDebug)
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
void SetDebugEnabled(bool _DebugEnabled)
void SetShowImagesTimeOut(vcl_size_t _ShowImagesTimeOut)
#define endodebug(msg)
void StringExplode(string str, string separator, set< string > *results)
void SetFilesToDebug(const std::set< std::string > &filesToDebug)
void SetDebugImagesOutputDirectory(const std::string &_DebugImagesOutputDirectory)
#define endodebugvar(var)