mirror of https://github.com/KLayout/klayout.git
RecursiveShapeIterator#property and RecursiveShapeIterator#properties
This commit is contained in:
parent
cf5e62a4ed
commit
f977973b85
|
|
@ -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",
|
||||
gsi::constructor ("new", &new_si1, gsi::arg ("layout"), gsi::arg ("cell"), gsi::arg ("layer"),
|
||||
"@brief Creates a recursive, single-layer shape iterator.\n"
|
||||
|
|
@ -622,6 +638,21 @@ Class<db::RecursiveShapeIterator> decl_RecursiveShapeIterator ("db", "RecursiveS
|
|||
"\n"
|
||||
"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,
|
||||
"@brief Gets the current shape\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -1315,8 +1315,8 @@ Class<db::Shape> decl_Shape ("db", "Shape",
|
|||
gsi::method_ext ("property", &get_property, gsi::arg ("key"),
|
||||
"@brief Gets the user property with the given key\n"
|
||||
"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 "
|
||||
"convenient than using the layout object and the properties ID to retrieve the property value. "
|
||||
"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.\n"
|
||||
"\n"
|
||||
"This method has been introduced in version 0.22."
|
||||
) +
|
||||
|
|
|
|||
|
|
@ -354,6 +354,25 @@ 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
|
||||
|
||||
load("test_epilogue.rb")
|
||||
|
|
|
|||
Loading…
Reference in New Issue