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/usdRi/statementsAPI.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 std::string
_Repr(const UsdRiStatementsAPI & self)54 _Repr(const UsdRiStatementsAPI &self)
55 {
56 std::string primRepr = TfPyRepr(self.GetPrim());
57 return TfStringPrintf(
58 "UsdRi.StatementsAPI(%s)",
59 primRepr.c_str());
60 }
61
62 struct UsdRiStatementsAPI_CanApplyResult :
63 public TfPyAnnotatedBoolResult<std::string>
64 {
UsdRiStatementsAPI_CanApplyResult__anon803f46620111::UsdRiStatementsAPI_CanApplyResult65 UsdRiStatementsAPI_CanApplyResult(bool val, std::string const &msg) :
66 TfPyAnnotatedBoolResult<std::string>(val, msg) {}
67 };
68
69 static UsdRiStatementsAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)70 _WrapCanApply(const UsdPrim& prim)
71 {
72 std::string whyNot;
73 bool result = UsdRiStatementsAPI::CanApply(prim, &whyNot);
74 return UsdRiStatementsAPI_CanApplyResult(result, whyNot);
75 }
76
77 } // anonymous namespace
78
wrapUsdRiStatementsAPI()79 void wrapUsdRiStatementsAPI()
80 {
81 typedef UsdRiStatementsAPI This;
82
83 UsdRiStatementsAPI_CanApplyResult::Wrap<UsdRiStatementsAPI_CanApplyResult>(
84 "_CanApplyResult", "whyNot");
85
86 class_<This, bases<UsdAPISchemaBase> >
87 cls("StatementsAPI");
88
89 cls
90 .def(init<UsdPrim>(arg("prim")))
91 .def(init<UsdSchemaBase const&>(arg("schemaObj")))
92 .def(TfTypePythonClass())
93
94 .def("Get", &This::Get, (arg("stage"), arg("path")))
95 .staticmethod("Get")
96
97 .def("CanApply", &_WrapCanApply, (arg("prim")))
98 .staticmethod("CanApply")
99
100 .def("Apply", &This::Apply, (arg("prim")))
101 .staticmethod("Apply")
102
103 .def("GetSchemaAttributeNames",
104 &This::GetSchemaAttributeNames,
105 arg("includeInherited")=true,
106 return_value_policy<TfPySequenceToList>())
107 .staticmethod("GetSchemaAttributeNames")
108
109 .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find<This>,
110 return_value_policy<return_by_value>())
111 .staticmethod("_GetStaticTfType")
112
113 .def(!self)
114
115
116 .def("__repr__", ::_Repr)
117 ;
118
119 _CustomWrapCode(cls);
120 }
121
122 // ===================================================================== //
123 // Feel free to add custom code below this line, it will be preserved by
124 // the code generator. The entry point for your custom code should look
125 // minimally like the following:
126 //
127 // WRAP_CUSTOM {
128 // _class
129 // .def("MyCustomMethod", ...)
130 // ;
131 // }
132 //
133 // Of course any other ancillary or support code may be provided.
134 //
135 // Just remember to wrap code in the appropriate delimiters:
136 // 'namespace {', '}'.
137 //
138 // ===================================================================== //
139 // --(BEGIN CUSTOM CODE)--
140
141 namespace {
142
143 static SdfPathVector
_GetModelCoordinateSystems(const UsdRiStatementsAPI & self)144 _GetModelCoordinateSystems(const UsdRiStatementsAPI &self)
145 {
146 SdfPathVector result;
147 self.GetModelCoordinateSystems(&result);
148 return result;
149 }
150
151 static SdfPathVector
_GetModelScopedCoordinateSystems(const UsdRiStatementsAPI & self)152 _GetModelScopedCoordinateSystems(const UsdRiStatementsAPI &self)
153 {
154 SdfPathVector result;
155 self.GetModelScopedCoordinateSystems(&result);
156 return result;
157 }
158
159 WRAP_CUSTOM {
160 _class
161 .def("CreateRiAttribute",
162 (UsdAttribute (UsdRiStatementsAPI::*)(
163 const TfToken &, const TfType &, const std::string &))
164 &UsdRiStatementsAPI::CreateRiAttribute,
165 (arg("name"), arg("tfType"), arg("nameSpace")="user"))
166 .def("CreateRiAttribute",
167 (UsdAttribute (UsdRiStatementsAPI::*)(
168 const TfToken &, const std::string &, const std::string &))
169 &UsdRiStatementsAPI::CreateRiAttribute,
170 (arg("name"), arg("riType"), arg("nameSpace")="user"))
171 .def("GetRiAttribute",
172 &UsdRiStatementsAPI::GetRiAttribute,
173 (arg("name"), arg("nameSpace")="user"))
174 .def("GetRiAttributes", &UsdRiStatementsAPI::GetRiAttributes,
175 (arg("nameSpace")=""),
176 return_value_policy<TfPySequenceToList>())
177 .def("GetRiAttributeName",
178 UsdRiStatementsAPI::GetRiAttributeName, (arg("prop")))
179 .staticmethod("GetRiAttributeName")
180 .def("GetRiAttributeNameSpace",
181 &UsdRiStatementsAPI::GetRiAttributeNameSpace, (arg("prop")))
182 .staticmethod("GetRiAttributeNameSpace")
183 .def("IsRiAttribute", &UsdRiStatementsAPI::IsRiAttribute, (arg("prop")))
184 .staticmethod("IsRiAttribute")
185 .def("MakeRiAttributePropertyName",
186 &UsdRiStatementsAPI::MakeRiAttributePropertyName, (arg("attrName")))
187 .staticmethod("MakeRiAttributePropertyName")
188 .def("SetCoordinateSystem", &UsdRiStatementsAPI::SetCoordinateSystem,
189 (arg("coordSysName")))
190 .def("GetCoordinateSystem", &UsdRiStatementsAPI::GetCoordinateSystem)
191 .def("HasCoordinateSystem", &UsdRiStatementsAPI::HasCoordinateSystem)
192
193 .def("SetScopedCoordinateSystem",
194 &UsdRiStatementsAPI::SetScopedCoordinateSystem,
195 (arg("coordSysName")))
196 .def("GetScopedCoordinateSystem",
197 &UsdRiStatementsAPI::GetScopedCoordinateSystem)
198 .def("HasScopedCoordinateSystem",
199 &UsdRiStatementsAPI::HasScopedCoordinateSystem)
200
201 .def("GetModelCoordinateSystems", _GetModelCoordinateSystems,
202 return_value_policy<TfPySequenceToList>())
203 .def("GetModelScopedCoordinateSystems", _GetModelScopedCoordinateSystems,
204 return_value_policy<TfPySequenceToList>())
205 ;
206 }
207
208 } // anonymous namespace
209