fbxquery.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 fbxquery.h
  9. #ifndef _FBXSDK_CORE_QUERY_H_
  10. #define _FBXSDK_CORE_QUERY_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/fbxclassid.h>
  13. #include <fbxsdk/core/fbxconnectionpoint.h>
  14. #include <fbxsdk/core/base/fbxmap.h>
  15. #include <fbxsdk/core/base/fbxmemorypool.h>
  16. #include <fbxsdk/fbxsdk_nsbegin.h>
  17. #define FBXSDK_QUERY_UNIQUE_ID 0x14000000
  18. class FbxProperty;
  19. /** Base class to manage query. A query contains a filter and reference ID, which will be used to search and retrieve objects.
  20. * The derived query classes are used to create FbxCriteria.
  21. * \nosubgrouping */
  22. class FBXSDK_DLL FbxQuery
  23. {
  24. public:
  25. //! Get unique filter Id
  26. virtual FbxInt GetUniqueId() const { return FBXSDK_QUERY_UNIQUE_ID; }
  27. /** Judge if the given property is valid.
  28. * \param pProperty The given property.
  29. * \return \c true always, not implemented. */
  30. virtual bool IsValid(const FbxProperty& pProperty) const;
  31. /** This compares whether two FbxQuery are the same, NOT whether the query matches or not. It's strictly the equivalent of an operator==, but virtual.
  32. * \param pOtherQuery The given FbxQuery */
  33. virtual bool IsEqual(FbxQuery* pOtherQuery) const;
  34. //! Add one to ref count.
  35. void Ref();
  36. //! Minus one to ref count, if ref count is zero, delete this query object.
  37. void Unref();
  38. /*****************************************************************************************************************************
  39. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  40. *****************************************************************************************************************************/
  41. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  42. protected:
  43. FbxQuery();
  44. virtual ~FbxQuery();
  45. private:
  46. class InternalFilter : public FbxConnectionPointFilter
  47. {
  48. public:
  49. InternalFilter(FbxQuery* pQuery);
  50. ~InternalFilter();
  51. public:
  52. FbxConnectionPointFilter* Ref();
  53. void Unref();
  54. FbxInt GetUniqueId() const { return mQuery->GetUniqueId(); }
  55. bool IsValid(FbxConnectionPoint* pConnect) const;
  56. bool IsEqual(FbxConnectionPointFilter* pConnectFilter) const;
  57. FbxQuery* mQuery;
  58. };
  59. InternalFilter mFilter;
  60. int mRefCount;
  61. FBXSDK_FRIEND_NEW();
  62. friend class FbxProperty;
  63. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  64. };
  65. /** Defines a filtering criteria for a query of objects, connections and properties, so that only those satisfying the criteria are
  66. * affected by the query. Some examples of kinds of criteria are object type, connection type, or property. Criteria can be combined
  67. * using logical operators such as "and" and "or".
  68. * \note
  69. * Objects are basic elements in FBX. Each of them has a hierarchy type and some properties. Objects and properties can be connected
  70. * through a connection to represent a relationship between them. (e.g. child-parent, container membership, reference, etc.,). In a
  71. * query, you could select object or properties based on these criteria.
  72. * Here are some examples:
  73. * \code
  74. * FbxObject* lObject = FbxObject::Create(lManager, "Object");
  75. * int lSrcLightCount = lObject->RootProperty.GetSrcObjectCount(FbxCriteria::ObjectType(FbxLight::ClassId));
  76. * int lSrcDeformerCount = lObject->RootProperty.GetSrcObjectCount(FbxCriteria::ObjectTypeStrict(FbxDeformer::ClassId));
  77. * int lSrcPropertyCount = lObject->RootProperty.GetSrcCount(FbxCriteria::IsProperty());
  78. * \endcode
  79. * \see FbxQuery
  80. * \see FbxProperty::GetSrcObjectCount(const FbxCriteria&) const
  81. * \see FbxCollection::GetMemberCount(const FbxCriteria&) const
  82. * \nosubgrouping */
  83. class FBXSDK_DLL FbxCriteria
  84. {
  85. public:
  86. /** Creates a new query criteria that only selects objects which have a specific
  87. * class ID or derive from a class with a specific class ID.
  88. * \param pClassId The base type class ID */
  89. static FbxCriteria ObjectType(const FbxClassId& pClassId);
  90. /** Creates a new query criteria that only selects objects which have a specific class ID.
  91. * \param pClassId The type class ID */
  92. static FbxCriteria ObjectTypeStrict(const FbxClassId& pClassId);
  93. //! Creates a new query criteria that only selects properties.
  94. static FbxCriteria IsProperty();
  95. /** Gets a logical conjunction (and) criteria from this and the specified criteria.
  96. * \param pCriteria The specified criteria */
  97. FbxCriteria operator&&(const FbxCriteria& pCriteria) const;
  98. /** Gets a logical disjunction (or) criteria from this and the specified criteria.
  99. * \param pCriteria The specified criteria */
  100. FbxCriteria operator||(const FbxCriteria& pCriteria) const;
  101. //! Returns a negated version of the criteria.
  102. FbxCriteria operator!() const;
  103. /** Retrieves the query.
  104. * \return The query of this criteria */
  105. FbxQuery* GetQuery() const;
  106. /*****************************************************************************************************************************
  107. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  108. *****************************************************************************************************************************/
  109. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  110. FbxCriteria();
  111. FbxCriteria(const FbxCriteria& pCriteria);
  112. FbxCriteria(FbxQuery* pQuery);
  113. ~FbxCriteria();
  114. FbxCriteria& operator=(const FbxCriteria& pCriteria);
  115. private:
  116. FbxQuery* mQuery;
  117. static void FreeGlobalCache();
  118. FBXSDK_FRIEND_NEW();
  119. friend class FbxManager;
  120. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  121. };
  122. //! Functor to compare FbxCriteria
  123. struct FbxCriteriaCompare
  124. {
  125. inline int operator()(const FbxCriteria& pKeyA, const FbxCriteria& pKeyB) const
  126. {
  127. const FbxQuery* lKeyA = pKeyA.GetQuery();
  128. const FbxQuery* lKeyB = pKeyB.GetQuery();
  129. return lKeyA < lKeyB ? -1 : (lKeyA > lKeyB ? 1 : 0);
  130. }
  131. };
  132. /*****************************************************************************************************************************
  133. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  134. *****************************************************************************************************************************/
  135. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  136. class FBXSDK_DLL FbxQueryOperator : public FbxQuery
  137. {
  138. public:
  139. FBXSDK_FRIEND_NEW();
  140. enum EType {eAND, eOR};
  141. static FbxQueryOperator* Create(FbxQuery* pA, EType pOperator, FbxQuery* pB);
  142. virtual FbxInt GetUniqueId() const { return FBXSDK_QUERY_UNIQUE_ID+1; }
  143. virtual bool IsValid(const FbxProperty& pProperty) const;
  144. virtual bool IsEqual(FbxQuery* pOtherQuery) const;
  145. protected:
  146. FbxQueryOperator(FbxQuery* pA, EType pOperator, FbxQuery* pB);
  147. virtual ~FbxQueryOperator();
  148. private:
  149. FbxQuery *mA, *mB;
  150. EType mOperator;
  151. };
  152. class FBXSDK_DLL FbxQueryOperatorUnary : public FbxQuery
  153. {
  154. public:
  155. FBXSDK_FRIEND_NEW();
  156. static FbxQueryOperatorUnary* Create(FbxQuery* pA);
  157. virtual FbxInt GetUniqueId() const{ return FBXSDK_QUERY_UNIQUE_ID+2; }
  158. virtual bool IsValid(const FbxProperty& pProperty) const;
  159. virtual bool IsEqual(FbxQuery* pOtherQuery) const;
  160. protected:
  161. FbxQueryOperatorUnary(FbxQuery* pA);
  162. virtual ~FbxQueryOperatorUnary();
  163. private:
  164. FbxQuery* mA;
  165. };
  166. class FBXSDK_DLL FbxQueryClassId : public FbxQuery
  167. {
  168. public:
  169. FBXSDK_FRIEND_NEW();
  170. static FbxQueryClassId* Create(const FbxClassId& pClassId);
  171. virtual FbxInt GetUniqueId() const{ return FBXSDK_QUERY_UNIQUE_ID+3; }
  172. virtual bool IsValid(const FbxProperty& pProperty) const;
  173. virtual bool IsEqual(FbxQuery* pOtherQuery) const;
  174. protected:
  175. FbxQueryClassId(const FbxClassId& pClassId);
  176. private:
  177. FbxClassId mClassId;
  178. };
  179. class FBXSDK_DLL FbxQueryIsA : public FbxQuery
  180. {
  181. public:
  182. FBXSDK_FRIEND_NEW();
  183. static FbxQueryIsA* Create(const FbxClassId& pClassId);
  184. virtual FbxInt GetUniqueId() const{ return FBXSDK_QUERY_UNIQUE_ID+4; }
  185. virtual bool IsValid(const FbxProperty& pProperty) const;
  186. virtual bool IsEqual(FbxQuery* pOtherQuery) const;
  187. protected:
  188. FbxQueryIsA(const FbxClassId& pClassId);
  189. private:
  190. FbxClassId mClassId;
  191. };
  192. class FBXSDK_DLL FbxQueryIsProperty : public FbxQuery
  193. {
  194. public:
  195. FBXSDK_FRIEND_NEW();
  196. static FbxQueryIsProperty* Create();
  197. virtual FbxInt GetUniqueId() const{ return FBXSDK_QUERY_UNIQUE_ID+5; }
  198. virtual bool IsValid(const FbxProperty& pProperty) const;
  199. virtual bool IsEqual(FbxQuery* pOtherQuery) const;
  200. protected:
  201. FbxQueryIsProperty();
  202. };
  203. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  204. #include <fbxsdk/fbxsdk_nsend.h>
  205. #endif /* _FBXSDK_CORE_QUERY_H_ */