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_RAMP "ramp"
33 #define HUSD_PROPERTY_VALUE_ORDERED "usdvalueordered"
34 #define HUSD_PROPERTY_APISCHEMA "usdapischema"
35 #define HUSD_PROPERTY_VALUENAME "usdvaluename"
36 #define HUSD_PROPERTY_RAMPCOUNTNAME "usdrampcountname"
37 #define HUSD_PROPERTY_RAMPBASISNAME "usdrampbasisname"
38 #define HUSD_PROPERTY_RAMPBASISISARRAY "usdrampbasisisarray"
39 #define HUSD_PROPERTY_RAMPBASISSUFFIX "_basis"
40 #define HUSD_PROPERTY_RAMPPOSNAME "usdrampposname"
41 #define HUSD_PROPERTY_RAMPPOSSUFFIX "_pos"
42 #define HUSD_PROPERTY_CONTROLPARM "usdcontrolparm"
43 #define HUSD_PROPERTY_XFORM_PARM_PREFIX "xformparmprefix"
44 #define HUSD_PROPERTY_ISCUSTOM "usdiscustomattrib"
45 #define HUSD_PROPERTY_ISCONNECTION "usdisconnection"
46 #define HUSD_PROPERTY_KEEPCOLLECTIONS "keepcollections"
47 
48 // These define custom data keys on the value attribute of the
49 // ramp attribute trio, to tie everything together.
50 #define HUSD_PROPERTY_RAMPVALUEATTR_KEY "rampvalueattr"
51 #define HUSD_PROPERTY_RAMPCOUNTATTR_KEY "rampcountattr"
52 #define HUSD_PROPERTY_RAMPBASISATTR_KEY "rampbasisattr"
53 #define HUSD_PROPERTY_RAMPBASISISARRAY_KEY "rampbasisisarray"
54 #define HUSD_PROPERTY_RAMPPOSATTR_KEY "rampposattr"
55 
56 // This defines an xformOp metadata key to indicate that the
57 // parameters to control this attribute should include the ability
58 // to specify a look at constraint.
59 #define HUSD_PROPERTY_XFORMOP_INCLUDE_LOOKAT "HoudiniIncludeLookAt"
60 
61 // Names of parameters that describe a look at constraint for use in
62 // conjunction with a set of transform parameters.
63 #define HUSD_PROPERTY_LOOKAT_ENABLE "lookatenable"
64 #define HUSD_PROPERTY_LOOKAT_PRIM "lookatprim"
65 #define HUSD_PROPERTY_LOOKAT_POSITION "lookatposition"
66 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD "upvecmethod"
67 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD_XAXIS "xaxis"
68 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD_YAXIS "yaxis"
69 #define HUSD_PROPERTY_LOOKAT_UPVECMETHOD_CUSTOM "custom"
70 #define HUSD_PROPERTY_LOOKAT_UPVEC "upvec"
71 #define HUSD_PROPERTY_LOOKAT_TWIST "twist"
72 
73 // This class is a standalone wrapper around a specific property in a USD
74 // stage wrapped in an HUSD_DataHandle. It's purpose is to serve as the data
75 // accessor for tree nodes in the Scene Graph Tree. It should not be used for
76 // any other purpose, as it is extremely inefficient. Each function call locks
77 // the HUSD_DataHandle, queries its information, then unlocks it again. This
78 // is a matter of convenience for the calling pattern of the scene graph tree.
79 // Because it is inefficient the scene graph tree caches any information that
80 // comes out of this object.
81 //
82 // Anyone else tempted to use this object should use HUSD_Info instead.
84 {
85 public:
88  const HUSD_PrimHandle &prim_handle,
89  const UT_StringRef &property_name);
90  ~HUSD_PropertyHandle() override;
91 
92  const HUSD_DataHandle &dataHandle() const override
93  { return myPrimHandle.dataHandle(); }
94  const HUSD_ConstOverridesPtr &overrides() const override
95  { return myPrimHandle.overrides(); }
96  const HUSD_ConstPostLayersPtr &postLayers() const override
97  { return myPrimHandle.postLayers(); }
98  const HUSD_PrimHandle &primHandle() const
99  { return myPrimHandle; }
100 
101  UT_StringHolder getSourceSchema() const;
102  UT_StringHolder getTypeDescription() const;
103  bool isCustom() const;
104  bool isXformOp() const;
105 
106  /// Creates a parameter that can specify a new value for the given USD
107  /// property. If prepend_control_parm is true, it also creates
108  /// a control menu parm before the value parm.
109  /// The control parm determines whether and how the USD property is edited.
110  /// It appends the created parameters to the given parms array.
111  void createScriptedParms(
113  const UT_StringRef &custom_name,
114  bool prepend_control_parm,
115  bool prefix_xform_parms) const;
116 
117  /// Creates a parameter that can specify a connection (ie, a source
118  /// attribute path) for the given input or output shading attribute.
119  /// If prepend_control_parm is true, it also creates a control menu parm
120  /// before the value parm.
121  /// The control parm determines whether and how the USD property is edited.
122  /// It appends the created parameter to the given parms array.
123  void createScriptedConnectionParms(
125  const UT_StringRef &custom_name,
126  bool prepend_control_parm) const;
127 
128 
129  /// Returns a control parameter for the given USD property name.
130  /// The given name can be also a node parameter name that corresponds
131  /// or encodes the property name. Though the parm name can also be
132  /// arbitrary (because usd prop name is stored as a parm tag), in which
133  /// case the property name should be provided as usdvaluename parameter.
135  createScriptedControlParm(
136  const UT_StringHolder &propbasename,
137  const UT_StringRef &usdvaluetype,
138  const UT_StringRef &usdvaluename = UT_StringRef(),
139  bool add_value_control_items = true,
140  bool add_connection_control_items = false);
141 
142  static UT_StringHolder
143  getScriptedControlDisableCondition(
144  const UT_StringRef &ctrl_parm_name,
145  const UT_StringRef &usdvaluetype = UT_StringRef(),
146  const UT_StringRef &usdvaluename = UT_StringRef());
147 
148 private:
149  HUSD_PrimHandle myPrimHandle;
150 };
151 
152 #endif
153 
const HUSD_ConstOverridesPtr & overrides() const override
#define HUSD_API
Definition: HUSD_API.h:32
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