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