24 #ifndef PXR_USD_SDF_PY_LIST_EDITOR_PROXY_H 25 #define PXR_USD_SDF_PY_LIST_EDITOR_PROXY_H 31 #include "pxr/usd/sdf/listOp.h" 37 #include "pxr/base/tf/pyResultConversions.h" 38 #include "pxr/base/tf/pyLock.h" 41 #include <boost/python.hpp> 43 PXR_NAMESPACE_OPEN_SCOPE
45 class Sdf_PyListEditorUtils {
47 template <
class T,
class V>
50 ApplyHelper(
const T& owner,
const boost::python::object& callback) :
57 boost::optional<V> operator()(SdfListOpType op,
const V& value)
59 using namespace boost::python;
62 object result = _callback(_owner, value, op);
66 return boost::optional<V>(e());
70 "incorrect return type.");
73 return boost::optional<V>();
84 ModifyHelper(
const boost::python::object& callback) :
90 boost::optional<V> operator()(
const V& value)
92 using namespace boost::python;
95 object result = _callback(value);
99 return boost::optional<V>(e());
103 "incorrect return type.");
106 return boost::optional<V>();
115 class SdfPyWrapListEditorProxy {
118 typedef typename Type::TypePolicy TypePolicy;
119 typedef typename Type::value_type value_type;
120 typedef typename Type::value_vector_type value_vector_type;
121 typedef typename Type::ApplyCallback ApplyCallback;
122 typedef typename Type::ModifyCallback ModifyCallback;
123 typedef SdfPyWrapListEditorProxy<Type> This;
126 SdfPyWrapListEditorProxy()
128 TfPyWrapOnce<Type>(&This::_Wrap);
129 SdfPyWrapListProxy<ListProxy>();
135 using namespace boost::python;
137 class_<Type>(_GetName().c_str(), no_init)
138 .def(
"__str__", &This::_GetStr)
139 .add_property(
"isExpired", &Type::IsExpired)
140 .add_property(
"explicitItems",
141 &Type::GetExplicitItems,
142 &This::_SetExplicitProxy)
143 .add_property(
"addedItems",
144 &Type::GetAddedItems,
145 &This::_SetAddedProxy)
146 .add_property(
"prependedItems",
147 &Type::GetPrependedItems,
148 &This::_SetPrependedProxy)
149 .add_property(
"appendedItems",
150 &Type::GetAppendedItems,
151 &This::_SetAppendedProxy)
152 .add_property(
"deletedItems",
153 &Type::GetDeletedItems,
154 &This::_SetDeletedProxy)
155 .add_property(
"orderedItems",
156 &Type::GetOrderedItems,
157 &This::_SetOrderedProxy)
158 .def(
"GetAddedOrExplicitItems", &Type::GetAddedOrExplicitItems,
159 return_value_policy<TfPySequenceToTuple>())
160 .add_property(
"isExplicit", &Type::IsExplicit)
161 .add_property(
"isOrderedOnly", &Type::IsOrderedOnly)
162 .def(
"ApplyEditsToList",
163 &This::_ApplyEditsToList,
164 return_value_policy<TfPySequenceToList>())
165 .def(
"ApplyEditsToList",
166 &This::_ApplyEditsToList2,
167 return_value_policy<TfPySequenceToList>())
169 .def(
"CopyItems", &Type::CopyItems)
170 .def(
"ClearEdits", &Type::ClearEdits)
171 .def(
"ClearEditsAndMakeExplicit", &Type::ClearEditsAndMakeExplicit)
172 .def(
"ContainsItemEdit", &Type::ContainsItemEdit,
173 (arg(
"item"), arg(
"onlyAddOrExplicit")=
false))
174 .def(
"RemoveItemEdits", &Type::RemoveItemEdits)
175 .def(
"ReplaceItemEdits", &Type::ReplaceItemEdits)
176 .def(
"ModifyItemEdits", &This::_ModifyEdits)
179 .def(
"Add", &Type::Add)
180 .def(
"Prepend", &Type::Prepend)
181 .def(
"Append", &Type::Append)
182 .def(
"Remove", &Type::Remove)
183 .def(
"Erase", &Type::Erase)
187 static std::string _GetName()
189 std::string name =
"ListEditorProxy_" +
190 ArchGetDemangled<TypePolicy>();
199 static std::string _GetStr(
const Type& x)
201 return x._listEditor ?
202 boost::lexical_cast<std::string>(*x._listEditor) : std::string();
205 static void _SetExplicitProxy(Type& x,
const value_vector_type& v)
207 x.GetExplicitItems() = v;
210 static void _SetAddedProxy(Type& x,
const value_vector_type& v)
212 x.GetAddedItems() = v;
215 static void _SetPrependedProxy(Type& x,
const value_vector_type& v)
217 x.GetPrependedItems() = v;
220 static void _SetAppendedProxy(Type& x,
const value_vector_type& v)
222 x.GetAppendedItems() = v;
225 static void _SetDeletedProxy(Type& x,
const value_vector_type& v)
227 x.GetDeletedItems() = v;
230 static void _SetOrderedProxy(Type& x,
const value_vector_type& v)
232 x.GetOrderedItems() = v;
235 static value_vector_type _ApplyEditsToList(
const Type& x,
236 const value_vector_type& v)
238 value_vector_type tmp = v;
239 x.ApplyEditsToList(&tmp);
243 static value_vector_type _ApplyEditsToList2(
const Type& x,
244 const value_vector_type& v,
245 const boost::python::object& cb)
247 value_vector_type tmp = v;
248 x.ApplyEditsToList(&tmp,
249 Sdf_PyListEditorUtils::ApplyHelper<Type, value_type>(x, cb));
253 static void _ModifyEdits(Type& x,
const boost::python::object& cb)
255 x.ModifyItemEdits(Sdf_PyListEditorUtils::ModifyHelper<value_type>(cb));
259 PXR_NAMESPACE_CLOSE_SCOPE
261 #endif // PXR_USD_SDF_PY_LIST_EDITOR_PROXY_H
Utilities for calling python callables.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definitions of basic string utilities in tf.
Low-level utilities for informing users of various internal and external diagnostic conditions.
Miscellaneous Utilities for dealing with script.
Demangle C++ typenames generated by the typeid() facility.
Convenience class for accessing the Python Global Interpreter Lock.
Represents a single list of list editing operations.
Provide a way to call a Python callable.
TF_API bool TfPyIsNone(boost::python::object const &obj)
Return true iff obj is None.
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)
Replaces all occurrences of string from with to in source.