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 fbxconnectionpoint.h
13#ifndef _FBXSDK_CORE_CONNECTION_POINT_H_
14#define _FBXSDK_CORE_CONNECTION_POINT_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxarray.h>
19
20#include <fbxsdk/fbxsdk_nsbegin.h>
21
22class FBXSDK_DLL FbxConnection
23{
24public:
25 enum EType
26 {
27 eNone = 0,
28 // System or user
29 eSystem = 1 << 0,
30 eUser = 1 << 1,
31 eSystemOrUser = eUser | eSystem,
32 // Type of Link
33 eReference = 1 << 2,
34 eContains = 1 << 3,
35 eData = 1 << 4,
36 eLinkType = eReference | eContains | eData,
37 eDefault = eUser | eReference,
38 eUnidirectional = 1 << 7
39 };
40};
41
42class FbxConnectionPointFilter;
43
44class FBXSDK_DLL FbxConnectionPoint
45{
46public:
47 enum EDirection
48 {
49 eDirSrc = 1 << 0, // Contains sources
50 eDirDst = 1 << 1, // Contains destinations
51 eDirUni = 1 << 2, // Connection is not 2 ways
52 eDirBoth = eDirSrc | eDirDst,
53 eDirMask = eDirSrc | eDirDst | eDirUni
54 };
55
56 enum EType
57 {
58 eStandard = 0,
59 eSubConnection = 1 << 3, // Connect is a sub Connect of another
60 eTypeMask = eSubConnection
61 };
62
63 enum EAttribute
64 {
65 eDefault = 0,
66 eCache = 1 << 4,
67 eAttributeMask = eCache
68 };
69
70 enum EAllocFlag
71 {
72 eNotAllocated = 0,
73 eAllocated = 1 << 5,
74 eAllocFlagMask = eAllocated
75 };
76
77 enum ECleanedFlag
78 {
79 eNotCleaned = 0,
80 eCleaned = 1 << 6,
81 eCleanedFlagMask = eCleaned
82 };
83
84 enum EEvent
85 {
86 eSrcConnectRequest,
87 eDstConnectRequest,
88 eSrcConnect,
89 eDstConnect,
90 eSrcConnected,
91 eDstConnected,
92 eSrcDisconnect,
93 eDstDisconnect,
94 eSrcDisconnected,
95 eDstDisconnected,
96 eSrcReplaceBegin,
97 eSrcReplaceEnd,
98 eDstReplaceBegin,
99 eDstReplaceEnd,
100 eSrcReorder,
101 eSrcReordered
102 };
103
104 // Constructor/Destructor
105 FbxConnectionPoint(void* pData=0);
106 virtual ~FbxConnectionPoint();
107
108 void SetFilter(FbxConnectionPointFilter* pConnectFilter, EType pType=eStandard);
109 void InternalClear();
110
111 //! Clear the ConnectList without any regards to what is connected
112 void WipeConnectionList();
113 void Destroy();
114 void SubConnectRemoveAll();
115
116 inline FbxConnectionPoint* GetSubOwnerConnect(){ return GetConnectType() == eSubConnection ? mOwner : NULL; }
117 inline FbxConnectionPointFilter* GetFilter(){ return mFilter; }
118
119 virtual bool IsInReplace(FbxConnectionPoint* p1, FbxConnectionPoint* p2);
120
121 inline void SetConnectType(EType pType){ mFlags = (mFlags & ~eTypeMask) | pType; }
122 inline EType GetConnectType(){ return EType(mFlags & eTypeMask); }
123 inline void SetDirection(int pDirections){ mFlags = (mFlags & ~eDirMask) | pDirections; }
124 inline EDirection GetDirection(){ return EDirection(mFlags & eDirMask); }
125 inline void SetAttribute(int pAttributes){ mFlags = (mFlags & ~eAttributeMask) | pAttributes; }
126 inline EAttribute GetAttribute(){ return EAttribute(mFlags & eAttributeMask); }
127 inline void SetAllocatedFlag(bool pBool){ mFlags = ( pBool ) ? mFlags | eAllocated : mFlags & ~eAllocFlagMask; }
128 inline bool GetAllocatedFlag(){ return ( mFlags & eAllocFlagMask ) ? true : false; }
129 inline void SetCleanedFlag(bool pBool){ mFlags = ( pBool ) ? mFlags | eCleaned : mFlags & ~eCleanedFlagMask; }
130 inline bool GetCleanedFlag(){ return ( mFlags & eCleanedFlagMask ) ? true : false; }
131
132 bool IsValidSrc(FbxConnectionPoint* pConnect);
133 bool IsValidDst(FbxConnectionPoint* pConnect);
134 bool IsValidSrcConnection(FbxConnectionPoint* pConnect, FbxConnection::EType pConnectionType);
135 bool IsValidDstConnection(FbxConnectionPoint* pConnect, FbxConnection::EType pConnectionType);
136 bool RequestValidSrcConnection(FbxConnectionPoint* pConnect, FbxConnection::EType pConnectionType );
137 bool RequestValidDstConnection(FbxConnectionPoint* pConnect, FbxConnection::EType pConnectionType );
138
139 bool ConnectSrc(FbxConnectionPoint* pSrc,FbxConnection::EType pConnectionType=FbxConnection::eNone);
140 bool ConnectDst(FbxConnectionPoint* pDst,FbxConnection::EType pConnectionType=FbxConnection::eNone);
141 bool ConnectSrcAt(int pDst_SrcIndex, FbxConnectionPoint* pSrc, FbxConnection::EType pConnectionType=FbxConnection::eNone);
142 bool ConnectDstAt(int pSrc_DstIndex, FbxConnectionPoint* pDst, FbxConnection::EType pConnectionType=FbxConnection::eNone);
143 static bool ConnectConnect(FbxConnectionPoint* pSrc,FbxConnectionPoint* pDst,FbxConnection::EType pConnectionType);
144 static bool ConnectAt(FbxConnectionPoint* pSrc, int pSrc_DstIndex, FbxConnectionPoint* pDst, int pDst_SrcIndex, FbxConnection::EType pConnectionType);
145
146 bool DisconnectDst(FbxConnectionPoint* pSrc);
147 bool DisconnectSrc(FbxConnectionPoint* pSrc);
148 void DisconnectAllSrc();
149 void DisconnectAllDst();
150 static bool DisconnectConnect(FbxConnectionPoint* pSrc,FbxConnectionPoint* pDst);
151 bool DisconnectDstAt(int pIndex);
152 bool DisconnectSrcAt(int pIndex);
153
154 bool ReplaceInDst(FbxConnectionPoint* pDstOld, FbxConnectionPoint* pDstNew, int pIndexInNew);
155 bool ReplaceInSrc(FbxConnectionPoint* pSrcOld, FbxConnectionPoint* pSrcNew, int pIndexInNew);
156 bool ReplaceDstAt(int pIndex, FbxConnectionPoint* pDst);
157 bool ReplaceSrcAt(int pIndex, FbxConnectionPoint* pSrc);
158 bool SwapSrc(int pIndexA, int pIndexB);
159
160 /** Change the position of a source Connect.
161 * \param pIndex Position of the Connect to move.
162 * \param pAtIndex Position where to move the Connect.
163 * \return \c True if the Connect was moved.
164 * \remarks After the move, the Connect will be precisely at position pAtIndex.
165 */
166 bool MoveSrcAt(int pIndex, int pAtIndex);
167
168 /** Change the position of a source Connect.
169 * \param pSrc Connect to move.
170 * \param pAtSrc Connect at which position to move.
171 * \return \c True if the Connect was moved.
172 * \remarks After the move, the Connect will be precisely at the position where pAtSrc was before the move.
173 */
174 bool MoveSrcAt(FbxConnectionPoint* pSrc, FbxConnectionPoint* pAtSrc);
175
176 // Access services
177 bool IsConnectedSrc(FbxConnectionPoint*);
178 bool IsConnectedDst(FbxConnectionPoint*);
179 inline bool IsConnected(FbxConnectionPoint* pConnect) { return IsConnectedSrc(pConnect) || IsConnectedDst(pConnect); }
180
181 inline int GetSrcCount() const { return mConnectionList.GetSrcCount(); }
182 inline FbxConnectionPoint* GetSrc(int pIndex) const { return mConnectionList.GetSrc(pIndex);}
183 inline FbxConnection::EType GetSrcType(int pIndex) const { return mConnectionList.GetSrcType(pIndex);}
184 inline int GetDstCount() const { return mConnectionList.GetDstCount(); }
185 inline FbxConnectionPoint* GetDst(int pIndex) const { return mConnectionList.GetDst(pIndex);}
186 inline FbxConnection::EType GetDstType(int pIndex) const { return mConnectionList.GetDstType(pIndex);}
187
188 inline int FindSrc(FbxConnectionPoint* pConnect){ return mConnectionList.FindSrc(pConnect); }
189 inline int FindDst(FbxConnectionPoint* pConnect){ return mConnectionList.FindDst(pConnect); }
190
191 // Filtered versions
192 inline int GetSrcCount(FbxConnectionPointFilter* pFilter){ return (pFilter) ? SubConnectGetOrCreate(pFilter)->GetSrcCount() : GetSrcCount(); }
193 inline FbxConnectionPoint* GetSrc(int pIndex,FbxConnectionPointFilter* pFilter){ return (pFilter) ? SubConnectGetOrCreate(pFilter)->GetSrc(pIndex) : GetSrc(pIndex); }
194 inline FbxConnection::EType GetSrcType(int pIndex,FbxConnectionPointFilter* pFilter){ return (pFilter) ? SubConnectGetOrCreate(pFilter)->GetSrcType(pIndex) : GetSrcType(pIndex); }
195 inline int GetDstCount(FbxConnectionPointFilter* pFilter){ return (pFilter) ? SubConnectGetOrCreate(pFilter)->GetDstCount() : GetDstCount(); }
196 inline FbxConnectionPoint* GetDst(int pIndex,FbxConnectionPointFilter* pFilter){ return (pFilter) ? SubConnectGetOrCreate(pFilter)->GetDst(pIndex): GetDst(pIndex); }
197 inline FbxConnection::EType GetDstType(int pIndex,FbxConnectionPointFilter* pFilter){ return (pFilter) ? SubConnectGetOrCreate(pFilter)->GetDstType(pIndex) : GetDstType(pIndex); }
198
199 void* GetData(){ return mData; }
200
201/*****************************************************************************************************************************
202** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
203*****************************************************************************************************************************/
204#ifndef DOXYGEN_SHOULD_SKIP_THIS
205protected:
206 class ConnectionList
207 {
208 public:
209 ConnectionList();
210 ~ConnectionList();
211
212 void Clear();
213
214 void InsertSrcAt(int pIndex, FbxConnectionPoint* pConnect, FbxConnection::EType pType);
215 void AddSrc(FbxConnectionPoint* pConnect, FbxConnection::EType pType);
216 void RemoveSrcAt(int pIndex);
217 int FindSrc(FbxConnectionPoint* pConnect) const;
218 int GetSrcCount() const;
219 FbxConnectionPoint* GetSrc(int pIndex) const;
220 FbxConnection::EType GetSrcType(int pIndex) const;
221
222 void InsertDstAt(int pIndex, FbxConnectionPoint* pConnect, FbxConnection::EType pType);
223 void AddDst(FbxConnectionPoint* pConnect, FbxConnection::EType pType);
224 void RemoveDstAt(int pIndex);
225 int FindDst(FbxConnectionPoint* pConnect) const;
226 int GetDstCount() const;
227 FbxConnectionPoint* GetDst(int pIndex) const;
228 FbxConnection::EType GetDstType(int pIndex) const;
229
230 protected:
231 struct Connection {
232 Connection(FbxConnectionPoint* pPoint, FbxConnection::EType pType) : mPoint(pPoint), mType(pType){}
233 FbxConnectionPoint* mPoint; FbxConnection::EType mType;
234 };
235 FbxArray<Connection> mSrcList;
236 FbxArray<Connection> mDstList;
237 };
238
239 void SubConnectAdd(FbxConnectionPoint* pConnect);
240 void SubConnectRemove(FbxConnectionPoint* pConnect);
241 FbxConnectionPoint* SubConnectFind(FbxConnectionPointFilter* pFilter);
242 FbxConnectionPoint* SubConnectGetOrCreate(FbxConnectionPointFilter* pFilter);
243 void SubConnectFill(FbxConnectionPoint* pConnect);
244
245 virtual bool ConnectNotify(EEvent pAction, FbxConnectionPoint* pThis, int pIndex, FbxConnectionPoint* pConnect=NULL, FbxConnection::EType pConnectionType=FbxConnection::eNone, FbxConnectionPoint* pNewConnect=NULL);
246 virtual void ConnectCleanUp(FbxConnectionPoint* pThis);
247
248 int FindSrcIndexFromOwnerConnectIndex(FbxConnectionPoint* pOwner, int pOwnerIndex);
249 int FindDstIndexFromOwnerConnectIndex(FbxConnectionPoint* pOwner, int pOwnerIndex);
250
251 bool InternalMoveSrcBefore(int pIndex, int pBeforeIndex);
252
253private:
254 inline void InsertSrcAt(int pIndex, FbxConnectionPoint* pConnect, FbxConnection::EType pConnectionType){ mConnectionList.InsertSrcAt(pIndex, pConnect, pConnectionType); }
255 inline void InsertDstAt(int pIndex, FbxConnectionPoint* pConnect, FbxConnection::EType pConnectionType){ mConnectionList.InsertDstAt(pIndex, pConnect, pConnectionType); }
256 inline void RemoveSrcAt(int pIndex){ mConnectionList.RemoveSrcAt(pIndex); }
257 inline void RemoveDstAt(int pIndex){ mConnectionList.RemoveDstAt(pIndex); }
258
259 static bool InternalConnectBefore(FbxConnectionPoint* pSrc, FbxConnectionPoint* pSrc_BeforeDst, FbxConnectionPoint* pDst, FbxConnectionPoint* pDst_BeforeSrc, FbxConnection::EType pConnectionType);
260 static bool UserConnectBefore(FbxConnectionPoint* pSrc, FbxConnectionPoint* pSrc_BeforeDst, FbxConnectionPoint* pDst, FbxConnectionPoint* pDst_BeforeSrc, FbxConnection::EType pConnectionType);
261 static bool EmitReplaceNotify(FbxConnectionPoint* pDstOwner, FbxConnectionPoint* pSrcOwner, FbxConnectionPoint* pDst, FbxConnectionPoint* pSrc, EEvent pConnectAction, FbxConnectionPoint* pNew);
262
263 virtual bool SetOwnerConnect(FbxConnectionPoint* pConnect);
264 inline FbxConnectionPoint* GetOwnerConnect(){ return mOwner; }
265 bool ConnectOwnedConnect(FbxConnectionPoint* pConnect);
266 bool DisconnectOwnedConnect(FbxConnectionPoint* pConnect);
267
268 void* mData;
269 int mFlags;
270 FbxConnectionPoint* mOwner;
271 ConnectionList mConnectionList;
272 FbxArray<FbxConnectionPoint*> mSubConnectList;
273 FbxArray<FbxConnectionPoint*> mSubConnectCreatedList;
274 FbxConnectionPointFilter* mFilter;
275#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
276};
277
278/** Class to manage Connect Filter */
279class FBXSDK_DLL FbxConnectionPointFilter
280{
281public:
282 virtual ~FbxConnectionPointFilter() {};
283
284 //! Return reference ConnectionPoint filter.
285 virtual FbxConnectionPointFilter* Ref();
286
287 //! Cancel reference
288 virtual void Unref();
289
290 //! Get unique filter ID
291 virtual FbxInt GetUniqueId() const { return 0; }
292
293 /** Judge if the given Connection Point is valid
294 * \param pConnect The given Connection Point.
295 * \return \c True if valid, \c false if not valid. */
296 virtual bool IsValid(FbxConnectionPoint* pConnect) const;
297
298 /** Judge if the given Connection Point is a valid connection
299 * \param pConnect The given Connection Point.
300 * \param pType Connection type.
301 * \return \c True if valid, \c false if not valid. */
302 virtual bool IsValidConnection(FbxConnectionPoint* pConnect, FbxConnection::EType pType) const;
303
304 /** Judge if it is equal with the given ConnectionPoint filter.
305 * \param pConnectFilter The given ConnectionPoint filter.
306 * \return \c True if equal, \c false if unequal. */
307 virtual bool IsEqual(FbxConnectionPointFilter* pConnectFilter) const;
308};
309
310#include <fbxsdk/fbxsdk_nsend.h>
311
312#endif /* _FBXSDK_CORE_CONNECTION_POINT_H_ */
313