forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkXMLMaterialParser.cxx
152 lines (128 loc) · 4.64 KB
/
vtkXMLMaterialParser.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLMaterialParser.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
* Copyright 2003 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the
* U.S. Government. Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that this Notice and any
* statement of authorship are reproduced on all copies.
*/
#include "vtkXMLMaterialParser.h"
#include "vtkXMLMaterial.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLUtilities.h"
#include <vtkstd/vector>
//-----------------------------------------------------------------------------
class vtkXMLMaterialParserInternals
{
public:
typedef vtkstd::vector<vtkSmartPointer<vtkXMLDataElement> > VectorOfElements;
VectorOfElements Stack;
};
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkXMLMaterialParser);
vtkCxxSetObjectMacro(vtkXMLMaterialParser, Material, vtkXMLMaterial);
//-----------------------------------------------------------------------------
vtkXMLMaterialParser::vtkXMLMaterialParser()
{
this->Material = vtkXMLMaterial::New();
this->Material->Register(this);
this->Material->Delete();
this->Internals = new vtkXMLMaterialParserInternals;
}
//-----------------------------------------------------------------------------
vtkXMLMaterialParser::~vtkXMLMaterialParser()
{
delete this->Internals;
this->SetMaterial(0);
}
//-----------------------------------------------------------------------------
int vtkXMLMaterialParser::Parse(const char* str)
{
return this->Superclass::Parse(str);
}
//-----------------------------------------------------------------------------
int vtkXMLMaterialParser::Parse(const char* str, unsigned int length)
{
return this->Superclass::Parse(str, length);
}
//-----------------------------------------------------------------------------
int vtkXMLMaterialParser::Parse()
{
this->Internals->Stack.clear();
return this->Superclass::Parse();
}
//-----------------------------------------------------------------------------
int vtkXMLMaterialParser::InitializeParser()
{
int ret = this->Superclass::InitializeParser();
if (ret)
{
this->Internals->Stack.clear();
}
return ret;
}
//-----------------------------------------------------------------------------
void vtkXMLMaterialParser::StartElement(const char* name, const char** atts)
{
vtkXMLDataElement* element = vtkXMLDataElement::New();
element->SetName(name);
element->SetXMLByteIndex(this->GetXMLByteIndex());
vtkXMLUtilities::ReadElementFromAttributeArray(element, atts, VTK_ENCODING_NONE);
const char* id = element->GetAttribute("id");
if (id)
{
element->SetId(id);
}
this->Internals->Stack.push_back(element);
element->Delete();
}
//-----------------------------------------------------------------------------
void vtkXMLMaterialParser::EndElement(const char* vtkNotUsed(name))
{
vtkXMLDataElement* finished = this->Internals->Stack.back().GetPointer();
int prev_pos = static_cast<int>(this->Internals->Stack.size()) - 2;
if (prev_pos >= 0)
{
this->Internals->Stack[prev_pos].GetPointer()->AddNestedElement(finished);
}
else
{
this->Material->SetRootElement(finished);
}
this->Internals->Stack.pop_back();
}
//-----------------------------------------------------------------------------
void vtkXMLMaterialParser::CharacterDataHandler( const char* inData, int inLength )
{
if (this->Internals->Stack.size() > 0)
{
vtkXMLDataElement* elem = this->Internals->Stack.back().GetPointer();
elem->AddCharacterData(inData, inLength);
}
/*
// this wont happen as the XML parser will flag it as an error.
else
{
vtkErrorMacro("Character data not enclosed in XML tags");
}
*/
}
//-----------------------------------------------------------------------------
void vtkXMLMaterialParser::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Material: " ;
this->Material->PrintSelf(os, indent.GetNextIndent());
}