forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkLSDynaSummaryParser.cxx
228 lines (210 loc) · 6.06 KB
/
vtkLSDynaSummaryParser.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*=========================================================================
Program: Visualization Toolkit
Module: vtkLSDynaSummaryParser.h
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.
=========================================================================*/
#include "vtkLSDynaSummaryParser.h"
#include "LSDynaMetaData.h"
#include "vtkObjectFactory.h"
#include <string>
vtkStandardNewMacro(vtkLSDynaSummaryParser);
namespace
{
static void vtkLSTrimWhitespace( std::string& line )
{
std::string::size_type llen = line.length();
while ( llen &&
( line[llen - 1] == ' ' ||
line[llen - 1] == '\t' ||
line[llen - 1] == '\r' ||
line[llen - 1] == '\n' ) )
{
--llen;
}
std::string::size_type nameStart = 0;
while ( nameStart < llen &&
( line[nameStart] == ' ' ||
line[nameStart] == '\t' ) )
{
++nameStart;
}
line = line.substr( nameStart, llen - nameStart );
}
}
//-----------------------------------------------------------------------------
vtkLSDynaSummaryParser::vtkLSDynaSummaryParser()
:MetaData(nullptr),
PartId(-1),
PartStatus(0),
PartMaterial(0),
InPart(0),
InDyna(0),
InName(0)
{
}
//-----------------------------------------------------------------------------
void vtkLSDynaSummaryParser::StartElement(const char* name, const char** atts)
{
int i;
if ( ! strcmp( name, "part" ) )
{
if ( ! this->InDyna || this->InPart )
{ // can't have loner parts or parts that contain parts
this->ReportUnknownElement( name );
}
else
{
this->InPart = 1;
this->PartName = "";
this->PartId = -1;
this->PartStatus = 1;
this->PartMaterial = -1;
for ( i = 0; atts[i] != nullptr; i += 2 )
{
if ( ! strcmp( atts[i], "id" ) )
{
if ( sscanf( atts[i+1], "%d", &this->PartId ) <= 0 )
{
this->PartId = -1;
this->ReportBadAttribute( name, atts[i], atts[i+1] );
}
}
else if ( ! strcmp( atts[i], "material" ) )
{
if ( sscanf( atts[i+1], "%d", &this->PartMaterial ) <= 0 )
{
this->PartMaterial = -1;
this->ReportBadAttribute( name, atts[i], atts[i+1] );
}
}
else if ( ! strcmp( atts[i], "status" ) )
{
if ( sscanf( atts[i+1], "%d", &this->PartStatus ) <= 0 )
{
this->PartStatus = 1;
this->ReportBadAttribute( name, atts[i], atts[i+1] );
}
}
}
if ( this->PartId < 0 )
{
this->ReportMissingAttribute( name, "id" );
}
}
}
else if ( ! strcmp( name, "name" ) )
{
if ( ! this->InDyna || ! this->InPart )
{ // name must be inside a part
this->ReportUnknownElement( name );
}
else
{
this->InName = 1;
this->PartName = "";
}
}
else if ( ! strcmp( name, "database" ) )
{ // database must be inside the lsdyna tag, but not inside a part or name
if ( ! this->InDyna || this->InPart || this->InName )
{
this->ReportUnknownElement( name );
}
else
{
const char* dbpath = nullptr;
const char* dbname = nullptr;
for ( i = 0; atts[i] != nullptr; i += 2 )
{
if ( ! strcmp( atts[i], "path" ) )
{
dbpath = atts[i+1];
}
else if ( ! strcmp( atts[i], "name" ) )
{
dbname = atts[i+1];
}
}
if ( dbpath && dbname )
{
this->MetaData->Fam.SetDatabaseDirectory( dbpath );
this->MetaData->Fam.SetDatabaseBaseName( dbname );
}
else
{
this->ReportXmlParseError();
}
}
}
else if ( ! strcmp( name, "lsdyna" ) )
{
if ( this->InPart || this->InName || this->InDyna )
{ // dyna must be outermost tag
this->ReportUnknownElement( name );
}
else
{
this->InDyna = 1;
}
}
}
//-----------------------------------------------------------------------------
void vtkLSDynaSummaryParser::EndElement(const char* name)
{
if ( ! strcmp( name, "part" ) )
{
this->InPart = this->InName = 0;
if ( this->PartName.empty() || this->PartId <= 0 ||
this->PartId > (int) this->MetaData->PartNames.size() )
{ // missing a name or an id
this->ReportXmlParseError();
}
else
{
vtkLSTrimWhitespace( this->PartName );
this->MetaData->PartNames[this->PartId - 1] = this->PartName;
this->MetaData->PartIds[this->PartId - 1] = this->PartId;
this->MetaData->PartMaterials[this->PartId - 1] = this->PartMaterial;
this->MetaData->PartStatus[this->PartId - 1] = this->PartStatus;
}
}
else if ( ! strcmp( name, "name" ) )
{
this->InName = 0;
}
else if ( ! strcmp( name, "lsdyna" ) )
{
this->InDyna = this->InPart = this->InName = 0;
}
}
//-----------------------------------------------------------------------------
void vtkLSDynaSummaryParser::CharacterDataHandler(const char* data, int length)
{
if ( ! this->InName )
{
return;
}
// skip leading whitespace
int i = 0;
while ( this->PartName.empty() && i < length && this->IsSpace( data[i] ) )
++i;
if ( i < length )
this->PartName.append( data + i, length - i );
}
//-----------------------------------------------------------------------------
void vtkLSDynaSummaryParser::PrintSelf( ostream &os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
os << indent << "PartName: \"" << this->PartName << "\"" << endl;
os << indent << "PartId: " << this->PartId << endl;
os << indent << "PartStatus: " << this->PartStatus << endl;
os << indent << "PartMaterial: " << this->PartMaterial << endl;
os << indent << "InPart: " << this->InPart << endl;
os << indent << "InDyna: " << this->InDyna << endl;
os << indent << "InName: " << this->InName << endl;
}