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