HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_PropertyHandle.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_PropertyHandle_h__
19 #define __HUSD_PropertyHandle_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_ObjectHandle.h"
23 #include "HUSD_PrimHandle.h"
24 
26 
27 // These defines specify node parameter sparte data tags that are used to
28 // describe how a parameter should be translated into a USD attribute.
29 #define HUSD_PROPERTY_VALUETYPE "usdvaluetype"
30 #define HUSD_PROPERTY_VALUETYPE_RELATIONSHIP "relationship"
31 #define HUSD_PROPERTY_VALUETYPE_XFORM "xform"
32 #define HUSD_PROPERTY_VALUETYPE_COLLECTION "collection"
33 #define HUSD_PROPERTY_VALUETYPE_RAMP "ramp"
34 #define HUSD_PROPERTY_VALUE_ORDERED "usdvalueordered"
35 #define HUSD_PROPERTY_APISCHEMA "usdapischema"
36 #define HUSD_PROPERTY_VALUENAME "usdvaluename"
37 #define HUSD_PROPERTY_RAMPCOUNTNAME "usdrampcountname"
38 #define HUSD_PROPERTY_RAMPBASISNAME "usdrampbasisname"
39 #define HUSD_PROPERTY_RAMPBASISISARRAY "usdrampbasisisarray"
40 #define HUSD_PROPERTY_RAMPBASISSUFFIX "_basis"
41 #define HUSD_PROPERTY_RAMPPOSNAME "usdrampposname"
42 #define HUSD_PROPERTY_RAMPPOSSUFFIX "_pos"
43 #define HUSD_PROPERTY_CONTROLPARM "usdcontrolparm"
44 #define HUSD_PROPERTY_XFORM_PARM_PREFIX "xformparmprefix"
45 #define HUSD_PROPERTY_ISCUSTOM "usdiscustomattrib"
46 #define HUSD_PROPERTY_ISCONNECTION "usdisconnection"
47 #define HUSD_PROPERTY_KEEPCOLLECTIONS "keepcollections"
48 
49 // These define custom data keys on the value attribute of the
50 // ramp attribute trio, to tie everything together.
51 #define HUSD_PROPERTY_RAMPVALUEATTR_KEY "rampvalueattr"
52 #define HUSD_PROPERTY_RAMPCOUNTATTR_KEY "rampcountattr"
53 #define HUSD_PROPERTY_RAMPBASISATTR_KEY "rampbasisattr"
54 #define HUSD_PROPERTY_RAMPBASISISARRAY_KEY "rampbasisisarray"
55 #define HUSD_PROPERTY_RAMPPOSATTR_KEY "rampposattr"
56 
57 // This defines a metadata key to identify an attribute that should
58 // result in the creation of a collection.
59 #define HUSD_PROPERTY_COLLECTIONATTR_KEY "HoudiniCollectionAttr"
60 
61 // This defines an xformOp metadata key to indicate that the
62 // parameters to control this attribute should include the ability
63 // to specify a look at constraint.
64 #define HUSD_PROPERTY_XFORMOP_INCLUDE_LOOKAT "HoudiniIncludeLookAt"
65 
66 // Names of parameters that describe a look at constraint for use in
67 // conjunction with a set of transform parameters.
68 #define HUSD_PROPERTY_LOOKAT_ENABLE "lookatenable"
69 #define HUSD_PROPERTY_LOOKAT_PRIM "lookatprim"
70 #define HUSD_PROPERTY_LOOKAT_POSITION "lookatposition"
71 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD "upvecmethod"
72 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD_XAXIS "xaxis"
73 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD_YAXIS "yaxis"
74 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD_CUSTOM "custom"
75 #define HUSD_PROPERTY_LOOKAT_UPVEC "upvec"
76 #define HUSD_PROPERTY_LOOKAT_TWIST "twist"
77 
78 // This class is a standalone wrapper around a specific property in a USD
79 // stage wrapped in an HUSD_DataHandle. It's purpose is to serve as the data
80 // accessor for tree nodes in the Scene Graph Tree. It should not be used for
81 // any other purpose, as it is extremely inefficient. Each function call locks
82 // the HUSD_DataHandle, queries its information, then unlocks it again. This
83 // is a matter of convenience for the calling pattern of the scene graph tree.
84 // Because it is inefficient the scene graph tree caches any information that
85 // comes out of this object.
86 //
87 // Anyone else tempted to use this object should use HUSD_Info instead.
89 {
90 public:
93  const HUSD_PrimHandle &prim_handle,
94  const UT_StringRef &property_name);
95  ~HUSD_PropertyHandle() override;
96 
97  const HUSD_DataHandle &dataHandle() const override
98  { return myPrimHandle.dataHandle(); }
99  const HUSD_ConstOverridesPtr &overrides() const override
100  { return myPrimHandle.overrides(); }
101  const HUSD_ConstPostLayersPtr &postLayers() const override
102  { return myPrimHandle.postLayers(); }
104  { return myPrimHandle; }
105 
106  UT_StringHolder getSourceSchema() const;
107  UT_StringHolder getTypeDescription() const;
108  bool isCustom() const;
109  bool isXformOp() const;
110 
111  /// Creates a parameter that can specify a new value for the given USD
112  /// property. If prepend_control_parm is true, it also creates
113  /// a control menu parm before the value parm.
114  /// The control parm determines whether and how the USD property is edited.
115  /// It appends the created parameters to the given parms array.
116  void createScriptedParms(
118  const UT_StringRef &custom_name,
119  bool prepend_control_parm,
120  bool prefix_xform_parms) const;
121 
122  /// Creates a parameter that can specify a connection (ie, a source
123  /// attribute path) for the given input or output shading attribute.
124  /// If prepend_control_parm is true, it also creates a control menu parm
125  /// before the value parm.
126  /// The control parm determines whether and how the USD property is edited.
127  /// It appends the created parameter to the given parms array.
128  void createScriptedConnectionParms(
130  const UT_StringRef &custom_name,
131  bool prepend_control_parm) const;
132 
133 
134  /// Returns a control parameter for the given USD property name.
135  /// The given name can be also a node parameter name that corresponds
136  /// or encodes the property name. Though the parm name can also be
137  /// arbitrary (because usd prop name is stored as a parm tag), in which
138  /// case the property name should be provided as usdvaluename parameter.
140  createScriptedControlParm(
141  const UT_StringHolder &propbasename,
142  const UT_StringRef &usdvaluetype,
143  const UT_StringRef &usdvaluename = UT_StringRef(),
144  bool add_value_control_items = true,
145  bool add_connection_control_items = false);
146 
147  static UT_StringHolder
148  getScriptedControlDisableCondition(
149  const UT_StringRef &ctrl_parm_name,
150  const UT_StringRef &usdvaluetype = UT_StringRef(),
151  const UT_StringRef &usdvaluename = UT_StringRef());
152 
153 private:
154  HUSD_PrimHandle myPrimHandle;
155 };
156 
157 #endif
158 
const HUSD_ConstOverridesPtr & overrides() const override
#define HUSD_API
Definition: HUSD_API.h:31
const HUSD_DataHandle & dataHandle() const override
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
const HUSD_PrimHandle & primHandle() const
const HUSD_ConstPostLayersPtr & postLayers() const override
GA_API const UT_StringHolder parms