#ifndef _X3D_PARSER_XERCES__H #define _X3D_PARSER_XERCES__H // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- #include #include "Mesh.h" #include XERCES_CPP_NAMESPACE_USE XERCES_CPP_NAMESPACE_BEGIN class AttributeList; XERCES_CPP_NAMESPACE_END namespace GtpVisibilityPreprocessor { class SceneGraphNode; class Mesh; class Material; class ViewCellsManager; class X3dParseHandlers : public HandlerBase { public: // used for generating name / key pair struct ltstr { bool operator()(const std::string &s1, const std::string &s2) const { return s1 < s2; } }; typedef map ResourceDefinitions; // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- X3dParseHandlers(SceneGraphNode *root, const bool loadMeshes = false); ~X3dParseHandlers(); // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- unsigned int GetElementCount() { return mElementCount; } unsigned int GetAttrCount() { return mAttrCount; } unsigned int GetCharacterCount() { return mCharacterCount; } unsigned int GetSpaceCount() { return mSpaceCount; } // ----------------------------------------------------------------------- // Handlers for the SAX DocumentHandler interface // ----------------------------------------------------------------------- void endElement(const XMLCh* const name); void startElement(const XMLCh* const name, AttributeList& attributes); void characters(const XMLCh* const chars, const unsigned int length); void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); void resetDocument(); SceneGraphNode *mCurrentNode; vector mCurrentVertexIndices; VertexContainer mCurrentVertices; //string mCurrentMeshName; Mesh *mCurrentMesh; Material *mCurrentMaterial; bool mLoadMeshes; typedef stack TrafoStack; bool mUsingMeshDefinition; // stack of accumulated transformations TrafoStack mTransformations; ResourceDefinitions mMaterialDefinitions; ResourceDefinitions mMeshDefinitions; bool mIsMeshDefinition; // Handlers for X3D void StartIndexedFaceSet( AttributeList& attributes); void EndShape(); void EndTransform(); void StartTransform(AttributeList& attributes); void StartCoordinate( AttributeList& attributes); void StartMaterial( AttributeList& attributes); /** applies transformation matrix m to this mesh. */ void ApplyTransformation(Mesh *mesh, const Matrix4x4 &m) const; /** transforms mesh using the given transformations. */ void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const; void ApplyTransformations(TrafoStack trafos, TransformedMeshInstance *mi) const; static int mUniqueMeshIdx; // ----------------------------------------------------------------------- // Handlers for the SAX ErrorHandler interface // ----------------------------------------------------------------------- void warning(const SAXParseException& exc); void error(const SAXParseException& exc); void fatalError(const SAXParseException& exc); private: // ----------------------------------------------------------------------- // Private data members // // fAttrCount // fCharacterCount // fElementCount // fSpaceCount // These are just counters that are run upwards based on the input // from the document handlers. // ----------------------------------------------------------------------- unsigned int mAttrCount; unsigned int mCharacterCount; unsigned int mElementCount; unsigned int mSpaceCount; }; /** Parser handlers for view cell x3d files. */ class X3dViewCellsParseHandlers : public HandlerBase { public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager, const float viewCellHeight); ~X3dViewCellsParseHandlers(); // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- unsigned int GetElementCount() { return mElementCount; } unsigned int GetAttrCount() { return mAttrCount; } unsigned int GetCharacterCount() { return mCharacterCount; } unsigned int GetSpaceCount() { return mSpaceCount; } // ----------------------------------------------------------------------- // Handlers for the SAX DocumentHandler interface // ----------------------------------------------------------------------- void endElement(const XMLCh* const name); void startElement(const XMLCh* const name, AttributeList& attributes); void characters(const XMLCh* const chars, const unsigned int length); void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); void resetDocument(); ViewCellsManager *mViewCellsManager; float mViewCellHeight; VertexIndexContainer mCurrentVertexIndices; VertexContainer mCurrentVertices; // Handlers for X3D void StartIndexedFaceSet( AttributeList& attributes); void EndShape(); void StartCoordinate( AttributeList& attributes); void StartMaterial( AttributeList& attributes); // ----------------------------------------------------------------------- // Handlers for the SAX ErrorHandler interface // ----------------------------------------------------------------------- void warning(const SAXParseException& exc); void error(const SAXParseException& exc); void fatalError(const SAXParseException& exc); private: // ----------------------------------------------------------------------- // Private data members // // fAttrCount // fCharacterCount // fElementCount // fSpaceCount // These are just counters that are run upwards based on the input // from the document handlers. // ----------------------------------------------------------------------- unsigned int mAttrCount; unsigned int mCharacterCount; unsigned int mElementCount; unsigned int mSpaceCount; }; // --------------------------------------------------------------------------- // This is a simple class that lets us do easy (though not terribly efficient) // trancoding of XMLCh data to local code page for display. // --------------------------------------------------------------------------- class StrX { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- StrX(const XMLCh* const toTranscode) { // Call the private transcoding method mLocalForm = XMLString::transcode(toTranscode); } ~StrX() { XMLString::release(&mLocalForm); } // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- const char* LocalForm() const { return mLocalForm; } private : // ----------------------------------------------------------------------- // Private data members // // fLocalForm // This is the local code page form of the string. // ----------------------------------------------------------------------- char* mLocalForm; }; inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump) { target << toDump.LocalForm(); return target; } } #endif