Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "opentimelineio/typeRegistry.h"
#include "opentimelineio/stackAlgorithm.h"

#include <ImathBox.h>

namespace py = pybind11;
using namespace pybind11::literals;

Expand Down Expand Up @@ -270,6 +272,8 @@ PYBIND11_MODULE(_otio, m) {
.def(py::init([](RationalTime rt) { return new PyAny(rt); }))
.def(py::init([](TimeRange tr) { return new PyAny(tr); }))
.def(py::init([](TimeTransform tt) { return new PyAny(tt); }))
.def(py::init([](IMATH_NAMESPACE::V2d v2d) { return new PyAny(v2d); }))
.def(py::init([](IMATH_NAMESPACE::Box2d box2d) { return new PyAny(box2d); }))
.def(py::init([](AnyVectorProxy* p) { return new PyAny(p->fetch_any_vector()); }))
.def(py::init([](AnyDictionaryProxy* p) { return new PyAny(p->fetch_any_dictionary()); }))
;
Expand Down
4 changes: 4 additions & 0 deletions src/py-opentimelineio/opentimelineio-bindings/otio_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "opentimelineio/safely_typed_any.h"
#include "opentimelineio/stringUtils.h"

#include <ImathBox.h>

#include <map>
#include <cstring>

Expand Down Expand Up @@ -60,6 +62,8 @@ void _build_any_to_py_dispatch_table() {
t[&typeid(RationalTime)] = [](std::any const& a, bool) { return py::cast(safely_cast_rational_time_any(a)); };
t[&typeid(TimeRange)] = [](std::any const& a, bool) { return py::cast(safely_cast_time_range_any(a)); };
t[&typeid(TimeTransform)] = [](std::any const& a, bool) { return py::cast(safely_cast_time_transform_any(a)); };
t[&typeid(IMATH_NAMESPACE::V2d)] = [](std::any const& a, bool) { return py::cast(safely_cast_point_any(a)); };
t[&typeid(IMATH_NAMESPACE::Box2d)] = [](std::any const& a, bool) { return py::cast(safely_cast_box_any(a)); };
t[&typeid(SerializableObject::Retainer<>)] = [](std::any const& a, bool) {
SerializableObject* so = safely_cast_retainer_any(a);
return py::cast(managing_ptr<SerializableObject>(so)); };
Expand Down
4 changes: 3 additions & 1 deletion tests/test_composable.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ def test_constructor(self):
self.assertEqual(seqi.metadata, {'foo': 'bar'})

def test_serialize(self):
b = otio.schema.Box2d(
otio.schema.V2d(0.0, 0.0), otio.schema.V2d(16.0, 9.0))
seqi = otio.core.Composable(
name="test",
metadata={"foo": "bar"}
metadata={"box": b}
)
encoded = otio.adapters.otio_json.write_to_string(seqi)
decoded = otio.adapters.otio_json.read_from_string(encoded)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_serializable_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def test_cycle_detection(self):
with self.assertRaises(ValueError):
o.clone()

def test_imath(self):
b = otio.schema.Box2d(
otio.schema.V2d(0.0, 0.0), otio.schema.V2d(16.0, 9.0))
so = otio.core.SerializableObjectWithMetadata()
so.metadata["box"] = b
self.assertEqual(repr(so.metadata["box"]), repr(b))
v = [b.min, b.max]
so.metadata["vectors"] = v
self.assertEqual(repr(so.metadata["vectors"]), repr(v))


class VersioningTests(unittest.TestCase, otio_test_utils.OTIOAssertions):
def test_schema_definition(self):
Expand Down