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/splineAPI.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 UsdRiSplineAPI & self)54 _Repr(const UsdRiSplineAPI &self)
55 {
56     std::string primRepr = TfPyRepr(self.GetPrim());
57     return TfStringPrintf(
58         "UsdRi.SplineAPI(%s)",
59         primRepr.c_str());
60 }
61 
62 struct UsdRiSplineAPI_CanApplyResult :
63     public TfPyAnnotatedBoolResult<std::string>
64 {
UsdRiSplineAPI_CanApplyResult__anon265445650111::UsdRiSplineAPI_CanApplyResult65     UsdRiSplineAPI_CanApplyResult(bool val, std::string const &msg) :
66         TfPyAnnotatedBoolResult<std::string>(val, msg) {}
67 };
68 
69 static UsdRiSplineAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)70 _WrapCanApply(const UsdPrim& prim)
71 {
72     std::string whyNot;
73     bool result = UsdRiSplineAPI::CanApply(prim, &whyNot);
74     return UsdRiSplineAPI_CanApplyResult(result, whyNot);
75 }
76 
77 } // anonymous namespace
78 
wrapUsdRiSplineAPI()79 void wrapUsdRiSplineAPI()
80 {
81     typedef UsdRiSplineAPI This;
82 
83     UsdRiSplineAPI_CanApplyResult::Wrap<UsdRiSplineAPI_CanApplyResult>(
84         "_CanApplyResult", "whyNot");
85 
86     class_<This, bases<UsdAPISchemaBase> >
87         cls("SplineAPI");
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 UsdAttribute
_CreateInterpolationAttr(UsdRiSplineAPI & self,object defaultVal,bool writeSparsely)144 _CreateInterpolationAttr(UsdRiSplineAPI &self,
145                                       object defaultVal, bool writeSparsely) {
146     return self.CreateInterpolationAttr(
147         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
148 }
149 
150 static UsdAttribute
_CreatePositionsAttr(UsdRiSplineAPI & self,object defaultVal,bool writeSparsely)151 _CreatePositionsAttr(UsdRiSplineAPI &self,
152                                       object defaultVal, bool writeSparsely) {
153     return self.CreatePositionsAttr(
154         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->FloatArray), writeSparsely);
155 }
156 
157 static UsdAttribute
_CreateValuesAttr(UsdRiSplineAPI & self,object defaultVal,bool writeSparsely)158 _CreateValuesAttr(UsdRiSplineAPI &self,
159                                       object defaultVal, bool writeSparsely) {
160     return self.CreateValuesAttr(
161         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->FloatArray), writeSparsely);
162 }
163 
164 static boost::python::tuple
_Validate(const UsdRiSplineAPI & self)165 _Validate(const UsdRiSplineAPI &self) {
166     std::string reason;
167     bool result = self.Validate(&reason);
168     return boost::python::make_tuple(result, reason);
169 }
170 
171 
172 WRAP_CUSTOM {
173     typedef UsdRiSplineAPI This;
174     _class
175         .def(init<const UsdPrim &, const TfToken &,
176              const SdfValueTypeName &, bool>())
177         .def(init<const UsdSchemaBase &, const TfToken &,
178              const SdfValueTypeName &, bool>())
179 
180         .def("GetValuesTypeName", &This::GetValuesTypeName)
181 
182         .def("GetInterpolationAttr",
183              &This::GetInterpolationAttr)
184         .def("CreateInterpolationAttr",
185              &_CreateInterpolationAttr,
186              (arg("defaultValue")=object(),
187               arg("writeSparsely")=false))
188         .def("GetPositionsAttr",
189              &This::GetPositionsAttr)
190         .def("CreatePositionsAttr",
191              &_CreatePositionsAttr,
192              (arg("defaultValue")=object(),
193               arg("writeSparsely")=false))
194         .def("GetValuesAttr",
195              &This::GetValuesAttr)
196         .def("CreateValuesAttr",
197              &_CreateValuesAttr,
198              (arg("defaultValue")=object(),
199               arg("writeSparsely")=false))
200 
201         .def("Validate", &_Validate)
202         ;
203 }
204 
205 }
206