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 - 2009 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/components/kbaselib/kaydaradef_h.h>
00042 #include <fbxfilesdk/components/kbaselib/kaydara.h>
00043 
00044 #include <fbxfilesdk/components/kbaselib/kbaselib_forward.h>
00045 
00046 #include <fbxfilesdk/kfbxplugins/kfbxmemoryallocator.h>
00047 #include <fbxfilesdk/kfbxplugins/kfbxgeometryconverter.h>
00048 #include <fbxfilesdk/kfbxplugins/kfbximageconverter.h>
00049 #include <fbxfilesdk/kfbxplugins/kfbxproperty.h>
00050 #include <fbxfilesdk/kfbxplugins/kfbxtypes.h>
00051 #include <fbxfilesdk/kfbxplugins/kfbxlayer.h>
00052 
00053 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00054 
00055 // Forward declarations
00056 class KFbxIOPluginRegistry;
00057 class KFbxUserNotification;
00058 class KFbxMessageEmitter;
00059 class KFbxIOSettings;
00060 class KFbxSdkManager_internal;
00061 class KFbxPreviewManager;
00062 class KFbxXRefManager;
00063 class KFbxLocalizationManager;
00064 class KFbxPlugin;
00065 
00079     class KFBX_DLL KFbxSdkManager
00080     {
00081     public:
00086 
00097             static bool SetMemoryAllocator(KFbxMemoryAllocator* pMemoryAllocator);
00099 
00100 
00109             static KFbxSdkManager* Create();
00110 
00114             virtual void Destroy();
00120             static void GetFileFormatVersion(int& pMajor, int& pMinor, int& pRevision);
00122 
00123 
00128         public:
00137             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) {
00138                 T1::ClassId  = Internal_RegisterFbxClass(pName,T2::ClassId,(kFbxPlugConstructor)T1::SdkManagerCreate,pFbxFileTypeName,pFbxFileSubTypeName );
00139                 return T1::ClassId;
00140             }
00141          
00149             template <typename T> inline kFbxClassId    RegisterRuntimeFbxClass(char const *pName,T const *pFBX_TYPE_ParentClass,const char *pFbxFileTypeName=0,const char *pFbxFileSubTypeName=0) {
00150                 return Internal_RegisterFbxClass(pName,T::ClassId,(kFbxPlugConstructor)T::SdkManagerCreate,pFbxFileTypeName,pFbxFileSubTypeName );
00151             }
00152             
00156             inline void UnregisterRuntimeFbxClass(char const* pName)
00157             {
00158                 kFbxClassId lClassId = FindClass(pName);
00159 
00160                 if( !(lClassId == kFbxClassId()) )
00161                 {
00162                     Internal_UnregisterFbxClass(lClassId);
00163                 }
00164             }
00165             
00171             template <typename T1,typename T2> inline kFbxClassId OverrideFbxClass(T1 const *pFBX_TYPE_Class,T2 const *pFBX_TYPE_OverridenClass) {
00172                 T1::ClassId  = Internal_OverrideFbxClass(T2::ClassId,(kFbxPlugConstructor)T1::SdkManagerCreate );
00173                 return T1::ClassId;
00174             }
00175 
00182             KFbxPlug*       CreateClass(kFbxClassId pClassId, char const *pName, const char* pFBXType=0, const char* pFBXSubType=0);
00183 
00191             KFbxPlug*       CreateClass(KFbxObject* pContainer, kFbxClassId pClassId, const char* pName, const char* pFBXType=0, const char* pFBXSubType=0);
00192 
00196             kFbxClassId     FindClass(const char* pClassName);
00197 
00202             kFbxClassId     FindFbxFileClass(const char* pFbxFileTypeName, const char* pFbxFileSubTypeName);
00203 
00207             template <typename T> inline void UnregisterFbxClass( T const* pFBX_TYPE_Class )
00208             {
00209                 Internal_UnregisterFbxClass( T::ClassId );
00210                 T::ClassId = kFbxClassId();
00211             }
00212 
00214 
00219         public:
00223             KError& GetError();
00224 
00227             typedef enum
00228             {
00229                 eOBJECT_NOT_FOUND,    
00230                 eNAME_ALREADY_IN_USE, 
00231                 eERROR_COUNT          
00232             } EError;
00233 
00237             EError GetLastErrorID() const;
00238 
00242             const char* GetLastErrorString() const;
00243 
00245 
00255             KFbxDataType CreateFbxDataType(const char *pName,EFbxType pType);
00256 
00261             KFbxDataType const &GetFbxDataTypeFromName(const char *pDataType);
00262 
00266             int GetFbxDataTypeCount();
00267 
00272             KFbxDataType &GetFbxDataType(int pIndex);
00274 
00275 
00284             KFbxUserNotification* GetUserNotification() const;
00285 
00289             void SetUserNotification(KFbxUserNotification* pUN);
00291 
00299             KFbxMessageEmitter & GetMessageEmitter();
00304             bool SetMessageEmitter(KFbxMessageEmitter * pMessageEmitter);
00306 
00307         private:
00308             KArrayTemplate<KFbxLocalizationManager *>   mKFbxLocalizations;
00309         public:
00317             void AddLocalization( KFbxLocalizationManager * pLocManager );
00321             void RemoveLocalization( KFbxLocalizationManager * pLocManager );
00325             bool SetLocale( const char * pLocale );
00332             const char * Localize( const char * pID, const char * pDefault = NULL) const;
00334 
00339 
00343             KFbxPreviewManager& GetPreviewManager();
00344 
00346 
00354             KFbxXRefManager& GetXRefManager();
00356 
00364             KFbxLibrary*    GetRootLibrary();
00365             KFbxLibrary*    GetSystemLibraries();
00366             KFbxLibrary*    GetUserLibraries();
00368 
00376             KFbxIOPluginRegistry* GetIOPluginRegistry() const;
00378 
00388             bool LoadPluginsDirectory (char *pFilename,char *pExtensions);
00389 
00394             bool LoadPlugin (char *pFilename);
00395 
00398             bool UnloadPlugins();
00399 
00403             bool EmitPluginsEvent(KFbxEventBase const &pEvent);
00404            
00406             KArrayTemplate<KFbxPlugin const*> GetPlugins() const;
00407 
00411             int GetPluginCount();
00412 
00418             KFbxPlugin* FindPlugin(char* pName, char* pVersion);
00420 
00421         private:
00426         // Add IOSettings in hierarchy from different modules
00427         
00431         void FillIOSettingsForReadersRegistered(KFbxIOSettings & pIOS);
00432 
00436         void FillIOSettingsForWritersRegistered(KFbxIOSettings & pIOS);
00437 
00442         void FillCommonIOSettings(KFbxIOSettings & pIOS, bool pImport);
00443 
00447         void Create_Common_Import_IOSettings_Groups(KFbxIOSettings & pIOS);
00448 
00452         void Create_Common_Export_IOSettings_Groups(KFbxIOSettings & pIOS);
00453 
00457         void Add_Common_Import_IOSettings(KFbxIOSettings & pIOS);
00458 
00462         void Add_Common_Export_IOSettings(KFbxIOSettings & pIOS);
00463 
00467         void Add_Common_RW_Import_IOSettings(KFbxIOSettings & pIOS);
00468 
00472         void Add_Common_RW_Export_IOSettings(KFbxIOSettings & pIOS);
00473 
00474         public:
00478         void Fill_Motion_Base_ReaderIOSettings(KFbxIOSettings& pIOS);
00479 
00483         void Fill_Motion_Base_WriterIOSettings(KFbxIOSettings& pIOS);
00485 
00486         // Temporary for Managing global objects
00491         protected:
00492             KArrayTemplate<KFbxObject *> mObjectArray;
00493 
00494         public:
00498             void RegisterObject(KFbxPlug const * pPlug);
00502             void UnregisterObject(KFbxPlug const * pPlug);
00503 
00504         private:
00505             KArrayTemplate<KFbxImageConverter *>    mKFbxImageConverterArray;
00506         public:
00509             inline int  GetSrcObjectCount(KFbxImageConverter const *)                                   { return mKFbxImageConverterArray.GetCount();  }
00513             inline KFbxImageConverter*      GetSrcObject(KFbxImageConverter const *,int pIndex=0)       { return mKFbxImageConverterArray.GetAt(pIndex); }
00514         private:
00515             KArrayTemplate<KFbxNode *>  mKFbxNodeArray;
00516         public:
00519             inline int  GetSrcObjectCount(KFbxNode const *)                         { return mKFbxNodeArray.GetCount();  }
00523             inline KFbxNode*        GetSrcObject(KFbxNode const *,int pIndex=0)     { return mKFbxNodeArray.GetAt(pIndex); }
00524         private:
00525             KArrayTemplate<KFbxTexture *>   mKFbxTextureArray;
00526         public:
00529             inline int  GetSrcObjectCount(KFbxTexture const *)                          { return mKFbxTextureArray.GetCount();  }
00533             inline KFbxTexture*     GetSrcObject(KFbxTexture const *,int pIndex=0)      { return mKFbxTextureArray.GetAt(pIndex); }
00534         private:
00535             KArrayTemplate<KFbxCluster *>   mKFbxClusterArray;
00536         public:
00539             inline int  GetSrcObjectCount(KFbxCluster const *)                          { return mKFbxClusterArray.GetCount();  }
00543             inline KFbxCluster*     GetSrcObject(KFbxCluster const *,int pIndex=0)      { return mKFbxClusterArray.GetAt(pIndex); }
00544         private:
00545             KArrayTemplate<KFbxScene *> mKFbxSceneArray;
00546         public:
00549             inline int  GetSrcObjectCount(KFbxScene const *)                            { return mKFbxSceneArray.GetCount();  }
00553             inline KFbxScene*       GetSrcObject(KFbxScene const *,int pIndex=0)        { return mKFbxSceneArray.GetAt(pIndex); }
00554         private:
00555             KArrayTemplate<KFbxDocument *>  mKFbxDocumentArray;
00556         public:
00559             inline int  GetSrcObjectCount(KFbxDocument const *)                         { return mKFbxDocumentArray.GetCount();  }
00563             inline KFbxDocument*        GetSrcObject(KFbxDocument const *,int pIndex=0)     { return mKFbxDocumentArray.GetAt(pIndex); }
00564         private:
00565             KArrayTemplate<KFbxSurfaceMaterial *>   mKFbxSurfaceMaterialArray;
00566         public:
00569             inline int  GetSrcObjectCount(KFbxSurfaceMaterial const *)                          { return mKFbxSurfaceMaterialArray.GetCount();  }
00573             inline KFbxSurfaceMaterial*     GetSrcObject(KFbxSurfaceMaterial const *,int pIndex=0)      { return mKFbxSurfaceMaterialArray.GetAt(pIndex); }
00574 
00575         public:
00585             static KString PrefixName(char const* pPrefix, char const* pName);
00586 
00587 
00589     //
00590     //  WARNING!
00591     //
00592     //  Anything beyond these lines may not be documented accurately and is
00593     //  subject to change without notice.
00594     //
00596 
00597     #ifndef DOXYGEN_SHOULD_SKIP_THIS
00598 
00599     public:
00600         bool CanDestroyFbxSrcObject(KFbxObject* pObject, KFbxObject* pSrcObject, bool pRecursive, bool pDependents);
00601 
00602         void CreateMissingBindPoses(KFbxScene *pScene);
00603         int  GetBindPoseCount(KFbxScene *pScene);
00604 
00605         KFbxPlug*       CreateClassFrom(kFbxClassId, const char *pName, const KFbxObject* pFrom, const char* pFBXType=0, const char* pFBXSubType=0);
00606 
00607     private:
00608         kFbxClassId     Internal_RegisterFbxClass(const char* pClassName, kFbxClassId pParentClassId, kFbxPlugConstructor=0, char const* pFbxFileTypeName=0, char const* pFbxFileSubTypeName=0);
00609         bool            Internal_RegisterFbxClass(kFbxClassId pClassId);
00610         kFbxClassId     Internal_OverrideFbxClass(kFbxClassId pClassId, kFbxPlugConstructor=0);
00611 
00612         void            Internal_UnregisterFbxClass (kFbxClassId    pClassId);
00613 
00614         template< class T > void RemoveObjectsOfType( KArrayTemplate<T>& pArray, kFbxClassId pClassId );
00615         KArrayTemplate<KFbxObject*> mSystemLockedObjects; // objects that can only be destroyed when the manager is destroyed
00616 
00617         #ifdef K_FBXNEWRENAMING
00618 
00619             enum ERenamingMode
00620             {
00621                 eMAYA_TO_FBX,
00622                 eFBX_TO_MAYA,
00623                 eLW_TO_FBX,
00624                 eFBX_TO_LW,
00625                 eXSI_TO_FBX,
00626                 eFBX_TO_XSI,
00627                 eMAX_TO_FBX,
00628                 eFBX_TO_MAX,
00629                 eMB_TO_FBX,
00630                 eFBX_TO_MB
00631             };
00632 
00633             void RenameFor(ERenamingMode pMode);
00634 
00644             void ResolveNameClashing(bool pFromFbx, bool pIgnoreNS, bool pIsCaseSensitive, bool pComvertToWideChar, bool pReplaceNonAlphaNum, KString pNameSpaceSymbol);
00645 
00646         #endif
00647 
00648 
00649     protected:
00650         KFbxSdkManager();
00651         virtual ~KFbxSdkManager();
00652 
00663         virtual void Clear(KArrayTemplate<kFbxClassId>* pExcludeList = NULL, bool pDestroyUserNotification=true);
00664 
00665         // this object is destroyed when the manager is destroyed.
00666         KFbxUserNotification* mUserNotification;
00667 
00668         // this object is destroyed when the manager is destroyed.
00669         KFbxMessageEmitter * mMessageEmitter;
00670 
00671         // this object is destroyed when the manager is destroyed.
00672         KFbxIOPluginRegistry* mRegistry;
00673 
00674         mutable KError mError;
00675 
00676         friend class KFbxPose;
00677 
00678         // Class Management
00679         bool ClassInit();
00680         bool ClassRelease();
00681 
00682     public:
00683         int GetFbxClassCount() const;
00684         kFbxClassId GetNextFbxClass(kFbxClassId pClassId /* invalid id: first one */) const;
00685 
00686     private:
00687         KFbxSdkManager_internal* mInternal;
00688 
00689     #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00690 
00691     };
00692 
00693     typedef KFbxSdkManager KFbxSdk;
00694 
00695     typedef KFbxSdkManager* HKFbxSdkManager;
00696 
00697     // Connection management
00698     template < class T > inline int KFbxGetSrcCount(KFbxSdkManager *pObject)                    { T const* FBXTYPE = 0; return pObject ? pObject->GetSrcObjectCount(FBXTYPE) : 0; }
00699     template < class T > inline int KFbxGetSrcCount(KFbxSdkManager *pObject, T const* FBXTYPE)  { return pObject ? pObject->GetSrcObjectCount(FBXTYPE) : 0; }
00700     template < class T > inline T*  KFbxGetSrc(KFbxSdkManager *pObject,int pIndex=0) { T const* FBXTYPE = 0; return pObject ? (T *)pObject->GetSrcObject(FBXTYPE,pIndex) : 0; }
00701     template < class T > inline T*  KFbxFindSrc(KFbxSdkManager *pObject,char const *pName)
00702     {
00703         for (int i=0; i<KFbxGetSrcCount<T>(pObject); i++) {
00704           T* lObject = KFbxGetSrc<T>(pObject,i);
00705             if (strcmp(lObject->GetName(),pName)==0 ){
00706                 return lObject;
00707             }
00708         }
00709         return 0;
00710     }
00711 
00712     // Take index
00713     #define TAKE_NO_ANIMATION   0
00714     #define TAKE_DEFAULT        -1
00715     #define TAKE_INVALID        -3
00716 
00717     // Class Registration management
00718 
00719 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00720 
00721 #endif // FBXFILESDK_KFBXPLUGINS_KFBXSDKMANAGER_H
00722