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 fbxprocessorxref.h
13#ifndef _FBXSDK_UTILS_PROCESSOR_XREF_H_
14#define _FBXSDK_UTILS_PROCESSOR_XREF_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxmap.h>
19#include <fbxsdk/utils/fbxprocessor.h>
20
21#include <fbxsdk/fbxsdk_nsbegin.h>
22
23/** This class contains objects
24 * This class also provides access to global settings and take information.
25 */
26class FBXSDK_DLL FbxProcessorXRefCopy : public FbxProcessor
27{
28 FBXSDK_OBJECT_DECLARE(FbxProcessorXRefCopy, FbxProcessor);
29
30public:
31 class FBXSDK_DLL MissingUrlHandler
32 {
33 public:
34 virtual ~MissingUrlHandler();
35 virtual void MissingUrl(const FbxString& pUrl, const FbxProperty&) = 0;
36 };
37
38 /**
39 * \name Properties
40 */
41 //@{
42 FbxPropertyT<FbxString> OutputDirectory;
43
44 /** As we resolve xref and copy assets, do we update properties to
45 * now use this relative path? Defaults to TRUE.
46 */
47 FbxPropertyT<FbxBool> UpdateProperties;
48
49 /** Default to FALSE -- when set, this informs the processor to track
50 * every properties that were modified during the scene processing.
51 */
52 FbxPropertyT<FbxBool> TrackUpdatedProperties;
53
54 /** Default to TRUE -- when not set, files are only copied if one of
55 * the following conditions is met:
56 *
57 * 1) Target does not exist
58 * 2) Target has a different time
59 * 3) Target has a different size
60 */
61 FbxPropertyT<FbxBool> ForceCopy;
62
63 /** Default to TRUE -- when copying a file, also copy its modification
64 * time. A bit of a requirement if you're not going to use ForceCopy.
65 */
66 FbxPropertyT<FbxBool> CopyFileTimes;
67 //@}
68
69 /** Optional callback; when set, this will be called when an Url cannot be
70 * be copied because the source is not found.
71 * Memory is owned by the client code, and will not be freed by us.
72 */
73 MissingUrlHandler* MissingUrlHandler;
74
75 /** Since FbxProperty is an opaque type, we can't do an efficient operator <
76 * on it, and must keep the data on the object, which can be compared through
77 * pointers, and then we can further compare against the property name.
78 */
79 struct PropertyUpdate
80 {
81 FbxProperty mProperty;
82 FbxString mOriginalValue;
83
84 inline PropertyUpdate() {}
85 inline PropertyUpdate(const FbxProperty& pProp, const FbxString& pVal) :
86 mProperty(pProp), mOriginalValue(pVal) {}
87
88 inline bool operator <(const PropertyUpdate& pOther) const
89 {
90 return strcmp(mProperty.GetName(), pOther.mProperty.GetName()) < 0;
91 }
92 };
93 typedef FbxSet<PropertyUpdate> UpdateSet;
94 typedef FbxMap<FbxObject*, UpdateSet> PropertyUpdateMap;
95
96 /** All properties that were updated, with their original value.
97 * Will always be empty if TrackUpdatedProperties
98 * was not set before calling ProcessCollection/ProcessObject.
99 * NOT cleared before each processing run.
100 */
101 PropertyUpdateMap& GetUpdatedProperties();
102
103 /** If property tracking was enabled, goes through and reverts all changes
104 * to the properties. Does not un-copy the files, naturally.
105 */
106 void RevertPropertyChanges();
107
108 /** This is just a safety net to make sure RevertPropertyChanges is called when
109 * this goes out of scope.
110 */
111 struct FBXSDK_DLL AutoRevertPropertyChanges
112 {
113 AutoRevertPropertyChanges(FbxProcessorXRefCopy* pCopy) : mXRefCopy(pCopy) {}
114 ~AutoRevertPropertyChanges()
115 {
116 if( mXRefCopy )
117 mXRefCopy->RevertPropertyChanges();
118 }
119
120 FbxProcessorXRefCopy* mXRefCopy;
121 };
122
123/*****************************************************************************************************************************
124** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
125*****************************************************************************************************************************/
126#ifndef DOXYGEN_SHOULD_SKIP_THIS
127protected:
128 virtual void Construct(const FbxObject* pFrom);
129 virtual void ConstructProperties(bool pForceSet);
130
131 PropertyUpdateMap mUpdatedProperties;
132
133 // Implements the rules specified for the ForceCopy property.
134 // Also checks the ForceCopy property.
135 bool ShouldCopyFile(const FbxString& pTarget, const FbxString& pSource) const;
136
137 virtual bool internal_ProcessCollectionBegin (FbxCollection* pObject);
138 virtual bool internal_ProcessCollectionEnd (FbxCollection* pObject);
139 virtual bool internal_ProcessObject (FbxObject* pObject);
140 bool ProcessPathProperty(FbxProperty &pProperty);
141 virtual bool ValidPropertyForXRefCopy(FbxObject* pObject, FbxProperty& lProperty) const;
142#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
143};
144
145#include <fbxsdk/fbxsdk_nsend.h>
146
147#endif /* _FBXSDK_UTILS_PROCESSOR_XREF_H_ */
148