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