7#ifndef PXR_USD_SDF_PY_LIST_EDITOR_PROXY_H
8#define PXR_USD_SDF_PY_LIST_EDITOR_PROXY_H
14#include "pxr/usd/sdf/listOp.h"
20#include "pxr/base/tf/pyResultConversions.h"
21#include "pxr/base/tf/pyLock.h"
24#include "pxr/external/boost/python.hpp"
26PXR_NAMESPACE_OPEN_SCOPE
28class Sdf_PyListEditorUtils {
30 template <
class T,
class V>
33 ApplyHelper(
const T& owner,
const pxr_boost::python::object& callback) :
40 std::optional<V> operator()(SdfListOpType op,
const V& value)
42 using namespace pxr_boost::python;
45 object result = _callback(_owner, value, op);
49 return std::optional<V>(e());
53 "incorrect return type.");
56 return std::optional<V>();
67 ModifyHelper(
const pxr_boost::python::object& callback) :
73 std::optional<V> operator()(
const V& value)
75 using namespace pxr_boost::python;
78 object result = _callback(value);
82 return std::optional<V>(e());
86 "incorrect return type.");
89 return std::optional<V>();
98class SdfPyWrapListEditorProxy {
101 typedef typename Type::TypePolicy TypePolicy;
102 typedef typename Type::value_type value_type;
103 typedef typename Type::value_vector_type value_vector_type;
104 typedef typename Type::ApplyCallback ApplyCallback;
105 typedef typename Type::ModifyCallback ModifyCallback;
106 typedef SdfPyWrapListEditorProxy<Type> This;
109 SdfPyWrapListEditorProxy()
111 TfPyWrapOnce<Type>(&This::_Wrap);
112 SdfPyWrapListProxy<ListProxy>();
118 using namespace pxr_boost::python;
120 class_<Type>(_GetName().c_str(), no_init)
121 .def(
"__str__", &This::_GetStr)
122 .add_property(
"isExpired", &Type::IsExpired)
123 .add_property(
"explicitItems",
124 &Type::GetExplicitItems,
125 &This::_SetExplicitProxy)
126 .add_property(
"addedItems",
127 &Type::GetAddedItems,
128 &This::_SetAddedProxy)
129 .add_property(
"prependedItems",
130 &Type::GetPrependedItems,
131 &This::_SetPrependedProxy)
132 .add_property(
"appendedItems",
133 &Type::GetAppendedItems,
134 &This::_SetAppendedProxy)
135 .add_property(
"deletedItems",
136 &Type::GetDeletedItems,
137 &This::_SetDeletedProxy)
138 .add_property(
"orderedItems",
139 &Type::GetOrderedItems,
140 &This::_SetOrderedProxy)
141 .def(
"GetAddedOrExplicitItems", &Type::GetAppliedItems,
142 return_value_policy<TfPySequenceToTuple>())
143 .def(
"GetAppliedItems", &Type::GetAppliedItems,
144 return_value_policy<TfPySequenceToTuple>())
145 .add_property(
"isExplicit", &Type::IsExplicit)
146 .add_property(
"isOrderedOnly", &Type::IsOrderedOnly)
147 .def(
"ApplyEditsToList",
148 &This::_ApplyEditsToList,
149 return_value_policy<TfPySequenceToList>())
150 .def(
"ApplyEditsToList",
151 &This::_ApplyEditsToList2,
152 return_value_policy<TfPySequenceToList>())
154 .def(
"CopyItems", &Type::CopyItems)
155 .def(
"ClearEdits", &Type::ClearEdits)
156 .def(
"ClearEditsAndMakeExplicit", &Type::ClearEditsAndMakeExplicit)
157 .def(
"ContainsItemEdit", &Type::ContainsItemEdit,
158 (arg(
"item"), arg(
"onlyAddOrExplicit")=
false))
159 .def(
"RemoveItemEdits", &Type::RemoveItemEdits)
160 .def(
"ReplaceItemEdits", &Type::ReplaceItemEdits)
161 .def(
"ModifyItemEdits", &This::_ModifyEdits)
164 .def(
"Add", &Type::Add)
165 .def(
"Prepend", &Type::Prepend)
166 .def(
"Append", &Type::Append)
167 .def(
"Remove", &Type::Remove)
168 .def(
"Erase", &Type::Erase)
172 static std::string _GetName()
174 std::string name =
"ListEditorProxy_" +
175 ArchGetDemangled<TypePolicy>();
184 static std::string _GetStr(
const Type& x)
186 return x._listEditor ?
TfStringify(*x._listEditor) :
std::string();
189 static void _SetExplicitProxy(Type& x,
const value_vector_type& v)
191 x.GetExplicitItems() = v;
194 static void _SetAddedProxy(Type& x,
const value_vector_type& v)
196 x.GetAddedItems() = v;
199 static void _SetPrependedProxy(Type& x,
const value_vector_type& v)
201 x.GetPrependedItems() = v;
204 static void _SetAppendedProxy(Type& x,
const value_vector_type& v)
206 x.GetAppendedItems() = v;
209 static void _SetDeletedProxy(Type& x,
const value_vector_type& v)
211 x.GetDeletedItems() = v;
214 static void _SetOrderedProxy(Type& x,
const value_vector_type& v)
216 x.GetOrderedItems() = v;
219 static value_vector_type _ApplyEditsToList(
const Type& x,
220 const value_vector_type& v)
222 value_vector_type tmp = v;
223 x.ApplyEditsToList(&tmp);
227 static value_vector_type _ApplyEditsToList2(
const Type& x,
228 const value_vector_type& v,
229 const pxr_boost::python::object& cb)
231 value_vector_type tmp = v;
232 x.ApplyEditsToList(&tmp,
233 Sdf_PyListEditorUtils::ApplyHelper<Type, value_type>(x, cb));
237 static void _ModifyEdits(Type& x,
const pxr_boost::python::object& cb)
239 x.ModifyItemEdits(Sdf_PyListEditorUtils::ModifyHelper<value_type>(cb));
243PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Miscellaneous Utilities for dealing with script.
TF_API bool TfPyIsNone(pxr_boost::python::object const &obj)
Return true iff obj is None.
Represents a single list of list editing operations.
Convenience class for accessing the Python Global Interpreter Lock.
Demangle C++ typenames generated by the typeid() facility.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
std::string TfStringify(const T &v)
Convert an arbitrary type into a string.
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.
Utilities for calling python callables.
Definitions of basic string utilities in tf.
Provide a way to call a Python callable.