From 88af31f4400d1b607d6071cd75c27b96fedf5659 Mon Sep 17 00:00:00 2001 From: StudioWEngineers Date: Mon, 16 Dec 2024 17:38:49 +0100 Subject: [PATCH 1/4] AddPoint with attributes --- src/bindings/bnd_extensions.cpp | 10 ++++++++++ src/bindings/bnd_extensions.h | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bindings/bnd_extensions.cpp b/src/bindings/bnd_extensions.cpp index 7fbf6eaa..46604f82 100644 --- a/src/bindings/bnd_extensions.cpp +++ b/src/bindings/bnd_extensions.cpp @@ -432,6 +432,13 @@ BND_UUID BND_ONXModel_ObjectTable::AddPoint1(double x, double y, double z) return ON_UUID_to_Binding(rc); } +BND_UUID BND_ONXModel_ObjectTable::AddPoint6(double x, double y, double z, const BND_3dmObjectAttributes* attributes) +{ + ON_Point point_geometry(x,y,z); + ON_UUID rc = Internal_ONX_Model_AddModelGeometry(m_model.get(), &point_geometry, attributes); + return ON_UUID_to_Binding(rc); +} + BND_UUID BND_ONXModel_ObjectTable::AddPointCloud(const BND_PointCloud& cloud, const BND_3dmObjectAttributes* attributes) { const ON_Geometry* g = cloud.GeometryPointer(); @@ -1705,8 +1712,11 @@ void initExtensionsBindings(rh3dmpymodule& m) .def("__iter__", [](py::object s) { return PyBNDIterator(s.cast(), s); }) #endif .def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint1, py::arg("x"), py::arg("y"), py::arg("z")) + .def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint6, py::arg("x"), py::arg("y"), py::arg("z"), py::arg("attributes")) .def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint2, py::arg("point")) + .def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint3, py::arg("point"), py::arg("attributes")) .def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint4, py::arg("point")) + .def("AddPoint", &BND_ONXModel_ObjectTable::AddPoint5, py::arg("point"), py::arg("attributes")) .def("AddPointCloud", &BND_ONXModel_ObjectTable::AddPointCloud, py::arg("cloud"), py::arg("attributes")=nullptr) .def("AddLine", &BND_ONXModel_ObjectTable::AddLine1, py::arg("from"), py::arg("to")) .def("AddPolyline", &BND_ONXModel_ObjectTable::AddPolyline1, py::arg("polyline"), py::arg("attributes")=nullptr) diff --git a/src/bindings/bnd_extensions.h b/src/bindings/bnd_extensions.h index e8d0d484..73d797d6 100644 --- a/src/bindings/bnd_extensions.h +++ b/src/bindings/bnd_extensions.h @@ -29,10 +29,11 @@ class BND_ONXModel_ObjectTable public: BND_ONXModel_ObjectTable(std::shared_ptr m) { m_model = m; } BND_UUID AddPoint1(double x, double y, double z); + BND_UUID AddPoint6(double x, double y, double z, const class BND_3dmObjectAttributes* attributes); BND_UUID AddPoint2(const ON_3dPoint& point) { return AddPoint1(point.x, point.y, point.z); } - //Guid AddPoint3(Point3d point, DocObjects.ObjectAttributes attributes) + BND_UUID AddPoint3(const ON_3dPoint& point, const class BND_3dmObjectAttributes* attributes) { return AddPoint6(point.x, point.y, point.z, attributes); } BND_UUID AddPoint4(const ON_3fPoint& point) { return AddPoint1(point.x, point.y, point.z); } - //Guid AddPoint5(Point3f point, DocObjects.ObjectAttributes attributes) + BND_UUID AddPoint5(const ON_3fPoint& point, const class BND_3dmObjectAttributes* attributes) { return AddPoint6(point.x, point.y, point.z, attributes); } //Guid[] AddPoints1(IEnumerable points) //Guid[] AddPoints2(IEnumerable points, DocObjects.ObjectAttributes attributes) //Guid[] AddPoints3(IEnumerable points) From 48e796f38d2f382f14fa03692290cbde5f7b7c5c Mon Sep 17 00:00:00 2001 From: StudioWEngineers Date: Mon, 16 Dec 2024 17:39:56 +0100 Subject: [PATCH 2/4] remove trailing whitespaces --- tests/python/test_File3dm_ObjectTable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/test_File3dm_ObjectTable.py b/tests/python/test_File3dm_ObjectTable.py index edf875e9..74ef8f6c 100644 --- a/tests/python/test_File3dm_ObjectTable.py +++ b/tests/python/test_File3dm_ObjectTable.py @@ -63,7 +63,7 @@ def test_deleteObject(self): self.assertTrue(qtyObjects == 2 and qtyObjects2 == 1) - + if __name__ == '__main__': print("running tests") From ddfb974ae37712bc0a92143f9f8d4e4a402f8070 Mon Sep 17 00:00:00 2001 From: StudioWEngineers Date: Mon, 16 Dec 2024 17:40:24 +0100 Subject: [PATCH 3/4] AddPoint with attributes - add Python tests --- tests/python/test_File3dm_ObjectTable.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/python/test_File3dm_ObjectTable.py b/tests/python/test_File3dm_ObjectTable.py index 74ef8f6c..e7da769b 100644 --- a/tests/python/test_File3dm_ObjectTable.py +++ b/tests/python/test_File3dm_ObjectTable.py @@ -3,6 +3,28 @@ #objective: to test that passing a list of points or a Point3dList to the CreateControlPointCurve method returns the same curve class TestFile3dmObjectTable(unittest.TestCase): + def test_addPoint(self) -> None: + """Tests for the `AddPoint` method. + """ + file_3dm = rhino3dm.File3dm() + + # create layers + file_3dm.Layers.AddLayer("layer1", (30, 144, 255, 255)) + file_3dm.Layers.AddLayer("layer2", (255, 215, 0, 255)) + + # points added without attributes are added to the current layer, i.e., the first + # layer added to the model + file_3dm.Objects.AddPoint(rhino3dm.Point3d(0, 0, 0)) + with self.subTest(msg="AddPoint without attributes"): + self.assertEqual(file_3dm.Objects[0].Attributes.LayerIndex, 0) + + # add point with attributes + obj_attr = rhino3dm.ObjectAttributes() + obj_attr.LayerIndex = 1 + file_3dm.Objects.AddPoint(rhino3dm.Point3d(1, 1, 0), obj_attr) + with self.subTest(msg="AddPoint with attributes"): + self.assertEqual(file_3dm.Objects[1].Attributes.LayerIndex, 1) + def test_addPolyline(self): pointArray = [] From 7ffea4271a9b47833a96cdee8e4a2b9df8498e15 Mon Sep 17 00:00:00 2001 From: StudioWEngineers Date: Tue, 17 Dec 2024 13:33:10 +0100 Subject: [PATCH 4/4] add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d4cd8fc..ee8891d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ diff: - (js) BND_PointCloud::CreateFromThreeJSON #642 - (js) Added several methods and properties for Planes #568 - (dotnet) Linux release builds in an Amazon Linux 2023 container +- (py) AddPoint now supports attributes #665 @StudioWEngineers ### Changed