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/boundable.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/pyContainerConversions.h"
31 #include "pxr/base/tf/pyResultConversions.h"
32 #include "pxr/base/tf/pyUtils.h"
33 #include "pxr/base/tf/wrapTypeHelpers.h"
34 
35 #include <boost/python.hpp>
36 
37 #include <string>
38 
39 using namespace boost::python;
40 
41 PXR_NAMESPACE_USING_DIRECTIVE
42 
43 namespace {
44 
45 #define WRAP_CUSTOM                                                     \
46     template <class Cls> static void _CustomWrapCode(Cls &_class)
47 
48 // fwd decl.
49 WRAP_CUSTOM;
50 
51 
52 static UsdAttribute
_CreateExtentAttr(UsdGeomBoundable & self,object defaultVal,bool writeSparsely)53 _CreateExtentAttr(UsdGeomBoundable &self,
54                                       object defaultVal, bool writeSparsely) {
55     return self.CreateExtentAttr(
56         UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float3Array), writeSparsely);
57 }
58 
59 static std::string
_Repr(const UsdGeomBoundable & self)60 _Repr(const UsdGeomBoundable &self)
61 {
62     std::string primRepr = TfPyRepr(self.GetPrim());
63     return TfStringPrintf(
64         "UsdGeom.Boundable(%s)",
65         primRepr.c_str());
66 }
67 
68 } // anonymous namespace
69 
wrapUsdGeomBoundable()70 void wrapUsdGeomBoundable()
71 {
72     typedef UsdGeomBoundable This;
73 
74     class_<This, bases<UsdGeomXformable> >
75         cls("Boundable");
76 
77     cls
78         .def(init<UsdPrim>(arg("prim")))
79         .def(init<UsdSchemaBase const&>(arg("schemaObj")))
80         .def(TfTypePythonClass())
81 
82         .def("Get", &This::Get, (arg("stage"), arg("path")))
83         .staticmethod("Get")
84 
85         .def("GetSchemaAttributeNames",
86              &This::GetSchemaAttributeNames,
87              arg("includeInherited")=true,
88              return_value_policy<TfPySequenceToList>())
89         .staticmethod("GetSchemaAttributeNames")
90 
91         .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find<This>,
92              return_value_policy<return_by_value>())
93         .staticmethod("_GetStaticTfType")
94 
95         .def(!self)
96 
97 
98         .def("GetExtentAttr",
99              &This::GetExtentAttr)
100         .def("CreateExtentAttr",
101              &_CreateExtentAttr,
102              (arg("defaultValue")=object(),
103               arg("writeSparsely")=false))
104 
105         .def("__repr__", ::_Repr)
106     ;
107 
108     _CustomWrapCode(cls);
109 }
110 
111 // ===================================================================== //
112 // Feel free to add custom code below this line, it will be preserved by
113 // the code generator.  The entry point for your custom code should look
114 // minimally like the following:
115 //
116 // WRAP_CUSTOM {
117 //     _class
118 //         .def("MyCustomMethod", ...)
119 //     ;
120 // }
121 //
122 // Of course any other ancillary or support code may be provided.
123 //
124 // Just remember to wrap code in the appropriate delimiters:
125 // 'namespace {', '}'.
126 //
127 // ===================================================================== //
128 // --(BEGIN CUSTOM CODE)--
129 
130 namespace {
131 
132 static object
_ComputeExtentFromPlugins(const UsdGeomBoundable & boundable,const UsdTimeCode & time)133 _ComputeExtentFromPlugins(
134     const UsdGeomBoundable &boundable,
135     const UsdTimeCode &time)
136 {
137     VtVec3fArray extent;
138     if (!UsdGeomBoundable::ComputeExtentFromPlugins(boundable,
139                                                     time,
140                                                     &extent)) {
141         return object();
142     }
143     return object(extent);
144 }
145 
146 static object
_ComputeExtentFromPluginsWithTransform(const UsdGeomBoundable & boundable,const UsdTimeCode & time,const GfMatrix4d & transform)147 _ComputeExtentFromPluginsWithTransform(
148     const UsdGeomBoundable &boundable,
149     const UsdTimeCode &time,
150     const GfMatrix4d &transform)
151 {
152     VtVec3fArray extent;
153     if (!UsdGeomBoundable::ComputeExtentFromPlugins(boundable,
154                                                     time,
155                                                     transform,
156                                                     &extent)) {
157         return object();
158     }
159     return object(extent);
160 }
161 
162 WRAP_CUSTOM {
163     _class
164         .def("ComputeExtentFromPlugins", &_ComputeExtentFromPlugins,
165              (arg("boundable"), arg("time")))
166         .def("ComputeExtentFromPlugins", &_ComputeExtentFromPluginsWithTransform,
167              (arg("boundable"), arg("time"), arg("transform")))
168         .staticmethod("ComputeExtentFromPlugins")
169     ;
170 }
171 
172 } // anonymous namespace
173