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