RecursiveShapeIterator#property and RecursiveShapeIterator#properties

This commit is contained in:
Matthias Koefferlein 2025-03-23 15:23:19 +01:00
parent cf5e62a4ed
commit f977973b85
3 changed files with 52 additions and 2 deletions

View File

@ -217,6 +217,22 @@ static void map_properties (db::RecursiveShapeIterator *c, const std::map<tl::Va
} }
} }
static tl::Variant get_property (const db::RecursiveShapeIterator *s, const tl::Variant &key)
{
db::properties_id_type id = s->prop_id ();
const db::PropertiesSet &props = db::properties (id);
return props.value (key);
}
static tl::Variant get_properties (const db::RecursiveShapeIterator *s)
{
db::properties_id_type id = s->prop_id ();
const db::PropertiesSet &props = db::properties (id);
return props.to_dict_var ();
}
Class<db::RecursiveShapeIterator> decl_RecursiveShapeIterator ("db", "RecursiveShapeIterator", Class<db::RecursiveShapeIterator> decl_RecursiveShapeIterator ("db", "RecursiveShapeIterator",
gsi::constructor ("new", &new_si1, gsi::arg ("layout"), gsi::arg ("cell"), gsi::arg ("layer"), gsi::constructor ("new", &new_si1, gsi::arg ("layout"), gsi::arg ("cell"), gsi::arg ("layer"),
"@brief Creates a recursive, single-layer shape iterator.\n" "@brief Creates a recursive, single-layer shape iterator.\n"
@ -622,6 +638,21 @@ Class<db::RecursiveShapeIterator> decl_RecursiveShapeIterator ("db", "RecursiveS
"\n" "\n"
"This attribute has been introduced in version 0.28.4." "This attribute has been introduced in version 0.28.4."
) + ) +
gsi::method_ext ("property", &get_property, gsi::arg ("key"),
"@brief Gets the effective user property with the given key\n"
"See \\prop_id for the definition of 'effective user property'.\n\n"
"This method is a convenience method that gets the effective property of the current shape with the given key. "
"If no property with that key exists, it will return nil.\n"
"\n"
"This method has been introduced in version 0.30."
) +
gsi::method_ext ("properties", &get_properties,
"@brief Gets the effective user properties\n"
"See \\prop_id for the definition of 'effective user properties'.\n\n"
"This method is a convenience method that gets the effective properties of the current shape as a single hash.\n"
"\n"
"This method has been introduced in version 0.30."
) +
gsi::method ("shape", &db::RecursiveShapeIterator::shape, gsi::method ("shape", &db::RecursiveShapeIterator::shape,
"@brief Gets the current shape\n" "@brief Gets the current shape\n"
"\n" "\n"

View File

@ -1315,8 +1315,8 @@ Class<db::Shape> decl_Shape ("db", "Shape",
gsi::method_ext ("property", &get_property, gsi::arg ("key"), gsi::method_ext ("property", &get_property, gsi::arg ("key"),
"@brief Gets the user property with the given key\n" "@brief Gets the user property with the given key\n"
"This method is a convenience method that gets the property with the given key. " "This method is a convenience method that gets the property with the given key. "
"If no property with that key does not exist, it will return nil. Using that method is more " "If no property with that key exists, it will return nil. Using that method is more "
"convenient than using the layout object and the properties ID to retrieve the property value. " "convenient than using the layout object and the properties ID to retrieve the property value.\n"
"\n" "\n"
"This method has been introduced in version 0.22." "This method has been introduced in version 0.22."
) + ) +

View File

@ -354,6 +354,25 @@ END
end end
def test_4
ly = RBA::Layout::new
top = ly.create_cell("TOP")
l1 = ly.layer(1, 0)
shape = top.shapes(l1).insert(RBA::BoxWithProperties::new(RBA::Box::new(1000, 2000), { 1 => 'A', 'X' => 17 }))
iter = top.begin_shapes_rec(l1)
iter.enable_properties
assert_equal(iter.at_end, false)
assert_equal(iter.prop_id, shape.prop_id)
assert_equal(iter.property('Y'), nil)
assert_equal(iter.property('X'), 17)
assert_equal(iter.properties, { 1 => 'A', 'X' => 17 })
end
end end
load("test_epilogue.rb") load("test_epilogue.rb")