Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkParamapPresetsParser.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 <vtkObjectFactory.h>
15 
16 #include "usGetModuleContext.h"
17 #include "usModuleContext.h"
18 #include "usModule.h"
19 #include "usModuleResource.h"
20 #include "usModuleResourceStream.h"
21 
22 namespace mitk {
23 
24  const std::string ParamapPresetsParser::PRESET = "preset";
25  const std::string ParamapPresetsParser::TYPE = "type";
26  const std::string ParamapPresetsParser::CODE_VALUE = "code_value";
27  const std::string ParamapPresetsParser::CODE_SCHEME = "coding_scheme";
28 
29  vtkStandardNewMacro(ParamapPresetsParser);
30 
32  {
33  us::ModuleResource presetResource = us::GetModuleContext()->GetModule()->GetResource("mitkParamapPresets.xml");
34  if (!presetResource) return false;
35 
36  us::ModuleResourceStream presetStream(presetResource);
37  vtkXMLParser::SetStream(&presetStream);
38  if (!vtkXMLParser::Parse())
39  {
40 #ifdef INTERDEBUG
41  MITK_INFO<<"ParamapPresetsParser::LoadPreset xml file cannot parse!"<<std::endl;
42 #endif
43  return false;
44  }
45  return true;
46  }
47 
48  bool ParamapPresetsParser::LoadPreset(const std::string& fileName)
49  {
50  if (fileName.empty())
51  return false;
52 
53  vtkXMLParser::SetFileName(fileName.c_str());
54 
55  if (!vtkXMLParser::Parse())
56  {
57 #ifdef INTERDEBUG
58  MITK_INFO<<"ParamapPresetsParser::LoadPreset xml file cannot parse!"<<std::endl;
59 #endif
60  }
61 
62  return true;
63 
64  }
65 
66  void ParamapPresetsParser::StartElement(const char *elementName, const char **atts)
67  {
68  std::string elementNameString = elementName;
69  if (elementNameString == PRESET)
70  {
71  m_presetName = ReadXMLStringAttribute("name", atts);
72  }
73 
74  else if (elementNameString == TYPE)
75  {
76  std::string value = ReadXMLStringAttribute(CODE_VALUE, atts);
77  std::string scheme = ReadXMLStringAttribute(CODE_SCHEME, atts);
78  m_Type[m_presetName] = Type(value, scheme);
79  }
80 
81  }
82 
83  std::string ParamapPresetsParser::ReadXMLStringAttribute(const std::string& name, const char **atts)
84  {
85  if (atts)
86  {
87  const char** attsIter = atts;
88 
89  while (*attsIter != nullptr)
90  {
91  if (name == *attsIter)
92  {
93  return *(++attsIter);
94  }
95  attsIter += 2;
96  }
97  }
98 
99  return std::string();
100  }
101 
102 
104  {
105  return m_Type[name];
106  }
107 
108 
109 
110  std::map<std::string, ParamapPresetsParser::Type> const ParamapPresetsParser::GetTypePresets()
111  {
112  return m_Type;
113  }
114 
115 
116 
117 
118 
119  void ParamapPresetsParser::NewPresets(std::map<std::string, ParamapPresetsParser::Type>& newType)
120  {
121  m_Type = newType;
122  }
123 
124 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
void NewPresets(ParamapPrestsType &newType)
DataCollection - Class to facilitate loading/accessing structured data.
ParamapPrestsType const GetTypePresets()
Module * GetModule() const
vtkStandardNewMacro(AnatomicalStructureColorPresets)
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Type GetType(const std::string &name)