From c112f78b1c3c17fa352ff588809b70120614a2c3 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 30 Dec 2024 23:47:34 +0100 Subject: [PATCH] WIP: edge and edge pairs with properties, tests, conversion constructors, edge neighborhood tests with properties. --- src/db/db/gsiDeclDbBox.cc | 12 ++++----- src/db/db/gsiDeclDbEdge.cc | 39 +++++++++++++++++++++++++++++ src/db/db/gsiDeclDbEdgePair.cc | 39 +++++++++++++++++++++++++++++ src/db/db/gsiDeclDbPath.cc | 12 ++++----- src/db/db/gsiDeclDbPolygon.cc | 8 +++--- src/db/db/gsiDeclDbText.cc | 12 ++++----- testdata/ruby/dbEdgeNeighborhood.rb | 29 +++++++++++---------- testdata/ruby/dbEdgePairTest.rb | 32 +++++++++++++++++++++++ testdata/ruby/dbEdgeTest.rb | 32 +++++++++++++++++++++++ 9 files changed, 180 insertions(+), 35 deletions(-) diff --git a/src/db/db/gsiDeclDbBox.cc b/src/db/db/gsiDeclDbBox.cc index 2266c7fee..ebb7ec00a 100644 --- a/src/db/db/gsiDeclDbBox.cc +++ b/src/db/db/gsiDeclDbBox.cc @@ -591,14 +591,14 @@ Class decl_Box ("db", "Box", "database objects." ); -static db::BoxWithProperties *new_box_with_properties (const db::Box &poly, db::properties_id_type pid) +static db::BoxWithProperties *new_box_with_properties (const db::Box &box, db::properties_id_type pid) { - return new db::BoxWithProperties (poly, pid); + return new db::BoxWithProperties (box, pid); } Class decl_BoxWithProperties (decl_Box, "db", "BoxWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_box_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_box_with_properties, gsi::arg ("box"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , @@ -665,14 +665,14 @@ Class decl_DBox ("db", "DBox", "database objects." ); -static db::DBoxWithProperties *new_dbox_with_properties (const db::DBox &poly, db::properties_id_type pid) +static db::DBoxWithProperties *new_dbox_with_properties (const db::DBox &box, db::properties_id_type pid) { - return new db::DBoxWithProperties (poly, pid); + return new db::DBoxWithProperties (box, pid); } Class decl_DBoxWithProperties (decl_DBox, "db", "DBoxWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_dbox_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_dbox_with_properties, gsi::arg ("box"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , diff --git a/src/db/db/gsiDeclDbEdge.cc b/src/db/db/gsiDeclDbEdge.cc index c50c89c18..3bca188b2 100644 --- a/src/db/db/gsiDeclDbEdge.cc +++ b/src/db/db/gsiDeclDbEdge.cc @@ -22,6 +22,7 @@ #include "gsiDecl.h" +#include "gsiDeclDbPropertiesSupport.h" #include "dbPoint.h" #include "dbEdge.h" #include "dbHash.h" @@ -694,6 +695,25 @@ Class decl_Edge ("db", "Edge", "database objects like the Edge class." ); +static db::EdgeWithProperties *new_edge_with_properties (const db::Edge &edge, db::properties_id_type pid) +{ + return new db::EdgeWithProperties (edge, pid); +} + +Class decl_EdgeWithProperties (decl_Edge, "db", "EdgeWithProperties", + gsi::properties_support_methods () + + constructor ("new", &new_edge_with_properties, gsi::arg ("edge"), gsi::arg ("properties_id", db::properties_id_type (0)), + "@brief Creates a new object from a property-less object and a properties ID." + ) + , + "@brief A Edge object with properties attached.\n" + "This class represents a combination of a Edge object an user properties. User properties are " + "stored in form of a properties ID. Convenience methods are provided to manipulate or retrieve " + "user properties directly.\n" + "\n" + "This class has been introduced in version 0.30." +); + static db::DEdge *dedge_from_iedge (const db::Edge &e) { return new db::DEdge (e); @@ -740,5 +760,24 @@ Class decl_DEdge ("db", "DEdge", "database objects like the Edge class." ); +static db::DEdgeWithProperties *new_dedge_with_properties (const db::DEdge &edge, db::properties_id_type pid) +{ + return new db::DEdgeWithProperties (edge, pid); +} + +Class decl_DEdgeWithProperties (decl_DEdge, "db", "DEdgeWithProperties", + gsi::properties_support_methods () + + constructor ("new", &new_dedge_with_properties, gsi::arg ("edge"), gsi::arg ("properties_id", db::properties_id_type (0)), + "@brief Creates a new object from a property-less object and a properties ID." + ) + , + "@brief A DEdge object with properties attached.\n" + "This class represents a combination of a DEdge object an user properties. User properties are " + "stored in form of a properties ID. Convenience methods are provided to manipulate or retrieve " + "user properties directly.\n" + "\n" + "This class has been introduced in version 0.30." +); + } diff --git a/src/db/db/gsiDeclDbEdgePair.cc b/src/db/db/gsiDeclDbEdgePair.cc index 071158558..21333e510 100644 --- a/src/db/db/gsiDeclDbEdgePair.cc +++ b/src/db/db/gsiDeclDbEdgePair.cc @@ -22,6 +22,7 @@ #include "gsiDecl.h" +#include "gsiDeclDbPropertiesSupport.h" #include "dbEdgePair.h" #include "dbHash.h" @@ -284,6 +285,25 @@ Class decl_EdgePair ("db", "EdgePair", "This class has been introduced in version 0.23.\n" ); +static db::EdgePairWithProperties *new_edge_pair_with_properties (const db::EdgePair &edge_pair, db::properties_id_type pid) +{ + return new db::EdgePairWithProperties (edge_pair, pid); +} + +Class decl_EdgePairWithProperties (decl_EdgePair, "db", "EdgePairWithProperties", + gsi::properties_support_methods () + + constructor ("new", &new_edge_pair_with_properties, gsi::arg ("edge_pair"), gsi::arg ("properties_id", db::properties_id_type (0)), + "@brief Creates a new object from a property-less object and a properties ID." + ) + , + "@brief A EdgePair object with properties attached.\n" + "This class represents a combination of a EdgePair object an user properties. User properties are " + "stored in form of a properties ID. Convenience methods are provided to manipulate or retrieve " + "user properties directly.\n" + "\n" + "This class has been introduced in version 0.30." +); + static db::DEdgePair *dedge_pair_from_iedge_pair (const db::EdgePair &e) { return new db::DEdgePair (e); @@ -332,4 +352,23 @@ Class decl_DEdgePair ("db", "DEdgePair", "This class has been introduced in version 0.23.\n" ); +static db::DEdgePairWithProperties *new_dedge_pair_with_properties (const db::DEdgePair &edge_pair, db::properties_id_type pid) +{ + return new db::DEdgePairWithProperties (edge_pair, pid); +} + +Class decl_DEdgePairWithProperties (decl_EdgePair, "db", "DEdgePairWithProperties", + gsi::properties_support_methods () + + constructor ("new", &new_dedge_pair_with_properties, gsi::arg ("edge_pair"), gsi::arg ("properties_id", db::properties_id_type (0)), + "@brief Creates a new object from a property-less object and a properties ID." + ) + , + "@brief A DEdgePair object with properties attached.\n" + "This class represents a combination of a DEdgePair object an user properties. User properties are " + "stored in form of a properties ID. Convenience methods are provided to manipulate or retrieve " + "user properties directly.\n" + "\n" + "This class has been introduced in version 0.30." +); + } diff --git a/src/db/db/gsiDeclDbPath.cc b/src/db/db/gsiDeclDbPath.cc index 1be94cfaf..cebd6a22d 100644 --- a/src/db/db/gsiDeclDbPath.cc +++ b/src/db/db/gsiDeclDbPath.cc @@ -385,14 +385,14 @@ Class decl_Path ("db", "Path", "database objects." ); -static db::PathWithProperties *new_path_with_properties (const db::Path &poly, db::properties_id_type pid) +static db::PathWithProperties *new_path_with_properties (const db::Path &path, db::properties_id_type pid) { - return new db::PathWithProperties (poly, pid); + return new db::PathWithProperties (path, pid); } Class decl_PathWithProperties (decl_Path, "db", "PathWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_path_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_path_with_properties, gsi::arg ("path"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , @@ -472,14 +472,14 @@ Class decl_DPath ("db", "DPath", "database objects." ); -static db::DPathWithProperties *new_dpath_with_properties (const db::DPath &poly, db::properties_id_type pid) +static db::DPathWithProperties *new_dpath_with_properties (const db::DPath &path, db::properties_id_type pid) { - return new db::DPathWithProperties (poly, pid); + return new db::DPathWithProperties (path, pid); } Class decl_DPathWithProperties (decl_DPath, "db", "DPathWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_dpath_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_dpath_with_properties, gsi::arg ("path"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , diff --git a/src/db/db/gsiDeclDbPolygon.cc b/src/db/db/gsiDeclDbPolygon.cc index 287dd0a5b..9edc1eab4 100644 --- a/src/db/db/gsiDeclDbPolygon.cc +++ b/src/db/db/gsiDeclDbPolygon.cc @@ -793,7 +793,7 @@ static db::SimplePolygonWithProperties *new_simple_polygon_with_properties (cons Class decl_SimplePolygonWithProperties (decl_SimplePolygon, "db", "SimplePolygonWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_simple_polygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_simple_polygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , @@ -880,7 +880,7 @@ static db::DSimplePolygonWithProperties *new_dsimple_polygon_with_properties (co Class decl_DSimplePolygonWithProperties (decl_DSimplePolygon, "db", "DSimplePolygonWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_dsimple_polygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_dsimple_polygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , @@ -2072,7 +2072,7 @@ static db::PolygonWithProperties *new_polygon_with_properties (const db::Polygon Class decl_PolygonWithProperties (decl_Polygon, "db", "PolygonWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_polygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_polygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , @@ -2186,7 +2186,7 @@ static db::DPolygonWithProperties *new_dpolygon_with_properties (const db::DPoly Class decl_DPolygonWithProperties (decl_DPolygon, "db", "DPolygonWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_dpolygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_dpolygon_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , diff --git a/src/db/db/gsiDeclDbText.cc b/src/db/db/gsiDeclDbText.cc index 63974976b..37f9325e8 100644 --- a/src/db/db/gsiDeclDbText.cc +++ b/src/db/db/gsiDeclDbText.cc @@ -449,14 +449,14 @@ Class decl_Text ("db", "Text", "database objects." ); -static db::TextWithProperties *new_text_with_properties (const db::Text &poly, db::properties_id_type pid) +static db::TextWithProperties *new_text_with_properties (const db::Text &text, db::properties_id_type pid) { - return new db::TextWithProperties (poly, pid); + return new db::TextWithProperties (text, pid); } Class decl_TextWithProperties (decl_Text, "db", "TextWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_text_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_text_with_properties, gsi::arg ("text"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , @@ -517,14 +517,14 @@ Class decl_DText ("db", "DText", "database objects." ); -static db::DTextWithProperties *new_dtext_with_properties (const db::DText &poly, db::properties_id_type pid) +static db::DTextWithProperties *new_dtext_with_properties (const db::DText &text, db::properties_id_type pid) { - return new db::DTextWithProperties (poly, pid); + return new db::DTextWithProperties (text, pid); } Class decl_DTextWithProperties (decl_DText, "db", "DTextWithProperties", gsi::properties_support_methods () + - constructor ("new", &new_dtext_with_properties, gsi::arg ("polygon"), gsi::arg ("properties_id"), + constructor ("new", &new_dtext_with_properties, gsi::arg ("text"), gsi::arg ("properties_id", db::properties_id_type (0)), "@brief Creates a new object from a property-less object and a properties ID." ) , diff --git a/testdata/ruby/dbEdgeNeighborhood.rb b/testdata/ruby/dbEdgeNeighborhood.rb index edfeda792..3a230e75d 100644 --- a/testdata/ruby/dbEdgeNeighborhood.rb +++ b/testdata/ruby/dbEdgeNeighborhood.rb @@ -93,10 +93,13 @@ class DBEdgeNeighborhood_TestClass < TestBase l1 = ly.layer(1, 0) cell = ly.create_cell("TOP") - cell.shapes(l1).insert(RBA::Box::new(0, 0, 1000, 1000)) + pid1 = RBA::Layout::properties_id({ 1 => "one" }) + + cell.shapes(l1).insert(RBA::Box::new(0, 0, 1000, 1000), pid1) cell.shapes(l1).insert(RBA::Box::new(-1100, 0, -100, 1000)) prim = RBA::Region::new(cell.begin_shapes_rec(l1)) + prim.enable_properties visitor = MyVisitor::new @@ -116,19 +119,19 @@ class DBEdgeNeighborhood_TestClass < TestBase res = prim.complex_op(node) assert_equal(visitor.log, - "Polygon: (-1100,0;-1100,1000;-100,1000;-100,0)\n" + - "edge = (-1100,0;-1100,1000)\n" + - "edge = (-1100,1000;-100,1000)\n" + - "edge = (-100,1000;-100,0)\n" + - " 0.0,1000.0 -> 0: (0,100;0,101;1000,101;1000,100)\n" + - "edge = (-100,0;-1100,0)\n" + + "Polygon: (-1100,0;-1100,1000;-100,1000;-100,0) props={}\n" + + "edge = (-1100,0;-1100,1000) props={}\n" + + "edge = (-1100,1000;-100,1000) props={}\n" + + "edge = (-100,1000;-100,0) props={}\n" + + " 0.0,1000.0 -> 0: (0,100;0,101;1000,101;1000,100) props={1=>one}\n" + + "edge = (-100,0;-1100,0) props={}\n" + "/Polygon\n" + - "Polygon: (0,0;0,1000;1000,1000;1000,0)\n" + - "edge = (0,0;0,1000)\n" + - " 0.0,1000.0 -> 0: (0,100;0,101;1000,101;1000,100)\n" + - "edge = (0,1000;1000,1000)\n" + - "edge = (1000,1000;1000,0)\n" + - "edge = (1000,0;0,0)\n" + + "Polygon: (0,0;0,1000;1000,1000;1000,0) props={1=>one}\n" + + "edge = (0,0;0,1000) props={1=>one}\n" + + " 0.0,1000.0 -> 0: (0,100;0,101;1000,101;1000,100) props={}\n" + + "edge = (0,1000;1000,1000) props={1=>one}\n" + + "edge = (1000,1000;1000,0) props={1=>one}\n" + + "edge = (1000,0;0,0) props={1=>one}\n" + "/Polygon\n" ) diff --git a/testdata/ruby/dbEdgePairTest.rb b/testdata/ruby/dbEdgePairTest.rb index 68ea708d0..61abb0010 100644 --- a/testdata/ruby/dbEdgePairTest.rb +++ b/testdata/ruby/dbEdgePairTest.rb @@ -246,6 +246,38 @@ class DBEdgePair_TestClass < TestBase end + def test_edgePairWithProperties + + s = RBA::EdgePairWithProperties::new + assert_equal(s.to_s, "(0,0;0,0)/(0,0;0,0) props={}") + + pid = RBA::Layout::properties_id({ 1 => "one" }) + s = RBA::EdgePairWithProperties::new(RBA::EdgePair::new(RBA::Edge::new(0, 0, 100, 200), RBA::Edge::new(10, 10, 110, 210)), pid) + assert_equal(s.to_s, "(0,0;100,200)/(10,10;110,210) props={1=>one}") + assert_equal(s.property(1), "one") + assert_equal(s.properties, { 1 => "one" }) + s.set_property(1, "xxx") + assert_equal(s.to_s, "(0,0;100,200)/(10,10;110,210) props={1=>xxx}") + s.delete_property(1) + assert_equal(s.to_s, "(0,0;100,200)/(10,10;110,210) props={}") + assert_equal(s.property(1), nil) + + s = RBA::DEdgePairWithProperties::new + assert_equal(s.to_s, "(0,0;0,0)/(0,0;0,0) props={}") + + pid = RBA::Layout::properties_id({ 1 => "one" }) + s = RBA::DEdgePairWithProperties::new(RBA::DEdgePair::new(RBA::DEdge::new(0, 0, 100, 200), RBA::DEdge::new(10, 10, 110, 210)), pid) + assert_equal(s.to_s, "(0,0;100,200)/(10,10;110,210) props={1=>one}") + assert_equal(s.property(1), "one") + assert_equal(s.properties, { 1 => "one" }) + s.set_property(1, "xxx") + assert_equal(s.to_s, "(0,0;100,200)/(10,10;110,210) props={1=>xxx}") + s.delete_property(1) + assert_equal(s.to_s, "(0,0;100,200)/(10,10;110,210) props={}") + assert_equal(s.property(1), nil) + + end + end load("test_epilogue.rb") diff --git a/testdata/ruby/dbEdgeTest.rb b/testdata/ruby/dbEdgeTest.rb index c5a98f8a9..8c9f18a7c 100644 --- a/testdata/ruby/dbEdgeTest.rb +++ b/testdata/ruby/dbEdgeTest.rb @@ -333,6 +333,38 @@ class DBEdge_TestClass < TestBase end + def test_edgeWithProperties + + s = RBA::EdgeWithProperties::new + assert_equal(s.to_s, "(0,0;0,0) props={}") + + pid = RBA::Layout::properties_id({ 1 => "one" }) + s = RBA::EdgeWithProperties::new(RBA::Edge::new(0, 0, 100, 200), pid) + assert_equal(s.to_s, "(0,0;100,200) props={1=>one}") + assert_equal(s.property(1), "one") + assert_equal(s.properties, { 1 => "one" }) + s.set_property(1, "xxx") + assert_equal(s.to_s, "(0,0;100,200) props={1=>xxx}") + s.delete_property(1) + assert_equal(s.to_s, "(0,0;100,200) props={}") + assert_equal(s.property(1), nil) + + s = RBA::DEdgeWithProperties::new + assert_equal(s.to_s, "(0,0;0,0) props={}") + + pid = RBA::Layout::properties_id({ 1 => "one" }) + s = RBA::DEdgeWithProperties::new(RBA::DEdge::new(0, 0, 100, 200), pid) + assert_equal(s.to_s, "(0,0;100,200) props={1=>one}") + assert_equal(s.property(1), "one") + assert_equal(s.properties, { 1 => "one" }) + s.set_property(1, "xxx") + assert_equal(s.to_s, "(0,0;100,200) props={1=>xxx}") + s.delete_property(1) + assert_equal(s.to_s, "(0,0;100,200) props={}") + assert_equal(s.property(1), nil) + + end + end load("test_epilogue.rb")