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