diff --git a/src/db/db/dbFlatEdgePairs.cc b/src/db/db/dbFlatEdgePairs.cc index 2d1a0d3ae..91e6650ac 100644 --- a/src/db/db/dbFlatEdgePairs.cc +++ b/src/db/db/dbFlatEdgePairs.cc @@ -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); } diff --git a/src/db/db/dbFlatEdges.cc b/src/db/db/dbFlatEdges.cc index a64d71603..43d5dd1dd 100644 --- a/src/db/db/dbFlatEdges.cc +++ b/src/db/db/dbFlatEdges.cc @@ -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); } diff --git a/src/db/db/dbFlatRegion.cc b/src/db/db/dbFlatRegion.cc index fcc3b083c..e6b6b7022 100644 --- a/src/db/db/dbFlatRegion.cc +++ b/src/db/db/dbFlatRegion.cc @@ -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); } diff --git a/src/db/db/dbFlatTexts.cc b/src/db/db/dbFlatTexts.cc index 3fe27e041..a724be4d1 100644 --- a/src/db/db/dbFlatTexts.cc +++ b/src/db/db/dbFlatTexts.cc @@ -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); } diff --git a/src/db/db/dbShapeCollection.cc b/src/db/db/dbShapeCollection.cc index 948032042..ea79c2b4b 100644 --- a/src/db/db/dbShapeCollection.cc +++ b/src/db/db/dbShapeCollection.cc @@ -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) { diff --git a/src/db/db/dbShapeCollection.h b/src/db/db/dbShapeCollection.h index 80005f55e..4e4824811 100644 --- a/src/db/db/dbShapeCollection.h +++ b/src/db/db/dbShapeCollection.h @@ -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; }; } diff --git a/src/db/db/gsiDeclDbContainerHelpers.h b/src/db/db/gsiDeclDbContainerHelpers.h index 34416353b..a2d4fe961 100644 --- a/src/db/db/gsiDeclDbContainerHelpers.h +++ b/src/db/db/gsiDeclDbContainerHelpers.h @@ -49,15 +49,19 @@ static void remove_properties (Container *c) template static void filter_properties (Container *c, const std::vector &keys) { - std::set 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 kf; + kf.insert (keys.begin (), keys.end ()); + c->apply_property_translator (db::PropertiesTranslator::make_filter (c->properties_repository (), kf)); + } } template static void map_properties (Container *c, const std::map &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 diff --git a/src/db/unit_tests/dbRegionTests.cc b/src/db/unit_tests/dbRegionTests.cc index 07b8b4339..dd7dd273d 100644 --- a/src/db/unit_tests/dbRegionTests.cc +++ b/src/db/unit_tests/dbRegionTests.cc @@ -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 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 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;