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