# Scene.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 #ifndef _SCENE_H
    00013 #define _SCENE_H
    00014
    00015 #include "Template.h"
    00016 #include "Logger.h"
    00017
    00018 class CSLScene;
    00019 class CSLModel;
    00020 class CSLAmbience;
    00021 class CSLAngle;
    00022 class CSLCoordinateSystem;
    00023 class CSLFileInfo;
    00024 class CSLSceneInfo;
    00025 class CSLEnvelopeList;
    00026 class CSLMaterialLibrary;
    00027 class CSLFog;
    00028 class CSLActionFCurve;
    00029 class CSLFCurve;
    00030 class CSLTransform;
    00031 class CSLAction;
    00032 class CSLShapeAnimation;
    00033 class CSLVisibility;
    00034 class CSLXSIMaterial;
    00035 class CSLImageLibrary;
    00036 class CSLImage;
    00037 class CSLXSIShader;
    00038
    00042 class XSIEXPORT CSLUnresolvedElement
    00043 {
    00044 public:
    00045     CSLUnresolvedElement
    00046     (
    00047         CSLTemplate *in_pUnresolvedObject,
    00048         CSLTemplate *in_pUnresolvedParent = 0,
    00049         SI_Char *in_pReferenceName = 0,
    00050         void *in_pUserData = 0
    00051     );
    00052
    00056     inline CSLTemplate* UnresolvedObject();
    00057
    00061     inline CSLTemplate* UnresolvedParent();
    00062
    00066     inline SI_Char*  ReferenceName();
    00067
    00071     inline void*         UserData();
    00072
    00073 private:
    00074     CSLTemplate *m_pUnresolvedObject;
    00075     CSLTemplate *m_pUnresolvedParent;
    00076     SI_Char *m_pReferenceName;
    00077     void *m_pUserData;
    00078
    00079     // This member is here to allow future improvement of the class.
    00080     void *m_pReserved;
    00081 };
    00082
    00083 inline CSLTemplate* CSLUnresolvedElement::UnresolvedObject()
    00084 {
    00085     return m_pUnresolvedObject;
    00086 }
    00087
    00088 inline CSLTemplate* CSLUnresolvedElement::UnresolvedParent()
    00089 {
    00090     return m_pUnresolvedParent;
    00091 }
    00092 inline SI_Char* CSLUnresolvedElement::ReferenceName()
    00093 {
    00094     return m_pReferenceName;
    00095 }
    00096
    00097 inline void* CSLUnresolvedElement::UserData()
    00098 {
    00099     return m_pUserData;
    00100 }
    00101
    00102 #ifdef  FTK_KERNEL
    00103 typedef std::multimap<SI_Char *, CSLUnresolvedElement, StrLessPred> CSLUnresolvedMap;
    00104 typedef CSLUnresolvedMap::iterator CSLUnresolvedMapIterator;
    00105 typedef std::pair<CSLUnresolvedMapIterator,CSLUnresolvedMapIterator> CSLUnresolvedMapRange;
    00106
    00107 typedef SI_StrMap<CSLModel *> CSLModelMap;
    00108 typedef CSLModelMap::iterator CSLModelMapIterator;
    00109 #else
    00110 typedef void CSLUnresolvedMap;
    00111 typedef void CSLModelMap;
    00112 #endif
    00113
    00117 struct XSIEXPORT SLContext
    00118 {
    00119 public:
    00120     SLContext();
    00121     SI_Void AddOrphan(CSLTemplate *in_pOrphanTemplate);
    00123     CSLTemplate *m_pCurrentTemplate;
    00124     CSLModel *m_pCurrentModel;
    00125     CSLScene *m_pScene;
    00126     CSLMaterialLibrary *m_pMaterialLibrary;
    00127     CSLXSIMaterial *m_pCurrentMaterial;
    00128     CSIBCArray<CSLTemplate *> *m_pOrphanList;
    00129     void *m_pTemplateUserData;
    00130     CSLUnresolvedMap *m_pUnresolvedMap;
    00131     CSLModelMap *m_pModelMap;
    00132     CSLImageLibrary *m_pImageLibrary;
    00133     CSLImage *m_pCurrentImage;
    00134     CSLXSIShader *m_pCurrentXSIShader;
    00135     void *m_pUserData;
    00137 private:
    00138     // This member is here to allow future improvement of the class.
    00139     void *m_pReserved;
    00140 };
    00141
    00142 typedef CSLTemplate *(*CSLCALLBACK) (CdotXSITemplate *in_pTemplate, SLContext *in_pContext);
    00143 typedef SI_Error (*CSLPOSTCHILDRENCALLBACK) (CSLTemplate *in_pTemplate, SLContext *in_pContext);
    00144 typedef SI_Error (*CSLLOADCALLBACK) (SLContext *in_pContext);
    00145
    00162 class XSIEXPORT SLTemplateCallback
    00163 {
    00164 public:
    00165     SLTemplateCallback();
    00166     void Clear();
    00167
    00168     CSLLOADCALLBACK m_PreLoadCallback;
    00169     CSLCALLBACK m_Callback;
    00170     CSLPOSTCHILDRENCALLBACK m_PostChildrenCallback;
    00171     CSLLOADCALLBACK m_PostLibraryCallback;
    00172     CSLLOADCALLBACK m_PostLoadCallback;
    00173
    00174     void *m_pUserData;
    00175
    00176 private:
    00177     // This member is here to allow future improvement of the class.
    00178     void *m_pReserved;
    00179 };
    00180
    00186 class XSIEXPORT CSLScene
    00187 {
    00188 public:
    00190     // Construction/destruction
    00192     CSLScene();
    00193     virtual ~CSLScene();
    00194
    00196     // File manipulation functions.
    00198
    00203     SI_Error Open(SI_Char *in_szFileName);
    00204
    00211     SI_Error Open(SI_Char *in_szFileName, SI_READ_CALLBACK_FNC in_pFunc);
    00212
    00220     SI_Error Create(SI_Char *in_szFileName, SI_Int in_nVersionMajor, SI_Int in_nVersionMinor, SI_Int in_nFormat = FORMAT_TEXT);
    00221
    00228     SI_Error Create(SI_Int in_nVersionMajor, SI_Int in_nVersionMinor, SI_Int in_nFormat = FORMAT_TEXT);
    00229
    00234     SI_Error Open(CXSIParser * in_parser);
    00238     SI_Error Read();
    00239
    00243     virtual SI_Error Write();
    00244
    00249     virtual SI_Error Write(SI_Char* in_szFileName);
    00250
    00254     SI_Error Close();
    00255
    00260     CSLModel*           FindModel(SI_Char* in_szModelName);
    00261
    00267     CSLModel*           FindModelRecursively(SI_Char* in_szModelName, CSLModel* in_pModel);
    00268
    00276     CSLAnimatableType*  FindParameter(SI_Char* in_szParameterName);
    00277
    00283     SI_Error            GetValue(SI_Char* in_szParameterName, SI_Float* out_pfValue);
    00284
    00290     SI_Error            SetValue(SI_Char* in_szParameterName, SI_Float in_fValue);
    00291
    00293     // Accessors
    00295
    00299     CSLAmbience *Ambience();
    00300
    00304     CSLAmbience *CreateAmbience();
    00305
    00309     SI_Error DestroyAmbience();
    00310
    00314     CSLCoordinateSystem* CoordinateSystem();
    00315
    00319     CSLEnvelopeList* EnvelopeList();
    00320
    00324     CSLFog* Fog();
    00325
    00329     CSLMaterialLibrary* GetMaterialLibrary();
    00330
    00334     CSLModel *Root();
    00335
    00339     CXSIParser* Parser();
    00340
    00344     CSLAngle* Angle();
    00345
    00349     CSLFileInfo* FileInfo();
    00350
    00354     CSLSceneInfo* SceneInfo();
    00355
    00359     CSLLogger* Logger();
    00360
    00364     CSIBCString &FileName();
    00365
    00369     CSLImageLibrary* GetImageLibrary();
    00370
    00374     SI_Error DestroyFog();
    00375
    00379     CSLFog* CreateFog();
    00380
    00384     SI_Error DestroyEnvelopeList();
    00385
    00389     virtual CSLEnvelopeList* CreateEnvelopeList();
    00390
    00395     virtual CSLImageLibrary* CreateImageLibrary();
    00396
    00401     SI_Error DestroyImageLibrary();
    00402
    00403
    00405     // Connection functions.
    00407
    00412     virtual CSLMaterialLibrary* ConnectMaterialLibrary(CSLMaterialLibrary *in_pNewMaterialLibrary);
    00413
    00418     CSLAngle* ConnectAngle(CSLAngle *in_pNewAngle);
    00419
    00424     CSLFileInfo* ConnectFileInfo(CSLFileInfo *in_pNewFileInfo);
    00425
    00430     CSLSceneInfo* ConnectSceneInfo(CSLSceneInfo* in_pToConnect);
    00431
    00436     CSLFog* ConnectFog( CSLFog *in_pNewFog );
    00437
    00442     CSLAmbience* ConnectAmbience( CSLAmbience *in_pNewAmbience );
    00443
    00448     CSLCoordinateSystem* ConnectCoordinateSystem( CSLCoordinateSystem *in_pNewCoordSystem );
    00449
    00454     CSLEnvelopeList* ConnectEnvelopeList( CSLEnvelopeList* in_pNewEnvList );
    00455
    00461     CSLImageLibrary* ConnectImageLibrary( CSLImageLibrary* in_pImageLibrary );
    00462
    00497     SI_Error RegisterCallback(SI_Char *in_pName, SLTemplateCallback *in_pTemplateCallback);
    00498
    00503     SI_Error UnregisterCallback(SI_Char *in_pName);
    00504
    00508     SI_Error UnregisterAllCallbacks();
    00509
    00514     SLTemplateCallback *Callback(SI_Char *in_pName);
    00515
    00517     // Coherancy functions
    00519     virtual SI_Error Fix();
    00520     virtual SI_Error Synchronize();
    00521
    00523     // Utility functions
    00525     SI_Error RemoveTemplate(CdotXSITemplate *in_pElement);
    00526     SI_Error ClearSLObjectArray(CSIBCArray<CSLTemplate *> *in_pArray);
    00527
    00533     SI_Bool SupportsTemplates( SI_Int in_nMajor, SI_Int in_nMinor );
    00534
    00538     SI_Void SetWarningCallback ( SI_WARNING_CALLBACK_FNC in_pfncCallback ) { m_pfncCallback = in_pfncCallback; };
    00539
    00543     SI_Void SetReadCallback ( SI_READ_CALLBACK_FNC in_pfncCallback ) { m_pfncReadCallback = in_pfncCallback; };
    00550     SI_Error    GetRefCount( CSLTemplate                ** in_ppObjects,
    00551                              SI_Int                     ** out_ppRefCounts,
    00552                              SI_Int                     in_iObjectCount,
    00553                              CSLTemplate::ETemplateType in_eType );
    00554
    00555
    00556     static CSLScene * CreateScene();
    00557 protected:
    00558
    00559     SI_Error    GetRefCountRecursively      ( CSLModel* in_pModel,
    00560                                                     CSLTemplate** in_ppObjects,
    00561                                                     SI_Int**    out_ppRefCounts,
    00562                                                     SI_Int      in_iObjectCount,
    00563                                                     CSLTemplate::ETemplateType in_eType );
    00564
    00565
    00566 protected:
    00567     CSLModel    * FindFullyQualifiedObject( SI_Char * in_pName, SI_Char ** out_pContainer, SI_Char ** out_pParameter );
    00568     virtual SI_Error PopulateScene();
    00569     SI_Error ReadTemplateRecursively(CdotXSITemplate *in_pTemplate, SLContext *in_pContext);
    00570     SI_Error ExecutePreLoadCallbacks(SLContext *in_pContext);
    00571     SI_Error ExecutePostLibraryCallbacks(SLContext *in_pContext);
    00572     SI_Error ExecutePostLoadCallbacks(SLContext *in_pContext);
    00573     virtual SI_Error RegisterAllCallbacks();
    00574     SI_Error Clear();
    00575
    00576 #ifdef  FTK_KERNEL
    00577     typedef SI_StrMap<SLTemplateCallback> CSLCallbackMap;
    00578     typedef CSLCallbackMap::iterator CSLCallbackMapIterator;
    00579 #else
    00580     typedef void    CSLCallbackMap;
    00581 #endif
    00582
    00583     CSLSceneInfo* m_pSceneInfo;
    00584     CSLFileInfo* m_pFileInfo;
    00585     CSLAmbience* m_pAmbience;
    00586     CSLAngle* m_pAngle;
    00587     CSLFog* m_pFog;
    00588     CSLEnvelopeList* m_pEnvelopeList;
    00589     CSLMaterialLibrary* m_pMaterialLibrary;
    00590     CSLCoordinateSystem* m_pCoordinateSystem;
    00591     CXSIParser* m_pParser;
    00592     CSLCallbackMap* m_pCallbackMap;
    00593     CSLModel *m_pRoot;
    00594     CSLLogger m_Logger;
    00595     CSLImageLibrary *m_pImageLibrary;
    00596
    00597     CSIBCString m_FileName;
    00598
    00599     SI_WARNING_CALLBACK_FNC m_pfncCallback;
    00600     SI_READ_CALLBACK_FNC    m_pfncReadCallback;
    00601
    00602     // This member is here to allow future improvement of the class.
    00603     void *m_pReserved;
    00604 };
    00605
    00606 #endif