kfbxsdkmanager.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXSDKMANAGER_H
00005 #define FBXFILESDK_KFBXPLUGINS_KFBXSDKMANAGER_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2010 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 #include <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #include <fbxfilesdk/kfbxplugins/kfbxobject.h>
00044 #include <fbxfilesdk/kfbxplugins/kfbxmemoryallocator.h>
00045 #include <fbxfilesdk/kfbxplugins/kfbxgeometryconverter.h>
00046 #include <fbxfilesdk/kfbxplugins/kfbxproperty.h>
00047 #include <fbxfilesdk/kfbxplugins/kfbxtypes.h>
00048 #include <fbxfilesdk/kfbxplugins/kfbxlayer.h>
00049 
00050 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00051 
00052 // Forward declarations
00053 class KFbxIOPluginRegistry;
00054 class KFbxUserNotification;
00055 class KFbxMessageEmitter;
00056 class KFbxIOSettings;
00057 class KFbxSdkManager_internal;
00058 class KFbxPreviewManager;
00059 class KFbxXRefManager;
00060 class KFbxLocalizationManager;
00061 class KFbxPlugin;
00062 class KFbxAnimStack;
00063 class KFbxReference;
00064 
00078     class KFBX_DLL KFbxSdkManager
00079     {
00080     public:
00085 
00096             static bool SetMemoryAllocator(KFbxMemoryAllocator* pMemoryAllocator);
00098 
00099 
00108             static KFbxSdkManager* Create();
00109 
00113             virtual void Destroy();
00114 
00120             static void GetFileFormatVersion(int& pMajor, int& pMinor, int& pRevision);
00122 
00123 
00128         public:
00139             template <typename T1,typename T2> inline kFbxClassId RegisterFbxClass(char const *pName,T1 const *pFBX_TYPE_Class,T2 const *pFBX_TYPE_ParentClass,const char *pFbxFileTypeName=0,const char *pFbxFileSubTypeName=0) {
00140                 T1::ClassId  = Internal_RegisterFbxClass(pName,T2::ClassId,(kFbxPlugConstructor)T1::SdkManagerCreate,pFbxFileTypeName,pFbxFileSubTypeName );
00141                 return T1::ClassId;
00142             }
00143          
00153             template <typename T> inline kFbxClassId    RegisterRuntimeFbxClass(char const *pName,T const *pFBX_TYPE_ParentClass,const char *pFbxFileTypeName=0,const char *pFbxFileSubTypeName=0) {
00154                 return Internal_RegisterFbxClass(pName,T::ClassId,(kFbxPlugConstructor)T::SdkManagerCreate,pFbxFileTypeName,pFbxFileSubTypeName );
00155             }
00156             
00160             inline void UnregisterRuntimeFbxClass(char const* pName)
00161             {
00162                 kFbxClassId lClassId = FindClass(pName);
00163 
00164                 if( !(lClassId == kFbxClassId()) )
00165                 {
00166                     Internal_UnregisterFbxClass(lClassId);
00167                 }
00168             }
00169             
00175             template <typename T1,typename T2> inline kFbxClassId OverrideFbxClass(T1 const *pFBX_TYPE_Class,T2 const *pFBX_TYPE_OverridenClass) {
00176                 T1::ClassId  = Internal_OverrideFbxClass(T2::ClassId,(kFbxPlugConstructor)T1::SdkManagerCreate );
00177                 return T1::ClassId;
00178             }
00179 
00187             K_DEPRECATED KFbxPlug* CreateClass(kFbxClassId pClassId, char const *pName, const char* pFBXType=0, const char* pFBXSubType=0);
00188 
00199             KFbxObject* CreateNewObjectFromClassId(kFbxClassId pClassId, char const* pName, KFbxObject* pContainer=NULL, const KFbxObject* pCloneFrom=NULL);
00200 
00209             K_DEPRECATED KFbxPlug* CreateClass(KFbxObject* pContainer, kFbxClassId pClassId, const char* pName, const char* pFBXType=0, const char* pFBXSubType=0);
00210 
00214             kFbxClassId     FindClass(const char* pClassName) const;
00215 
00220             kFbxClassId     FindFbxFileClass(const char* pFbxFileTypeName, const char* pFbxFileSubTypeName) const;
00221 
00225             template <typename T> inline void UnregisterFbxClass( T const* pFBX_TYPE_Class )
00226             {
00227                 Internal_UnregisterFbxClass( T::ClassId );
00228                 T::ClassId = kFbxClassId();
00229             }
00230 
00232 
00237         public:
00241             KError& GetError();
00242 
00245             typedef enum
00246             {
00247                 eOBJECT_NOT_FOUND,    
00248                 eNAME_ALREADY_IN_USE, 
00249                 eERROR_COUNT          
00250             } EError;
00251 
00255             EError GetLastErrorID() const;
00256 
00260             const char* GetLastErrorString() const;
00261 
00263 
00273             KFbxDataType CreateFbxDataType(const char *pName,EFbxType pType);
00274 
00279             KFbxDataType const &GetFbxDataTypeFromName(const char *pDataType);
00280 
00284             int GetFbxDataTypeCount() const;
00285 
00290             KFbxDataType &GetFbxDataType(int pIndex);
00292 
00293 
00302             KFbxUserNotification* GetUserNotification() const;
00303 
00307             void SetUserNotification(KFbxUserNotification* pUN);
00309 
00318             virtual KFbxIOSettings * GetIOSettings() const;
00319 
00323             virtual void SetIOSettings(KFbxIOSettings * pIOSettings);
00325 
00326 
00334             KFbxMessageEmitter & GetMessageEmitter();
00339             bool SetMessageEmitter(KFbxMessageEmitter * pMessageEmitter);
00341 
00342         private:
00343             KArrayTemplate<KFbxLocalizationManager *>   mKFbxLocalizations;
00344         public:
00352             void AddLocalization( KFbxLocalizationManager * pLocManager );
00356             void RemoveLocalization( KFbxLocalizationManager * pLocManager );
00360             bool SetLocale( const char * pLocale );
00367             const char * Localize( const char * pID, const char * pDefault = NULL) const;
00369 
00374 
00378             KFbxPreviewManager& GetPreviewManager();
00379 
00381 
00389             KFbxXRefManager& GetXRefManager();
00391 
00399             KFbxLibrary*    GetRootLibrary() const;
00400             KFbxLibrary*    GetSystemLibraries() const;
00401             KFbxLibrary*    GetUserLibraries() const;
00403 
00411             KFbxIOPluginRegistry* GetIOPluginRegistry() const;
00413 
00423             bool LoadPluginsDirectory (char *pFilename,char *pExtensions);
00424 
00429             bool LoadPlugin (char *pFilename);
00430 
00433             bool UnloadPlugins();
00434 
00438             bool EmitPluginsEvent(KFbxEventBase const &pEvent);
00439            
00441             KArrayTemplate<KFbxPlugin const*> GetPlugins() const;
00442 
00446             int GetPluginCount() const;
00447 
00453             KFbxPlugin* FindPlugin(const char* pName, const char* pVersion) const;
00455 
00456         
00461         // Add IOSettings in hierarchy from different modules
00462         
00466         void FillIOSettingsForReadersRegistered(KFbxIOSettings & pIOS);
00467 
00471         void FillIOSettingsForWritersRegistered(KFbxIOSettings & pIOS);
00472 
00477         void FillCommonIOSettings(KFbxIOSettings & pIOS, bool pImport);
00478 
00479         private:
00480 
00484         void Create_Common_Import_IOSettings_Groups(KFbxIOSettings & pIOS);
00485 
00489         void Create_Common_Export_IOSettings_Groups(KFbxIOSettings & pIOS);
00490 
00494         void Add_Common_Import_IOSettings(KFbxIOSettings & pIOS);
00495 
00499         void Add_Common_Export_IOSettings(KFbxIOSettings & pIOS);
00500 
00504         void Add_Common_RW_Import_IOSettings(KFbxIOSettings & pIOS);
00505 
00509         void Add_Common_RW_Export_IOSettings(KFbxIOSettings & pIOS);
00510 
00512 
00513         // Temporary for Managing global objects
00518 
00519         protected:
00520             KArrayTemplate<KFbxObject*>     mObjectArray;
00521             KArrayTemplate<KFbxObject*>     mDestroyingObjects;
00522             KArrayTemplate<KFbxNode*>       mDestroyingKFbxNode;
00523             KArrayTemplate<KFbxTexture*>    mDestroyingKFbxTexture;
00524             KArrayTemplate<KFbxCluster*>    mDestroyingKFbxCluster;
00525             KArrayTemplate<KFbxDocument*>   mDestroyingKFbxDocument;
00526             KArrayTemplate<KFbxScene*>      mDestroyingKFbxScene;
00527             KArrayTemplate<KFbxSurfaceMaterial*> mDestroyingKFbxSurfaceMaterial;
00528 
00529             int                             mIsDestroyingScene;
00530 
00531         public:
00537             void RegisterObject(KFbxPlug const* pPlug);
00538 
00543             void UnregisterObject(KFbxPlug const* pPlug);
00544 
00549             void RegisterObjects(const KArrayTemplate<KFbxObject*>& pArray);
00550 
00555             void UnregisterObjects(const KArrayTemplate<KFbxObject*>& pArray);
00556 
00557             void IncreaseDestroyingSceneFlag();
00558             void DecreaseDestroyingSceneFlag();
00559 
00560         private:
00561             KArrayTemplate<KFbxNode *>  mKFbxNodeArray;
00562 
00563         public:
00566             inline int  GetSrcObjectCount(KFbxNode const *) const                 { return mKFbxNodeArray.GetCount();  }
00570             inline KFbxNode*        GetSrcObject(KFbxNode const *,int pIndex=0)  const    { return mKFbxNodeArray.GetAt(pIndex); }
00571         private:
00572             KArrayTemplate<KFbxTexture *>   mKFbxTextureArray;
00573         public:
00576             inline int  GetSrcObjectCount(KFbxTexture const *) const              { return mKFbxTextureArray.GetCount();  }
00580             inline KFbxTexture*     GetSrcObject(KFbxTexture const *,int pIndex=0)  const   { return mKFbxTextureArray.GetAt(pIndex); }
00581         private:
00582             KArrayTemplate<KFbxCluster *>   mKFbxClusterArray;
00583         public:
00586             inline int  GetSrcObjectCount(KFbxCluster const *) const                     { return mKFbxClusterArray.GetCount();  }
00590             inline KFbxCluster*     GetSrcObject(KFbxCluster const *,int pIndex=0) const   { return mKFbxClusterArray.GetAt(pIndex); }
00591         private:
00592             KArrayTemplate<KFbxScene *> mKFbxSceneArray;
00593         public:
00596             inline int  GetSrcObjectCount(KFbxScene const *) const                 { return mKFbxSceneArray.GetCount();  }
00600             inline KFbxScene*       GetSrcObject(KFbxScene const *,int pIndex=0) const  { return mKFbxSceneArray.GetAt(pIndex); }
00601         private:
00602             KArrayTemplate<KFbxDocument *>  mKFbxDocumentArray;
00603         public:
00606             inline int  GetSrcObjectCount(KFbxDocument const *) const            { return mKFbxDocumentArray.GetCount();  }
00610             inline KFbxDocument*        GetSrcObject(KFbxDocument const *,int pIndex=0) const     { return mKFbxDocumentArray.GetAt(pIndex); }
00611         private:
00612             KArrayTemplate<KFbxSurfaceMaterial *>   mKFbxSurfaceMaterialArray;
00613         public:
00616             inline int  GetSrcObjectCount(KFbxSurfaceMaterial const *)  const               { return mKFbxSurfaceMaterialArray.GetCount();  }
00620             inline KFbxSurfaceMaterial*     GetSrcObject(KFbxSurfaceMaterial const *,int pIndex=0) const      { return mKFbxSurfaceMaterialArray.GetAt(pIndex); }
00621        
00622 
00623         private:
00624              KArrayTemplate<KFbxReference *>   mKFbxReferenceArray;
00625         public:
00630 
00634             int GetReferenceCount() const;
00635 
00640             KFbxReference* GetReference(int pIndex) const;
00641 
00647             int AddReference(KFbxReference* pReference);
00648 
00654             bool RemoveReference(KFbxReference* pReference);
00655 
00661             bool ClearReference(KFbxReference* pReference);
00662 
00664 
00665         public:
00675             static KString PrefixName(char const* pPrefix, char const* pName);
00676 
00677 
00679     //
00680     //  WARNING!
00681     //
00682     //  Anything beyond these lines may not be documented accurately and is
00683     //  subject to change without notice.
00684     //
00686 
00687     #ifndef DOXYGEN_SHOULD_SKIP_THIS
00688 
00689     public:
00690     
00691         static KFbxSdkManager* GetDefaultKFbxManager();
00692     
00693         bool CanDestroyFbxSrcObject(KFbxObject* pObject, KFbxObject* pSrcObject, bool pRecursive, bool pDependents) const;
00694 
00695         void CreateMissingBindPoses(KFbxScene *pScene);
00696         int  GetBindPoseCount(KFbxScene *pScene) const;
00697 
00698     private:
00699         kFbxClassId     Internal_RegisterFbxClass(const char* pClassName, kFbxClassId pParentClassId, kFbxPlugConstructor=0, char const* pFbxFileTypeName=0, char const* pFbxFileSubTypeName=0);
00700         bool            Internal_RegisterFbxClass(kFbxClassId pClassId);
00701         kFbxClassId     Internal_OverrideFbxClass(kFbxClassId pClassId, kFbxPlugConstructor=0);
00702 
00703         void            Internal_UnregisterFbxClass (kFbxClassId    pClassId);
00704 
00705         template< class T > void RemoveObjectsOfType( KArrayTemplate<T>& pArray, kFbxClassId pClassId );
00706         KArrayTemplate<KFbxObject*> mSystemLockedObjects; // objects that can only be destroyed when the manager is destroyed
00707 
00708         #ifdef K_FBXNEWRENAMING
00709 
00710             enum ERenamingMode
00711             {
00712                 eMAYA_TO_FBX,
00713                 eFBX_TO_MAYA,
00714                 eLW_TO_FBX,
00715                 eFBX_TO_LW,
00716                 eXSI_TO_FBX,
00717                 eFBX_TO_XSI,
00718                 eMAX_TO_FBX,
00719                 eFBX_TO_MAX,
00720                 eMB_TO_FBX,
00721                 eFBX_TO_MB
00722             };
00723 
00724             void RenameFor(ERenamingMode pMode);
00725 
00735             void ResolveNameClashing(bool pFromFbx, bool pIgnoreNS, bool pIsCaseSensitive, bool pComvertToWideChar, bool pReplaceNonAlphaNum, KString pNameSpaceSymbol);
00736 
00737         #endif
00738 
00739 
00740     protected:
00741         KFBXNEW_DECLARE_FRIEND
00742         KFbxSdkManager();
00743         virtual ~KFbxSdkManager();
00744 
00757         virtual void Clear(KArrayTemplate<kFbxClassId>* pExcludeList = NULL, bool pDestroyUserNotification=true);
00758 
00759         // this object is destroyed when the manager is destroyed.
00760         KFbxUserNotification* mUserNotification;
00761 
00762         // this object is destroyed when the manager is destroyed.
00763         KFbxIOSettings * mIOSettings;
00764 
00765         // this object is destroyed when the manager is destroyed.
00766         KFbxMessageEmitter * mMessageEmitter;
00767 
00768         // this object is destroyed when the manager is destroyed.
00769         KFbxIOPluginRegistry* mRegistry;
00770 
00771         mutable KError mError;
00772 
00773         friend class KFbxPose;
00774 
00775         // Class Management
00776         void ClassInit();
00777         void ClassRelease();
00778 
00779     public:
00780         int GetFbxClassCount() const;
00781         kFbxClassId GetNextFbxClass(kFbxClassId pClassId /* invalid id: first one */) const;
00782 
00783     private:
00784         KFbxSdkManager_internal* mInternal;
00785         static KFbxSdkManager* smDefaultManager;
00786 
00787     #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00788 
00789     };
00790 
00791     typedef KFbxSdkManager KFbxSdk;
00792 
00793     typedef KFbxSdkManager* HKFbxSdkManager;
00794 
00795     // Connection management
00796     template < class T > inline int KFbxGetSrcCount(KFbxSdkManager *pObject)                    { T const* FBXTYPE = 0; return pObject ? pObject->GetSrcObjectCount(FBXTYPE) : 0; }
00797     template < class T > inline int KFbxGetSrcCount(KFbxSdkManager *pObject, T const* FBXTYPE)   { return pObject ? pObject->GetSrcObjectCount(FBXTYPE) : 0; }
00798     template < class T > inline T*  KFbxGetSrc(KFbxSdkManager *pObject,int pIndex=0)  { T const* FBXTYPE = 0; return pObject ? (T *)pObject->GetSrcObject(FBXTYPE,pIndex) : 0; }
00799     template < class T > inline T*  KFbxFindSrc(KFbxSdkManager *pObject,char const *pName) 
00800     {
00801         for (int i=0; i<KFbxGetSrcCount<T>(pObject); i++) {
00802           T* lObject = KFbxGetSrc<T>(pObject,i);
00803             if (strcmp(lObject->GetName(),pName)==0 ){
00804                 return lObject;
00805             }
00806         }
00807         return 0;
00808     }
00809 
00810     // Take index
00811     #define TAKE_NO_ANIMATION   0
00812     #define TAKE_DEFAULT        -1
00813     #define TAKE_INVALID        -3
00814 
00815     // Class Registration management
00816 
00817 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00818 
00819 #endif // FBXFILESDK_KFBXPLUGINS_KFBXSDKMANAGER_H
00820