From 420f8cfdc3e625d00a72d6509df7d15973dd6555 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 1 Jan 2023 18:45:37 +0100 Subject: [PATCH] Fixed issue #1240 (Layer is not activated from layer properties file on first creation) --- src/db/db/dbLayout.cc | 16 ++++++++++++++++ src/db/db/dbLayout.h | 7 ++----- src/db/db/dbLayoutLayers.cc | 19 +------------------ src/db/db/dbLayoutLayers.h | 2 +- src/db/unit_tests/dbLayoutTests.cc | 6 ++++++ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index b181bd2e0..8c3296bc8 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -1856,6 +1856,22 @@ Layout::delete_layer (unsigned int n) layer_properties_changed (); } +unsigned int +Layout::get_layer (const db::LayerProperties &props) +{ + int li = get_layer_maybe (props); + if (li >= 0) { + return (unsigned int) li; + } + + if (props.is_null ()) { + // for a null layer info always create a layer + return insert_layer (); + } else { + return insert_layer (props); + } +} + unsigned int Layout::insert_layer (const LayerProperties &props) { diff --git a/src/db/db/dbLayout.h b/src/db/db/dbLayout.h index 7b7cc1278..0dc93cdf7 100644 --- a/src/db/db/dbLayout.h +++ b/src/db/db/dbLayout.h @@ -1644,15 +1644,12 @@ public: * If there already is a layer matching the given properties, it's index will be * returned. Otherwise a new layer with these properties is created. */ - unsigned int get_layer (const db::LayerProperties &props) - { - return m_layers.get_layer (props); - } + unsigned int get_layer (const db::LayerProperties &props); /** * @brief Gets the layer with the given properties or -1 if such a layer does not exist */ - int get_layer_maybe (const db::LayerProperties &props) + int get_layer_maybe (const db::LayerProperties &props) const { return m_layers.get_layer_maybe (props); } diff --git a/src/db/db/dbLayoutLayers.cc b/src/db/db/dbLayoutLayers.cc index e6f8eb251..33e51b474 100644 --- a/src/db/db/dbLayoutLayers.cc +++ b/src/db/db/dbLayoutLayers.cc @@ -157,25 +157,8 @@ LayoutLayers::insert_layer (unsigned int index, const LayerProperties &props) set_properties (index, props); } -unsigned int -LayoutLayers::get_layer (const db::LayerProperties &lp) -{ - if (lp.is_null ()) { - // for a null layer info always create a layer - return insert_layer (); - } else { - auto i = m_layers_by_props.find (lp); - if (i != m_layers_by_props.end () && i->first.log_equal (lp)) { - return i->second; - } else { - // otherwise create a new layer - return insert_layer (lp); - } - } -} - int -LayoutLayers::get_layer_maybe (const db::LayerProperties &lp) +LayoutLayers::get_layer_maybe (const db::LayerProperties &lp) const { if (lp.is_null ()) { return -1; diff --git a/src/db/db/dbLayoutLayers.h b/src/db/db/dbLayoutLayers.h index fbe0988bf..653c14375 100644 --- a/src/db/db/dbLayoutLayers.h +++ b/src/db/db/dbLayoutLayers.h @@ -187,7 +187,7 @@ public: /** * @brief Gets the layer with the given properties or -1 if such a layer does not exist. */ - int get_layer_maybe (const db::LayerProperties &props); + int get_layer_maybe (const db::LayerProperties &props) const; /** * @brief Insert a new special layer with the given properties diff --git a/src/db/unit_tests/dbLayoutTests.cc b/src/db/unit_tests/dbLayoutTests.cc index 1d4829e23..b0f0e49cf 100644 --- a/src/db/unit_tests/dbLayoutTests.cc +++ b/src/db/unit_tests/dbLayoutTests.cc @@ -478,6 +478,12 @@ TEST(4) ps.insert (std::make_pair (g.properties_repository ().prop_name_id (tl::Variant (1)), tl::Variant ("XXX"))); prop_id = g.properties_repository ().properties_id (ps); EXPECT_EQ (el.property_ids_dirty, true); + + el.layer_properties_dirty = false; + EXPECT_EQ (g.get_layer_maybe (db::LayerProperties (42, 17)), -1); + EXPECT_EQ (el.layer_properties_dirty, false); + EXPECT_EQ (g.get_layer (db::LayerProperties (42, 17)) >= 0, true); + EXPECT_EQ (el.layer_properties_dirty, true); // new layer got inserted } static std::string l2s (const db::Layout &layout)