[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 | // -----------------------------------------------------------------------
|
---|
| 26 | X3dParseHandlers(SceneGraphNode *root);
|
---|
| 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;
|
---|
[490] | 66 | //int mCurrentObjectId;
|
---|
| 67 |
|
---|
[180] | 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 |
|
---|
[260] | 110 | /** Parser handlers for view cell x3d files.
|
---|
| 111 | */
|
---|
| 112 | class X3dViewCellsParseHandlers : public HandlerBase
|
---|
| 113 | {
|
---|
| 114 | public:
|
---|
| 115 | // -----------------------------------------------------------------------
|
---|
| 116 | // Constructors and Destructor
|
---|
| 117 | // -----------------------------------------------------------------------
|
---|
[439] | 118 | X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
|
---|
[313] | 119 | float viewCellHeight);
|
---|
[260] | 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 | }
|
---|
[180] | 145 |
|
---|
[260] | 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 |
|
---|
[439] | 156 | ViewCellsManager *mViewCellsManager;
|
---|
[312] | 157 | float mViewCellHeight;
|
---|
| 158 |
|
---|
[261] | 159 | VertexIndexContainer mCurrentVertexIndices;
|
---|
| 160 |
|
---|
[260] | 161 | // Handlers for X3D
|
---|
| 162 | void
|
---|
| 163 | StartIndexedFaceSet(
|
---|
| 164 | AttributeList& attributes);
|
---|
| 165 |
|
---|
| 166 | void
|
---|
| 167 | EndShape();
|
---|
| 168 |
|
---|
| 169 | void
|
---|
| 170 | StartCoordinate(
|
---|
| 171 | AttributeList& attributes);
|
---|
| 172 |
|
---|
| 173 | void
|
---|
| 174 | StartMaterial(
|
---|
| 175 | AttributeList& attributes);
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | // -----------------------------------------------------------------------
|
---|
| 179 | // Handlers for the SAX ErrorHandler interface
|
---|
| 180 | // -----------------------------------------------------------------------
|
---|
| 181 | void warning(const SAXParseException& exc);
|
---|
| 182 | void error(const SAXParseException& exc);
|
---|
| 183 | void fatalError(const SAXParseException& exc);
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | private:
|
---|
| 187 | // -----------------------------------------------------------------------
|
---|
| 188 | // Private data members
|
---|
| 189 | //
|
---|
| 190 | // fAttrCount
|
---|
| 191 | // fCharacterCount
|
---|
| 192 | // fElementCount
|
---|
| 193 | // fSpaceCount
|
---|
| 194 | // These are just counters that are run upwards based on the input
|
---|
| 195 | // from the document handlers.
|
---|
| 196 | // -----------------------------------------------------------------------
|
---|
| 197 | unsigned int mAttrCount;
|
---|
| 198 | unsigned int mCharacterCount;
|
---|
| 199 | unsigned int mElementCount;
|
---|
| 200 | unsigned int mSpaceCount;
|
---|
| 201 | };
|
---|
| 202 |
|
---|
| 203 |
|
---|
[180] | 204 | // ---------------------------------------------------------------------------
|
---|
| 205 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
| 206 | // trancoding of XMLCh data to local code page for display.
|
---|
| 207 | // ---------------------------------------------------------------------------
|
---|
| 208 | class StrX
|
---|
| 209 | {
|
---|
| 210 | public :
|
---|
| 211 | // -----------------------------------------------------------------------
|
---|
| 212 | // Constructors and Destructor
|
---|
| 213 | // -----------------------------------------------------------------------
|
---|
| 214 | StrX(const XMLCh* const toTranscode)
|
---|
| 215 | {
|
---|
| 216 | // Call the private transcoding method
|
---|
| 217 | mLocalForm = XMLString::transcode(toTranscode);
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | ~StrX()
|
---|
| 221 | {
|
---|
| 222 | XMLString::release(&mLocalForm);
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | // -----------------------------------------------------------------------
|
---|
| 226 | // Getter methods
|
---|
| 227 | // -----------------------------------------------------------------------
|
---|
| 228 | const char* LocalForm() const
|
---|
| 229 | {
|
---|
| 230 | return mLocalForm;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | private :
|
---|
| 234 | // -----------------------------------------------------------------------
|
---|
| 235 | // Private data members
|
---|
| 236 | //
|
---|
| 237 | // fLocalForm
|
---|
| 238 | // This is the local code page form of the string.
|
---|
| 239 | // -----------------------------------------------------------------------
|
---|
| 240 | char* mLocalForm;
|
---|
| 241 | };
|
---|
| 242 |
|
---|
| 243 | inline XERCES_STD_QUALIFIER ostream&
|
---|
| 244 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
| 245 | {
|
---|
| 246 | target << toDump.LocalForm();
|
---|
| 247 | return target;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | #endif
|
---|