From bcd6c466fb49de53a62f20554888dc1e86fb0338 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 13 Aug 2018 09:30:28 +0200 Subject: [PATCH] Fixed #152 (shape count wrong) --- src/db/db/gsiDeclDbShapes.cc | 17 ++++++++++++++++- testdata/oasis/issue_152.oas | Bin 0 -> 396 bytes testdata/ruby/dbShapesTest.rb | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 testdata/oasis/issue_152.oas 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 0000000000000000000000000000000000000000..44eb8f084124a51da83f6b3439cac6dc805a58d1 GIT binary patch literal 396 zcmY!lcJ=kt^>+;R4CduxWH!_@V0gjKfDB|rrGn#q9V6m{J>C6WUE)3cLR{TlgW|(I zT|zuKSY&u*Akv|J*c8Z!as|hS_y@#0yZZR>Fqh;PFoOtQ29bJ3hCfUbn6I)wVPzEJ Pc)|XHovC3Y0|o{F`~09@ literal 0 HcmV?d00001 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")