Move some PCB_GENERATOR special-cases to propMgr listeners.

This commit is contained in:
Jeff Young 2023-12-15 21:04:33 +00:00
parent 0ab474e596
commit 1df84f4d92
9 changed files with 73 additions and 60 deletions

View File

@ -432,13 +432,24 @@ PROPERTY_MANAGER::CLASSES_INFO PROPERTY_MANAGER::GetAllClasses()
void PROPERTY_MANAGER::PropertyChanged( INSPECTABLE* aObject, PROPERTY_BASE* aProperty )
{
auto listeners = m_listeners.find( TYPE_HASH( *aObject ) );
auto callListeners =
[&]( TYPE_ID typeId )
{
auto listeners = m_listeners.find( typeId );
if( listeners == m_listeners.end() )
return;
if( listeners != m_listeners.end() )
{
for( const PROPERTY_LISTENER& listener : listeners->second )
listener( aObject, aProperty, m_managedCommit );
}
};
for( const PROPERTY_LISTENER& listener : listeners->second )
listener( aObject, aProperty, m_managedCommit );
CLASS_DESC& objectClass = getClass( TYPE_HASH( *aObject ) );
callListeners( objectClass.m_id );
for( CLASS_DESC& superClass : objectClass.m_bases )
callListeners( superClass.m_id );
}

View File

@ -298,16 +298,6 @@ public:
virtual bool IsLocked() const;
virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; }
/**
* A higher-level version of SetLocked() to be called from the property manager. Handles
* things like making sure a generator follows the locked state of its children. This is a
* huge hack because the property system won't let us pass a COMMIT through the calls, so
* the caller has to ensure that the parent generator is added to the COMMIT (along with the
* item itself).
* @param aLocked
*/
virtual void SetLockedProperty( bool aLocked );
virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) { }
/**

View File

@ -82,24 +82,6 @@ bool BOARD_ITEM::IsLocked() const
}
/**
* A higher-level version of SetLocked() to be called from the property manager. Handles
* things like making sure a generator follows the locked state of its children. This is a
* huge hack because the property system won't let us pass a COMMIT through the calls, so
* the caller has to ensure that the parent generator is added to the COMMIT (along with the
* item itself).
*/
void BOARD_ITEM::SetLockedProperty( bool aLocked )
{
PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( GetParentGroup() );
if( generator )
generator->SetLocked( aLocked );
else
SetLocked( aLocked );
}
STROKE_PARAMS BOARD_ITEM::GetStroke() const
{
wxCHECK( false, STROKE_PARAMS( pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ) ) );
@ -357,7 +339,7 @@ static struct BOARD_ITEM_DESC
propMgr.AddProperty( new PROPERTY_ENUM<BOARD_ITEM, PCB_LAYER_ID>( _HKI( "Layer" ),
&BOARD_ITEM::SetLayer, &BOARD_ITEM::GetLayer ) );
propMgr.AddProperty( new PROPERTY<BOARD_ITEM, bool>( _HKI( "Locked" ),
&BOARD_ITEM::SetLockedProperty, &BOARD_ITEM::IsLocked ) )
&BOARD_ITEM::SetLocked, &BOARD_ITEM::IsLocked ) )
.SetAvailableFunc(
[=]( INSPECTABLE* aItem ) -> bool
{

View File

@ -1801,10 +1801,12 @@ void PCB_TUNING_PATTERN::ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame )
BOARD_COMMIT commit( aEditFrame );
commit.Modify( this );
m_settings = settings;
commit.Push( _( "Edit Tuning Pattern" ) );
}
aEditFrame->GetToolManager()->PostAction<PCB_GENERATOR*>( PCB_ACTIONS::regenerateItem, this );
GENERATOR_TOOL* generatorTool = aEditFrame->GetToolManager()->GetTool<GENERATOR_TOOL>();
EditStart( generatorTool, GetBoard(), aEditFrame, &commit );
Update( generatorTool, GetBoard(), aEditFrame, &commit );
EditPush( generatorTool, GetBoard(), aEditFrame, &commit );
}
}

View File

@ -489,6 +489,44 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
Bind( EDA_EVT_CLOSE_NET_INSPECTOR_DIALOG, &PCB_EDIT_FRAME::onCloseNetInspectorDialog, this );
Bind( EDA_EVT_UNITS_CHANGED, &PCB_EDIT_FRAME::onUnitsChanged, this );
PROPERTY_MANAGER::Instance().RegisterListener( TYPE_HASH( BOARD_ITEM ),
[&]( INSPECTABLE* aItem, PROPERTY_BASE* aProperty, COMMIT* aCommit )
{
// Special case: propagate lock from generated items to parent generator
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( aItem );
if( item && aProperty->Name() == _HKI( "Locked" ) )
{
if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( item->GetParentGroup() ) )
{
if( aCommit->GetStatus( generator ) != CHT_MODIFY )
aCommit->Modify( generator );
// Must set generator to unlocked first or item->IsLocked() will just
// return the parent's locked state.
generator->SetLocked( false );
generator->SetLocked( item->IsLocked() );
}
}
} );
PROPERTY_MANAGER::Instance().RegisterListener( TYPE_HASH( PCB_GENERATOR ),
[&]( INSPECTABLE* aItem, PROPERTY_BASE* aProperty, COMMIT* aCommit )
{
// Special case: regenerator generators when their properties change
if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( aItem ) )
{
BOARD_COMMIT* commit = static_cast<BOARD_COMMIT*>( aCommit );
GENERATOR_TOOL* generatorTool = GetToolManager()->GetTool<GENERATOR_TOOL>();
generator->EditStart( generatorTool, GetBoard(), this, commit );
generator->Update( generatorTool, GetBoard(), this, commit );
generator->EditPush( generatorTool, GetBoard(), this, commit );
}
} );
m_acceptedExts.emplace( KiCadPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
m_acceptedExts.emplace( LegacyPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
DragAcceptFiles( true );

View File

@ -1254,15 +1254,22 @@ int BOARD_EDITOR_CONTROL::modifyLockSelected( MODIFY_MODE aMode )
PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( board_item->GetParentGroup() );
if( generator )
if( generator && commit.GetStatus( generator ) != CHT_MODIFY )
{
commit.Modify( generator );
if( aMode == ON )
generator->SetLocked( true );
else
generator->SetLocked( false );
}
commit.Modify( board_item );
if( aMode == ON )
board_item->SetLockedProperty( true );
board_item->SetLocked( true );
else
board_item->SetLockedProperty( false );
board_item->SetLocked( false );
}
if( !commit.Empty() )

View File

@ -267,7 +267,6 @@ void GENERATOR_TOOL::setTransitions()
Go( &GENERATOR_TOOL::RegenerateAllOfType, PCB_ACTIONS::regenerateAllTuning.MakeEvent() );
Go( &GENERATOR_TOOL::RegenerateAllOfType, PCB_ACTIONS::regenerateAll.MakeEvent() );
Go( &GENERATOR_TOOL::RegenerateSelected, PCB_ACTIONS::regenerateSelected.MakeEvent() );
Go( &GENERATOR_TOOL::RegenerateItem, PCB_ACTIONS::regenerateItem.MakeEvent() );
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genStartEdit.MakeEvent() );
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genUpdateEdit.MakeEvent() );

View File

@ -2428,10 +2428,6 @@ TOOL_ACTION PCB_ACTIONS::regenerateSelected( TOOL_ACTION_ARGS()
.Icon( BITMAPS::refresh ) );
TOOL_ACTION PCB_ACTIONS::regenerateItem( TOOL_ACTION_ARGS()
.Name( "pcbnew.Generator.regenerateItem" )
.Scope( AS_CONTEXT ) );
TOOL_ACTION PCB_ACTIONS::genStartEdit( TOOL_ACTION_ARGS()
.Name( "pcbnew.Generator.genStartEdit" )
.Scope( AS_CONTEXT ) );

View File

@ -207,29 +207,17 @@ void PCB_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
wxVariant newValue = aEvent.GetPropertyValue();
BOARD_COMMIT changes( m_frame );
PROPERTY_COMMIT_HANDLER handler( &changes );
for( EDA_ITEM* edaItem : selection )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( edaItem );
PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( item->GetParentGroup() );
if( generator )
changes.Modify( generator );
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( edaItem );
changes.Modify( item );
item->Set( property, newValue );
}
changes.Push( _( "Change property" ) );
for( EDA_ITEM* edaItem : selection )
{
if( edaItem->Type() == PCB_GENERATOR_T )
{
m_frame->GetToolManager()->RunAction<PCB_GENERATOR*>(
PCB_ACTIONS::regenerateItem, static_cast<PCB_GENERATOR*>( edaItem ) );
}
}
m_frame->Refresh();
// Perform grid updates as necessary based on value change