diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc b/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc index 76197bc28..15628938a 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc +++ b/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc @@ -1343,20 +1343,24 @@ OASISWriter::write (db::Layout &layout, tl::OutputStream &stream, const db::Save } - // emit property name required for the PCell context information - std::vector context_prop_strings; - for (std::vector::const_iterator cell = cells.begin (); cell != cells.end (); ++cell) { + if (options.write_context_info ()) { - const db::Cell &cref (layout.cell (*cell)); - if (cref.is_proxy () && ! cref.is_top () && layout.get_context_info (*cell, context_prop_strings)) { + // emit property name required for the PCell context information + std::vector context_prop_strings; + for (std::vector::const_iterator cell = cells.begin (); cell != cells.end (); ++cell) { + + const db::Cell &cref (layout.cell (*cell)); + if (cref.is_proxy () && ! cref.is_top () && layout.get_context_info (*cell, context_prop_strings)) { + + if (m_propnames.insert (std::make_pair (std::string (klayout_context_name), m_propname_id)).second) { + begin_table (propnames_table_pos); + write_record_id (7); + write_nstring (klayout_context_name); + ++m_propname_id; + } + break; - if (m_propnames.insert (std::make_pair (std::string (klayout_context_name), m_propname_id)).second) { - begin_table (propnames_table_pos); - write_record_id (7); - write_nstring (klayout_context_name); - ++m_propname_id; } - break; } @@ -1422,25 +1426,29 @@ OASISWriter::write (db::Layout &layout, tl::OutputStream &stream, const db::Save } - // emit property string id's required for the PCell context information - std::vector context_prop_strings; - for (std::vector::const_iterator cell = cells.begin (); cell != cells.end (); ++cell) { + if (options.write_context_info ()) { - m_progress.set (mp_stream->pos ()); + // emit property string id's required for the PCell context information + std::vector context_prop_strings; + for (std::vector::const_iterator cell = cells.begin (); cell != cells.end (); ++cell) { - const db::Cell &cref (layout.cell (*cell)); - if (cref.is_proxy () && ! cref.is_top ()) { + m_progress.set (mp_stream->pos ()); - context_prop_strings.clear (); - if (layout.get_context_info (*cell, context_prop_strings)) { + const db::Cell &cref (layout.cell (*cell)); + if (cref.is_proxy () && ! cref.is_top ()) { - for (std::vector ::const_iterator c = context_prop_strings.begin (); c != context_prop_strings.end (); ++c) { - if (m_propstrings.insert (std::make_pair (*c, m_propstring_id)).second) { - begin_table (propstrings_table_pos); - write_record_id (9); - write_bstring (c->c_str ()); - ++m_propstring_id; + context_prop_strings.clear (); + if (layout.get_context_info (*cell, context_prop_strings)) { + + for (std::vector ::const_iterator c = context_prop_strings.begin (); c != context_prop_strings.end (); ++c) { + if (m_propstrings.insert (std::make_pair (*c, m_propstring_id)).second) { + begin_table (propstrings_table_pos); + write_record_id (9); + write_bstring (c->c_str ()); + ++m_propstring_id; + } } + } } @@ -1604,7 +1612,7 @@ OASISWriter::write (db::Layout &layout, tl::OutputStream &stream, const db::Save } // context information as property named KLAYOUT_CONTEXT - if (cref.is_proxy ()) { + if (cref.is_proxy () && options.write_context_info ()) { context_prop_strings.clear (); diff --git a/src/plugins/streamers/oasis/unit_tests/dbOASISWriter.cc b/src/plugins/streamers/oasis/unit_tests/dbOASISWriter.cc index 68bec61d0..13aef7df0 100644 --- a/src/plugins/streamers/oasis/unit_tests/dbOASISWriter.cc +++ b/src/plugins/streamers/oasis/unit_tests/dbOASISWriter.cc @@ -26,6 +26,8 @@ #include "dbLayoutDiff.h" #include "dbWriter.h" #include "dbTextWriter.h" +#include "dbLibraryProxy.h" +#include "dbTestSupport.h" #include "tlUnitTest.h" @@ -1258,61 +1260,6 @@ TEST(115) EXPECT_EQ (std::string (os.string ()), std::string (expected)) } -TEST(118) -{ - // 1x1 arrays (#902) - - db::Manager m; - db::Layout g (&m); - - db::LayerProperties lp1; - lp1.layer = 1; - lp1.datatype = 0; - - g.insert_layer (0, lp1); - - db::Cell &c1 (g.cell (g.add_cell ())); - c1.shapes (0).insert (db::Box (100, 0, 100, 200)); - - db::Cell &c2 (g.cell (g.add_cell ())); - c2.insert (db::array (db::CellInst (c1.cell_index ()), db::Trans (), db::Vector (0, 1), db::Vector (1, 0), 1, 1)); - c2.insert (db::array (db::CellInst (c1.cell_index ()), db::Trans (db::Vector (17, -42)), db::Vector (0, 1), db::Vector (1, 0), 1, 1)); - - std::string tmp_file = tl::TestBase::tmp_file ("tmp.oas"); - - { - tl::OutputStream out (tmp_file); - db::SaveLayoutOptions options; - options.set_format ("OASIS"); - db::Writer writer (options); - writer.write (g, out); - } - - tl::InputStream in (tmp_file); - db::Reader reader (in); - db::Layout gg; - reader.set_warnings_as_errors (true); - reader.read (gg); - - const char *expected = - "begin_lib 0.001\n" - "begin_cell {$1}\n" - "box 1 0 {100 0} {100 200}\n" - "end_cell\n" - "begin_cell {$2}\n" - "sref {$1} 0 0 1 {0 0}\n" - "sref {$1} 0 0 1 {17 -42}\n" - "end_cell\n" - "end_lib\n" - ; - - tl::OutputStringStream os; - tl::OutputStream stream (os); - db::TextWriter textwriter (stream); - textwriter.write (gg); - EXPECT_EQ (std::string (os.string ()), std::string (expected)) -} - TEST(116) { db::Manager m; @@ -1728,3 +1675,133 @@ TEST(117) EXPECT_EQ (std::string (os.string ()), std::string (expected)) } +TEST(118) +{ + // 1x1 arrays (#902) + + db::Manager m; + db::Layout g (&m); + + db::LayerProperties lp1; + lp1.layer = 1; + lp1.datatype = 0; + + g.insert_layer (0, lp1); + + db::Cell &c1 (g.cell (g.add_cell ())); + c1.shapes (0).insert (db::Box (100, 0, 100, 200)); + + db::Cell &c2 (g.cell (g.add_cell ())); + c2.insert (db::array (db::CellInst (c1.cell_index ()), db::Trans (), db::Vector (0, 1), db::Vector (1, 0), 1, 1)); + c2.insert (db::array (db::CellInst (c1.cell_index ()), db::Trans (db::Vector (17, -42)), db::Vector (0, 1), db::Vector (1, 0), 1, 1)); + + std::string tmp_file = tl::TestBase::tmp_file ("tmp.oas"); + + { + tl::OutputStream out (tmp_file); + db::SaveLayoutOptions options; + options.set_format ("OASIS"); + db::Writer writer (options); + writer.write (g, out); + } + + tl::InputStream in (tmp_file); + db::Reader reader (in); + db::Layout gg; + reader.set_warnings_as_errors (true); + reader.read (gg); + + const char *expected = + "begin_lib 0.001\n" + "begin_cell {$1}\n" + "box 1 0 {100 0} {100 200}\n" + "end_cell\n" + "begin_cell {$2}\n" + "sref {$1} 0 0 1 {0 0}\n" + "sref {$1} 0 0 1 {17 -42}\n" + "end_cell\n" + "end_lib\n" + ; + + tl::OutputStringStream os; + tl::OutputStream stream (os); + db::TextWriter textwriter (stream); + textwriter.write (gg); + EXPECT_EQ (std::string (os.string ()), std::string (expected)) +} + +TEST(119_WithAndWithoutContext) +{ + // PCells with context and without + + db::Manager m; + db::Layout g (&m); + + // Note: this sample requires the BASIC lib + + { + std::string fn (tl::testsrc ()); + fn += "/testdata/oasis/pcell_test.gds"; + tl::InputStream stream (fn); + db::Reader reader (stream); + reader.read (g); + } + + std::string tmp_file = tl::TestBase::tmp_file (tl::sprintf ("tmp_dbOASISWriter119a.oas")); + + { + tl::OutputStream out (tmp_file); + db::SaveLayoutOptions options; + options.set_format ("OASIS"); + db::Writer writer (options); + writer.write (g, out); + } + + { + tl::InputStream in (tmp_file); + db::Reader reader (in); + db::Layout gg; + reader.set_warnings_as_errors (true); + reader.read (gg); + + std::pair tc = gg.cell_by_name ("TEXT"); + tl_assert (tc.first); + + const db::Cell &text_cell = gg.cell (tc.second); + EXPECT_EQ (text_cell.is_proxy (), true); + EXPECT_EQ (text_cell.get_display_name (), "Basic.TEXT('KLAYOUT RULES')"); + + CHECKPOINT (); + db::compare_layouts (_this, gg, tl::testsrc () + "/testdata/oasis/dbOASISWriter119_au.gds", db::NoNormalization); + } + + tmp_file = tl::TestBase::tmp_file (tl::sprintf ("tmp_dbOASISWriter119b.oas")); + + { + tl::OutputStream out (tmp_file); + db::SaveLayoutOptions options; + options.set_write_context_info (false); + options.set_format ("OASIS"); + db::Writer writer (options); + writer.write (g, out); + } + + { + tl::InputStream in (tmp_file); + db::Reader reader (in); + db::Layout gg; + reader.set_warnings_as_errors (true); + reader.read (gg); + + std::pair tc = gg.cell_by_name ("TEXT"); + tl_assert (tc.first); + + const db::Cell &text_cell = gg.cell (tc.second); + EXPECT_EQ (text_cell.is_proxy (), false); + EXPECT_EQ (text_cell.get_display_name (), "TEXT"); + + CHECKPOINT (); + db::compare_layouts (_this, gg, tl::testsrc () + "/testdata/oasis/dbOASISWriter119_au.gds", db::NoNormalization); + } + +} diff --git a/testdata/oasis/dbOASISWriter119_au.gds b/testdata/oasis/dbOASISWriter119_au.gds new file mode 100644 index 000000000..120a3f609 Binary files /dev/null and b/testdata/oasis/dbOASISWriter119_au.gds differ diff --git a/testdata/oasis/pcell_test.gds b/testdata/oasis/pcell_test.gds new file mode 100644 index 000000000..031c8f8e2 Binary files /dev/null and b/testdata/oasis/pcell_test.gds differ