MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkEndoDebugToXmlFile.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 <tinyxml2.h>
15
16namespace mitk
17{
19 {
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
36
38 {
39 std::string _FileName = *d->m_FileName;
40
41 tinyxml2::XMLDocument doc;
42 tinyxml2::XMLElement* root = nullptr;
43 tinyxml2::XMLElement* elem = nullptr;
44 // check if element is already available
45 if(tinyxml2::XML_SUCCESS == doc.LoadFile(_FileName.c_str()))
46 {
47 root = doc.FirstChildElement("data");
48 if(nullptr != root)
49 {
50 elem = root->FirstChildElement( "EndoDebug" );
51 if (nullptr != elem)
52 {
53 root->DeleteChild(elem);
54 elem = nullptr;
55 }
56 }
57 }
58 else
59 {
60 // document did not exist, create new one with declration
61 doc.InsertEndChild( doc.NewDeclaration() );
62 // create root
63 root = doc.NewElement( "data" );
64 doc.InsertEndChild( root );
65 }
66
67 // create elem if not existent
68 elem = doc.NewElement( "EndoDebug" );
69
70 elem->SetAttribute( "DebugEnabled",
71 (d->m_EndoDebug->GetDebugEnabled()? 1:0) );
72 elem->SetAttribute( "ShowImagesInDebug",
73 (d->m_EndoDebug->GetShowImagesInDebug()? 1:0) );
74 elem->SetAttribute( "ShowImagesTimeOut",
75 (static_cast<int>(d->m_EndoDebug->GetShowImagesTimeOut())) );
76 elem->SetAttribute( "DebugImagesOutputDirectory",
78
79 std::set<std::string> _FilesToDebug = d->m_EndoDebug->GetFilesToDebug();
80 std::string _FilesToDebugString;
81 auto it = _FilesToDebug.begin();
82 while( it != _FilesToDebug.end() )
83 {
84 if( it != _FilesToDebug.begin() )
85 _FilesToDebugString.append( ";" );
86 _FilesToDebugString.append( *it );
87 ++it;
88 }
89 elem->SetAttribute( "FilesToDebug", _FilesToDebugString.c_str() );
90
91 std::set<std::string> _SymbolsToDebug = d->m_EndoDebug->GetSymbolsToDebug();
92 std::string _SymbolsToDebugString;
93 it = _SymbolsToDebug.begin();
94 while( it != _SymbolsToDebug.end() )
95 {
96 if( it != _SymbolsToDebug.begin() )
97 _SymbolsToDebugString.append( ";" );
98 _SymbolsToDebugString.append( *it );
99 ++it;
100 }
101 elem->SetAttribute( "SymbolsToDebug", _SymbolsToDebugString.c_str() );
102
103 endodebug("adding the EndoDebug as child element of the data node")
104 root->InsertEndChild(elem);
105
106 endodebug("saving file " << _FileName)
107 if( tinyxml2::XML_SUCCESS != doc.SaveFile( _FileName.c_str() ) )
108 {
109 endodebug("File " << _FileName << " could not be written. Please check permissions.");
110 }
111 }
112
114 {
115 d->m_EndoDebug = _EndoDebug;
116 }
117
118 void EndoDebugToXmlFile::SetFileName(const std::string *_FileName)
119 {
120 d->m_FileName = _FileName;
121 }
122}
void SetEndoDebug(EndoDebug *_EndoDebug)
EndoDebugToXmlFile(EndoDebug *_EndoDebug=nullptr, const std::string *_FileName=nullptr)
void SetFileName(const std::string *_FileName)
#define endodebug(msg)
IGT Exceptions.
std::set< std::string > GetSymbolsToDebug()
size_t GetShowImagesTimeOut()
std::string GetDebugImagesOutputDirectory() const
std::set< std::string > GetFilesToDebug()