1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #include "pxr/usd/usdContrived/derived.h"
25 #include "pxr/usd/usd/schemaRegistry.h"
26 #include "pxr/usd/usd/typed.h"
27 
28 #include "pxr/usd/sdf/types.h"
29 #include "pxr/usd/sdf/assetPath.h"
30 
31 namespace foo { namespace bar { namespace baz {
32 
33 // Register the schema with the TfType system.
TF_REGISTRY_FUNCTION(TfType)34 TF_REGISTRY_FUNCTION(TfType)
35 {
36     TfType::Define<UsdContrivedDerived,
37         TfType::Bases< UsdContrivedBase > >();
38 
39     // Register the usd prim typename as an alias under UsdSchemaBase. This
40     // enables one to call
41     // TfType::Find<UsdSchemaBase>().FindDerivedByName("Derived")
42     // to find TfType<UsdContrivedDerived>, which is how IsA queries are
43     // answered.
44     TfType::AddAlias<UsdSchemaBase, UsdContrivedDerived>("Derived");
45 }
46 
47 /* virtual */
~UsdContrivedDerived()48 UsdContrivedDerived::~UsdContrivedDerived()
49 {
50 }
51 
52 /* static */
53 UsdContrivedDerived
Get(const UsdStagePtr & stage,const SdfPath & path)54 UsdContrivedDerived::Get(const UsdStagePtr &stage, const SdfPath &path)
55 {
56     if (!stage) {
57         TF_CODING_ERROR("Invalid stage");
58         return UsdContrivedDerived();
59     }
60     return UsdContrivedDerived(stage->GetPrimAtPath(path));
61 }
62 
63 /* static */
64 UsdContrivedDerived
Define(const UsdStagePtr & stage,const SdfPath & path)65 UsdContrivedDerived::Define(
66     const UsdStagePtr &stage, const SdfPath &path)
67 {
68     static TfToken usdPrimTypeName("Derived");
69     if (!stage) {
70         TF_CODING_ERROR("Invalid stage");
71         return UsdContrivedDerived();
72     }
73     return UsdContrivedDerived(
74         stage->DefinePrim(path, usdPrimTypeName));
75 }
76 
77 /* virtual */
_GetSchemaKind() const78 UsdSchemaKind UsdContrivedDerived::_GetSchemaKind() const
79 {
80     return UsdContrivedDerived::schemaKind;
81 }
82 
83 /* static */
84 const TfType &
_GetStaticTfType()85 UsdContrivedDerived::_GetStaticTfType()
86 {
87     static TfType tfType = TfType::Find<UsdContrivedDerived>();
88     return tfType;
89 }
90 
91 /* static */
92 bool
_IsTypedSchema()93 UsdContrivedDerived::_IsTypedSchema()
94 {
95     static bool isTyped = _GetStaticTfType().IsA<UsdTyped>();
96     return isTyped;
97 }
98 
99 /* virtual */
100 const TfType &
_GetTfType() const101 UsdContrivedDerived::_GetTfType() const
102 {
103     return _GetStaticTfType();
104 }
105 
106 UsdAttribute
GetPivotPositionAttr() const107 UsdContrivedDerived::GetPivotPositionAttr() const
108 {
109     return GetPrim().GetAttribute(UsdContrivedTokens->pivotPosition);
110 }
111 
112 UsdAttribute
CreatePivotPositionAttr(VtValue const & defaultValue,bool writeSparsely) const113 UsdContrivedDerived::CreatePivotPositionAttr(VtValue const &defaultValue, bool writeSparsely) const
114 {
115     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->pivotPosition,
116                        SdfValueTypeNames->Float3,
117                        /* custom = */ false,
118                        SdfVariabilityVarying,
119                        defaultValue,
120                        writeSparsely);
121 }
122 
123 UsdAttribute
GetMyVecfArrayAttr() const124 UsdContrivedDerived::GetMyVecfArrayAttr() const
125 {
126     return GetPrim().GetAttribute(UsdContrivedTokens->myVecfArray);
127 }
128 
129 UsdAttribute
CreateMyVecfArrayAttr(VtValue const & defaultValue,bool writeSparsely) const130 UsdContrivedDerived::CreateMyVecfArrayAttr(VtValue const &defaultValue, bool writeSparsely) const
131 {
132     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->myVecfArray,
133                        SdfValueTypeNames->Float3Array,
134                        /* custom = */ false,
135                        SdfVariabilityVarying,
136                        defaultValue,
137                        writeSparsely);
138 }
139 
140 UsdAttribute
GetHoleIndicesAttr() const141 UsdContrivedDerived::GetHoleIndicesAttr() const
142 {
143     return GetPrim().GetAttribute(UsdContrivedTokens->holeIndices);
144 }
145 
146 UsdAttribute
CreateHoleIndicesAttr(VtValue const & defaultValue,bool writeSparsely) const147 UsdContrivedDerived::CreateHoleIndicesAttr(VtValue const &defaultValue, bool writeSparsely) const
148 {
149     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->holeIndices,
150                        SdfValueTypeNames->IntArray,
151                        /* custom = */ false,
152                        SdfVariabilityVarying,
153                        defaultValue,
154                        writeSparsely);
155 }
156 
157 UsdAttribute
GetCornerIndicesAttr() const158 UsdContrivedDerived::GetCornerIndicesAttr() const
159 {
160     return GetPrim().GetAttribute(UsdContrivedTokens->cornerIndices);
161 }
162 
163 UsdAttribute
CreateCornerIndicesAttr(VtValue const & defaultValue,bool writeSparsely) const164 UsdContrivedDerived::CreateCornerIndicesAttr(VtValue const &defaultValue, bool writeSparsely) const
165 {
166     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->cornerIndices,
167                        SdfValueTypeNames->IntArray,
168                        /* custom = */ false,
169                        SdfVariabilityVarying,
170                        defaultValue,
171                        writeSparsely);
172 }
173 
174 UsdAttribute
GetCornerSharpnessesAttr() const175 UsdContrivedDerived::GetCornerSharpnessesAttr() const
176 {
177     return GetPrim().GetAttribute(UsdContrivedTokens->cornerSharpnesses);
178 }
179 
180 UsdAttribute
CreateCornerSharpnessesAttr(VtValue const & defaultValue,bool writeSparsely) const181 UsdContrivedDerived::CreateCornerSharpnessesAttr(VtValue const &defaultValue, bool writeSparsely) const
182 {
183     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->cornerSharpnesses,
184                        SdfValueTypeNames->FloatArray,
185                        /* custom = */ false,
186                        SdfVariabilityVarying,
187                        defaultValue,
188                        writeSparsely);
189 }
190 
191 UsdAttribute
GetCreaseLengthsAttr() const192 UsdContrivedDerived::GetCreaseLengthsAttr() const
193 {
194     return GetPrim().GetAttribute(UsdContrivedTokens->creaseLengths);
195 }
196 
197 UsdAttribute
CreateCreaseLengthsAttr(VtValue const & defaultValue,bool writeSparsely) const198 UsdContrivedDerived::CreateCreaseLengthsAttr(VtValue const &defaultValue, bool writeSparsely) const
199 {
200     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->creaseLengths,
201                        SdfValueTypeNames->IntArray,
202                        /* custom = */ false,
203                        SdfVariabilityVarying,
204                        defaultValue,
205                        writeSparsely);
206 }
207 
208 UsdAttribute
GetTransformAttr() const209 UsdContrivedDerived::GetTransformAttr() const
210 {
211     return GetPrim().GetAttribute(UsdContrivedTokens->transform);
212 }
213 
214 UsdAttribute
CreateTransformAttr(VtValue const & defaultValue,bool writeSparsely) const215 UsdContrivedDerived::CreateTransformAttr(VtValue const &defaultValue, bool writeSparsely) const
216 {
217     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->transform,
218                        SdfValueTypeNames->Matrix4d,
219                        /* custom = */ false,
220                        SdfVariabilityVarying,
221                        defaultValue,
222                        writeSparsely);
223 }
224 
225 UsdAttribute
GetTestingAssetAttr() const226 UsdContrivedDerived::GetTestingAssetAttr() const
227 {
228     return GetPrim().GetAttribute(UsdContrivedTokens->testingAsset);
229 }
230 
231 UsdAttribute
CreateTestingAssetAttr(VtValue const & defaultValue,bool writeSparsely) const232 UsdContrivedDerived::CreateTestingAssetAttr(VtValue const &defaultValue, bool writeSparsely) const
233 {
234     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->testingAsset,
235                        SdfValueTypeNames->AssetArray,
236                        /* custom = */ false,
237                        SdfVariabilityVarying,
238                        defaultValue,
239                        writeSparsely);
240 }
241 
242 UsdAttribute
GetNamespacedPropertyAttr() const243 UsdContrivedDerived::GetNamespacedPropertyAttr() const
244 {
245     return GetPrim().GetAttribute(UsdContrivedTokens->namespacedProperty);
246 }
247 
248 UsdAttribute
CreateNamespacedPropertyAttr(VtValue const & defaultValue,bool writeSparsely) const249 UsdContrivedDerived::CreateNamespacedPropertyAttr(VtValue const &defaultValue, bool writeSparsely) const
250 {
251     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->namespacedProperty,
252                        SdfValueTypeNames->Float,
253                        /* custom = */ false,
254                        SdfVariabilityVarying,
255                        defaultValue,
256                        writeSparsely);
257 }
258 
259 UsdAttribute
GetJustDefaultAttr() const260 UsdContrivedDerived::GetJustDefaultAttr() const
261 {
262     return GetPrim().GetAttribute(UsdContrivedTokens->justDefault);
263 }
264 
265 UsdAttribute
CreateJustDefaultAttr(VtValue const & defaultValue,bool writeSparsely) const266 UsdContrivedDerived::CreateJustDefaultAttr(VtValue const &defaultValue, bool writeSparsely) const
267 {
268     return UsdSchemaBase::_CreateAttr(UsdContrivedTokens->justDefault,
269                        SdfValueTypeNames->Token,
270                        /* custom = */ false,
271                        SdfVariabilityVarying,
272                        defaultValue,
273                        writeSparsely);
274 }
275 
276 UsdRelationship
GetBindingRel() const277 UsdContrivedDerived::GetBindingRel() const
278 {
279     return GetPrim().GetRelationship(UsdContrivedTokens->binding);
280 }
281 
282 UsdRelationship
CreateBindingRel() const283 UsdContrivedDerived::CreateBindingRel() const
284 {
285     return GetPrim().CreateRelationship(UsdContrivedTokens->binding,
286                        /* custom = */ false);
287 }
288 
289 namespace {
290 static inline TfTokenVector
_ConcatenateAttributeNames(const TfTokenVector & left,const TfTokenVector & right)291 _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right)
292 {
293     TfTokenVector result;
294     result.reserve(left.size() + right.size());
295     result.insert(result.end(), left.begin(), left.end());
296     result.insert(result.end(), right.begin(), right.end());
297     return result;
298 }
299 }
300 
301 /*static*/
302 const TfTokenVector&
GetSchemaAttributeNames(bool includeInherited)303 UsdContrivedDerived::GetSchemaAttributeNames(bool includeInherited)
304 {
305     static TfTokenVector localNames = {
306         UsdContrivedTokens->pivotPosition,
307         UsdContrivedTokens->myVecfArray,
308         UsdContrivedTokens->holeIndices,
309         UsdContrivedTokens->cornerIndices,
310         UsdContrivedTokens->cornerSharpnesses,
311         UsdContrivedTokens->creaseLengths,
312         UsdContrivedTokens->transform,
313         UsdContrivedTokens->testingAsset,
314         UsdContrivedTokens->namespacedProperty,
315         UsdContrivedTokens->justDefault,
316     };
317     static TfTokenVector allNames =
318         _ConcatenateAttributeNames(
319             UsdContrivedBase::GetSchemaAttributeNames(true),
320             localNames);
321 
322     if (includeInherited)
323         return allNames;
324     else
325         return localNames;
326 }
327 
328 }}}
329 
330 // ===================================================================== //
331 // Feel free to add custom code below this line. It will be preserved by
332 // the code generator.
333 //
334 // Just remember to wrap code in the appropriate delimiters:
335 // 'namespace foo { namespace bar { namespace baz {', '}}}'.
336 // ===================================================================== //
337 // --(BEGIN CUSTOM CODE)--
338