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/schemaBase.h"
26
27 #include "pxr/usd/sdf/primSpec.h"
28
29 #include "pxr/usd/usd/pyConversions.h"
30 #include "pxr/base/tf/pyAnnotatedBoolResult.h"
31 #include "pxr/base/tf/pyContainerConversions.h"
32 #include "pxr/base/tf/pyResultConversions.h"
33 #include "pxr/base/tf/pyUtils.h"
34 #include "pxr/base/tf/wrapTypeHelpers.h"
35
36 #include <boost/python.hpp>
37
38 #include <string>
39
40 using namespace boost::python;
41
42 PXR_NAMESPACE_USING_DIRECTIVE
43
44 namespace {
45
46 #define WRAP_CUSTOM \
47 template <class Cls> static void _CustomWrapCode(Cls &_class)
48
49 // fwd decl.
50 WRAP_CUSTOM;
51
52
53 static UsdAttribute
_CreatePosAttr(UsdUINodeGraphNodeAPI & self,object defaultVal,bool writeSparsely)54 _CreatePosAttr(UsdUINodeGraphNodeAPI &self,
55 object defaultVal, bool writeSparsely) {
56 return self.CreatePosAttr(
57 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float2), writeSparsely);
58 }
59
60 static UsdAttribute
_CreateStackingOrderAttr(UsdUINodeGraphNodeAPI & self,object defaultVal,bool writeSparsely)61 _CreateStackingOrderAttr(UsdUINodeGraphNodeAPI &self,
62 object defaultVal, bool writeSparsely) {
63 return self.CreateStackingOrderAttr(
64 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Int), writeSparsely);
65 }
66
67 static UsdAttribute
_CreateDisplayColorAttr(UsdUINodeGraphNodeAPI & self,object defaultVal,bool writeSparsely)68 _CreateDisplayColorAttr(UsdUINodeGraphNodeAPI &self,
69 object defaultVal, bool writeSparsely) {
70 return self.CreateDisplayColorAttr(
71 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Color3f), writeSparsely);
72 }
73
74 static UsdAttribute
_CreateIconAttr(UsdUINodeGraphNodeAPI & self,object defaultVal,bool writeSparsely)75 _CreateIconAttr(UsdUINodeGraphNodeAPI &self,
76 object defaultVal, bool writeSparsely) {
77 return self.CreateIconAttr(
78 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Asset), writeSparsely);
79 }
80
81 static UsdAttribute
_CreateExpansionStateAttr(UsdUINodeGraphNodeAPI & self,object defaultVal,bool writeSparsely)82 _CreateExpansionStateAttr(UsdUINodeGraphNodeAPI &self,
83 object defaultVal, bool writeSparsely) {
84 return self.CreateExpansionStateAttr(
85 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
86 }
87
88 static UsdAttribute
_CreateSizeAttr(UsdUINodeGraphNodeAPI & self,object defaultVal,bool writeSparsely)89 _CreateSizeAttr(UsdUINodeGraphNodeAPI &self,
90 object defaultVal, bool writeSparsely) {
91 return self.CreateSizeAttr(
92 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float2), writeSparsely);
93 }
94
95 static std::string
_Repr(const UsdUINodeGraphNodeAPI & self)96 _Repr(const UsdUINodeGraphNodeAPI &self)
97 {
98 std::string primRepr = TfPyRepr(self.GetPrim());
99 return TfStringPrintf(
100 "UsdUI.NodeGraphNodeAPI(%s)",
101 primRepr.c_str());
102 }
103
104 struct UsdUINodeGraphNodeAPI_CanApplyResult :
105 public TfPyAnnotatedBoolResult<std::string>
106 {
UsdUINodeGraphNodeAPI_CanApplyResult__anon5b4a2a3b0111::UsdUINodeGraphNodeAPI_CanApplyResult107 UsdUINodeGraphNodeAPI_CanApplyResult(bool val, std::string const &msg) :
108 TfPyAnnotatedBoolResult<std::string>(val, msg) {}
109 };
110
111 static UsdUINodeGraphNodeAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)112 _WrapCanApply(const UsdPrim& prim)
113 {
114 std::string whyNot;
115 bool result = UsdUINodeGraphNodeAPI::CanApply(prim, &whyNot);
116 return UsdUINodeGraphNodeAPI_CanApplyResult(result, whyNot);
117 }
118
119 } // anonymous namespace
120
wrapUsdUINodeGraphNodeAPI()121 void wrapUsdUINodeGraphNodeAPI()
122 {
123 typedef UsdUINodeGraphNodeAPI This;
124
125 UsdUINodeGraphNodeAPI_CanApplyResult::Wrap<UsdUINodeGraphNodeAPI_CanApplyResult>(
126 "_CanApplyResult", "whyNot");
127
128 class_<This, bases<UsdAPISchemaBase> >
129 cls("NodeGraphNodeAPI");
130
131 cls
132 .def(init<UsdPrim>(arg("prim")))
133 .def(init<UsdSchemaBase const&>(arg("schemaObj")))
134 .def(TfTypePythonClass())
135
136 .def("Get", &This::Get, (arg("stage"), arg("path")))
137 .staticmethod("Get")
138
139 .def("CanApply", &_WrapCanApply, (arg("prim")))
140 .staticmethod("CanApply")
141
142 .def("Apply", &This::Apply, (arg("prim")))
143 .staticmethod("Apply")
144
145 .def("GetSchemaAttributeNames",
146 &This::GetSchemaAttributeNames,
147 arg("includeInherited")=true,
148 return_value_policy<TfPySequenceToList>())
149 .staticmethod("GetSchemaAttributeNames")
150
151 .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find<This>,
152 return_value_policy<return_by_value>())
153 .staticmethod("_GetStaticTfType")
154
155 .def(!self)
156
157
158 .def("GetPosAttr",
159 &This::GetPosAttr)
160 .def("CreatePosAttr",
161 &_CreatePosAttr,
162 (arg("defaultValue")=object(),
163 arg("writeSparsely")=false))
164
165 .def("GetStackingOrderAttr",
166 &This::GetStackingOrderAttr)
167 .def("CreateStackingOrderAttr",
168 &_CreateStackingOrderAttr,
169 (arg("defaultValue")=object(),
170 arg("writeSparsely")=false))
171
172 .def("GetDisplayColorAttr",
173 &This::GetDisplayColorAttr)
174 .def("CreateDisplayColorAttr",
175 &_CreateDisplayColorAttr,
176 (arg("defaultValue")=object(),
177 arg("writeSparsely")=false))
178
179 .def("GetIconAttr",
180 &This::GetIconAttr)
181 .def("CreateIconAttr",
182 &_CreateIconAttr,
183 (arg("defaultValue")=object(),
184 arg("writeSparsely")=false))
185
186 .def("GetExpansionStateAttr",
187 &This::GetExpansionStateAttr)
188 .def("CreateExpansionStateAttr",
189 &_CreateExpansionStateAttr,
190 (arg("defaultValue")=object(),
191 arg("writeSparsely")=false))
192
193 .def("GetSizeAttr",
194 &This::GetSizeAttr)
195 .def("CreateSizeAttr",
196 &_CreateSizeAttr,
197 (arg("defaultValue")=object(),
198 arg("writeSparsely")=false))
199
200 .def("__repr__", ::_Repr)
201 ;
202
203 _CustomWrapCode(cls);
204 }
205
206 // ===================================================================== //
207 // Feel free to add custom code below this line, it will be preserved by
208 // the code generator. The entry point for your custom code should look
209 // minimally like the following:
210 //
211 // WRAP_CUSTOM {
212 // _class
213 // .def("MyCustomMethod", ...)
214 // ;
215 // }
216 //
217 // Of course any other ancillary or support code may be provided.
218 //
219 // Just remember to wrap code in the appropriate delimiters:
220 // 'namespace {', '}'.
221 //
222 // ===================================================================== //
223 // --(BEGIN CUSTOM CODE)--
224
225 namespace {
226
227 WRAP_CUSTOM {
228 }
229
230 } // anonymous namespace
231