XSIParser.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.
00006 // Use of this software is subject to the terms of the Autodesk license agreement
00007 // provided at the time of installation or download, or which otherwise accompanies
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 //***************************************************************************************
00013 // Defines
00014 //***************************************************************************************
00015 #ifndef __CXSIParser_H__
00016 #define __CXSIParser_H__
00017 
00018 
00019 //***************************************************************************************
00020 // Includes
00021 //***************************************************************************************
00022 #include <SIBCUtil.h>
00023 #include <SIBCString.h>
00024 
00025 #include "dotXSITemplate.h"
00026 #include "CXSIFilter.h"
00027 
00028 namespace xercesc_2_7
00029 {
00030     class SAX2XMLReader;
00031 }
00032 class CCOLLADATemplate;
00033 
00034 #define FORMAT_TEXT     0
00035 #define FORMAT_BINARY   1
00036 #define FORMAT_COLLADA  2
00037 
00038 #define OPEN_READ       0
00039 #define OPEN_WRITE      1
00040 
00041 
00042 //***************************************************************************************
00043 // Typedefs
00044 //***************************************************************************************
00045 class CdotXSITemplate;
00046 class CdotXSITemplates;
00047 
00048 typedef struct
00049 {
00050     SI_Int      nLen;
00051     SI_Char    *pLabel;
00052 } TdotXSIDictEntry;
00053 
00054 class CXSIParser;
00055 
00056 typedef SI_Void (*SI_READ_CALLBACK_FNC) ( CXSIParser* );
00057 
00059 class XSIEXPORT CXSIReturn
00060 {
00061     public:
00062         void            *m_pPointer;
00063         CSIBCString     m_Parameter;
00064         int             m_Flags;
00065 };
00066 
00067 
00069 class XSIEXPORT CdotXSIDict
00070 {
00071 public :
00073     CdotXSIDict();
00075     ~CdotXSIDict();
00079     SI_Void     Init( SI_Int i_nCount );
00083     SI_Void     Add( SI_Char *i_pLabel );
00087     SI_Int      GetCount();
00092     SI_Void     Find( SI_Int i_nInd, SI_Char **o_pLabel );
00097     SI_Int      Find( SI_Char *i_pLabel );
00101     SI_Void     Read( _SI_FILE i_pFptr );
00105     SI_Void     Write( _SI_FILE i_pFptr );
00106 
00107 private :
00108     SI_Int              m_nTotalCount;
00109     SI_Int              m_nCount;
00110     TdotXSIDictEntry   *m_Dict;
00111 };
00112 
00114 class XSIEXPORT CXSIParser
00115 {
00116 public:
00117     CXSIParser();                                   
00118     ~CXSIParser();                                  
00119 
00123     SI_Error    Open(const CSIBCString &in_filename);
00127     SI_Bool     EndOfFile();                        // end of file ?
00131     SI_Error    Close();                            // Closes a file
00132 
00136     CSIBCString &FileName() { return m_sFilename; }
00137 
00141     SI_Int      GetNbSupportedTemplates();
00145     SI_Char     *GetSupportedTemplate(SI_Int in_lIndex);
00146 
00150     SI_Char     *GetNextTokenAsCharPtr();
00154     SI_Char     *GetNextTokenAsString();
00158     SI_Float    GetNextTokenAsFloat();
00162     SI_Int      GetNextTokenAsInteger();
00172     SI_Error    GetNextTokensAsFloatArray(  SI_Int numFloats,
00173                                             SI_Int fileStepCount,   //Step = number of sequential floats to read first,
00174                                             SI_Int fileSkipCount,   //Skip = number of tokens to skip before reading the next sequence of floats
00175                                             SI_Int arrayStepCount,  //Step = number of sequential floats to write to first
00176                                             SI_Int arraySkipCount,  //Skip = number of array indices to skip before writing the next sequence of floats
00177                                             SI_Float *i_pArray );   //Get the next series of tokens
00178 
00188     SI_Error    GetNextTokensAsIntegerArray(    SI_Int numInts,
00189                                                 SI_Int fileStepCount,   //Step = number of sequential floats to read first,
00190                                                 SI_Int fileSkipCount,   //Skip = number of tokens to skip before reading the next sequence of floats
00191                                                 SI_Int arrayStepCount,  //Step = number of sequential floats to write to first
00192                                                 SI_Int arraySkipCount,  //Skip = number of array indices to skip before writing the next sequence of floats
00193                                                 SI_Int *i_pArray ); //Get the next series of tokens
00194 
00204     SI_Error    GetNextTokensAsUnsignedShortArray(  SI_Int numUShorts,
00205                                                 SI_Int fileStepCount,   //Step = number of sequential floats to read first,
00206                                                 SI_Int fileSkipCount,   //Skip = number of tokens to skip before reading the next sequence of floats
00207                                                 SI_Int arrayStepCount,  //Step = number of sequential floats to write to first
00208                                                 SI_Int arraySkipCount,  //Skip = number of array indices to skip before writing the next sequence of floats
00209                                                 SI_UShort *i_pArray );  //Get the next series of tokens
00210 
00214     SI_Char     *GetCurrentTokenAsCharPtr();
00218     SI_Float    GetCurrentTokenAsFloat();
00219 
00223     SI_Int      GetCurrentTokenAsInteger();
00224 
00230     SI_Error    GetNextPairAsFloat( SI_Float &fX, SI_Float &fY );
00235     SI_Error    GetNextPairAsInt( SI_Int &nX, SI_Int &nY );
00236 
00243     SI_Error    GetNextTrippletAsFloat( SI_Float &fX, SI_Float &fY, SI_Float &fZ );
00249     SI_Error    GetNextTrippletAsInt( SI_Int &nX, SI_Int &nY, SI_Int &nZ );
00250 
00254     SI_Void     SetOpenMode( SI_Int i_nMode );
00258     SI_Int      GetOpenMode() { return m_nOpenMode; }
00259 
00260     // dotXSIFile support
00261 
00266     SI_Int              CheckNextToken( CSIBCString *i_pReadString );
00270     SI_Long              GetdotXSIFileVersionMajor() { return m_dotXSIFileVersionMajor; }
00274     SI_Long              GetdotXSIFileVersionMinor() { return m_dotXSIFileVersionMinor; }
00278     SI_Int              GetdotXSIFormat() { return m_dotXSIFormat; }                      //@mfunc SI_Int | CXSIParser | GetdotXSIFormat | Gets
00282     SI_Void             SetdotXSIFormat( SI_Int dotXSIFormat ) { m_dotXSIFormat = dotXSIFormat; } //@mfunc SI_Void | CXSIParser | SetdotXSIFormat | Sets the dotXSI file Formation.
00283                                                                                                   // @parm SI_Int | dotXSIFormat | dotXSI format flag.
00287     SI_Int              GetdotXSISystemFlags() { return m_dotXSISystemFlags; }                  //@mfunc SI_Int | CXSIParser | GetdotXSISystemFlags | Gets the dotXSI System Flags.
00291     SI_Void             SetdotXSISystemFlags( SI_Int dotXSISystemFlags ) { m_dotXSISystemFlags = dotXSISystemFlags; }   //@mfunc SI_Void | CXSIParser | SetdotXSISystemFlags | Sets the dotXSI System Flags.
00292                                                                                                     // @parm SI_Int | dotXSIFormat | dotXSI format flag.
00297     SI_Int              SetdotXSIFileVersion( SI_Int, SI_Int );
00301     SI_Int              GetdotXSINumFileVersion();
00308     SI_Error            GetdotXSIFileVersion( int, int*, int* );
00312     SI_Error            Read();
00316     SI_Error            Write();
00322     SI_Bool             ReadTemplate( CSIBCString *i_sTemplateName, CdotXSITemplate *i_pParent );
00328     SI_Void             WriteTemplate( CdotXSITemplates *dotXSITemplates, SI_Int i_nInd, SI_Int i_nLevel );
00333     CdotXSITemplates   *dotXSITemplate() { return m_dotXSITemplates; }  //@mfunc CdotXSITemplates* | CXSIParser | dotXSITemplate | Checks for dotXSI templates.
00337     CdotXSITemplates   *dotXSISupported() { return m_dotXSISupported; } //@mfunc CdotXSITemplates* | CXSIParser | ditXSISupported | Checks for dotXSI support.
00341     SI_Int              GetString();
00346     SI_Error            AddEscapeChar ( const SI_Char *in_pStr, SI_Char *out_pStr );                        //@mfunc adds an escape character in front of invalid ones (ie. \" )
00347 
00348     // Read utility functions
00363     SI_Error ReadGenericParameters( CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbParam );
00373     SI_Error ReadParameterValue( SI_TinyVariant *o_vValue, SI_Int i_nLastInt );
00374 
00384     SI_Error ReadCOLLADAParameterValue( SI_TinyVariant *o_vValue, char **in_pStream );
00385 
00386 
00398     SI_Error ReadIntegerArray( CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbVertices, SI_Char *i_sName );
00399 
00410     SI_Error ReadFloatArray( CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbVertices, SI_Char *i_sName );
00411 
00422     SI_Error ReadDoubleArray( CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbVertices, SI_Char *i_sName );
00423 
00424     // Write utility functions
00429     SI_Void WriteTabs( SI_Int i_nLevel );
00436     SI_Void WriteGenericParameters( CdotXSITemplate *i_pCurrentTemplate, SI_Int i_nNbParams, SI_Int i_nLevel );
00443     SI_Void WriteParameterValue( SI_TinyVariant *i_vValue, SI_Int i_nLevel, SI_Int in_nFlag = 0 );
00449     SI_Void RegisterdotXSINativeTemplates( SI_Long i_lMajor, SI_Long i_lMinor, SI_Int i_lFormat );
00454     SI_Void CleardotXSINativeTemplates();
00458     CdotXSITemplates* GetdotXSINativeTemplates();
00459 
00460     //
00461     // New centralized IO functions
00462     //
00466     SI_Int          FTK_Eof ();
00472     SI_Int          FTK_Open (SI_Char* in_szName, _SI_FILE_MODE in_Mode );
00476     SI_Int          FTK_Close ();
00482     SI_Long         FTK_Read (void *out_pBuffer, SI_Long size, SI_Long count);
00488     SI_Int          FTK_Write (void *in_pBuffer, SI_Long size, SI_Long count);
00492     SI_Int          FTK_Printf (SI_Char* in_szData );
00498     SI_Int          FTK_Seek (SI_Long in_lCount, SI_Int in_iMode );
00502     SI_Long         FTK_Tell ();
00506     SI_Int          FTK_FGetc ();
00510     SI_Int          FTK_Getc ();
00511 
00512     //
00513     // Warning callback
00514     //
00519     SI_Void         SetWarningCallback ( SI_WARNING_CALLBACK_FNC in_pfncCallback );
00525     SI_Void         FTK_Warning ( SI_Char *in_szWarning, SI_Int in_iWarningLevel );
00526 
00530     SI_Error        GetLastError() { return m_nLastError; }
00531 
00532     //
00533     // read callback
00534     //
00539     SI_Void                 SetReadCallback(SI_READ_CALLBACK_FNC in_pCallback);
00543     SI_READ_CALLBACK_FNC    GetReadCallback();
00544 
00548     SI_Void ClearSkipTable();
00549 
00553     SI_Void SkipTemplate ( CSIBCString );
00554 
00555       // -----------------------------------------------------------------------
00556     //  Implementations of the SAX DocumentHandler interface
00557     // -----------------------------------------------------------------------
00558     void endDocument();
00559 
00560     void endElement( const void* const uri,
00561                      const void* const localname,
00562                      const void* const qname);
00563 
00564     void characters(const void* const chars, const unsigned int length);
00565 
00566     void ignorableWhitespace
00567     (
00568         const   void* const    chars
00569         , const unsigned int    length
00570     );
00571 
00572     void processingInstruction
00573     (
00574         const   void* const    target
00575         , const void* const    data
00576     );
00577 
00578     void startDocument();
00579 
00580     void startElement(  const   void* const    uri,
00581                         const   void* const    localname,
00582                         const   void* const    qname,
00583                         const   void*       attributes);
00584 
00585     SI_Char* GetErrors() { return m_csError.GetText (); }
00586 
00587 
00588     // -----------------------------------------------------------------------
00589     //  Implementations of the SAX ErrorHandler interface
00590     // -----------------------------------------------------------------------
00591     void warning(const void* exception);
00592     void error(const void* exception);
00593     void fatalError(const void* exception);
00594 
00595     CdotXSITemplate*    ResolveTemplateURL ( const SI_Char* in_szLibrary, const SI_Char* in_URL );
00596 
00597 
00598 protected:
00599     SI_Error    ParseToken();                               // Parse content for next token
00600     SI_Error    ParseCOLLADAToken(char **in_pStream);       // Parse COLLADA content for next token
00601 
00602     SI_Int      CheckFileType();                            // check first few bytes for the file type
00603 
00604 private:
00605 
00606     SI_Error            ReadCOLLADA();
00607     SI_Error            WriteCOLLADA();
00608     SI_Void             WriteCOLLADATemplate( CdotXSITemplates *dotXSITemplates, SI_Int i_nInd, SI_Int i_nLevel );
00609 
00610     enum
00611     {
00612         BUFFER_SIZE = 1024,
00613         FILE_BUFFER_SIZE = 16384
00614     };
00615 
00616     CSIBCString m_sFilename;                        // File name
00617     SI_Char     *m_Buffer;                          // File read buffer
00618     SI_Int      m_BufferSize;
00619     SI_Char     *m_pCurrentToken;                   // Current token
00620     SI_Int      m_nOpenMode;                        // 0 = READ, 1 = WRITE
00621     SI_Error    m_nLastError;                       // Holds the last error that occurred during parsing.
00622 
00623     SI_Bool     IsInvalidParameterValue();          // Checks the current token, to see if it might not be a valid parameter.
00624     SI_Error    IncrementParseSpot();
00625     SI_Error    GetNextByte(SI_Byte *in_pRead);
00626     void        CreateFilter ();
00627     SI_Error    ReadDotXSIHeader();
00628     CXSIFilter* CreateFilterFromID ( SI_Char* in_szID );
00629 
00630     // dotXSIFile support
00631     CdotXSITemplates   *m_dotXSITemplates;
00632     CdotXSITemplates   *m_dotXSISupported;
00633     CdotXSITemplates   *m_dotXSIUnsupported;
00634 
00635     SI_Long             m_dotXSIFileVersionMajor;
00636     SI_Long             m_dotXSIFileVersionMinor;
00637     SI_Int              m_dotXSIFormat;                 // TEXT | BINARY
00638     SI_Int              m_dotXSISystemFlags;
00639 
00640     CdotXSIDict         m_dotXSIDict;
00641     CdotXSITemplates    m_dotXSINativeTemplates;
00642     CSIAccumString      m_szAccumBuffer;
00643     SI_Long             m_lFilePtr;
00644 
00645     //
00646     // IO Filter
00647     //
00648 
00649     CXSIFilter          *m_pParserFilter;
00650     SI_Int              m_iDataExported;
00651 
00652     //
00653     // Warning reporting callback
00654     //
00655     SI_WARNING_CALLBACK_FNC m_pfncWarningCallback;
00656 
00657     // read callback
00658     SI_READ_CALLBACK_FNC m_pReadCallback;
00659 
00660     //
00661     // COLLADA Specific
00662     //
00663     xercesc_2_7::SAX2XMLReader      *m_pXMLParser;
00664     CSIBCString         m_XMLBuffer;
00665     CSIBCString         m_csError;
00666     CCOLLADATemplate    *m_pParentTemplate;
00667     CdotXSITemplate*    RecurseResolveURL ( CdotXSITemplate* in_pTemplate, const SI_Char* libID, const SI_Char* in_URL );
00668 
00669     CSIBCArray<CSIBCString> m_SkipTable;
00670     SI_Int                  m_iIsInsideExtra;
00671     bool                    m_bNoTyping;
00672 };
00673 
00674 
00675 //***************************************************************************************
00676 // Global Functions
00677 //***************************************************************************************
00686 extern SI_Bool IsSeparator( SI_Char i_Char );
00687 
00688 
00689 /* @} */
00690 
00702 SI_Error dotXSICB_ReadGeneric( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00708 SI_Error dotXSICB_ReadCluster( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00714 SI_Error dotXSICB_ReadConstraint( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00720 SI_Error dotXSICB_ReadCustomPSet( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00726 SI_Error dotXSICB_ReadEnvelope( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00732 SI_Error dotXSICB_ReadFCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00738 SI_Error dotXSICB_ReadFileInfo( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00744 SI_Error dotXSICB_ReadIKRoot( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00750 SI_Error dotXSICB_ReadImageClip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00756 SI_Error dotXSICB_ReadLight( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00762 SI_Error dotXSICB_ReadNurbsSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00768 SI_Error dotXSICB_ReadNurbsCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00774 SI_Error dotXSICB_ReadPatchSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00780 SI_Error dotXSICB_ReadPolygonList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00786 SI_Error dotXSICB_ReadScene( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00792 SI_Error dotXSICB_ReadShape( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00798 SI_Error dotXSICB_ReadTriangleList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00804 SI_Error dotXSICB_ReadTriStrip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00805 
00811 SI_Error dotXSICB_WriteGeneric( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00817 SI_Error dotXSICB_WriteCluster( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00823 SI_Error dotXSICB_WriteConstraint( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00829 SI_Error dotXSICB_WriteCustomPSet( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00835 SI_Error dotXSICB_WriteEnvelope( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00841 SI_Error dotXSICB_WriteFCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00847 SI_Error dotXSICB_WriteFileInfo( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00853 SI_Error dotXSICB_WriteIKRoot( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00859 SI_Error dotXSICB_WriteImageClip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00865 SI_Error dotXSICB_WriteNurbsSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00871 SI_Error dotXSICB_WriteNurbsCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00877 SI_Error dotXSICB_WritePatchSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00883 SI_Error dotXSICB_WritePolygonList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00889 SI_Error dotXSICB_WriteShape( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00895 SI_Error dotXSICB_WriteTriangleList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00901 SI_Error dotXSICB_WriteTriStrip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00902 
00903 /* @} */
00904 
00905 #endif // CXSIParser