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/sceneGraphPrimAPI.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
_CreateDisplayNameAttr(UsdUISceneGraphPrimAPI & self,object defaultVal,bool writeSparsely)54 _CreateDisplayNameAttr(UsdUISceneGraphPrimAPI &self,
55 object defaultVal, bool writeSparsely) {
56 return self.CreateDisplayNameAttr(
57 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
58 }
59
60 static UsdAttribute
_CreateDisplayGroupAttr(UsdUISceneGraphPrimAPI & self,object defaultVal,bool writeSparsely)61 _CreateDisplayGroupAttr(UsdUISceneGraphPrimAPI &self,
62 object defaultVal, bool writeSparsely) {
63 return self.CreateDisplayGroupAttr(
64 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
65 }
66
67 static std::string
_Repr(const UsdUISceneGraphPrimAPI & self)68 _Repr(const UsdUISceneGraphPrimAPI &self)
69 {
70 std::string primRepr = TfPyRepr(self.GetPrim());
71 return TfStringPrintf(
72 "UsdUI.SceneGraphPrimAPI(%s)",
73 primRepr.c_str());
74 }
75
76 struct UsdUISceneGraphPrimAPI_CanApplyResult :
77 public TfPyAnnotatedBoolResult<std::string>
78 {
UsdUISceneGraphPrimAPI_CanApplyResult__anone1f3c6f50111::UsdUISceneGraphPrimAPI_CanApplyResult79 UsdUISceneGraphPrimAPI_CanApplyResult(bool val, std::string const &msg) :
80 TfPyAnnotatedBoolResult<std::string>(val, msg) {}
81 };
82
83 static UsdUISceneGraphPrimAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)84 _WrapCanApply(const UsdPrim& prim)
85 {
86 std::string whyNot;
87 bool result = UsdUISceneGraphPrimAPI::CanApply(prim, &whyNot);
88 return UsdUISceneGraphPrimAPI_CanApplyResult(result, whyNot);
89 }
90
91 } // anonymous namespace
92
wrapUsdUISceneGraphPrimAPI()93 void wrapUsdUISceneGraphPrimAPI()
94 {
95 typedef UsdUISceneGraphPrimAPI This;
96
97 UsdUISceneGraphPrimAPI_CanApplyResult::Wrap<UsdUISceneGraphPrimAPI_CanApplyResult>(
98 "_CanApplyResult", "whyNot");
99
100 class_<This, bases<UsdAPISchemaBase> >
101 cls("SceneGraphPrimAPI");
102
103 cls
104 .def(init<UsdPrim>(arg("prim")))
105 .def(init<UsdSchemaBase const&>(arg("schemaObj")))
106 .def(TfTypePythonClass())
107
108 .def("Get", &This::Get, (arg("stage"), arg("path")))
109 .staticmethod("Get")
110
111 .def("CanApply", &_WrapCanApply, (arg("prim")))
112 .staticmethod("CanApply")
113
114 .def("Apply", &This::Apply, (arg("prim")))
115 .staticmethod("Apply")
116
117 .def("GetSchemaAttributeNames",
118 &This::GetSchemaAttributeNames,
119 arg("includeInherited")=true,
120 return_value_policy<TfPySequenceToList>())
121 .staticmethod("GetSchemaAttributeNames")
122
123 .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find<This>,
124 return_value_policy<return_by_value>())
125 .staticmethod("_GetStaticTfType")
126
127 .def(!self)
128
129
130 .def("GetDisplayNameAttr",
131 &This::GetDisplayNameAttr)
132 .def("CreateDisplayNameAttr",
133 &_CreateDisplayNameAttr,
134 (arg("defaultValue")=object(),
135 arg("writeSparsely")=false))
136
137 .def("GetDisplayGroupAttr",
138 &This::GetDisplayGroupAttr)
139 .def("CreateDisplayGroupAttr",
140 &_CreateDisplayGroupAttr,
141 (arg("defaultValue")=object(),
142 arg("writeSparsely")=false))
143
144 .def("__repr__", ::_Repr)
145 ;
146
147 _CustomWrapCode(cls);
148 }
149
150 // ===================================================================== //
151 // Feel free to add custom code below this line, it will be preserved by
152 // the code generator. The entry point for your custom code should look
153 // minimally like the following:
154 //
155 // WRAP_CUSTOM {
156 // _class
157 // .def("MyCustomMethod", ...)
158 // ;
159 // }
160 //
161 // Of course any other ancillary or support code may be provided.
162 //
163 // Just remember to wrap code in the appropriate delimiters:
164 // 'namespace {', '}'.
165 //
166 // ===================================================================== //
167 // --(BEGIN CUSTOM CODE)--
168
169 namespace {
170
171 WRAP_CUSTOM {
172 }
173
174 } // anonymous namespace
175