diff --git a/src/db/db/gsiDeclDbShapes.cc b/src/db/db/gsiDeclDbShapes.cc index fbc5e5167..f07933072 100644 --- a/src/db/db/gsiDeclDbShapes.cc +++ b/src/db/db/gsiDeclDbShapes.cc @@ -50,6 +50,21 @@ static void dump_mem_statistics (const db::Shapes *shapes, bool detailed) ms.print (); } +static size_t shapes_size (const db::Shapes *shapes) +{ + // we may have shape arrays - expand their count to match the shape count with the shapes delivered + size_t n = 0; + for (db::Shapes::shape_iterator i = shapes->begin (db::ShapeIterator::All); ! i.at_end (); ++i) { + if (i.in_array ()) { + n += i.array ().array_size (); + i.finish_array (); + } else { + ++n; + } + } + return n; +} + template static db::Shape insert (db::Shapes *s, const Sh &p) { @@ -1088,7 +1103,7 @@ Class decl_Shapes ("Shapes", "@brief Clears the shape container\n" "This method has been introduced in version 0.16. It can only be used in editable mode." ) + - gsi::method ("size", (size_t (db::Shapes::*)() const) &db::Shapes::size, + gsi::method_ext ("size", &shapes_size, "@brief Gets the number of shapes in this container\n" "This method was introduced in version 0.16\n" "@return The number of shapes in this container\n" diff --git a/testdata/oasis/issue_152.oas b/testdata/oasis/issue_152.oas new file mode 100644 index 000000000..44eb8f084 Binary files /dev/null and b/testdata/oasis/issue_152.oas differ diff --git a/testdata/ruby/dbShapesTest.rb b/testdata/ruby/dbShapesTest.rb index d4eee02fd..98d55dd30 100644 --- a/testdata/ruby/dbShapesTest.rb +++ b/testdata/ruby/dbShapesTest.rb @@ -1377,6 +1377,23 @@ class DBShapes_TestClass < TestBase end + # issue 152 (number of shapes count wrong in viewer mode) + def test_10 + + ly = RBA::Layout::new(true) + ly.read(File.join($ut_testsrc, "testdata", "oasis", "issue_152.oas")) + assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 200) + ly.top_cell.shapes(ly.layer(1, 0)).insert(RBA::Polygon::new(RBA::Box::new(0, 0, 100, 100))) + assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 201) + + ly = RBA::Layout::new(false) + ly.read(File.join($ut_testsrc, "testdata", "oasis", "issue_152.oas")) + assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 200) + ly.top_cell.shapes(ly.layer(1, 0)).insert(RBA::Polygon::new(RBA::Box::new(0, 0, 100, 100))) + assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 201) + + end + end load("test_epilogue.rb")