From 3d5780db2b73493d64cb01c74e8b60486422a7f7 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 6 Apr 2018 23:27:29 +0200 Subject: [PATCH] Bugfix #109 (part 3): OASIS/GDS writer fixed + unit test added. --- src/db/db/dbGDS2WriterBase.cc | 9 +------ src/db/db/dbOASISWriter.cc | 4 ++- testdata/python/dbLayoutTest.py | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/db/db/dbGDS2WriterBase.cc b/src/db/db/dbGDS2WriterBase.cc index cd6df2a99..d8dd26614 100644 --- a/src/db/db/dbGDS2WriterBase.cc +++ b/src/db/db/dbGDS2WriterBase.cc @@ -831,15 +831,8 @@ GDS2WriterBase::write_properties (const db::Layout &layout, db::properties_id_ty const tl::Variant &name = layout.properties_repository ().prop_name (p->first); long attr = -1; - if (name.is_long ()) { + if (name.can_convert_to_long ()) { attr = name.to_long (); - } else if (name.is_a_string ()) { - // string names representing a number are converted to numeric property names - tl::Extractor ex (name.to_string ()); - long a = 0; - if (ex.try_read (a) && ex.at_end ()) { - attr = a; - } } if (attr >= 0 && attr < 65535) { diff --git a/src/db/db/dbOASISWriter.cc b/src/db/db/dbOASISWriter.cc index ba2e2546e..4f41cde4b 100644 --- a/src/db/db/dbOASISWriter.cc +++ b/src/db/db/dbOASISWriter.cc @@ -55,7 +55,9 @@ make_gds_property (const tl::Variant &name) { // We write S_GDS_PROPERTY properties, because that is the only way to write properties // with numerical keys - return (name.is_long () && (name.to_long () < 0x8000 || name.to_long () >= 0)) || + return (name.is_longlong () && name.to_longlong () < 0x8000 && name.to_longlong () >= 0) || + (name.is_ulonglong () && name.to_ulonglong () < 0x8000) || + (name.is_long () && name.to_long () < 0x8000 && name.to_long () >= 0) || (name.is_ulong () && name.to_ulong () < 0x8000); } diff --git a/testdata/python/dbLayoutTest.py b/testdata/python/dbLayoutTest.py index b9baad341..4377479f8 100644 --- a/testdata/python/dbLayoutTest.py +++ b/testdata/python/dbLayoutTest.py @@ -19,6 +19,7 @@ import pya import unittest import sys +import os class DBLayoutTest(unittest.TestCase): @@ -1104,6 +1105,53 @@ class DBLayoutTest(unittest.TestCase): ly._destroy() + # Bug #109 + def test_bug109(self): + + testtmp = os.getenv("TESTTMP_WITH_NAME", os.getenv("TESTTMP", ".")) + + file_gds = os.path.join(testtmp, "bug109.gds") + file_oas = os.path.join(testtmp, "bug109.oas") + + ly = pya.Layout() + top = ly.create_cell("TOP") + l1 = ly.layer(1, 0) + shape = top.shapes(l1).insert(pya.Box(0, 10, 20, 30)) + shape.set_property(2, "hello, world") + shape.set_property("42", "the answer") + + ly.write(file_gds) + ly.write(file_oas) + + ly2 = pya.Layout() + ly2.read(file_gds) + l2 = ly2.layer(1, 0) + shape = None + for s in ly2.top_cell().shapes(l2).each(): + shape = s + self.assertEqual(shape.property(2), "hello, world") + self.assertEqual(shape.property("2"), None) + self.assertEqual(shape.property(2.0), "hello, world") + self.assertEqual(shape.property(22), None) + self.assertEqual(shape.property(42), "the answer") + self.assertEqual(shape.property("42"), None) + self.assertEqual(shape.property(42.0), "the answer") + + ly2 = pya.Layout() + ly2.read(file_oas) + l2 = ly2.layer(1, 0) + shape = None + for s in ly2.top_cell().shapes(l2).each(): + shape = s + self.assertEqual(shape.property(2), "hello, world") + self.assertEqual(shape.property("2"), None) + self.assertEqual(shape.property(2.0), "hello, world") + self.assertEqual(shape.property(22), None) + self.assertEqual(shape.property("42"), "the answer") + self.assertEqual(shape.property(42), None) + self.assertEqual(shape.property(42.0), None) + + # run unit tests if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(DBLayoutTest)