1 | #ifndef _X3D_PARSER_XERCES__H
|
---|
2 | #define _X3D_PARSER_XERCES__H
|
---|
3 |
|
---|
4 | // ---------------------------------------------------------------------------
|
---|
5 | // Includes
|
---|
6 | // ---------------------------------------------------------------------------
|
---|
7 | #include <xercesc/sax/HandlerBase.hpp>
|
---|
8 | #include "Mesh.h"
|
---|
9 |
|
---|
10 | XERCES_CPP_NAMESPACE_USE
|
---|
11 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
12 | class AttributeList;
|
---|
13 | XERCES_CPP_NAMESPACE_END
|
---|
14 |
|
---|
15 | class SceneGraphNode;
|
---|
16 | class Mesh;
|
---|
17 | class Material;
|
---|
18 | class ViewCellsManager;
|
---|
19 |
|
---|
20 | class X3dParseHandlers : public HandlerBase
|
---|
21 | {
|
---|
22 | public:
|
---|
23 | // -----------------------------------------------------------------------
|
---|
24 | // Constructors and Destructor
|
---|
25 | // -----------------------------------------------------------------------
|
---|
26 | X3dParseHandlers(SceneGraphNode *root, const bool loadPolygonsAsMeshes = false);
|
---|
27 | ~X3dParseHandlers();
|
---|
28 |
|
---|
29 |
|
---|
30 | // -----------------------------------------------------------------------
|
---|
31 | // Getter methods
|
---|
32 | // -----------------------------------------------------------------------
|
---|
33 | unsigned int GetElementCount()
|
---|
34 | {
|
---|
35 | return mElementCount;
|
---|
36 | }
|
---|
37 |
|
---|
38 | unsigned int GetAttrCount()
|
---|
39 | {
|
---|
40 | return mAttrCount;
|
---|
41 | }
|
---|
42 |
|
---|
43 | unsigned int GetCharacterCount()
|
---|
44 | {
|
---|
45 | return mCharacterCount;
|
---|
46 | }
|
---|
47 |
|
---|
48 | unsigned int GetSpaceCount()
|
---|
49 | {
|
---|
50 | return mSpaceCount;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | // -----------------------------------------------------------------------
|
---|
55 | // Handlers for the SAX DocumentHandler interface
|
---|
56 | // -----------------------------------------------------------------------
|
---|
57 | void endElement(const XMLCh* const name);
|
---|
58 | void startElement(const XMLCh* const name, AttributeList& attributes);
|
---|
59 | void characters(const XMLCh* const chars, const unsigned int length);
|
---|
60 | void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
|
---|
61 | void resetDocument();
|
---|
62 |
|
---|
63 | SceneGraphNode *mCurrentNode;
|
---|
64 | Mesh *mCurrentMesh;
|
---|
65 | Material *mCurrentMaterial;
|
---|
66 | bool mLoadPolygonsAsMeshes;
|
---|
67 |
|
---|
68 | // Handlers for X3D
|
---|
69 | void
|
---|
70 | StartIndexedFaceSet(
|
---|
71 | AttributeList& attributes);
|
---|
72 |
|
---|
73 | void
|
---|
74 | EndShape();
|
---|
75 |
|
---|
76 | void
|
---|
77 | StartCoordinate(
|
---|
78 | AttributeList& attributes);
|
---|
79 |
|
---|
80 | void
|
---|
81 | StartMaterial(
|
---|
82 | AttributeList& attributes);
|
---|
83 |
|
---|
84 |
|
---|
85 | // -----------------------------------------------------------------------
|
---|
86 | // Handlers for the SAX ErrorHandler interface
|
---|
87 | // -----------------------------------------------------------------------
|
---|
88 | void warning(const SAXParseException& exc);
|
---|
89 | void error(const SAXParseException& exc);
|
---|
90 | void fatalError(const SAXParseException& exc);
|
---|
91 |
|
---|
92 |
|
---|
93 | private:
|
---|
94 | // -----------------------------------------------------------------------
|
---|
95 | // Private data members
|
---|
96 | //
|
---|
97 | // fAttrCount
|
---|
98 | // fCharacterCount
|
---|
99 | // fElementCount
|
---|
100 | // fSpaceCount
|
---|
101 | // These are just counters that are run upwards based on the input
|
---|
102 | // from the document handlers.
|
---|
103 | // -----------------------------------------------------------------------
|
---|
104 | unsigned int mAttrCount;
|
---|
105 | unsigned int mCharacterCount;
|
---|
106 | unsigned int mElementCount;
|
---|
107 | unsigned int mSpaceCount;
|
---|
108 | };
|
---|
109 |
|
---|
110 | /** Parser handlers for view cell x3d files.
|
---|
111 | */
|
---|
112 | class X3dViewCellsParseHandlers : public HandlerBase
|
---|
113 | {
|
---|
114 | public:
|
---|
115 | // -----------------------------------------------------------------------
|
---|
116 | // Constructors and Destructor
|
---|
117 | // -----------------------------------------------------------------------
|
---|
118 | X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
|
---|
119 | const float viewCellHeight);
|
---|
120 | ~X3dViewCellsParseHandlers();
|
---|
121 |
|
---|
122 |
|
---|
123 | // -----------------------------------------------------------------------
|
---|
124 | // Getter methods
|
---|
125 | // -----------------------------------------------------------------------
|
---|
126 | unsigned int GetElementCount()
|
---|
127 | {
|
---|
128 | return mElementCount;
|
---|
129 | }
|
---|
130 |
|
---|
131 | unsigned int GetAttrCount()
|
---|
132 | {
|
---|
133 | return mAttrCount;
|
---|
134 | }
|
---|
135 |
|
---|
136 | unsigned int GetCharacterCount()
|
---|
137 | {
|
---|
138 | return mCharacterCount;
|
---|
139 | }
|
---|
140 |
|
---|
141 | unsigned int GetSpaceCount()
|
---|
142 | {
|
---|
143 | return mSpaceCount;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | // -----------------------------------------------------------------------
|
---|
148 | // Handlers for the SAX DocumentHandler interface
|
---|
149 | // -----------------------------------------------------------------------
|
---|
150 | void endElement(const XMLCh* const name);
|
---|
151 | void startElement(const XMLCh* const name, AttributeList& attributes);
|
---|
152 | void characters(const XMLCh* const chars, const unsigned int length);
|
---|
153 | void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
|
---|
154 | void resetDocument();
|
---|
155 |
|
---|
156 | ViewCellsManager *mViewCellsManager;
|
---|
157 | float mViewCellHeight;
|
---|
158 |
|
---|
159 |
|
---|
160 | VertexIndexContainer mCurrentVertexIndices;
|
---|
161 |
|
---|
162 | // Handlers for X3D
|
---|
163 | void
|
---|
164 | StartIndexedFaceSet(
|
---|
165 | AttributeList& attributes);
|
---|
166 |
|
---|
167 | void
|
---|
168 | EndShape();
|
---|
169 |
|
---|
170 | void
|
---|
171 | StartCoordinate(
|
---|
172 | AttributeList& attributes);
|
---|
173 |
|
---|
174 | void
|
---|
175 | StartMaterial(
|
---|
176 | AttributeList& attributes);
|
---|
177 |
|
---|
178 |
|
---|
179 | // -----------------------------------------------------------------------
|
---|
180 | // Handlers for the SAX ErrorHandler interface
|
---|
181 | // -----------------------------------------------------------------------
|
---|
182 | void warning(const SAXParseException& exc);
|
---|
183 | void error(const SAXParseException& exc);
|
---|
184 | void fatalError(const SAXParseException& exc);
|
---|
185 |
|
---|
186 |
|
---|
187 | private:
|
---|
188 | // -----------------------------------------------------------------------
|
---|
189 | // Private data members
|
---|
190 | //
|
---|
191 | // fAttrCount
|
---|
192 | // fCharacterCount
|
---|
193 | // fElementCount
|
---|
194 | // fSpaceCount
|
---|
195 | // These are just counters that are run upwards based on the input
|
---|
196 | // from the document handlers.
|
---|
197 | // -----------------------------------------------------------------------
|
---|
198 | unsigned int mAttrCount;
|
---|
199 | unsigned int mCharacterCount;
|
---|
200 | unsigned int mElementCount;
|
---|
201 | unsigned int mSpaceCount;
|
---|
202 | };
|
---|
203 |
|
---|
204 |
|
---|
205 | // ---------------------------------------------------------------------------
|
---|
206 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
207 | // trancoding of XMLCh data to local code page for display.
|
---|
208 | // ---------------------------------------------------------------------------
|
---|
209 | class StrX
|
---|
210 | {
|
---|
211 | public :
|
---|
212 | // -----------------------------------------------------------------------
|
---|
213 | // Constructors and Destructor
|
---|
214 | // -----------------------------------------------------------------------
|
---|
215 | StrX(const XMLCh* const toTranscode)
|
---|
216 | {
|
---|
217 | // Call the private transcoding method
|
---|
218 | mLocalForm = XMLString::transcode(toTranscode);
|
---|
219 | }
|
---|
220 |
|
---|
221 | ~StrX()
|
---|
222 | {
|
---|
223 | XMLString::release(&mLocalForm);
|
---|
224 | }
|
---|
225 |
|
---|
226 | // -----------------------------------------------------------------------
|
---|
227 | // Getter methods
|
---|
228 | // -----------------------------------------------------------------------
|
---|
229 | const char* LocalForm() const
|
---|
230 | {
|
---|
231 | return mLocalForm;
|
---|
232 | }
|
---|
233 |
|
---|
234 | private :
|
---|
235 | // -----------------------------------------------------------------------
|
---|
236 | // Private data members
|
---|
237 | //
|
---|
238 | // fLocalForm
|
---|
239 | // This is the local code page form of the string.
|
---|
240 | // -----------------------------------------------------------------------
|
---|
241 | char* mLocalForm;
|
---|
242 | };
|
---|
243 |
|
---|
244 | inline XERCES_STD_QUALIFIER ostream&
|
---|
245 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
246 | {
|
---|
247 | target << toDump.LocalForm();
|
---|
248 | return target;
|
---|
249 | }
|
---|
250 |
|
---|
251 | #endif
|
---|