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 | bool mIsMeshDefinition;
|
---|
95 | // Handlers for X3D
|
---|
96 | void
|
---|
97 | StartIndexedFaceSet(
|
---|
98 | AttributeList& attributes);
|
---|
99 |
|
---|
100 | void
|
---|
101 | EndShape();
|
---|
102 |
|
---|
103 | void EndTransform();
|
---|
104 | void StartTransform(AttributeList& attributes);
|
---|
105 |
|
---|
106 | void
|
---|
107 | StartCoordinate(
|
---|
108 | AttributeList& attributes);
|
---|
109 |
|
---|
110 | void
|
---|
111 | StartMaterial(
|
---|
112 | AttributeList& attributes);
|
---|
113 |
|
---|
114 | /// applies transformation m to this mesh
|
---|
115 | void ApplyTransformation(Mesh *mesh, const Matrix4x4 &m) const;
|
---|
116 |
|
---|
117 | /// transforms mesh using the given transformations
|
---|
118 | void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const;
|
---|
119 |
|
---|
120 |
|
---|
121 | // -----------------------------------------------------------------------
|
---|
122 | // Handlers for the SAX ErrorHandler interface
|
---|
123 | // -----------------------------------------------------------------------
|
---|
124 | void warning(const SAXParseException& exc);
|
---|
125 | void error(const SAXParseException& exc);
|
---|
126 | void fatalError(const SAXParseException& exc);
|
---|
127 |
|
---|
128 |
|
---|
129 | private:
|
---|
130 | // -----------------------------------------------------------------------
|
---|
131 | // Private data members
|
---|
132 | //
|
---|
133 | // fAttrCount
|
---|
134 | // fCharacterCount
|
---|
135 | // fElementCount
|
---|
136 | // fSpaceCount
|
---|
137 | // These are just counters that are run upwards based on the input
|
---|
138 | // from the document handlers.
|
---|
139 | // -----------------------------------------------------------------------
|
---|
140 | unsigned int mAttrCount;
|
---|
141 | unsigned int mCharacterCount;
|
---|
142 | unsigned int mElementCount;
|
---|
143 | unsigned int mSpaceCount;
|
---|
144 | };
|
---|
145 |
|
---|
146 | /** Parser handlers for view cell x3d files.
|
---|
147 | */
|
---|
148 | class X3dViewCellsParseHandlers : public HandlerBase
|
---|
149 | {
|
---|
150 | public:
|
---|
151 | // -----------------------------------------------------------------------
|
---|
152 | // Constructors and Destructor
|
---|
153 | // -----------------------------------------------------------------------
|
---|
154 | X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
|
---|
155 | const float viewCellHeight);
|
---|
156 | ~X3dViewCellsParseHandlers();
|
---|
157 |
|
---|
158 |
|
---|
159 | // -----------------------------------------------------------------------
|
---|
160 | // Getter methods
|
---|
161 | // -----------------------------------------------------------------------
|
---|
162 | unsigned int GetElementCount()
|
---|
163 | {
|
---|
164 | return mElementCount;
|
---|
165 | }
|
---|
166 |
|
---|
167 | unsigned int GetAttrCount()
|
---|
168 | {
|
---|
169 | return mAttrCount;
|
---|
170 | }
|
---|
171 |
|
---|
172 | unsigned int GetCharacterCount()
|
---|
173 | {
|
---|
174 | return mCharacterCount;
|
---|
175 | }
|
---|
176 |
|
---|
177 | unsigned int GetSpaceCount()
|
---|
178 | {
|
---|
179 | return mSpaceCount;
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | // -----------------------------------------------------------------------
|
---|
184 | // Handlers for the SAX DocumentHandler interface
|
---|
185 | // -----------------------------------------------------------------------
|
---|
186 | void endElement(const XMLCh* const name);
|
---|
187 | void startElement(const XMLCh* const name, AttributeList& attributes);
|
---|
188 | void characters(const XMLCh* const chars, const unsigned int length);
|
---|
189 | void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
|
---|
190 | void resetDocument();
|
---|
191 |
|
---|
192 | ViewCellsManager *mViewCellsManager;
|
---|
193 | float mViewCellHeight;
|
---|
194 |
|
---|
195 |
|
---|
196 | VertexIndexContainer mCurrentVertexIndices;
|
---|
197 |
|
---|
198 | // Handlers for X3D
|
---|
199 | void
|
---|
200 | StartIndexedFaceSet(
|
---|
201 | AttributeList& attributes);
|
---|
202 |
|
---|
203 | void
|
---|
204 | EndShape();
|
---|
205 |
|
---|
206 | void
|
---|
207 | StartCoordinate(
|
---|
208 | AttributeList& attributes);
|
---|
209 |
|
---|
210 | void
|
---|
211 | StartMaterial(
|
---|
212 | AttributeList& attributes);
|
---|
213 |
|
---|
214 |
|
---|
215 | // -----------------------------------------------------------------------
|
---|
216 | // Handlers for the SAX ErrorHandler interface
|
---|
217 | // -----------------------------------------------------------------------
|
---|
218 | void warning(const SAXParseException& exc);
|
---|
219 | void error(const SAXParseException& exc);
|
---|
220 | void fatalError(const SAXParseException& exc);
|
---|
221 |
|
---|
222 |
|
---|
223 | private:
|
---|
224 | // -----------------------------------------------------------------------
|
---|
225 | // Private data members
|
---|
226 | //
|
---|
227 | // fAttrCount
|
---|
228 | // fCharacterCount
|
---|
229 | // fElementCount
|
---|
230 | // fSpaceCount
|
---|
231 | // These are just counters that are run upwards based on the input
|
---|
232 | // from the document handlers.
|
---|
233 | // -----------------------------------------------------------------------
|
---|
234 | unsigned int mAttrCount;
|
---|
235 | unsigned int mCharacterCount;
|
---|
236 | unsigned int mElementCount;
|
---|
237 | unsigned int mSpaceCount;
|
---|
238 | };
|
---|
239 |
|
---|
240 |
|
---|
241 | // ---------------------------------------------------------------------------
|
---|
242 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
243 | // trancoding of XMLCh data to local code page for display.
|
---|
244 | // ---------------------------------------------------------------------------
|
---|
245 | class StrX
|
---|
246 | {
|
---|
247 | public :
|
---|
248 | // -----------------------------------------------------------------------
|
---|
249 | // Constructors and Destructor
|
---|
250 | // -----------------------------------------------------------------------
|
---|
251 | StrX(const XMLCh* const toTranscode)
|
---|
252 | {
|
---|
253 | // Call the private transcoding method
|
---|
254 | mLocalForm = XMLString::transcode(toTranscode);
|
---|
255 | }
|
---|
256 |
|
---|
257 | ~StrX()
|
---|
258 | {
|
---|
259 | XMLString::release(&mLocalForm);
|
---|
260 | }
|
---|
261 |
|
---|
262 | // -----------------------------------------------------------------------
|
---|
263 | // Getter methods
|
---|
264 | // -----------------------------------------------------------------------
|
---|
265 | const char* LocalForm() const
|
---|
266 | {
|
---|
267 | return mLocalForm;
|
---|
268 | }
|
---|
269 |
|
---|
270 | private :
|
---|
271 | // -----------------------------------------------------------------------
|
---|
272 | // Private data members
|
---|
273 | //
|
---|
274 | // fLocalForm
|
---|
275 | // This is the local code page form of the string.
|
---|
276 | // -----------------------------------------------------------------------
|
---|
277 | char* mLocalForm;
|
---|
278 | };
|
---|
279 |
|
---|
280 | inline XERCES_STD_QUALIFIER ostream&
|
---|
281 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
282 | {
|
---|
283 | target << toDump.LocalForm();
|
---|
284 | return target;
|
---|
285 | }
|
---|
286 |
|
---|
287 | #endif
|
---|