connectableAPIBehavior.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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 #ifndef PXR_USD_USD_SHADE_CONNECTABLE_BEHAVIOR_H
25 #define PXR_USD_USD_SHADE_CONNECTABLE_BEHAVIOR_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdShade/api.h"
31 
32 #include "pxr/base/gf/vec3f.h"
33 #include "pxr/base/vt/array.h"
34 
35 #include "pxr/base/tf/type.h"
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 class UsdAttribute;
40 class UsdShadeInput;
41 class UsdShadeOutput;
42 
49 {
50 public:
51 
55  {
56  BasicNodes, // Shader, NodeGraph
57  DerivedContainerNodes, // Material, etc
58  };
59 
60  // By default we want a connectableBehavior to not exhibit a container like
61  // behavior. And we want encapsulation behavior enabled by default.
62  USDSHADE_API
64  : _isContainer(false), _requiresEncapsulation(true) {}
65 
66  USDSHADE_API
67  UsdShadeConnectableAPIBehavior(const bool isContainer,
68  const bool requiresEncapsulation)
69  : _isContainer(isContainer),
70  _requiresEncapsulation(requiresEncapsulation) {}
71 
72  USDSHADE_API
74 
88  USDSHADE_API
89  virtual bool
91  const UsdAttribute &,
92  std::string *reason) const;
93 
106  USDSHADE_API
107  virtual bool
109  const UsdAttribute &,
110  std::string *reason) const;
111 
117  USDSHADE_API
118  virtual bool
119  IsContainer() const final;
120 
127  //
132  USDSHADE_API
133  virtual bool
134  RequiresEncapsulation() const final;
135 
136 protected:
144  USDSHADE_API
146  std::string *reason,
147  ConnectableNodeTypes nodeType =
148  ConnectableNodeTypes::BasicNodes) const;
149 
150  USDSHADE_API
151  bool _CanConnectOutputToSource(const UsdShadeOutput&, const UsdAttribute&,
152  std::string *reason,
153  ConnectableNodeTypes nodeType =
154  ConnectableNodeTypes::BasicNodes) const;
155 private:
156  bool _isContainer;
157  bool _requiresEncapsulation;
158 };
159 
206 template <class PrimType, class BehaviorType = UsdShadeConnectableAPIBehavior>
207 inline void
209 {
211  TfType::Find<PrimType>(),
212  std::shared_ptr<UsdShadeConnectableAPIBehavior>(new BehaviorType));
213 }
214 
217 USDSHADE_API
218 void
220  const TfType& connectablePrimType,
221  const std::shared_ptr<UsdShadeConnectableAPIBehavior>& behavior);
222 
223 PXR_NAMESPACE_CLOSE_SCOPE
224 
225 #endif // PXR_USD_USD_SHADE_CONNECTABLE_BEHAVIOR_H
void UsdShadeRegisterConnectableAPIBehavior()
Registers behavior to define connectability of attributes for PrimType.
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
virtual USDSHADE_API bool CanConnectOutputToSource(const UsdShadeOutput &, const UsdAttribute &, std::string *reason) const
The prim owning the output is guaranteed to be of the type this behavior was registered with.
ConnectableNodeTypes
An enum describing the types of connectable nodes which will govern what connectibility rule is invok...
This class encapsulates a shader or node-graph input, which is a connectable attribute representing a...
Definition: input.h:48
USDSHADE_API bool _CanConnectInputToSource(const UsdShadeInput &, const UsdAttribute &, std::string *reason, ConnectableNodeTypes nodeType=ConnectableNodeTypes::BasicNodes) const
Helper function to separate and share special connectivity logic for specialized, NodeGraph-derived n...
virtual USDSHADE_API bool IsContainer() const final
The function must be thread-safe.
virtual USDSHADE_API bool RequiresEncapsulation() const final
The function must be thread-safe.
TfType represents a dynamic runtime type.
Definition: type.h:64
virtual USDSHADE_API bool CanConnectInputToSource(const UsdShadeInput &, const UsdAttribute &, std::string *reason) const
The prim owning the input is guaranteed to be of the type this behavior was registered with.
This class encapsulates a shader or node-graph output, which is a connectable attribute representing ...
Definition: output.h:47
UsdShadeConnectableAPIBehavior defines the compatibilty and behavior UsdShadeConnectableAPIof when ap...