Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkEndoDebugToXmlFile.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 
13 #include "mitkEndoDebugToXmlFile.h"
14 #include <tinyxml.h>
15 
16 namespace mitk
17 {
18  struct EndoDebugToXmlFileData
19  {
20  EndoDebug* m_EndoDebug;
21  const std::string* m_FileName;
22  };
23 
25  const std::string* _FileName)
26  : d( new EndoDebugToXmlFileData )
27  {
28  d->m_EndoDebug = _EndoDebug;
29  d->m_FileName = _FileName;
30  }
31 
33  {
34  delete d;
35  }
36 
38  {
39  std::string _FileName = *d->m_FileName;
40 
41  TiXmlDocument doc( _FileName.c_str() );
42  TiXmlElement* root = nullptr;
43  TiXmlElement* elem = nullptr;
44  // check if element is already available
45  if(doc.LoadFile())
46  {
47  root = doc.FirstChildElement("data");
48  if(root)
49  {
50  elem = root->FirstChildElement( "EndoDebug" );
51  if(elem)
52  root->RemoveChild(elem);
53  elem = nullptr;
54  }
55  }
56  else
57  {
58  // document did not exist, create new one with declration
59  auto decl = new TiXmlDeclaration( "1.0", "", "" );
60  doc.LinkEndChild( decl );
61  // create root
62  root = new TiXmlElement( "data" );
63  doc.LinkEndChild( root );
64  }
65 
66  // create elem if not existent
67  elem = new TiXmlElement( "EndoDebug" );
68 
69  elem->SetAttribute( "DebugEnabled",
70  (d->m_EndoDebug->GetDebugEnabled()? 1:0) );
71  elem->SetAttribute( "ShowImagesInDebug",
72  (d->m_EndoDebug->GetShowImagesInDebug()? 1:0) );
73  elem->SetAttribute( "ShowImagesTimeOut",
74  (static_cast<int>(d->m_EndoDebug->GetShowImagesTimeOut())) );
75  elem->SetAttribute( "DebugImagesOutputDirectory",
76  d->m_EndoDebug->GetDebugImagesOutputDirectory() );
77 
78  std::set<std::string> _FilesToDebug = d->m_EndoDebug->GetFilesToDebug();
79  std::string _FilesToDebugString;
80  auto it = _FilesToDebug.begin();
81  while( it != _FilesToDebug.end() )
82  {
83  if( it != _FilesToDebug.begin() )
84  _FilesToDebugString.append( ";" );
85  _FilesToDebugString.append( *it );
86  ++it;
87  }
88  elem->SetAttribute( "FilesToDebug", _FilesToDebugString );
89 
90  std::set<std::string> _SymbolsToDebug = d->m_EndoDebug->GetSymbolsToDebug();
91  std::string _SymbolsToDebugString;
92  it = _SymbolsToDebug.begin();
93  while( it != _SymbolsToDebug.end() )
94  {
95  if( it != _SymbolsToDebug.begin() )
96  _SymbolsToDebugString.append( ";" );
97  _SymbolsToDebugString.append( *it );
98  ++it;
99  }
100  elem->SetAttribute( "SymbolsToDebug", _SymbolsToDebugString );
101 
102  endodebug("adding the EndoDebug as child element of the data node")
103  root->LinkEndChild(elem);
104 
105  endodebug("saving file " << _FileName)
106  if( !doc.SaveFile( _FileName ) )
107  {
108  endodebug("File " << _FileName << " could not be written. Please check permissions.");
109  }
110  }
111 
113  {
114  d->m_EndoDebug = _EndoDebug;
115  }
116 
117  void EndoDebugToXmlFile::SetFileName(const std::string *_FileName)
118  {
119  d->m_FileName = _FileName;
120  }
121 }
void SetEndoDebug(EndoDebug *_EndoDebug)
void SetFileName(const std::string *_FileName)
DataCollection - Class to facilitate loading/accessing structured data.
EndoDebugToXmlFile(EndoDebug *_EndoDebug=nullptr, const std::string *_FileName=nullptr)
#define endodebug(msg)