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/usdPhysics/rigidBodyAPI.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
_CreateRigidBodyEnabledAttr(UsdPhysicsRigidBodyAPI & self,object defaultVal,bool writeSparsely)54 _CreateRigidBodyEnabledAttr(UsdPhysicsRigidBodyAPI &self,
55                                       object defaultVal, bool writeSparsely) {
56     return self.CreateRigidBodyEnabledAttr(
57         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
58 }
59 
60 static UsdAttribute
_CreateKinematicEnabledAttr(UsdPhysicsRigidBodyAPI & self,object defaultVal,bool writeSparsely)61 _CreateKinematicEnabledAttr(UsdPhysicsRigidBodyAPI &self,
62                                       object defaultVal, bool writeSparsely) {
63     return self.CreateKinematicEnabledAttr(
64         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
65 }
66 
67 static UsdAttribute
_CreateStartsAsleepAttr(UsdPhysicsRigidBodyAPI & self,object defaultVal,bool writeSparsely)68 _CreateStartsAsleepAttr(UsdPhysicsRigidBodyAPI &self,
69                                       object defaultVal, bool writeSparsely) {
70     return self.CreateStartsAsleepAttr(
71         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely);
72 }
73 
74 static UsdAttribute
_CreateVelocityAttr(UsdPhysicsRigidBodyAPI & self,object defaultVal,bool writeSparsely)75 _CreateVelocityAttr(UsdPhysicsRigidBodyAPI &self,
76                                       object defaultVal, bool writeSparsely) {
77     return self.CreateVelocityAttr(
78         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Vector3f), writeSparsely);
79 }
80 
81 static UsdAttribute
_CreateAngularVelocityAttr(UsdPhysicsRigidBodyAPI & self,object defaultVal,bool writeSparsely)82 _CreateAngularVelocityAttr(UsdPhysicsRigidBodyAPI &self,
83                                       object defaultVal, bool writeSparsely) {
84     return self.CreateAngularVelocityAttr(
85         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Vector3f), writeSparsely);
86 }
87 
88 static std::string
_Repr(const UsdPhysicsRigidBodyAPI & self)89 _Repr(const UsdPhysicsRigidBodyAPI &self)
90 {
91     std::string primRepr = TfPyRepr(self.GetPrim());
92     return TfStringPrintf(
93         "UsdPhysics.RigidBodyAPI(%s)",
94         primRepr.c_str());
95 }
96 
97 struct UsdPhysicsRigidBodyAPI_CanApplyResult :
98     public TfPyAnnotatedBoolResult<std::string>
99 {
UsdPhysicsRigidBodyAPI_CanApplyResult__anonb55a263f0111::UsdPhysicsRigidBodyAPI_CanApplyResult100     UsdPhysicsRigidBodyAPI_CanApplyResult(bool val, std::string const &msg) :
101         TfPyAnnotatedBoolResult<std::string>(val, msg) {}
102 };
103 
104 static UsdPhysicsRigidBodyAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)105 _WrapCanApply(const UsdPrim& prim)
106 {
107     std::string whyNot;
108     bool result = UsdPhysicsRigidBodyAPI::CanApply(prim, &whyNot);
109     return UsdPhysicsRigidBodyAPI_CanApplyResult(result, whyNot);
110 }
111 
112 } // anonymous namespace
113 
wrapUsdPhysicsRigidBodyAPI()114 void wrapUsdPhysicsRigidBodyAPI()
115 {
116     typedef UsdPhysicsRigidBodyAPI This;
117 
118     UsdPhysicsRigidBodyAPI_CanApplyResult::Wrap<UsdPhysicsRigidBodyAPI_CanApplyResult>(
119         "_CanApplyResult", "whyNot");
120 
121     class_<This, bases<UsdAPISchemaBase> >
122         cls("RigidBodyAPI");
123 
124     cls
125         .def(init<UsdPrim>(arg("prim")))
126         .def(init<UsdSchemaBase const&>(arg("schemaObj")))
127         .def(TfTypePythonClass())
128 
129         .def("Get", &This::Get, (arg("stage"), arg("path")))
130         .staticmethod("Get")
131 
132         .def("CanApply", &_WrapCanApply, (arg("prim")))
133         .staticmethod("CanApply")
134 
135         .def("Apply", &This::Apply, (arg("prim")))
136         .staticmethod("Apply")
137 
138         .def("GetSchemaAttributeNames",
139              &This::GetSchemaAttributeNames,
140              arg("includeInherited")=true,
141              return_value_policy<TfPySequenceToList>())
142         .staticmethod("GetSchemaAttributeNames")
143 
144         .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find<This>,
145              return_value_policy<return_by_value>())
146         .staticmethod("_GetStaticTfType")
147 
148         .def(!self)
149 
150 
151         .def("GetRigidBodyEnabledAttr",
152              &This::GetRigidBodyEnabledAttr)
153         .def("CreateRigidBodyEnabledAttr",
154              &_CreateRigidBodyEnabledAttr,
155              (arg("defaultValue")=object(),
156               arg("writeSparsely")=false))
157 
158         .def("GetKinematicEnabledAttr",
159              &This::GetKinematicEnabledAttr)
160         .def("CreateKinematicEnabledAttr",
161              &_CreateKinematicEnabledAttr,
162              (arg("defaultValue")=object(),
163               arg("writeSparsely")=false))
164 
165         .def("GetStartsAsleepAttr",
166              &This::GetStartsAsleepAttr)
167         .def("CreateStartsAsleepAttr",
168              &_CreateStartsAsleepAttr,
169              (arg("defaultValue")=object(),
170               arg("writeSparsely")=false))
171 
172         .def("GetVelocityAttr",
173              &This::GetVelocityAttr)
174         .def("CreateVelocityAttr",
175              &_CreateVelocityAttr,
176              (arg("defaultValue")=object(),
177               arg("writeSparsely")=false))
178 
179         .def("GetAngularVelocityAttr",
180              &This::GetAngularVelocityAttr)
181         .def("CreateAngularVelocityAttr",
182              &_CreateAngularVelocityAttr,
183              (arg("defaultValue")=object(),
184               arg("writeSparsely")=false))
185 
186 
187         .def("GetSimulationOwnerRel",
188              &This::GetSimulationOwnerRel)
189         .def("CreateSimulationOwnerRel",
190              &This::CreateSimulationOwnerRel)
191         .def("__repr__", ::_Repr)
192     ;
193 
194     _CustomWrapCode(cls);
195 }
196 
197 // ===================================================================== //
198 // Feel free to add custom code below this line, it will be preserved by
199 // the code generator.  The entry point for your custom code should look
200 // minimally like the following:
201 //
202 // WRAP_CUSTOM {
203 //     _class
204 //         .def("MyCustomMethod", ...)
205 //     ;
206 // }
207 //
208 // Of course any other ancillary or support code may be provided.
209 //
210 // Just remember to wrap code in the appropriate delimiters:
211 // 'namespace {', '}'.
212 //
213 // ===================================================================== //
214 // --(BEGIN CUSTOM CODE)--
215 
216 namespace {
217 
218 WRAP_CUSTOM {
219 }
220 
221 }
222