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/usdUI/nodeGraphNodeAPI.h"
25 #include "pxr/usd/usd/schemaRegistry.h"
26 #include "pxr/usd/usd/typed.h"
27 #include "pxr/usd/usd/tokens.h"
28 
29 #include "pxr/usd/sdf/types.h"
30 #include "pxr/usd/sdf/assetPath.h"
31 
32 PXR_NAMESPACE_OPEN_SCOPE
33 
34 // Register the schema with the TfType system.
TF_REGISTRY_FUNCTION(TfType)35 TF_REGISTRY_FUNCTION(TfType)
36 {
37     TfType::Define<UsdUINodeGraphNodeAPI,
38         TfType::Bases< UsdAPISchemaBase > >();
39 
40 }
41 
42 TF_DEFINE_PRIVATE_TOKENS(
43     _schemaTokens,
44     (NodeGraphNodeAPI)
45 );
46 
47 /* virtual */
~UsdUINodeGraphNodeAPI()48 UsdUINodeGraphNodeAPI::~UsdUINodeGraphNodeAPI()
49 {
50 }
51 
52 /* static */
53 UsdUINodeGraphNodeAPI
Get(const UsdStagePtr & stage,const SdfPath & path)54 UsdUINodeGraphNodeAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
55 {
56     if (!stage) {
57         TF_CODING_ERROR("Invalid stage");
58         return UsdUINodeGraphNodeAPI();
59     }
60     return UsdUINodeGraphNodeAPI(stage->GetPrimAtPath(path));
61 }
62 
63 
64 /* virtual */
_GetSchemaKind() const65 UsdSchemaKind UsdUINodeGraphNodeAPI::_GetSchemaKind() const
66 {
67     return UsdUINodeGraphNodeAPI::schemaKind;
68 }
69 
70 /* static */
71 bool
CanApply(const UsdPrim & prim,std::string * whyNot)72 UsdUINodeGraphNodeAPI::CanApply(
73     const UsdPrim &prim, std::string *whyNot)
74 {
75     return prim.CanApplyAPI<UsdUINodeGraphNodeAPI>(whyNot);
76 }
77 
78 /* static */
79 UsdUINodeGraphNodeAPI
Apply(const UsdPrim & prim)80 UsdUINodeGraphNodeAPI::Apply(const UsdPrim &prim)
81 {
82     if (prim.ApplyAPI<UsdUINodeGraphNodeAPI>()) {
83         return UsdUINodeGraphNodeAPI(prim);
84     }
85     return UsdUINodeGraphNodeAPI();
86 }
87 
88 /* static */
89 const TfType &
_GetStaticTfType()90 UsdUINodeGraphNodeAPI::_GetStaticTfType()
91 {
92     static TfType tfType = TfType::Find<UsdUINodeGraphNodeAPI>();
93     return tfType;
94 }
95 
96 /* static */
97 bool
_IsTypedSchema()98 UsdUINodeGraphNodeAPI::_IsTypedSchema()
99 {
100     static bool isTyped = _GetStaticTfType().IsA<UsdTyped>();
101     return isTyped;
102 }
103 
104 /* virtual */
105 const TfType &
_GetTfType() const106 UsdUINodeGraphNodeAPI::_GetTfType() const
107 {
108     return _GetStaticTfType();
109 }
110 
111 UsdAttribute
GetPosAttr() const112 UsdUINodeGraphNodeAPI::GetPosAttr() const
113 {
114     return GetPrim().GetAttribute(UsdUITokens->uiNodegraphNodePos);
115 }
116 
117 UsdAttribute
CreatePosAttr(VtValue const & defaultValue,bool writeSparsely) const118 UsdUINodeGraphNodeAPI::CreatePosAttr(VtValue const &defaultValue, bool writeSparsely) const
119 {
120     return UsdSchemaBase::_CreateAttr(UsdUITokens->uiNodegraphNodePos,
121                        SdfValueTypeNames->Float2,
122                        /* custom = */ false,
123                        SdfVariabilityUniform,
124                        defaultValue,
125                        writeSparsely);
126 }
127 
128 UsdAttribute
GetStackingOrderAttr() const129 UsdUINodeGraphNodeAPI::GetStackingOrderAttr() const
130 {
131     return GetPrim().GetAttribute(UsdUITokens->uiNodegraphNodeStackingOrder);
132 }
133 
134 UsdAttribute
CreateStackingOrderAttr(VtValue const & defaultValue,bool writeSparsely) const135 UsdUINodeGraphNodeAPI::CreateStackingOrderAttr(VtValue const &defaultValue, bool writeSparsely) const
136 {
137     return UsdSchemaBase::_CreateAttr(UsdUITokens->uiNodegraphNodeStackingOrder,
138                        SdfValueTypeNames->Int,
139                        /* custom = */ false,
140                        SdfVariabilityUniform,
141                        defaultValue,
142                        writeSparsely);
143 }
144 
145 UsdAttribute
GetDisplayColorAttr() const146 UsdUINodeGraphNodeAPI::GetDisplayColorAttr() const
147 {
148     return GetPrim().GetAttribute(UsdUITokens->uiNodegraphNodeDisplayColor);
149 }
150 
151 UsdAttribute
CreateDisplayColorAttr(VtValue const & defaultValue,bool writeSparsely) const152 UsdUINodeGraphNodeAPI::CreateDisplayColorAttr(VtValue const &defaultValue, bool writeSparsely) const
153 {
154     return UsdSchemaBase::_CreateAttr(UsdUITokens->uiNodegraphNodeDisplayColor,
155                        SdfValueTypeNames->Color3f,
156                        /* custom = */ false,
157                        SdfVariabilityUniform,
158                        defaultValue,
159                        writeSparsely);
160 }
161 
162 UsdAttribute
GetIconAttr() const163 UsdUINodeGraphNodeAPI::GetIconAttr() const
164 {
165     return GetPrim().GetAttribute(UsdUITokens->uiNodegraphNodeIcon);
166 }
167 
168 UsdAttribute
CreateIconAttr(VtValue const & defaultValue,bool writeSparsely) const169 UsdUINodeGraphNodeAPI::CreateIconAttr(VtValue const &defaultValue, bool writeSparsely) const
170 {
171     return UsdSchemaBase::_CreateAttr(UsdUITokens->uiNodegraphNodeIcon,
172                        SdfValueTypeNames->Asset,
173                        /* custom = */ false,
174                        SdfVariabilityUniform,
175                        defaultValue,
176                        writeSparsely);
177 }
178 
179 UsdAttribute
GetExpansionStateAttr() const180 UsdUINodeGraphNodeAPI::GetExpansionStateAttr() const
181 {
182     return GetPrim().GetAttribute(UsdUITokens->uiNodegraphNodeExpansionState);
183 }
184 
185 UsdAttribute
CreateExpansionStateAttr(VtValue const & defaultValue,bool writeSparsely) const186 UsdUINodeGraphNodeAPI::CreateExpansionStateAttr(VtValue const &defaultValue, bool writeSparsely) const
187 {
188     return UsdSchemaBase::_CreateAttr(UsdUITokens->uiNodegraphNodeExpansionState,
189                        SdfValueTypeNames->Token,
190                        /* custom = */ false,
191                        SdfVariabilityUniform,
192                        defaultValue,
193                        writeSparsely);
194 }
195 
196 UsdAttribute
GetSizeAttr() const197 UsdUINodeGraphNodeAPI::GetSizeAttr() const
198 {
199     return GetPrim().GetAttribute(UsdUITokens->uiNodegraphNodeSize);
200 }
201 
202 UsdAttribute
CreateSizeAttr(VtValue const & defaultValue,bool writeSparsely) const203 UsdUINodeGraphNodeAPI::CreateSizeAttr(VtValue const &defaultValue, bool writeSparsely) const
204 {
205     return UsdSchemaBase::_CreateAttr(UsdUITokens->uiNodegraphNodeSize,
206                        SdfValueTypeNames->Float2,
207                        /* custom = */ false,
208                        SdfVariabilityUniform,
209                        defaultValue,
210                        writeSparsely);
211 }
212 
213 namespace {
214 static inline TfTokenVector
_ConcatenateAttributeNames(const TfTokenVector & left,const TfTokenVector & right)215 _ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right)
216 {
217     TfTokenVector result;
218     result.reserve(left.size() + right.size());
219     result.insert(result.end(), left.begin(), left.end());
220     result.insert(result.end(), right.begin(), right.end());
221     return result;
222 }
223 }
224 
225 /*static*/
226 const TfTokenVector&
GetSchemaAttributeNames(bool includeInherited)227 UsdUINodeGraphNodeAPI::GetSchemaAttributeNames(bool includeInherited)
228 {
229     static TfTokenVector localNames = {
230         UsdUITokens->uiNodegraphNodePos,
231         UsdUITokens->uiNodegraphNodeStackingOrder,
232         UsdUITokens->uiNodegraphNodeDisplayColor,
233         UsdUITokens->uiNodegraphNodeIcon,
234         UsdUITokens->uiNodegraphNodeExpansionState,
235         UsdUITokens->uiNodegraphNodeSize,
236     };
237     static TfTokenVector allNames =
238         _ConcatenateAttributeNames(
239             UsdAPISchemaBase::GetSchemaAttributeNames(true),
240             localNames);
241 
242     if (includeInherited)
243         return allNames;
244     else
245         return localNames;
246 }
247 
248 PXR_NAMESPACE_CLOSE_SCOPE
249 
250 // ===================================================================== //
251 // Feel free to add custom code below this line. It will be preserved by
252 // the code generator.
253 //
254 // Just remember to wrap code in the appropriate delimiters:
255 // 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'.
256 // ===================================================================== //
257 // --(BEGIN CUSTOM CODE)--
258