FBX SDK Reference Guide: kfbxsdkmanager.h Source File
Go to the documentation of this file.
00001 
00004 #ifndef _FBXSDK_SDK_MANAGER_H_
00005 #define _FBXSDK_SDK_MANAGER_H_
00006 
00007 /**************************************************************************************
00008 
00009  Copyright  2001 - 2008 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 <kaydaradef.h>
00042 #ifndef KFBX_DLL
00043     #define KFBX_DLL K_DLLIMPORT
00044 #endif
00045 
00046 #include <kaydara.h>
00047 
00048 #ifndef MB_FBXSDK
00049     #include <kbaselib_nsuse.h>
00050 #endif
00051 
00052 #include <kbaselib_forward.h>
00053 
00054 #include <kfbxplugins/kfbxmemoryallocator.h>
00055 #include <kfbxplugins/kfbxgeometryconverter.h>
00056 #include <kfbxplugins/kfbximageconverter.h>
00057 #include <kfbxplugins/kfbxproperty.h>
00058 #include <kfbxplugins/kfbxtypes.h>
00059 #include <kfbxplugins/kfbxlayer.h>
00060 
00061 #include <fbxfilesdk_nsbegin.h>
00062 
00063 // Forward declarations
00064 class KFbxIOPluginRegistry;
00065 class KFbxUserNotification;
00066 class KFbxMessageEmitter;
00067 class KFbxIOSettings;
00068 class KFbxSdkManager_internal;
00069 class KFbxPreviewManager;
00070 class KFbxXRefManager;
00071 class KFbxLocalizationManager;
00072 class KFbxPlugin;
00073 
00087     class KFBX_DLL KFbxSdkManager
00088     {
00089     public:
00094 
00104             static bool SetMemoryAllocator(KFbxMemoryAllocator* pMemoryAllocator);
00106 
00107 
00116             static KFbxSdkManager* Create();
00117 
00121             virtual void Destroy();
00123 
00124 
00129         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 
00144             template <typename T> inline kFbxClassId    RegisterRuntimeFbxClass(char const *pName,T const *pFBX_TYPE_ParentClass,const char *pFbxFileTypeName=0,const char *pFbxFileSubTypeName=0) {
00145                 return Internal_RegisterFbxClass(pName,T::ClassId,(kFbxPlugConstructor)T::SdkManagerCreate,pFbxFileTypeName,pFbxFileSubTypeName );
00146             }
00147 
00148             inline void UnregisterRuntimeFbxClass(char const* pName)
00149             {
00150                 kFbxClassId lClassId = FindClass(pName);
00151 
00152                 if( !(lClassId == kFbxClassId()) )
00153                 {
00154                     Internal_UnregisterFbxClass(lClassId);
00155                 }
00156             }
00157 
00158             template <typename T1,typename T2> inline kFbxClassId OverrideFbxClass(T1 const *pFBX_TYPE_Class,T2 const *pFBX_TYPE_OverridenClass) {
00159                 T1::ClassId  = Internal_OverrideFbxClass(T2::ClassId,(kFbxPlugConstructor)T1::SdkManagerCreate );
00160                 return T1::ClassId;
00161             }
00162 
00163             KFbxPlug*       CreateClass(kFbxClassId pClassId, char const *pName, const char* pFBXType=0, const char* pFBXSubType=0);
00164             KFbxPlug*       CreateClass(KFbxObject* pContainer, kFbxClassId pClassId, const char* pName, const char* pFBXType=0, const char* pFBXSubType=0);
00165             kFbxClassId     FindClass(const char* pClassName);
00166             kFbxClassId     FindFbxFileClass(const char* pFbxFileTypeName, const char* pFbxFileSubTypeName);
00167 
00168             template <typename T> inline void UnregisterFbxClass( T const* pFBX_TYPE_Class )
00169             {
00170                 Internal_UnregisterFbxClass( T::ClassId );
00171                 T::ClassId = kFbxClassId();
00172             }
00173 
00175 
00180         public:
00184             KError& GetError();
00185 
00188             typedef enum
00189             {
00190                 eOBJECT_NOT_FOUND,    
00191                 eNAME_ALREADY_IN_USE, 
00192                 eERROR_COUNT          
00193             } EError;
00194 
00198             EError GetLastErrorID() const;
00199 
00203             const char* GetLastErrorString() const;
00204 
00206 
00214             KFbxDataType CreateFbxDataType(const char *pName,EFbxType pType);
00215 
00219             KFbxDataType const &GetFbxDataTypeFromName(const char *pDataType);
00220 
00224             int GetFbxDataTypeCount();
00225 
00229             KFbxDataType &GetFbxDataType(int pIndex);
00231 
00232 
00241             KFbxUserNotification* GetUserNotification() const;
00242             void SetUserNotification(KFbxUserNotification* pUN);
00244 
00252             KFbxMessageEmitter & GetMessageEmitter();
00257             bool SetMessageEmitter(KFbxMessageEmitter * pMessageEmitter);
00259 
00260         private:
00261             KArrayTemplate<KFbxLocalizationManager *>   mKFbxLocalizations;
00262         public:
00270             void AddLocalization( KFbxLocalizationManager * pLocManager );
00274             void RemoveLocalization( KFbxLocalizationManager * pLocManager );
00278             bool SetLocale( const char * pLocale );
00285             const char * Localize( const char * pID, const char * pDefault = NULL) const;
00287 
00292 
00296             KFbxPreviewManager& GetPreviewManager();
00297 
00299 
00307             KFbxXRefManager& GetXRefManager();
00309 
00317             KFbxLibrary*    GetRootLibrary();
00318             KFbxLibrary*    GetSystemLibraries();
00319             KFbxLibrary*    GetUserLibraries();
00321 
00329             KFbxIOPluginRegistry* GetIOPluginRegistry() const;
00331 
00338             bool LoadPluginsDirectory (char *pFilename,char *pExtensions);
00341             bool LoadPlugin (char *pFilename);
00344             bool UnloadPlugins();
00345             bool EmitPluginsEvent(KFbxEventBase const &pEvent);
00346             KArrayTemplate<KFbxPlugin const*> GetPlugins() const;
00348 
00349 
00356         void FillIOSettingsForReadersRegistered(KFbxIOSettings & pIOS);
00357         void FillIOSettingsForWritersRegistered(KFbxIOSettings & pIOS);
00358         void FillCommonIOSettings(KFbxIOSettings & pIOS, bool pImport);
00359         void Create_Common_Import_IOSettings_Groups(KFbxIOSettings & pIOS);
00360         void Create_Common_Export_IOSettings_Groups(KFbxIOSettings & pIOS);
00361         void Add_Common_Import_IOSettings(KFbxIOSettings & pIOS);
00362         void Add_Common_Export_IOSettings(KFbxIOSettings & pIOS);
00363         void Add_Common_RW_Import_IOSettings(KFbxIOSettings & pIOS);
00364         void Add_Common_RW_Export_IOSettings(KFbxIOSettings & pIOS);
00365         void Fill_Motion_Base_ReaderIOSettings(KFbxIOSettings& pIOS);
00366         void Fill_Motion_Base_WriterIOSettings(KFbxIOSettings& pIOS);
00368 
00369         // Temporary for Managing global objects
00374         protected:
00375             KArrayTemplate<KFbxObject *> mObjectArray;
00376 
00377         public:
00380             void RegisterObject(KFbxPlug const * pPlug);
00383             void UnregisterObject(KFbxPlug const * pPlug);
00384 
00385         private:
00386             KArrayTemplate<KFbxImageConverter *>    mKFbxImageConverterArray;
00387         public:
00388             inline int  GetSrcObjectCount(KFbxImageConverter const *)                                   { return mKFbxImageConverterArray.GetCount();  }
00389             inline KFbxImageConverter*      GetSrcObject(KFbxImageConverter const *,int pIndex=0)       { return mKFbxImageConverterArray.GetAt(pIndex); }
00390         private:
00391             KArrayTemplate<KFbxNode *>  mKFbxNodeArray;
00392         public:
00393             inline int  GetSrcObjectCount(KFbxNode const *)                         { return mKFbxNodeArray.GetCount();  }
00394             inline KFbxNode*        GetSrcObject(KFbxNode const *,int pIndex=0)     { return mKFbxNodeArray.GetAt(pIndex); }
00395         private:
00396             KArrayTemplate<KFbxTexture *>   mKFbxTextureArray;
00397         public:
00398             inline int  GetSrcObjectCount(KFbxTexture const *)                          { return mKFbxTextureArray.GetCount();  }
00399             inline KFbxTexture*     GetSrcObject(KFbxTexture const *,int pIndex=0)      { return mKFbxTextureArray.GetAt(pIndex); }
00400         private:
00401             KArrayTemplate<KFbxCluster *>   mKFbxClusterArray;
00402         public:
00403             inline int  GetSrcObjectCount(KFbxCluster const *)                          { return mKFbxClusterArray.GetCount();  }
00404             inline KFbxCluster*     GetSrcObject(KFbxCluster const *,int pIndex=0)      { return mKFbxClusterArray.GetAt(pIndex); }
00405         private:
00406             KArrayTemplate<KFbxScene *> mKFbxSceneArray;
00407         public:
00408             inline int  GetSrcObjectCount(KFbxScene const *)                            { return mKFbxSceneArray.GetCount();  }
00409             inline KFbxScene*       GetSrcObject(KFbxScene const *,int pIndex=0)        { return mKFbxSceneArray.GetAt(pIndex); }
00410         private:
00411             KArrayTemplate<KFbxDocument *>  mKFbxDocumentArray;
00412         public:
00413             inline int  GetSrcObjectCount(KFbxDocument const *)                         { return mKFbxDocumentArray.GetCount();  }
00414             inline KFbxDocument*        GetSrcObject(KFbxDocument const *,int pIndex=0)     { return mKFbxDocumentArray.GetAt(pIndex); }
00415         private:
00416             KArrayTemplate<KFbxSurfaceMaterial *>   mKFbxSurfaceMaterialArray;
00417         public:
00418             inline int  GetSrcObjectCount(KFbxSurfaceMaterial const *)                          { return mKFbxSurfaceMaterialArray.GetCount();  }
00419             inline KFbxSurfaceMaterial*     GetSrcObject(KFbxSurfaceMaterial const *,int pIndex=0)      { return mKFbxSurfaceMaterialArray.GetAt(pIndex); }
00420 
00421         public:
00431             static KString PrefixName(char const* pPrefix, char const* pName);
00432 
00433 
00435     //
00436     //  WARNING!
00437     //
00438     //  Anything beyond these lines may not be documented accurately and is
00439     //  subject to change without notice.
00440     //
00442 
00443     #ifndef DOXYGEN_SHOULD_SKIP_THIS
00444 
00445     public:
00446         bool CanDestroyFbxSrcObject(KFbxObject* pObject, KFbxObject* pSrcObject, bool pRecursive, bool pDependents);
00447 
00448         void CreateMissingBindPoses(KFbxScene *pScene);
00449         int  GetBindPoseCount(KFbxScene *pScene);
00450 
00451         KFbxPlug*       CreateClassFrom(kFbxClassId, const char *pName, const KFbxObject* pFrom, const char* pFBXType=0, const char* pFBXSubType=0);
00452 
00453     private:
00454         kFbxClassId     Internal_RegisterFbxClass(const char* pClassName, kFbxClassId pParentClassId, kFbxPlugConstructor=0, char const* pFbxFileTypeName=0, char const* pFbxFileSubTypeName=0);
00455         bool            Internal_RegisterFbxClass(kFbxClassId pClassId);
00456         kFbxClassId     Internal_OverrideFbxClass(kFbxClassId pClassId, kFbxPlugConstructor=0);
00457 
00458         void            Internal_UnregisterFbxClass (kFbxClassId    pClassId);
00459 
00460         template< class T > void RemoveObjectsOfType( KArrayTemplate<T>& pArray, kFbxClassId pClassId );
00461         KArrayTemplate<KFbxObject*> mSystemLockedObjects; // objects that can only be destroied when the manager is detroyed
00462 
00463         #ifdef K_FBXNEWRENAMING
00464 
00465             enum ERenamingMode
00466             {
00467                 eMAYA_TO_FBX,
00468                 eFBX_TO_MAYA,
00469                 eLW_TO_FBX,
00470                 eFBX_TO_LW,
00471                 eXSI_TO_FBX,
00472                 eFBX_TO_XSI,
00473                 eMAX_TO_FBX,
00474                 eFBX_TO_MAX,
00475                 eMB_TO_FBX,
00476                 eFBX_TO_MB
00477             };
00478 
00479             void RenameFor(ERenamingMode pMode);
00480 
00490             void ResolveNameClashing(bool pFromFbx, bool pIgnoreNS, bool pIsCaseSensitive, bool pComvertToWideChar, bool pReplaceNonAlphaNum, KString pNameSpaceSymbol);
00491 
00492         #endif
00493 
00494 
00495     protected:
00496         KFbxSdkManager();
00497         virtual ~KFbxSdkManager();
00498 
00509         virtual void Clear(KArrayTemplate<kFbxClassId>* pExcludeList = NULL, bool pDestroyUserNotification=true);
00510 
00511         // this object is destroyed when the manager is destroyed.
00512         KFbxUserNotification* mUserNotification;
00513 
00514         // this object is destroyed when the manager is destroyed.
00515         KFbxMessageEmitter * mMessageEmitter;
00516 
00517         // this object is destroyed when the manager is destroyed.
00518         KFbxIOPluginRegistry* mRegistry;
00519 
00520         mutable KError mError;
00521 
00522         friend class KFbxReaderFbx;
00523         friend class KFbxReaderFbx6;
00524         friend struct KFbxReaderFbx7Impl;
00525         friend class KFbxWriterFbx;
00526         friend class KFbxWriterFbx6;
00527         friend struct KFbxWriterFbx7Impl;
00528         friend class KFbxPose;
00529 
00530         // Class Management
00531         bool ClassInit();
00532         bool ClassRelease();
00533 
00534         int GetFbxClassCount() const;
00535         kFbxClassId GetNextFbxClass(kFbxClassId pClassId /* invalid id: first one */) const;
00536 
00537         private:
00538             KFbxSdkManager_internal* mInternal;
00539 
00540     #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00541 
00542     };
00543 
00544     typedef KFbxSdkManager KFbxSdk;
00545 
00546     typedef KFbxSdkManager* HKFbxSdkManager;
00547 
00548     // Connection management
00549     template < class T > inline int KFbxGetSrcCount(KFbxSdkManager *pObject)                    { T const* FBXTYPE = 0; return pObject ? pObject->GetSrcObjectCount(FBXTYPE) : 0; }
00550     template < class T > inline int KFbxGetSrcCount(KFbxSdkManager *pObject, T const* FBXTYPE)  { return pObject ? pObject->GetSrcObjectCount(FBXTYPE) : 0; }
00551     template < class T > inline T*  KFbxGetSrc(KFbxSdkManager *pObject,int pIndex=0) { T const* FBXTYPE = 0; return pObject ? (T *)pObject->GetSrcObject(FBXTYPE,pIndex) : 0; }
00552     template < class T > inline T*  KFbxFindSrc(KFbxSdkManager *pObject,char const *pName)
00553     {
00554         for (int i=0; i<KFbxGetSrcCount<T>(pObject); i++) {
00555           T* lObject = KFbxGetSrc<T>(pObject,i);
00556             if (strcmp(lObject->GetName(),pName)==0 ){
00557                 return lObject;
00558             }
00559         }
00560         return 0;
00561     }
00562 
00563     // Class Registration management
00564 
00565 #include <fbxfilesdk_nsend.h>
00566 
00567 #endif // #ifndef _FBXSDK_SDK_MANAGER_H_
00568 
00569