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/massAPI.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
_CreateMassAttr(UsdPhysicsMassAPI & self,object defaultVal,bool writeSparsely)54 _CreateMassAttr(UsdPhysicsMassAPI &self,
55 object defaultVal, bool writeSparsely) {
56 return self.CreateMassAttr(
57 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely);
58 }
59
60 static UsdAttribute
_CreateDensityAttr(UsdPhysicsMassAPI & self,object defaultVal,bool writeSparsely)61 _CreateDensityAttr(UsdPhysicsMassAPI &self,
62 object defaultVal, bool writeSparsely) {
63 return self.CreateDensityAttr(
64 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely);
65 }
66
67 static UsdAttribute
_CreateCenterOfMassAttr(UsdPhysicsMassAPI & self,object defaultVal,bool writeSparsely)68 _CreateCenterOfMassAttr(UsdPhysicsMassAPI &self,
69 object defaultVal, bool writeSparsely) {
70 return self.CreateCenterOfMassAttr(
71 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Point3f), writeSparsely);
72 }
73
74 static UsdAttribute
_CreateDiagonalInertiaAttr(UsdPhysicsMassAPI & self,object defaultVal,bool writeSparsely)75 _CreateDiagonalInertiaAttr(UsdPhysicsMassAPI &self,
76 object defaultVal, bool writeSparsely) {
77 return self.CreateDiagonalInertiaAttr(
78 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float3), writeSparsely);
79 }
80
81 static UsdAttribute
_CreatePrincipalAxesAttr(UsdPhysicsMassAPI & self,object defaultVal,bool writeSparsely)82 _CreatePrincipalAxesAttr(UsdPhysicsMassAPI &self,
83 object defaultVal, bool writeSparsely) {
84 return self.CreatePrincipalAxesAttr(
85 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Quatf), writeSparsely);
86 }
87
88 static std::string
_Repr(const UsdPhysicsMassAPI & self)89 _Repr(const UsdPhysicsMassAPI &self)
90 {
91 std::string primRepr = TfPyRepr(self.GetPrim());
92 return TfStringPrintf(
93 "UsdPhysics.MassAPI(%s)",
94 primRepr.c_str());
95 }
96
97 struct UsdPhysicsMassAPI_CanApplyResult :
98 public TfPyAnnotatedBoolResult<std::string>
99 {
UsdPhysicsMassAPI_CanApplyResult__anon74b241d60111::UsdPhysicsMassAPI_CanApplyResult100 UsdPhysicsMassAPI_CanApplyResult(bool val, std::string const &msg) :
101 TfPyAnnotatedBoolResult<std::string>(val, msg) {}
102 };
103
104 static UsdPhysicsMassAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)105 _WrapCanApply(const UsdPrim& prim)
106 {
107 std::string whyNot;
108 bool result = UsdPhysicsMassAPI::CanApply(prim, &whyNot);
109 return UsdPhysicsMassAPI_CanApplyResult(result, whyNot);
110 }
111
112 } // anonymous namespace
113
wrapUsdPhysicsMassAPI()114 void wrapUsdPhysicsMassAPI()
115 {
116 typedef UsdPhysicsMassAPI This;
117
118 UsdPhysicsMassAPI_CanApplyResult::Wrap<UsdPhysicsMassAPI_CanApplyResult>(
119 "_CanApplyResult", "whyNot");
120
121 class_<This, bases<UsdAPISchemaBase> >
122 cls("MassAPI");
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("GetMassAttr",
152 &This::GetMassAttr)
153 .def("CreateMassAttr",
154 &_CreateMassAttr,
155 (arg("defaultValue")=object(),
156 arg("writeSparsely")=false))
157
158 .def("GetDensityAttr",
159 &This::GetDensityAttr)
160 .def("CreateDensityAttr",
161 &_CreateDensityAttr,
162 (arg("defaultValue")=object(),
163 arg("writeSparsely")=false))
164
165 .def("GetCenterOfMassAttr",
166 &This::GetCenterOfMassAttr)
167 .def("CreateCenterOfMassAttr",
168 &_CreateCenterOfMassAttr,
169 (arg("defaultValue")=object(),
170 arg("writeSparsely")=false))
171
172 .def("GetDiagonalInertiaAttr",
173 &This::GetDiagonalInertiaAttr)
174 .def("CreateDiagonalInertiaAttr",
175 &_CreateDiagonalInertiaAttr,
176 (arg("defaultValue")=object(),
177 arg("writeSparsely")=false))
178
179 .def("GetPrincipalAxesAttr",
180 &This::GetPrincipalAxesAttr)
181 .def("CreatePrincipalAxesAttr",
182 &_CreatePrincipalAxesAttr,
183 (arg("defaultValue")=object(),
184 arg("writeSparsely")=false))
185
186 .def("__repr__", ::_Repr)
187 ;
188
189 _CustomWrapCode(cls);
190 }
191
192 // ===================================================================== //
193 // Feel free to add custom code below this line, it will be preserved by
194 // the code generator. The entry point for your custom code should look
195 // minimally like the following:
196 //
197 // WRAP_CUSTOM {
198 // _class
199 // .def("MyCustomMethod", ...)
200 // ;
201 // }
202 //
203 // Of course any other ancillary or support code may be provided.
204 //
205 // Just remember to wrap code in the appropriate delimiters:
206 // 'namespace {', '}'.
207 //
208 // ===================================================================== //
209 // --(BEGIN CUSTOM CODE)--
210
211 namespace {
212
213 WRAP_CUSTOM {
214 }
215
216 }
217