From 8396463daf14f749b0201dfec8c819b45969e8ce Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 7 Jul 2017 00:02:52 +0200 Subject: [PATCH] Added text support in DRC - A new constructor for RBA::Region has been provided to create text markers from a shape iterator - The DRC framework has been enhanced with a "text" function --- src/db/dbRegion.h | 10 +++++ src/db/gsiDeclDbRegion.cc | 64 ++++++++++++++++++++++++++++++++ src/lay/built_in_macros/drc.lym | 29 +++++++++++++++ testdata/drc/drctest.drc | 3 ++ testdata/drc/drctest.gds | Bin 2718 -> 2858 bytes testdata/ruby/dbRegionTest.rb | 12 ++++++ 6 files changed, 118 insertions(+) diff --git a/src/db/dbRegion.h b/src/db/dbRegion.h index cccf3e86c..b26cfc71f 100644 --- a/src/db/dbRegion.h +++ b/src/db/dbRegion.h @@ -1493,6 +1493,16 @@ public: return db::RecursiveShapeIterator (m_iter).at_end (); } + /** + * @brief Gets the internal iterator + * + * This method is intended for users who know what they are doing + */ + const db::RecursiveShapeIterator &iter () const + { + return m_iter; + } + /** * @brief Ensures the region has valid polygons * diff --git a/src/db/gsiDeclDbRegion.cc b/src/db/gsiDeclDbRegion.cc index 25dff930b..39ebc5122 100644 --- a/src/db/gsiDeclDbRegion.cc +++ b/src/db/gsiDeclDbRegion.cc @@ -26,6 +26,9 @@ #include "dbPolygonTools.h" #include "dbLayoutUtils.h" #include "dbShapes.h" +#include "tlGlobPattern.h" + +#include namespace gsi { @@ -69,6 +72,43 @@ static db::Region *new_shapes (const db::Shapes &s) return r; } +static db::Region *new_si_texts (const db::RecursiveShapeIterator &si_in, const std::string &pat, bool pattern) +{ + db::RecursiveShapeIterator si (si_in); + si.shape_flags (db::ShapeIterator::Texts); + + tl::GlobPattern glob_pat; + bool all = false; + if (pattern) { + if (pat == "*") { + all = true; + } else { + glob_pat = tl::GlobPattern (pat); + } + } + + std::auto_ptr r (new db::Region ()); + + while (! si.at_end ()) { + if (si.shape ().is_text () && + (all || (pattern && glob_pat.match (si.shape ().text_string ())) || (!pattern && si.shape ().text_string () == pat))) { + db::Text t; + si.shape ().text (t); + t.transform (si.trans ()); + r->insert (db::Box (t.box ().enlarged (db::Vector (1, 1)))); + } + si.next (); + } + + return r.release (); +} + +static db::Region texts (const db::Region *r, const std::string &pat, bool pattern) +{ + std::auto_ptr o (new_si_texts (r->iter (), pat, pattern)); + return *o; +} + static db::Region *new_si (const db::RecursiveShapeIterator &si) { return new db::Region (si); @@ -595,6 +635,30 @@ Class decl_Region ("Region", "r = RBA::Region::new(layout.begin_shapes(cell, layer), RBA::ICplxTrans::new(layout.dbu / dbu))\n" "@/code\n" ) + + constructor ("new", &new_si_texts, gsi::arg("shape_iterator"), gsi::arg ("expr"), gsi::arg ("as_pattern", true), + "@brief Constructor from a text set\n" + "\n" + "@param shape_iterator The iterator from which to derive the texts\n" + "@param expr The selection string\n" + "@param as_pattern If true, the selection string is treated as a glob pattern. Otherwise the match is exact.\n" + "\n" + "This special constructor will create a region from the text objects delivered by the shape iterator. " + "Each text object will deliver a small (non-empty) box that represents the text origin.\n" + "Texts can be selected by their strings - either through a glob pattern or by exact comparison with " + "the given string. The following options are available:\n" + "\n" + "@code\n" + "region = RBA::Region::new(iter, \"*\") # all texts\n" + "region = RBA::Region::new(iter, \"A*\") # all texts starting with an 'A'\n" + "region = RBA::Region::new(iter, \"A*\", false) # all texts exactly matchin 'A*'\n" + "@/code\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("texts", &texts, gsi::arg ("expr", std::string ("*")), gsi::arg ("as_pattern", true), + "@hide\n" + "This method is provided for DRC implementation only." + ) + method ("merged_semantics=", &db::Region::set_merged_semantics, "@brief Enables or disables merged semantics\n" "@args f\n" diff --git a/src/lay/built_in_macros/drc.lym b/src/lay/built_in_macros/drc.lym index 27e367904..e6baff795 100644 --- a/src/lay/built_in_macros/drc.lym +++ b/src/lay/built_in_macros/drc.lym @@ -801,6 +801,35 @@ CODE DRCLayer::new(@engine, @engine._tcmd(@data, 0, RBA::Region, :smoothed, prep_value(d))) end + # %DRC% + # @name texts + # @brief Selects texts from an original layer + # @synopsis layer.texts + # @synopsis layer.texts(text) + # @synopsis layer.texts(text, true) + # @synopsis layer.texts(text, false) + # This method can be applied to original layers - i.e. ones that have + # been created with \input. It will produce a small box (2x2 DBU) on each + # selected texts. + # + # Texts can be selected either by exact match or pattern match with a + # glob-style pattern. The second argument selects pattern style (true) + # or exact match (false). + # + # @code + # # Selects all texts + # t = input(1, 0).texts + # # Selects all texts beginning with an "A" + # t = input(1, 0).texts("A*") + # t = input(1, 0).texts("A*", true) + # # Selects all texts whose string is "A*" + # t = input(1, 0).texts("A*", false) + # @/code + + def texts(expr = "*", as_pattern = true) + DRCLayer::new(@engine, @engine._tcmd(@data, 0, RBA::Region, :texts, expr, as_pattern)) + end + # %DRC% # @name odd_polygons # @brief Checks for odd polygons (self-overlapping, non-orientable) diff --git a/testdata/drc/drctest.drc b/testdata/drc/drctest.drc index cab2b23a7..de4ee2647 100644 --- a/testdata/drc/drctest.drc +++ b/testdata/drc/drctest.drc @@ -497,6 +497,9 @@ cell("TOP") c1.rounded_corners(0.5, 0.5, 16).output(1010, 0) c1.smoothed(1.5).output(1011, 0) +a1.texts.output(1020, 0) +a1.texts("A*").output(1021, 0) +a1.texts("A*", false).output(1022, 0) puts "=== Single-cell testsuite ===" diff --git a/testdata/drc/drctest.gds b/testdata/drc/drctest.gds index 9026772e64a0fb18feaaa3cf54568d6cc95f614e..daa662289933d7f997212fe962987c77568ffd8c 100644 GIT binary patch delta 332 zcmbOyx=JjGfsKKQDS|&S1cxfXrqPU}E!g4UhNnbP93|iez9AVP>^+ z>@@d2w)}&o%MSeov!g;7WLR delta 201 zcmZ1_HcwQOfsKKQDS|