mirror of https://github.com/KLayout/klayout.git
WIP: bug fixing, new tests for property filters
This commit is contained in:
parent
75c20aa03a
commit
d230691ae4
|
|
@ -190,7 +190,7 @@ const db::RecursiveShapeIterator *FlatEdgePairs::iter () const
|
|||
|
||||
void FlatEdgePairs::apply_property_translator (const db::PropertiesTranslator &pt)
|
||||
{
|
||||
db::Shapes new_edge_pairs;
|
||||
db::Shapes new_edge_pairs (mp_edge_pairs->is_editable ());
|
||||
new_edge_pairs.assign (*mp_edge_pairs, pt);
|
||||
mp_edge_pairs->swap (new_edge_pairs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ const db::RecursiveShapeIterator *FlatEdges::iter () const
|
|||
|
||||
void FlatEdges::apply_property_translator (const db::PropertiesTranslator &pt)
|
||||
{
|
||||
db::Shapes new_edges;
|
||||
db::Shapes new_edges (mp_edges->is_editable ());
|
||||
new_edges.assign (*mp_edges, pt);
|
||||
mp_edges->swap (new_edges);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ const db::RecursiveShapeIterator *FlatRegion::iter () const
|
|||
|
||||
void FlatRegion::apply_property_translator (const db::PropertiesTranslator &pt)
|
||||
{
|
||||
db::Shapes new_polygons;
|
||||
db::Shapes new_polygons (mp_polygons->is_editable ());
|
||||
new_polygons.assign (*mp_polygons, pt);
|
||||
mp_polygons->swap (new_polygons);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ const db::RecursiveShapeIterator *FlatTexts::iter () const
|
|||
|
||||
void FlatTexts::apply_property_translator (const db::PropertiesTranslator &pt)
|
||||
{
|
||||
db::Shapes new_texts;
|
||||
db::Shapes new_texts (mp_texts->is_editable ());
|
||||
new_texts.assign (*mp_texts, pt);
|
||||
mp_texts->swap (new_texts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ DeepShapeCollectionDelegateBase::apply_property_translator (const db::Properties
|
|||
|
||||
db::Shapes &shapes = c->shapes (m_deep_layer.layer ());
|
||||
|
||||
db::Shapes new_shapes;
|
||||
db::Shapes new_shapes (shapes.is_editable ());
|
||||
new_shapes.assign (shapes, pt);
|
||||
shapes.swap (new_shapes);
|
||||
|
||||
|
|
@ -82,6 +82,12 @@ ShapeCollection::properties_repository ()
|
|||
return *r;
|
||||
}
|
||||
|
||||
bool
|
||||
ShapeCollection::has_properties_repository () const
|
||||
{
|
||||
return get_delegate () && get_delegate ()->properties_repository ();
|
||||
}
|
||||
|
||||
void
|
||||
ShapeCollection::apply_property_translator (const db::PropertiesTranslator &pt)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -120,6 +120,11 @@ public:
|
|||
* Use this object to decode property IDs.
|
||||
*/
|
||||
const db::PropertiesRepository &properties_repository () const;
|
||||
|
||||
/**
|
||||
* @brief Gets a value indicating whether a properties repository is available
|
||||
*/
|
||||
bool has_properties_repository () const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,15 +49,19 @@ static void remove_properties (Container *c)
|
|||
template <class Container>
|
||||
static void filter_properties (Container *c, const std::vector<tl::Variant> &keys)
|
||||
{
|
||||
std::set<tl::Variant> kf;
|
||||
kf.insert (keys.begin (), keys.end ());
|
||||
c->apply_property_translator (db::PropertiesTranslator::make_filter (c->properties_repository (), kf));
|
||||
if (c->has_properties_repository ()) {
|
||||
std::set<tl::Variant> kf;
|
||||
kf.insert (keys.begin (), keys.end ());
|
||||
c->apply_property_translator (db::PropertiesTranslator::make_filter (c->properties_repository (), kf));
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
static void map_properties (Container *c, const std::map<tl::Variant, tl::Variant> &map)
|
||||
{
|
||||
c->apply_property_translator (db::PropertiesTranslator::make_key_mapper (c->properties_repository (), map));
|
||||
if (c->has_properties_repository ()) {
|
||||
c->apply_property_translator (db::PropertiesTranslator::make_key_mapper (c->properties_repository (), map));
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
|
|
|
|||
|
|
@ -2386,6 +2386,140 @@ TEST(53_PropertiesDeepFromLayout)
|
|||
EXPECT_EQ (s.at_end (), true);
|
||||
}
|
||||
|
||||
TEST(54_PropertiesFilterDeep)
|
||||
{
|
||||
db::DeepShapeStore dss ("TOP", 0.001);
|
||||
db::Region r (dss);
|
||||
|
||||
db::PropertiesRepository &rp = r.properties_repository ();
|
||||
db::property_names_id_type key1 = rp.prop_name_id (1);
|
||||
db::property_names_id_type key2 = rp.prop_name_id (2);
|
||||
db::property_names_id_type key3 = rp.prop_name_id (3);
|
||||
|
||||
db::PropertiesRepository::properties_set ps;
|
||||
ps.insert (std::make_pair (key1, 100));
|
||||
ps.insert (std::make_pair (key2, 101));
|
||||
db::properties_id_type prop1a = rp.properties_id (ps);
|
||||
|
||||
ps.clear ();
|
||||
ps.insert (std::make_pair (key1, 0));
|
||||
ps.insert (std::make_pair (key2, 101));
|
||||
db::properties_id_type prop1b = rp.properties_id (ps);
|
||||
|
||||
ps.clear ();
|
||||
ps.insert (std::make_pair (key1, 100));
|
||||
ps.insert (std::make_pair (key3, 102));
|
||||
db::properties_id_type prop2 = rp.properties_id (ps);
|
||||
|
||||
ps.clear ();
|
||||
ps.insert (std::make_pair (key1, 100));
|
||||
db::properties_id_type prop3 = rp.properties_id (ps);
|
||||
|
||||
r.insert (db::BoxWithProperties (db::Box (1, 2, 101, 202), prop1a));
|
||||
r.insert (db::BoxWithProperties (db::Box (10, 12, 111, 212), prop1b));
|
||||
r.insert (db::BoxWithProperties (db::Box (20, 22, 121, 222), prop2));
|
||||
r.insert (db::BoxWithProperties (db::Box (30, 32, 131, 232), prop3));
|
||||
|
||||
db::Region rr = r;
|
||||
|
||||
std::set<tl::Variant> kf;
|
||||
kf.insert (1);
|
||||
|
||||
rr.apply_property_translator (db::PropertiesTranslator::make_filter (rr.properties_repository (), kf));
|
||||
|
||||
db::Region::const_iterator s = rr.begin ();
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=100");
|
||||
EXPECT_EQ (s->to_string (), "(1,2;1,202;101,202;101,2)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=0");
|
||||
EXPECT_EQ (s->to_string (), "(10,12;10,212;111,212;111,12)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=100");
|
||||
EXPECT_EQ (s->to_string (), "(20,22;20,222;121,222;121,22)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=100");
|
||||
EXPECT_EQ (s->to_string (), "(30,32;30,232;131,232;131,32)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), true);
|
||||
|
||||
s = r.begin ();
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (r.properties_repository (), s.prop_id ()), "1=100\n2=101");
|
||||
EXPECT_EQ (s->to_string (), "(1,2;1,202;101,202;101,2)");
|
||||
}
|
||||
|
||||
TEST(55_PropertiesFilterFlat)
|
||||
{
|
||||
db::Region r;
|
||||
// force flat:
|
||||
r.insert (db::Box (0, 0, 1, 1));
|
||||
r.clear ();
|
||||
|
||||
db::PropertiesRepository &rp = r.properties_repository ();
|
||||
db::property_names_id_type key1 = rp.prop_name_id (1);
|
||||
db::property_names_id_type key2 = rp.prop_name_id (2);
|
||||
db::property_names_id_type key3 = rp.prop_name_id (3);
|
||||
|
||||
db::PropertiesRepository::properties_set ps;
|
||||
ps.insert (std::make_pair (key1, 100));
|
||||
ps.insert (std::make_pair (key2, 101));
|
||||
db::properties_id_type prop1a = rp.properties_id (ps);
|
||||
|
||||
ps.clear ();
|
||||
ps.insert (std::make_pair (key1, 0));
|
||||
ps.insert (std::make_pair (key2, 101));
|
||||
db::properties_id_type prop1b = rp.properties_id (ps);
|
||||
|
||||
ps.clear ();
|
||||
ps.insert (std::make_pair (key1, 100));
|
||||
ps.insert (std::make_pair (key3, 102));
|
||||
db::properties_id_type prop2 = rp.properties_id (ps);
|
||||
|
||||
ps.clear ();
|
||||
ps.insert (std::make_pair (key1, 100));
|
||||
db::properties_id_type prop3 = rp.properties_id (ps);
|
||||
|
||||
r.insert (db::BoxWithProperties (db::Box (1, 2, 101, 202), prop1a));
|
||||
r.insert (db::BoxWithProperties (db::Box (10, 12, 111, 212), prop1b));
|
||||
r.insert (db::BoxWithProperties (db::Box (20, 22, 121, 222), prop2));
|
||||
r.insert (db::BoxWithProperties (db::Box (30, 32, 131, 232), prop3));
|
||||
|
||||
db::Region rr = r;
|
||||
|
||||
std::set<tl::Variant> kf;
|
||||
kf.insert (1);
|
||||
|
||||
rr.apply_property_translator (db::PropertiesTranslator::make_filter (rr.properties_repository (), kf));
|
||||
|
||||
db::Region::const_iterator s = rr.begin ();
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=100");
|
||||
EXPECT_EQ (s->to_string (), "(1,2;1,202;101,202;101,2)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=0");
|
||||
EXPECT_EQ (s->to_string (), "(10,12;10,212;111,212;111,12)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=100");
|
||||
EXPECT_EQ (s->to_string (), "(20,22;20,222;121,222;121,22)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (rr.properties_repository (), s.prop_id ()), "1=100");
|
||||
EXPECT_EQ (s->to_string (), "(30,32;30,232;131,232;131,32)");
|
||||
++s;
|
||||
EXPECT_EQ (s.at_end (), true);
|
||||
|
||||
s = r.begin ();
|
||||
EXPECT_EQ (s.at_end (), false);
|
||||
EXPECT_EQ (db::prop2string (r.properties_repository (), s.prop_id ()), "1=100\n2=101");
|
||||
EXPECT_EQ (s->to_string (), "(1,2;1,202;101,202;101,2)");
|
||||
}
|
||||
|
||||
TEST(100_Processors)
|
||||
{
|
||||
db::Region r;
|
||||
|
|
|
|||
Loading…
Reference in New Issue