HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aOVSettingsAPI.cpp
Go to the documentation of this file.
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 ".//aOVSettingsAPI.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 
33 
34 // Register the schema with the TfType system.
36 {
39 
40 }
41 
43  _schemaTokens,
44  (KarmaAOVSettingsAPI)
45  (aov)
46 );
47 
48 /* virtual */
50 {
51 }
52 
53 /* static */
55 usdKarmaAOVSettingsAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
56 {
57  if (!stage) {
58  TF_CODING_ERROR("Invalid stage");
59  return usdKarmaAOVSettingsAPI();
60  }
61  TfToken name;
62  if (!IsKarmaAOVSettingsAPIPath(path, &name)) {
63  TF_CODING_ERROR("Invalid aov path <%s>.", path.GetText());
64  return usdKarmaAOVSettingsAPI();
65  }
66  return usdKarmaAOVSettingsAPI(stage->GetPrimAtPath(path.GetPrimPath()), name);
67 }
68 
71 {
72  return usdKarmaAOVSettingsAPI(prim, name);
73 }
74 
75 
76 /* static */
77 bool
79 {
80  static TfTokenVector attrsAndRels = {
81  usdKarmaTokens()->karmaPlaneDefaultvalue,
82  usdKarmaTokens()->karmaPlaneDisable,
83  usdKarmaTokens()->karmaPlaneDither,
84  usdKarmaTokens()->karmaPlaneExclude_dcm,
85  usdKarmaTokens()->karmaPlaneFilename,
86  usdKarmaTokens()->karmaPlaneFilter,
87  usdKarmaTokens()->karmaPlaneSampling,
88  };
89 
90  return find(attrsAndRels.begin(), attrsAndRels.end(), baseName)
91  != attrsAndRels.end();
92 }
93 
94 /* static */
95 bool
97  const SdfPath &path, TfToken *name)
98 {
99  if (!path.IsPropertyPath()) {
100  return false;
101  }
102 
103  std::string propertyName = path.GetName();
104  TfTokenVector tokens = SdfPath::TokenizeIdentifierAsTokens(propertyName);
105 
106  // The baseName of the path can't be one of the
107  // schema properties. We should validate this in the creation (or apply)
108  // API.
109  TfToken baseName = *tokens.rbegin();
110  if (IsSchemaPropertyBaseName(baseName)) {
111  return false;
112  }
113 
114  if (tokens.size() >= 2
115  && tokens[0] == _schemaTokens->aov) {
116  *name = TfToken(propertyName.substr(
117  _schemaTokens->aov.GetString().size() + 1));
118  return true;
119  }
120 
121  return false;
122 }
123 
124 /* virtual */
127 }
128 
129 /* static */
132 {
133  return UsdAPISchemaBase::_MultipleApplyAPISchema<usdKarmaAOVSettingsAPI>(
134  prim, _schemaTokens->KarmaAOVSettingsAPI, name);
135 }
136 
137 /* static */
138 const TfType &
139 usdKarmaAOVSettingsAPI::_GetStaticTfType()
140 {
141  static TfType tfType = TfType::Find<usdKarmaAOVSettingsAPI>();
142  return tfType;
143 }
144 
145 /* static */
146 bool
147 usdKarmaAOVSettingsAPI::_IsTypedSchema()
148 {
149  static bool isTyped = _GetStaticTfType().IsA<UsdTyped>();
150  return isTyped;
151 }
152 
153 /* virtual */
154 const TfType &
155 usdKarmaAOVSettingsAPI::_GetTfType() const
156 {
157  return _GetStaticTfType();
158 }
159 
160 /// Returns the property name prefixed with the correct namespace prefix, which
161 /// is composed of the the API's propertyNamespacePrefix metadata and the
162 /// instance name of the API.
163 inline
164 TfToken
165 _GetNamespacedPropertyName(const TfToken instanceName, const TfToken propName)
166 {
167  TfTokenVector identifiers =
168  {_schemaTokens->aov, instanceName, propName};
169  return TfToken(SdfPath::JoinIdentifier(identifiers));
170 }
171 
174 {
175  return GetPrim().GetAttribute(
177  GetName(),
178  usdKarmaTokens()->karmaPlaneDefaultvalue));
179 }
180 
182 usdKarmaAOVSettingsAPI::CreateKarmaPlaneDefaultvalueAttr(VtValue const &defaultValue, bool writeSparsely) const
183 {
186  GetName(),
187  usdKarmaTokens()->karmaPlaneDefaultvalue),
188  SdfValueTypeNames->Float,
189  /* custom = */ false,
191  defaultValue,
192  writeSparsely);
193 }
194 
197 {
198  return GetPrim().GetAttribute(
200  GetName(),
201  usdKarmaTokens()->karmaPlaneDisable));
202 }
203 
205 usdKarmaAOVSettingsAPI::CreateKarmaPlaneDisableAttr(VtValue const &defaultValue, bool writeSparsely) const
206 {
209  GetName(),
210  usdKarmaTokens()->karmaPlaneDisable),
211  SdfValueTypeNames->Bool,
212  /* custom = */ false,
214  defaultValue,
215  writeSparsely);
216 }
217 
220 {
221  return GetPrim().GetAttribute(
223  GetName(),
224  usdKarmaTokens()->karmaPlaneDither));
225 }
226 
228 usdKarmaAOVSettingsAPI::CreateKarmaPlaneDitherAttr(VtValue const &defaultValue, bool writeSparsely) const
229 {
232  GetName(),
233  usdKarmaTokens()->karmaPlaneDither),
234  SdfValueTypeNames->Float,
235  /* custom = */ false,
237  defaultValue,
238  writeSparsely);
239 }
240 
243 {
244  return GetPrim().GetAttribute(
246  GetName(),
247  usdKarmaTokens()->karmaPlaneExclude_dcm));
248 }
249 
251 usdKarmaAOVSettingsAPI::CreateKarmaPlaneExclude_dcmAttr(VtValue const &defaultValue, bool writeSparsely) const
252 {
255  GetName(),
256  usdKarmaTokens()->karmaPlaneExclude_dcm),
257  SdfValueTypeNames->Bool,
258  /* custom = */ false,
260  defaultValue,
261  writeSparsely);
262 }
263 
266 {
267  return GetPrim().GetAttribute(
269  GetName(),
270  usdKarmaTokens()->karmaPlaneFilename));
271 }
272 
274 usdKarmaAOVSettingsAPI::CreateKarmaPlaneFilenameAttr(VtValue const &defaultValue, bool writeSparsely) const
275 {
278  GetName(),
279  usdKarmaTokens()->karmaPlaneFilename),
280  SdfValueTypeNames->String,
281  /* custom = */ false,
283  defaultValue,
284  writeSparsely);
285 }
286 
289 {
290  return GetPrim().GetAttribute(
292  GetName(),
293  usdKarmaTokens()->karmaPlaneFilter));
294 }
295 
297 usdKarmaAOVSettingsAPI::CreateKarmaPlaneFilterAttr(VtValue const &defaultValue, bool writeSparsely) const
298 {
301  GetName(),
302  usdKarmaTokens()->karmaPlaneFilter),
303  SdfValueTypeNames->String,
304  /* custom = */ false,
306  defaultValue,
307  writeSparsely);
308 }
309 
312 {
313  return GetPrim().GetAttribute(
315  GetName(),
316  usdKarmaTokens()->karmaPlaneSampling));
317 }
318 
320 usdKarmaAOVSettingsAPI::CreateKarmaPlaneSamplingAttr(VtValue const &defaultValue, bool writeSparsely) const
321 {
324  GetName(),
325  usdKarmaTokens()->karmaPlaneSampling),
326  SdfValueTypeNames->Token,
327  /* custom = */ false,
329  defaultValue,
330  writeSparsely);
331 }
332 
333 namespace {
334 static inline TfTokenVector
335 _ConcatenateAttributeNames(
336  const TfToken instanceName,
337  const TfTokenVector& left,
338  const TfTokenVector& right)
339 {
341  result.reserve(left.size() + right.size());
342  result.insert(result.end(), left.begin(), left.end());
343 
344  for (const TfToken attrName : right) {
345  result.push_back(
346  _GetNamespacedPropertyName(instanceName, attrName));
347  }
348  result.insert(result.end(), right.begin(), right.end());
349  return result;
350 }
351 }
352 
353 /*static*/
354 const TfTokenVector&
356  bool includeInherited, const TfToken instanceName)
357 {
358  static TfTokenVector localNames = {
359  usdKarmaTokens()->karmaPlaneDefaultvalue,
360  usdKarmaTokens()->karmaPlaneDisable,
361  usdKarmaTokens()->karmaPlaneDither,
362  usdKarmaTokens()->karmaPlaneExclude_dcm,
363  usdKarmaTokens()->karmaPlaneFilename,
364  usdKarmaTokens()->karmaPlaneFilter,
365  usdKarmaTokens()->karmaPlaneSampling,
366  };
367  static TfTokenVector allNames =
368  _ConcatenateAttributeNames(
369  instanceName,
371  localNames);
372 
373  if (includeInherited)
374  return allNames;
375  else
376  return localNames;
377 }
378 
380 
381 // ===================================================================== //
382 // Feel free to add custom code below this line. It will be preserved by
383 // the code generator.
384 //
385 // Just remember to wrap code in the appropriate delimiters:
386 // 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'.
387 // ===================================================================== //
388 // --(BEGIN CUSTOM CODE)--
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
SDF_API const std::string & GetName() const
static const UsdSchemaType schemaType
static bool IsSchemaPropertyBaseName(const TfToken &baseName)
GLuint const GLchar * name
Definition: glew.h:1814
UsdAttribute CreateKarmaPlaneExclude_dcmAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdAttribute GetKarmaPlaneDefaultvalueAttr() const
GLint left
Definition: glew.h:8008
UsdAttribute GetKarmaPlaneSamplingAttr() const
static const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true, const TfToken instanceName=TfToken())
#define TF_CODING_ERROR
TF_DEFINE_PRIVATE_TOKENS(_schemaTokens,(KarmaAOVSettingsAPI)(aov))
UsdAttribute GetKarmaPlaneFilenameAttr() const
UsdAttribute GetKarmaPlaneFilterAttr() const
usdKarmaAOVSettingsAPI(const UsdPrim &prim=UsdPrim(), const TfToken &name=TfToken())
UsdAttribute CreateKarmaPlaneFilterAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdAttribute CreateKarmaPlaneSamplingAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
virtual UsdSchemaType _GetSchemaType() const
Definition: token.h:89
UsdAttribute GetKarmaPlaneExclude_dcmAttr() const
static TfType const & Define()
Definition: type_Impl.h:78
UsdAttribute GetKarmaPlaneDitherAttr() const
UsdSchemaType
Definition: common.h:149
Definition: prim.h:131
Definition: typed.h:47
static SDF_API std::string JoinIdentifier(const std::vector< std::string > &names)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
UsdAttribute CreateKarmaPlaneFilenameAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static usdKarmaAOVSettingsAPI Get(const UsdStagePtr &stage, const SdfPath &path)
GLfloat right
Definition: glew.h:15186
Definition: path.h:287
GLsizei const GLchar *const * path
Definition: glew.h:6461
UsdAttribute GetKarmaPlaneDisableAttr() const
SDF_API TfStaticData< const Sdf_ValueTypeNamesType, Sdf_ValueTypeNamesType::_Init > SdfValueTypeNames
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
TfToken GetName() const
Returns the name of this multiple-apply schema instance.
virtual ~usdKarmaAOVSettingsAPI()
Destructor.
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
Definition: format.h:2104
USD_API UsdAttribute _CreateAttr(TfToken const &attrName, SdfValueTypeName const &typeName, bool custom, SdfVariability variability, VtValue const &defaultValue, bool writeSparsely) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
static USD_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: type.h:70
UsdAttribute CreateKarmaPlaneDitherAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
GLuint64EXT * result
Definition: glew.h:14007
TF_API bool IsA(TfType queryType) const
SDF_API bool IsPropertyPath() const
TfToken _GetNamespacedPropertyName(const TfToken instanceName, const TfToken propName)
TfStaticData< usdKarmaTokensType > & usdKarmaTokens()
Definition: tokens.cpp:168
UsdAttribute CreateKarmaPlaneDefaultvalueAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
PXR_NAMESPACE_OPEN_SCOPE TF_REGISTRY_FUNCTION(TfType)
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:119
UsdAttribute CreateKarmaPlaneDisableAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:182
SDF_API SdfPath GetPrimPath() const
static bool IsKarmaAOVSettingsAPIPath(const SdfPath &path, TfToken *name)
static usdKarmaAOVSettingsAPI Apply(const UsdPrim &prim, const TfToken &name)
static SDF_API TfTokenVector TokenizeIdentifierAsTokens(const std::string &name)