Skip to content

Commit

Permalink
Merge pull request #657 from mcneel/luis/delete
Browse files Browse the repository at this point in the history
Luis/delete
  • Loading branch information
fraguada authored Nov 20, 2024
2 parents 59dc784 + 6d2f02b commit d7f1c66
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 12 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [8.10.0] - UNRELEASED
## [8.13.0-beta] - UNRELEASED

diff:

### Fixed
### Added

- (dotnet) Changes to ViewInfo.Viewport would not set.
- (js, py) DimensionStyle.Id
- (js, py) Several delete methods for File3dm Tables: File3dmMaterialTable::Delete, BND_File3dmLayerTable::Delete, BND_File3dmDimStyleTable::Delete
- (js, py) Added tests for various ::Delete methods.

### Changed

- (py) switching from pybind11 to nanobind
- (js) File3dm.objects().deleteItem(id) -> File3dm.objects().delete(id)

### Fixed

- (dotnet) Changes to ViewInfo.Viewport would not set.
- (py) uuid conversion in c++ was broken


## [8.9.0] - 2024.07.19

Expand Down
6 changes: 4 additions & 2 deletions src/bindings/bnd_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ void BND_Bitmap::SetTrackedPointer(ON_Bitmap* bitmap, const ON_ModelComponentRef

void initBitmapBindings(rh3dmpymodule& m)
{
py::class_<BND_Bitmap>(m, "Bitmap")
py::class_<BND_Bitmap, BND_CommonObject>(m, "Bitmap")
.def(py::init<>())
.def_property_readonly("Width", &BND_Bitmap::Width)
.def_property_readonly("Height", &BND_Bitmap::Height)
.def_property_readonly("BitsPerPixel", &BND_Bitmap::BitsPerPixel)
.def_property_readonly("SizeOfScan", &BND_Bitmap::SizeOfScan)
.def_property_readonly("SizeOfImage", &BND_Bitmap::SizeOfImage)
.def_property_readonly("Id", &BND_Bitmap::GetId)
;
}
#endif
Expand All @@ -36,13 +37,14 @@ using namespace emscripten;

void initBitmapBindings(void*)
{
class_<BND_Bitmap>("Bitmap")
class_<BND_Bitmap, base<BND_CommonObject>>("Bitmap")
.constructor<>()
.property("width", &BND_Bitmap::Width)
.property("height", &BND_Bitmap::Height)
.property("bitsPerPixel", &BND_Bitmap::BitsPerPixel)
.property("sizeOfScan", &BND_Bitmap::SizeOfScan)
.property("sizeOfImage", &BND_Bitmap::SizeOfImage)
.property("id", &BND_Bitmap::GetId)
;
}
#endif
1 change: 1 addition & 0 deletions src/bindings/bnd_bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BND_Bitmap : public BND_CommonObject
//const unsigned char* Bits(int scan_line_index) const;
//const ON_FileReference& FileReference() const;
//void SetFileReference(const ON_FileReference& file_reference);
BND_UUID GetId() const { return ON_UUID_to_Binding( m_bitmap->Id()); }
void SetFileFullPath(std::wstring path) { m_bitmap->SetFileFullPath(path.c_str(), true); }

protected:
Expand Down
2 changes: 2 additions & 0 deletions src/bindings/bnd_dimensionstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void initDimensionStyleBindings(rh3dmpymodule& m)
.def_property_readonly("IsChild", &BND_DimensionStyle::IsChild)
.def("IsChildOf", &BND_DimensionStyle::IsChildOf, py::arg("id"))
.def_property("ParentId", &BND_DimensionStyle::GetParentId, &BND_DimensionStyle::SetParentId)
.def_property_readonly("Id", &BND_DimensionStyle::GetId)
;

py::enum_<ON_DimStyle::field>(pyDimStyle, "Field")
Expand Down Expand Up @@ -261,6 +262,7 @@ void initDimensionStyleBindings(void*)
.property("isChild", &BND_DimensionStyle::IsChild)
.function("isChildOf", &BND_DimensionStyle::IsChildOf)
.property("parentId", &BND_DimensionStyle::GetParentId, &BND_DimensionStyle::SetParentId)
.property("id", &BND_DimensionStyle::GetId)
;
}
#endif
2 changes: 2 additions & 0 deletions src/bindings/bnd_dimensionstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class BND_DimensionStyle : public BND_CommonObject
class BND_Font* GetFont() const;
void SetFont(const class BND_Font* font);

BND_UUID GetId() const { return ON_UUID_to_Binding( m_dimstyle->Id()); }

void ScaleLengthValues(double scale) { m_dimstyle->Scale(scale); }
BND_UUID GetArrowBlockId1() const { return ON_UUID_to_Binding(m_dimstyle->ArrowBlockId1()); }
void SetArrowBlockId1(BND_UUID id) { m_dimstyle->SetArrowBlockId1(Binding_to_ON_UUID(id)); }
Expand Down
39 changes: 36 additions & 3 deletions src/bindings/bnd_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ static ON_UUID Internal_ONX_Model_AddModelGeometry(
return ON_ModelGeometryComponent::FromModelComponentRef(model_component_reference, &ON_ModelGeometryComponent::Unset)->Id();
}

static bool DeleteModelComponent(BND_UUID id, ON_ModelComponent::Type objectType, std::shared_ptr<ONX_Model> m_model)
{
ON_UUID _id = Binding_to_ON_UUID(id);
ON_ModelComponentReference compref = m_model->RemoveModelComponent(objectType, _id);
return !compref.IsEmpty();
}

BND_UUID BND_ONXModel_ObjectTable::AddPoint1(double x, double y, double z)
{
Expand Down Expand Up @@ -763,6 +769,11 @@ int BND_File3dmMaterialTable::Add(const BND_Material& material)
return material_index;
}

bool BND_File3dmMaterialTable::Delete(BND_UUID id)
{
return DeleteModelComponent(id, ON_ModelComponent::Type::Material, m_model);
}

BND_Material* BND_File3dmMaterialTable::IterIndex(int index)
{
return FindIndex(index);
Expand Down Expand Up @@ -923,9 +934,14 @@ void BND_File3dmBitmapTable::Add(const BND_Bitmap& bitmap)
m_model->AddModelComponent(*b);
}

bool BND_File3dmBitmapTable::Delete(BND_UUID id)
{
return DeleteModelComponent(id, ON_ModelComponent::Type::Image, m_model);
}

BND_Bitmap* BND_File3dmBitmapTable::FindIndex(int index)
{
ON_ModelComponentReference compref = m_model->MaterialFromIndex(index);
ON_ModelComponentReference compref = m_model->ImageFromIndex(index);
const ON_ModelComponent* model_component = compref.ModelComponent();
ON_Bitmap* modelbitmap = const_cast<ON_Bitmap*>(ON_Bitmap::Cast(model_component));
if (modelbitmap)
Expand Down Expand Up @@ -954,7 +970,6 @@ BND_Bitmap* BND_File3dmBitmapTable::FindId(BND_UUID id)
return nullptr;
}


int BND_File3dmLayerTable::Add(const BND_Layer& layer)
{
const ON_Layer* l = layer.m_layer;
Expand All @@ -971,6 +986,11 @@ int BND_File3dmLayerTable::AddLayer(std::wstring name, BND_Color color)
return rc;
}

bool BND_File3dmLayerTable::Delete(BND_UUID id)
{
return DeleteModelComponent(id, ON_ModelComponent::Type::Layer, m_model);
}

BND_Layer* BND_File3dmLayerTable::FindName(std::wstring name, BND_UUID parentId)
{
ON_UUID id = Binding_to_ON_UUID(parentId);
Expand Down Expand Up @@ -1169,6 +1189,11 @@ void BND_File3dmDimStyleTable::Add(const BND_DimensionStyle& dimstyle)
m_model->AddModelComponent(*ds);
}

bool BND_File3dmDimStyleTable::Delete(BND_UUID id)
{
return DeleteModelComponent(id, ON_ModelComponent::Type::DimStyle, m_model);
}

BND_DimensionStyle* BND_File3dmDimStyleTable::FindIndex(int index) const
{
ON_ModelComponentReference compref = m_model->DimensionStyleFromIndex(index);
Expand Down Expand Up @@ -1718,6 +1743,7 @@ void initExtensionsBindings(rh3dmpymodule& m)
.def("__iter__", [](py::object s) { return PyBNDIterator<BND_File3dmMaterialTable&, BND_Material*>(s.cast<BND_File3dmMaterialTable &>(), s); })
#endif
.def("Add", &BND_File3dmMaterialTable::Add, py::arg("material"))
.def("Delete", &BND_File3dmMaterialTable::Delete, py::arg("id"))
.def("FindIndex", &BND_File3dmMaterialTable::FindIndex, py::arg("index"))
.def("FindId", &BND_File3dmMaterialTable::FindId, py::arg("id"))
.def("FindFromAttributes", &BND_File3dmMaterialTable::FromAttributes)
Expand Down Expand Up @@ -1759,6 +1785,7 @@ void initExtensionsBindings(rh3dmpymodule& m)
.def("__iter__", [](py::object s) { return PyBNDIterator<BND_File3dmBitmapTable&, BND_Bitmap*>(s.cast<BND_File3dmBitmapTable &>(), s); })
#endif
.def("Add", &BND_File3dmBitmapTable::Add, py::arg("bitmap"))
.def("Delete", &BND_File3dmBitmapTable::Delete, py::arg("id"))
.def("FindIndex", &BND_File3dmBitmapTable::FindIndex, py::arg("index"))
.def("FindId", &BND_File3dmBitmapTable::FindId, py::arg("id"))
;
Expand All @@ -1776,6 +1803,7 @@ void initExtensionsBindings(rh3dmpymodule& m)
#endif
.def("Add", &BND_File3dmLayerTable::Add, py::arg("layer"))
.def("AddLayer", &BND_File3dmLayerTable::AddLayer, py::arg("name"), py::arg("color"))
.def("Delete", &BND_File3dmLayerTable::Delete, py::arg("id"))
.def("FindName", &BND_File3dmLayerTable::FindName, py::arg("name"), py::arg("parentId"))
.def("FindIndex", &BND_File3dmLayerTable::FindIndex, py::arg("index"))
.def("FindId", &BND_File3dmLayerTable::FindId, py::arg("id"))
Expand Down Expand Up @@ -1813,6 +1841,7 @@ void initExtensionsBindings(rh3dmpymodule& m)
.def("__iter__", [](py::object s) { return PyBNDIterator<BND_File3dmDimStyleTable&, BND_DimensionStyle*>(s.cast<BND_File3dmDimStyleTable &>(), s); })
#endif
.def("Add", &BND_File3dmDimStyleTable::Add, py::arg("dimstyle"))
.def("Delete", &BND_File3dmDimStyleTable::Delete, py::arg("id"))
.def("FindIndex", &BND_File3dmDimStyleTable::FindIndex, py::arg("index"))
.def("FindId", &BND_File3dmDimStyleTable::FindId, py::arg("id"))
;
Expand Down Expand Up @@ -2051,14 +2080,15 @@ void initExtensionsBindings(void*)
.function("addObject", &BND_ONXModel_ObjectTable::AddObject, allow_raw_pointers())
.function("addInstanceObject", &BND_ONXModel_ObjectTable::AddInstanceObject2, allow_raw_pointers())
.function("getBoundingBox", &BND_ONXModel_ObjectTable::GetBoundingBox)
.function("deleteItem", &BND_ONXModel_ObjectTable::Delete)
.function("delete", &BND_ONXModel_ObjectTable::Delete)
.function("findId", &BND_ONXModel_ObjectTable::FindId, allow_raw_pointers())
;

class_<BND_File3dmMaterialTable>("File3dmMaterialTable")
.property("count", &BND_File3dmMaterialTable::Count)
.function("get", &BND_File3dmMaterialTable::FindIndex, allow_raw_pointers())
.function("add", &BND_File3dmMaterialTable::Add)
.function("delete", &BND_File3dmMaterialTable::Delete)
.function("findIndex", &BND_File3dmMaterialTable::FindIndex, allow_raw_pointers())
.function("findId", &BND_File3dmMaterialTable::FindId, allow_raw_pointers())
.function("findFromAttributes", &BND_File3dmMaterialTable::FromAttributes, allow_raw_pointers())
Expand All @@ -2080,6 +2110,7 @@ void initExtensionsBindings(void*)
.property("count", &BND_File3dmBitmapTable::Count)
.function("get", &BND_File3dmBitmapTable::FindIndex, allow_raw_pointers())
.function("add", &BND_File3dmBitmapTable::Add)
.function("delete", &BND_File3dmBitmapTable::Delete)
.function("findIndex", &BND_File3dmBitmapTable::FindIndex, allow_raw_pointers())
.function("findId", &BND_File3dmBitmapTable::FindId, allow_raw_pointers())
;
Expand All @@ -2089,6 +2120,7 @@ void initExtensionsBindings(void*)
.function("get", &BND_File3dmLayerTable::FindIndex, allow_raw_pointers())
.function("add", &BND_File3dmLayerTable::Add)
.function("addLayer", &BND_File3dmLayerTable::AddLayer)
.function("delete", &BND_File3dmLayerTable::Delete)
.function("findName", &BND_File3dmLayerTable::FindName, allow_raw_pointers())
.function("findIndex", &BND_File3dmLayerTable::FindIndex, allow_raw_pointers())
.function("findId", &BND_File3dmLayerTable::FindId, allow_raw_pointers())
Expand All @@ -2109,6 +2141,7 @@ void initExtensionsBindings(void*)
.property("count", &BND_File3dmDimStyleTable::Count)
.function("get", &BND_File3dmDimStyleTable::FindIndex, allow_raw_pointers())
.function("add", &BND_File3dmDimStyleTable::Add)
.function("delete", &BND_File3dmDimStyleTable::Delete)
.function("findIndex", &BND_File3dmDimStyleTable::FindIndex, allow_raw_pointers())
.function("findId", &BND_File3dmDimStyleTable::FindId, allow_raw_pointers())
;
Expand Down
4 changes: 4 additions & 0 deletions src/bindings/bnd_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class BND_File3dmMaterialTable
BND_File3dmMaterialTable(std::shared_ptr<ONX_Model> m) { m_model = m; }
int Count() const { return m_model->ActiveComponentCount(ON_ModelComponent::Type::RenderMaterial); }
int Add(const class BND_Material& material);
bool Delete(BND_UUID id);
class BND_Material* FindIndex(int index);
class BND_Material* IterIndex(int index); // helper function for iterator
class BND_Material* FindId(BND_UUID id);
Expand Down Expand Up @@ -140,6 +141,7 @@ class BND_File3dmBitmapTable
BND_File3dmBitmapTable(std::shared_ptr<ONX_Model> m) { m_model = m; }
int Count() const { return m_model.get()->ActiveComponentCount(ON_ModelComponent::Type::Image); }
void Add(const class BND_Bitmap& bitmap);
bool Delete(BND_UUID id);
class BND_Bitmap* FindIndex(int index);
class BND_Bitmap* IterIndex(int index); // helper function for iterator
class BND_Bitmap* FindId(BND_UUID id);
Expand All @@ -153,6 +155,7 @@ class BND_File3dmLayerTable
int Count() const { return m_model.get()->ActiveComponentCount(ON_ModelComponent::Type::Layer); }
int Add(const class BND_Layer& layer);
int AddLayer(std::wstring name, BND_Color color);
bool Delete(BND_UUID id);
class BND_Layer* FindName(std::wstring name, BND_UUID parentId);
//BND_Layer* FindNameHash(NameHash nameHash)
class BND_Layer* FindIndex(int index);
Expand Down Expand Up @@ -183,6 +186,7 @@ class BND_File3dmDimStyleTable
BND_File3dmDimStyleTable(std::shared_ptr<ONX_Model> m) { m_model = m; }
int Count() const { return m_model.get()->ActiveComponentCount(ON_ModelComponent::Type::DimStyle); }
void Add(const class BND_DimensionStyle& dimstyle);
bool Delete(BND_UUID id);
class BND_DimensionStyle* FindIndex(int index) const;
class BND_DimensionStyle* IterIndex(int index) const; // helper function for iterator
class BND_DimensionStyle* FindId(BND_UUID id) const;
Expand Down
4 changes: 4 additions & 0 deletions src/bindings/bnd_uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ BND_UUID ON_UUID_to_Binding(const ON_UUID& id)

ON_UUID Binding_to_ON_UUID(const BND_UUID& id)
{
#if !defined(NANOBIND)
std::string s = pybind11::str(id);
#else
std::string s = py::cast<std::string>(id);
#endif
return ON_UuidFromString(s.c_str());
}

Expand Down
33 changes: 33 additions & 0 deletions tests/javascript/file3dm.BitmapTable.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const rhino3dm = require('rhino3dm')

let rhino
beforeEach( async() => {
rhino = await rhino3dm()
})
//TODO
// Skipping for now.
test.skip('DeleteBitmap', async () => {

const file3dm = new rhino.File3dm()
file3dm.applicationName = 'rhino3dm.js'
file3dm.applicationDetails = 'rhino3dm-tests-bitmapTable-deleteBitmap'
file3dm.applicationUrl = 'https://rhino3d.com'

const bm1 = new rhino.Bitmap()
const bm2 = new rhino.Bitmap()

// .bitmaps().add() is void
model.bitmaps().add(bm1)
model.bitmaps().add(bm2)

const qtyBitmaps1 = model.bitmaps().count

const id1 = model.bitmaps().get(0).id

model.bitmaps().delete(id1)

const qtyBitmaps2 = model.bitmaps().count

expect(qtyBitmaps1 === 2 && qtyBitmaps2 === 1).toBe(true)

})
33 changes: 33 additions & 0 deletions tests/javascript/file3dm.DimStyleTable.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const rhino3dm = require('rhino3dm')

let rhino
beforeEach( async() => {
rhino = await rhino3dm()
})
//TODO
// Skipping for now.
test('DeleteDimStyle', async () => {

const file3dm = new rhino.File3dm()
file3dm.applicationName = 'rhino3dm.js'
file3dm.applicationDetails = 'rhino3dm-tests-dimStyleTable-deleteDimStyle'
file3dm.applicationUrl = 'https://rhino3d.com'

const ds1 = new rhino.DimensionStyle()
const ds2 = new rhino.DimensionStyle()

// .dimstyles().add() is void
file3dm.dimstyles().add(ds1)
file3dm.dimstyles().add(ds2)

const qtyDimStyles1 = file3dm.dimstyles().count

const id1 = file3dm.dimstyles().get(0).id

file3dm.dimstyles().delete(id1)

const qtyDimStyles2 = file3dm.dimstyles().count

expect(qtyDimStyles1 === 2 && qtyDimStyles2 === 1).toBe(true)

})
30 changes: 30 additions & 0 deletions tests/javascript/file3dm.LayerTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,34 @@ test('CreateFileWithLayers', async () => {

expect(qtyLayers === 2 && qtyLayers2 === 2).toBe(true)

})

test('DeleteLayer', async () => {

const file3dm = new rhino.File3dm()
file3dm.applicationName = 'rhino3dm.js'
file3dm.applicationDetails = 'rhino3dm-tests-layerTable-deleteLayer'
file3dm.applicationUrl = 'https://rhino3d.com'

//create layers
const layer1 = new rhino.Layer()
layer1.Name = 'layer1'
layer1.Color = { r: 255, g: 0, b: 255, a: 255 }

const layer2 = new rhino.Layer()
layer2.Name = 'layer2'

const index1 = file3dm.layers().add(layer1)
const index2 = file3dm.layers().add(layer2)

const qtyLayers = file3dm.layers().count

const id1 = file3dm.layers().findIndex(index1).id

file3dm.layers().delete(id1)

const qtyLayers2 = file3dm.layers().count

expect(qtyLayers === 2 && qtyLayers2 === 1).toBe(true)

})
Loading

0 comments on commit d7f1c66

Please sign in to comment.