Skip to content

Commit

Permalink
adding delete for DimStyleTable
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Nov 20, 2024
1 parent eb5e366 commit 6902122
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 7 deletions.
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
33 changes: 29 additions & 4 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 @@ -972,9 +988,7 @@ int BND_File3dmLayerTable::AddLayer(std::wstring name, BND_Color color)

bool BND_File3dmLayerTable::Delete(BND_UUID id)
{
ON_UUID _id = Binding_to_ON_UUID(id);
ON_ModelComponentReference compref = m_model->RemoveModelComponent(ON_ModelComponent::Type::Layer, _id);
return !compref.IsEmpty();
return DeleteModelComponent(id, ON_ModelComponent::Type::Layer, m_model);
}

BND_Layer* BND_File3dmLayerTable::FindName(std::wstring name, BND_UUID parentId)
Expand Down Expand Up @@ -1175,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 @@ -1724,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 @@ -1765,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 Down Expand Up @@ -1820,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 @@ -2066,6 +2088,7 @@ void initExtensionsBindings(void*)
.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 @@ -2087,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 Down Expand Up @@ -2117,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
3 changes: 3 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 Down Expand Up @@ -184,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
2 changes: 1 addition & 1 deletion tests/javascript/file3dm.BitmapTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ test.skip('DeleteBitmap', async () => {

const qtyBitmaps2 = model.bitmaps().count

expect(qtyDims1 === 2 && qtyDims2 === 1).toBe(true)
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()

// .bitmaps().add() is void
model.dimstyles().add(ds1)
model.dimstyles().add(ds2)

const qtyDimStyles1 = model.dimstyles().count

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

model.dimstyles().delete(id1)

const qtyDimStyles2 = model.dimstyles().count

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

})
33 changes: 33 additions & 0 deletions tests/python/test_File3dm_DimStyleTable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import rhino3dm
import unittest

#objective: to test creating file with bitmaps
class TestFile3dmBitmapTable(unittest.TestCase):

def test_deleteDimStyle(self):
file3dm = rhino3dm.File3dm()
file3dm.ApplicationName = 'python'
file3dm.ApplicationDetails = 'rhino3dm-tests-deleteDimStyle'
file3dm.ApplicationUrl = 'https://rhino3d.com'

#create bitmaps
bm1 = rhino3dm.DimensionStyle()
bm2 = rhino3dm.DimensionStyle()

file3dm.DimStyles.Add(bm1)
file3dm.DimStyles.Add(bm2)

qtyDimStyles1 = len(file3dm.DimStyles)

id1 = file3dm.DimStyles[0].Id

file3dm.DimStyles.Delete(id1)

qtyDimStyles2 = len(file3dm.DimStyles)

self.assertTrue(qtyDimStyles1 == 2 and qtyDimStyles2 == 1)

if __name__ == '__main__':
print("running tests")
unittest.main()
print("tests complete")

0 comments on commit 6902122

Please sign in to comment.