fbxevent.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxevent.h
  9. #ifndef _FBXSDK_CORE_EVENT_H_
  10. #define _FBXSDK_CORE_EVENT_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/fbxpropertytypes.h>
  13. #include <fbxsdk/fbxsdk_nsbegin.h>
  14. /** FBX SDK event base class.
  15. * An event is something that is emitted by an emitter, with the goal of being filled by the listener that listen to it.
  16. * You can see that like a form that you send to some people. If those people know how to fill the form, they fill it and return
  17. * it to you with the right information in it. FBX object could be used as emitter, since FbxObject is derived from FbxEmitter.
  18. * Meanwhile, plug-in could be used as listener, since FbxPlugin is derived from FbxListener.
  19. * The derived class of FbxEventBase contains a type ID to distinguish different types of events.
  20. * FBX object can emit different types of FBX events at different conditions.
  21. * \par The whole process of event is:
  22. * \li 1. Create an emitter and a listener, then bind them together via the same event handler.
  23. * \li 2. Emitter can emit an event at certain conditions. The event could be handled by event handler.
  24. * \li 3. Once an event is emitted, the listener to this event will receive a signal.
  25. * \li 4. And then the listener could process the event data according to the types of event, by calling event handler.
  26. * \note The event data is process by the callback function of event handler.
  27. * For example, if a certain property of a FBX object is changed, the FBX object(emitter) can emit an event which type is FbxObjectPropertyChanged.
  28. * The plug-in(listener) who are listening to FbxObjectPropertyChanged, will receive a signal and take action to process the event data.
  29. * \nosubgrouping
  30. * \see FbxEvent FbxEventHandler FbxListener FbxEmitter
  31. */
  32. class FBXSDK_DLL FbxEventBase
  33. {
  34. public:
  35. /**
  36. * \name Constructor and Destructor
  37. */
  38. //@{
  39. //!Destructor
  40. virtual ~FbxEventBase();
  41. //@}
  42. /** Retrieve the event type ID
  43. * \return type id
  44. */
  45. virtual int GetTypeId() const = 0;
  46. /** Force events to give us a name
  47. * \return event name
  48. */
  49. virtual const char* GetEventName() const = 0;
  50. protected:
  51. static int GetStaticTypeId(const char*);
  52. };
  53. // Force events to declare a name by using an abstract method, and force them to use
  54. // the proper name by making the call from FbxEvent<> go through the private static
  55. // method.
  56. #define FBXSDK_EVENT_DECLARE(Class) \
  57. public: virtual const char* GetEventName() const { return FbxEventName(); } \
  58. private: static const char* FbxEventName() { return #Class; } \
  59. friend class FbxEvent<Class>; \
  60. //
  61. // Similar to above, but to be used when you've got an event template, and the
  62. // type is something know to FBX
  63. //
  64. #define FBXSDK_EVENT_TYPE_DECLARE(Class, FBXType) \
  65. public: virtual const char* GetEventName() const { return FbxEventName(); } \
  66. private: \
  67. static const char* FbxEventName() { \
  68. static FbxString lEventName = FbxString(#Class) + FbxString("<") + \
  69. FbxGetDataTypeFromEnum(FbxTypeOf(*((const FBXType *)0))).GetName() + ">"; \
  70. \
  71. return lEventName.Buffer(); \
  72. } \
  73. friend class FbxEvent< Class<FBXType> >;
  74. //This is for templates classes that will uses non fbxtypes in their templates
  75. //We force the the creation of an UNIQUE string for each types so that we can
  76. //retrieve the event within multiple DLLs
  77. //to be able to use this, the char EventName[] = "uniqueEventName"; must be declared
  78. //globally.
  79. #define FBXSDK_EVENT_TEMPLATE_HEADER(ClassName, TemplateName)\
  80. template < class TemplateName, const char* T > \
  81. class ClassName: public FbxEvent< ClassName <TemplateName,T> >\
  82. {\
  83. public: virtual const char* GetEventName() const {return FbxEventName();}\
  84. private: static const char* FbxEventName() {\
  85. static FbxString lEventName = (FbxString(#ClassName) +"<"+ FbxString(T) +">");\
  86. return lEventName.Buffer();\
  87. }\
  88. friend class FbxEvent< ClassName<TemplateName, T> >;
  89. //This is the footer macro, to put at the end to close the template class
  90. //created by FBXSDK_EVENT_TEMPLATE_HEADER
  91. #define FBXSDK_EVENT_TEMPLATE_FOOTER()\
  92. };
  93. /** FBX event class, derived from FbxEventBase, and it contains a type ID for event.
  94. * It's a template class. You can derive your own types of even. Such as:
  95. * \code class FbxEventCustom : public FbxEvent<FbxEventCustom> \endcode
  96. * \see FbxObjectPropertyChanged FbxEventReferencedDocument FbxEventPostExport
  97. * \see FbxEventPostImport FbxEventPreExport FbxEventPreImport FbxEventPopulateSystemLibrary
  98. * \nosubgrouping
  99. * \remarks A FBX event is something that is emitted by an emitter, with the goal of being filled by the listener that listen to it.
  100. * An object(emitter) can emit a certain type of event, the plug-in(listener) who are listening to that type of event,
  101. * will receive a signal and take action to process the event data.
  102. * \par The whole process of event is:
  103. * \li 1. Create an emitter and a listener, then bind them together via the same event handler.
  104. * \li 2. Emitter can emit an event at certain conditions. The event could be handled by event handler.
  105. * \li 3. Once an event is emitted, the listener to this event will receive a signal.
  106. * \li 4. And then the listener could process the event data according to the types of event, by calling event handler.
  107. * \note The event data is process by the callback function of event handler.
  108. * \see FbxEventBase FbxEventHandler FbxListener FbxEmitter
  109. */
  110. //---------------------------------------------------
  111. // T : We use the curiously recurring template pattern
  112. // to initialize the typeId of each event type
  113. template<typename T> class FbxEvent : public FbxEventBase
  114. {
  115. public:
  116. //!Destructor
  117. virtual ~FbxEvent(){}
  118. /** Update the type ID of current event with the given type ID.
  119. * \param pTypeId the new type ID.
  120. */
  121. static void ForceTypeId(int pTypeId)
  122. {
  123. // This is to handle specific cases where the type ID must be hard coded
  124. // It is useful for shared event across DLL. We can then guarantee that
  125. // The ID of a certain type will always have the same ID
  126. smTypeId = pTypeId;
  127. }
  128. /** Retrieve the event type ID
  129. * \note This may be called from multiple threads.
  130. * \return type id
  131. */
  132. virtual int GetTypeId() const
  133. {
  134. return GetStaticTypeId();
  135. }
  136. /** Retrieve the event type ID
  137. * \return type id
  138. */
  139. static int GetStaticTypeId()
  140. {
  141. if( !smTypeId )
  142. {
  143. if( !smTypeId )
  144. {
  145. // If this does not compile, you need to add
  146. // FBXSDK_EVENT_DECLARE(YourEventClassName) to your class declaration
  147. smTypeId = FbxEventBase::GetStaticTypeId(T::FbxEventName());
  148. }
  149. }
  150. return smTypeId;
  151. }
  152. private:
  153. //! The type ID of event
  154. static int smTypeId;
  155. };
  156. // Static members implementation
  157. template<typename T> int FbxEvent<T>::smTypeId = 0;
  158. #include <fbxsdk/fbxsdk_nsend.h>
  159. #endif /* _FBXSDK_CORE_EVENT_H_ */