Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include <itksys/SystemTools.hxx>
19 #include <tinyxml.h>
20 #include <set>
21 using namespace std;
22 
23 namespace mitk
24 {
25  struct EndoDebugFromXmlFileData
26  {
27  const std::string* m_FileName;
28 
29  // private
30  EndoDebug* m_EndoDebug;
31  long int m_FileModifiedTime;
32  };
33 
34  EndoDebugFromXmlFile::EndoDebugFromXmlFile(
35  const std::string* _FileName, EndoDebug* _EndoDebug )
36  : d( new EndoDebugFromXmlFileData )
37  {
38  d->m_FileName = _FileName;
39  d->m_EndoDebug = _EndoDebug;
40  d->m_FileModifiedTime = 0;
41  }
42 
44  {
45  delete d;
46  }
47 
48  void StringExplode(string str, string separator, set<string>* results){
49  std::size_t found;
50  found = str.find_first_of(separator);
51  while(found != string::npos){
52  if(found != 0){
53  results->insert(str.substr(0,found));
54  }
55  str = str.substr(found+1);
56  found = str.find_first_of(separator);
57  }
58  if(!str.empty()){
59  results->insert(str);
60  }
61  }
62 
63 #ifdef _MSC_VER
64 # pragma warning(push)
65 # pragma warning(disable:4390)
66 #endif
67 
69  {
70  endodebug( __FUNCTION__ )
71 
72  std::string _FileName = *d->m_FileName;
73  if( !itksys::SystemTools::FileExists( _FileName.c_str() ) )
74  {
75  endodebug(_FileName << " does not exist");
76  return;
77  }
78 
79  long int _FileModifiedTime
80  = itksys::SystemTools::ModifiedTime( _FileName.c_str() );
81  // file has changed: we know an older version...
82  if( d->m_FileModifiedTime >= _FileModifiedTime )
83  {
84  endodebug("File not changed. No Update necessary.");
85  return;
86  }
87 
88  // reread
89  endodebugvar( _FileName )
90  TiXmlDocument doc( _FileName );
91  doc.LoadFile();
92  TiXmlHandle docHandle( &doc );
93  TiXmlElement* elem = docHandle.FirstChildElement().FirstChildElement( "EndoDebug" ).ToElement();
94 
95  if(elem == nullptr)
96  {
97  endodebug("EndoDebug element not found");
98  return;
99  }
100 
101  int _DebugEnabled = d->m_EndoDebug->GetDebugEnabled();
102  if( elem->QueryIntAttribute("DebugEnabled",&_DebugEnabled) != TIXML_SUCCESS )
103  endodebug("DebugEnabled attribute not found");
104 
105  int _ShowImagesInDebug = d->m_EndoDebug->GetShowImagesInDebug();
106  if( elem->QueryIntAttribute("ShowImagesInDebug",&_ShowImagesInDebug) != TIXML_SUCCESS )
107  endodebug("ShowImagesInDebug attribute not found");
108 
109  int _ShowImagesTimeOut = static_cast<int>(d->m_EndoDebug->GetShowImagesTimeOut());
110  if( elem->QueryIntAttribute("ShowImagesTimeOut",&_ShowImagesTimeOut) != TIXML_SUCCESS )
111  endodebug("ShowImagesTimeOut attribute not found");
112 
113  std::string _DebugImagesOutputDirectory = d->m_EndoDebug->GetDebugImagesOutputDirectory();
114  if( elem->QueryStringAttribute("DebugImagesOutputDirectory",&_DebugImagesOutputDirectory) != TIXML_SUCCESS )
115  endodebug("DebugImagesOutputDirectory attribute not found");
116 
117  std::set<std::string> _FilesToDebug;
118  std::string _FilesToDebugString;
119  if( elem->QueryStringAttribute("FilesToDebug",&_FilesToDebugString) != TIXML_SUCCESS )
120  {
121  endodebug("FilesToDebug attribute not found");
122  }
123  else
124  {
125  StringExplode( _FilesToDebugString, ";", &_FilesToDebug );
126  }
127 
128  std::set<std::string> _SymbolsToDebug;
129  std::string _SymbolsToDebugString;
130  if( elem->QueryStringAttribute("SymbolsToDebug",&_SymbolsToDebugString) != TIXML_SUCCESS )
131  {
132  endodebug("SymbolsToDebug attribute not found");
133  }
134  else
135  {
136  StringExplode( _SymbolsToDebugString, ";", &_SymbolsToDebug );
137  }
138 
139  // save
140  mitk::EndoDebug::GetInstance().SetDebugEnabled( _DebugEnabled == 1? true: false );
141  mitk::EndoDebug::GetInstance().SetShowImagesInDebug( _ShowImagesInDebug == 1? true: false );
142  mitk::EndoDebug::GetInstance().SetShowImagesTimeOut( _ShowImagesTimeOut );
143  mitk::EndoDebug::GetInstance().SetDebugImagesOutputDirectory( _DebugImagesOutputDirectory );
146 
147  // save that modified time
148  d->m_FileModifiedTime = _FileModifiedTime;
149  }
150 
151 #ifdef _MSC_VER
152 # pragma warning(pop)
153 #endif
154 
155 }
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)