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/meshCollisionAPI.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
_CreateApproximationAttr(UsdPhysicsMeshCollisionAPI & self,object defaultVal,bool writeSparsely)54 _CreateApproximationAttr(UsdPhysicsMeshCollisionAPI &self,
55 object defaultVal, bool writeSparsely) {
56 return self.CreateApproximationAttr(
57 UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely);
58 }
59
60 static std::string
_Repr(const UsdPhysicsMeshCollisionAPI & self)61 _Repr(const UsdPhysicsMeshCollisionAPI &self)
62 {
63 std::string primRepr = TfPyRepr(self.GetPrim());
64 return TfStringPrintf(
65 "UsdPhysics.MeshCollisionAPI(%s)",
66 primRepr.c_str());
67 }
68
69 struct UsdPhysicsMeshCollisionAPI_CanApplyResult :
70 public TfPyAnnotatedBoolResult<std::string>
71 {
UsdPhysicsMeshCollisionAPI_CanApplyResult__anon7cb333bb0111::UsdPhysicsMeshCollisionAPI_CanApplyResult72 UsdPhysicsMeshCollisionAPI_CanApplyResult(bool val, std::string const &msg) :
73 TfPyAnnotatedBoolResult<std::string>(val, msg) {}
74 };
75
76 static UsdPhysicsMeshCollisionAPI_CanApplyResult
_WrapCanApply(const UsdPrim & prim)77 _WrapCanApply(const UsdPrim& prim)
78 {
79 std::string whyNot;
80 bool result = UsdPhysicsMeshCollisionAPI::CanApply(prim, &whyNot);
81 return UsdPhysicsMeshCollisionAPI_CanApplyResult(result, whyNot);
82 }
83
84 } // anonymous namespace
85
wrapUsdPhysicsMeshCollisionAPI()86 void wrapUsdPhysicsMeshCollisionAPI()
87 {
88 typedef UsdPhysicsMeshCollisionAPI This;
89
90 UsdPhysicsMeshCollisionAPI_CanApplyResult::Wrap<UsdPhysicsMeshCollisionAPI_CanApplyResult>(
91 "_CanApplyResult", "whyNot");
92
93 class_<This, bases<UsdAPISchemaBase> >
94 cls("MeshCollisionAPI");
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("GetApproximationAttr",
124 &This::GetApproximationAttr)
125 .def("CreateApproximationAttr",
126 &_CreateApproximationAttr,
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 }
159
160 }
161