From 4844cffc00bd32f3c6a93f1399209938825d73d9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 15 Dec 2023 17:36:42 +0000 Subject: [PATCH] Make sure PCB_GENERATOR's lock status follows their members. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16372 --- include/board_item.h | 1 + pcbnew/board_item.cpp | 18 +++++++++++++++--- pcbnew/tools/board_editor_control.cpp | 20 +++++++++----------- pcbnew/widgets/pcb_properties_panel.cpp | 7 ++++++- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/board_item.h b/include/board_item.h index fa3aa99279..d69a9fc767 100644 --- a/include/board_item.h +++ b/include/board_item.h @@ -297,6 +297,7 @@ public: virtual bool IsLocked() const; virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; } + virtual void SetLockedProperty( bool aLocked ); virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) { } diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp index fb64435af3..bc89150398 100644 --- a/pcbnew/board_item.cpp +++ b/pcbnew/board_item.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -72,8 +73,8 @@ BOARD* BOARD_ITEM::GetBoard() bool BOARD_ITEM::IsLocked() const { - if( GetParentGroup() ) - return GetParentGroup()->IsLocked(); + if( GetParentGroup() && GetParentGroup()->IsLocked() ) + return true; const BOARD* board = GetBoard(); @@ -81,6 +82,17 @@ bool BOARD_ITEM::IsLocked() const } +void BOARD_ITEM::SetLockedProperty( bool aLocked ) +{ + PCB_GENERATOR* generator = dynamic_cast( GetParentGroup() ); + + if( generator ) + generator->SetLocked( aLocked ); + else + SetLocked( aLocked ); +} + + STROKE_PARAMS BOARD_ITEM::GetStroke() const { wxCHECK( false, STROKE_PARAMS( pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ) ) ); @@ -338,7 +350,7 @@ static struct BOARD_ITEM_DESC propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Layer" ), &BOARD_ITEM::SetLayer, &BOARD_ITEM::GetLayer ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Locked" ), - &BOARD_ITEM::SetLocked, &BOARD_ITEM::IsLocked ) ) + &BOARD_ITEM::SetLockedProperty, &BOARD_ITEM::IsLocked ) ) .SetAvailableFunc( [=]( INSPECTABLE* aItem ) -> bool { diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 619b70c408..e644b603e9 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -1246,28 +1247,25 @@ int BOARD_EDITOR_CONTROL::modifyLockSelected( MODIFY_MODE aMode ) } } - bool modified = false; - for( EDA_ITEM* item : selection ) { BOARD_ITEM* board_item = dynamic_cast( item ); wxCHECK2( board_item, continue ); + PCB_GENERATOR* generator = dynamic_cast( board_item->GetParentGroup() ); + + if( generator ) + commit.Modify( generator ); + commit.Modify( board_item ); if( aMode == ON ) - { - modified |= !board_item->IsLocked(); - board_item->SetLocked( true ); - } + board_item->SetLockedProperty( true ); else - { - modified |= board_item->IsLocked(); - board_item->SetLocked( false ); - } + board_item->SetLockedProperty( false ); } - if( modified ) + if( !commit.Empty() ) { commit.Push( aMode == ON ? _( "Lock" ) : _( "Unlock" ) ); diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index 23c3dfab5c..b9fb187b20 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -209,7 +209,12 @@ void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent ) for( EDA_ITEM* edaItem : selection ) { - BOARD_ITEM* item = static_cast( edaItem ); + BOARD_ITEM* item = static_cast( edaItem ); + PCB_GENERATOR* generator = dynamic_cast( item->GetParentGroup() ); + + if( generator ) + changes.Modify( generator ); + changes.Modify( item ); item->Set( property, newValue ); }