Added Region#being_shapes_rec and Region#begin_merged_shapes_rec, mainly for being able to retrieve shapes with properties from Region#nets

This commit is contained in:
Matthias Koefferlein 2024-07-24 22:54:47 +02:00
parent 92e44bd9b9
commit 58d489b39a
3 changed files with 96 additions and 1 deletions

View File

@ -1132,6 +1132,24 @@ rasterize1 (const db::Region *region, const db::Point &origin, const db::Vector
return rasterize2 (region, origin, pixel_size, pixel_size, nx, ny);
}
static tl::Variant begin_shapes_rec (const db::Region *region)
{
auto res = region->begin_iter ();
tl::Variant r = tl::Variant (std::vector<tl::Variant> ());
r.push (tl::Variant (res.first));
r.push (tl::Variant (res.second));
return r;
}
static tl::Variant begin_merged_shapes_rec (const db::Region *region)
{
auto res = region->begin_merged_iter ();
tl::Variant r = tl::Variant (std::vector<tl::Variant> ());
r.push (tl::Variant (res.first));
r.push (tl::Variant (res.second));
return r;
}
static db::Point default_origin;
// provided by gsiDeclDbPolygon.cc:
@ -3757,7 +3775,32 @@ Class<db::Region> decl_Region (decl_dbShapeCollection, "db", "Region",
"metal1_all_nets = metal1.nets\n"
"@/code\n"
"\n"
"This method was introduced in version 0.28.4"
"This method was introduced in version 0.28.4."
) +
gsi::method_ext ("begin_shapes_rec", &begin_shapes_rec,
"@brief Returns a recursive shape iterator plus a transformation for the shapes constituting this region.\n"
"This method returns a pair consisting of a \\RecursiveShapeIterator plus a \\ICplxTrans transformation. "
"Both objects allow accessing the shapes (polygons) of the region in a detailed fashion. To iterate the "
"the polygons use a code like this:\n"
"\n"
"@code\n"
"iter, trans = region.begin_shapes_rec\n"
"iter.each do |i|\n"
" polygon = trans * iter.trans * i.shape.polygon\n"
" ...\n"
"end\n"
"@/code\n"
"\n"
"This method is the most powerful way of accessing the shapes inside the region. I allows for example to obtain the "
"properties attached to the polygons of the region. It is primarily intended for special applications like iterating net-annotated shapes.\n"
"\n"
"This speciality method was introduced in version 0.29.5."
) +
gsi::method_ext ("begin_merged_shapes_rec", &begin_merged_shapes_rec,
"@brief Returns a recursive shape iterator plus a transformation for the shapes constituting the merged region.\n"
"It can be used like \\begin_shapes_rec, but delivers shapes from the merged polygons pool.\n"
"\n"
"This speciality method was introduced in version 0.29.5."
) +
gsi::make_property_methods<db::Region> ()
,

View File

@ -81,6 +81,31 @@ class DBRegionTest(unittest.TestCase):
dss = None
self.assertEqual(pya.DeepShapeStore.instance_count(), 0)
# begin_shapes_rec and begin_shapes_merged_rec
def test_extended_iter(self):
r = pya.Region()
# NOTE: this also tests the copy semantics of the RecursiveShape to Variant binding in RBA:
it, trans = r.begin_shapes_rec()
s = ",".join([ str(trans*i.trans()*i.shape().polygon) for i in it.each() ])
self.assertEqual(s, "")
it, trans = r.begin_merged_shapes_rec()
s = ",".join([ str(trans*i.trans()*i.shape().polygon) for i in it.each() ])
self.assertEqual(s, "")
r.insert(pya.Box(0, 0, 100, 100))
r.insert(pya.Box(50, 50, 200, 200))
it, trans = r.begin_shapes_rec()
s = ",".join([ str(trans*i.trans()*i.shape().polygon) for i in it.each() ])
self.assertEqual(s, "(0,0;0,100;100,100;100,0),(50,50;50,200;200,200;200,50)")
it, trans = r.begin_merged_shapes_rec()
s = ",".join([ str(trans*i.trans()*i.shape().polygon) for i in it.each() ])
self.assertEqual(s, "(0,0;0,100;50,100;50,200;200,200;200,50;100,50;100,0)")
# run unit tests
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(DBRegionTest)

View File

@ -1471,6 +1471,33 @@ class DBRegion_TestClass < TestBase
end
# begin_shapes_rec and begin_shapes_merged_rec
def test_extended_iter
r = RBA::Region::new()
# NOTE: this also tests the copy semantics of the RecursiveShape to Variant binding in RBA:
iter, trans = r.begin_shapes_rec
str = iter.each.collect { |i| (trans*i.trans*i.shape.polygon).to_s }.join(",")
assert_equal(str, "")
iter, trans = r.begin_merged_shapes_rec
str = iter.each.collect { |i| (trans*i.trans*i.shape.polygon).to_s }.join(",")
assert_equal(str, "")
r.insert(RBA::Box::new(0, 0, 100, 100))
r.insert(RBA::Box::new(50, 50, 200, 200))
iter, trans = r.begin_shapes_rec
str = iter.each.collect { |i| (trans*i.trans*i.shape.polygon).to_s }.join(",")
assert_equal(str, "(0,0;0,100;100,100;100,0),(50,50;50,200;200,200;200,50)")
iter, trans = r.begin_merged_shapes_rec
str = iter.each.collect { |i| (trans*i.trans*i.shape.polygon).to_s }.join(",")
assert_equal(str, "(0,0;0,100;50,100;50,200;200,200;200,50;100,50;100,0)")
end
end
load("test_epilogue.rb")