From 24ddc728e8934f12ff3f02cae5156aad921a173f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 19 Oct 2023 01:31:01 +0100 Subject: [PATCH] Add PCB_ACTIONS::regenerateAllTuning.... ... and move GENERATOR_TOOL to RegenerateAllOfType(). --- pcbnew/generators/pcb_tuning_pattern.cpp | 9 +- pcbnew/menubar_pcb_editor.cpp | 2 +- pcbnew/pcb_generator.cpp | 21 +-- pcbnew/pcb_generator.h | 11 +- pcbnew/tools/generator_tool.cpp | 158 +++++++++++++---------- pcbnew/tools/generator_tool.h | 5 +- pcbnew/tools/pcb_actions.cpp | 14 +- pcbnew/tools/pcb_actions.h | 2 +- 8 files changed, 131 insertions(+), 91 deletions(-) diff --git a/pcbnew/generators/pcb_tuning_pattern.cpp b/pcbnew/generators/pcb_tuning_pattern.cpp index eedc881825..8c650b8921 100644 --- a/pcbnew/generators/pcb_tuning_pattern.cpp +++ b/pcbnew/generators/pcb_tuning_pattern.cpp @@ -91,6 +91,11 @@ public: return wxString( _( "Tuning Pattern" ) ); } + wxString GetPluralName() const override + { + return wxString( _( "Tuning Patterns" ) ); + } + static PCB_TUNING_PATTERN* CreateNew( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame, BOARD_CONNECTED_ITEM* aStartItem, LENGTH_TUNING_MODE aMode ); @@ -1042,7 +1047,6 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, if( bounds.PointInside( track->GetPosition(), 2 ) && bounds.PointInside( track->GetEnd(), 2 ) ) { - item->SetSelected(); AddItem( item ); groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) ); } @@ -1753,6 +1757,9 @@ int DRAWING_TOOL::PlaceTuningPattern( const TOOL_EVENT& aEvent ) m_tuningPattern->Update( generatorTool, m_board, m_frame, &commit ); m_tuningPattern->EditPush( generatorTool, m_board, m_frame, &commit, _( "Tune" ) ); + for( BOARD_ITEM* item : m_tuningPattern->GetItems() ) + item->SetSelected(); + break; } } diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index a76df886a4..ff951b67e2 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -214,6 +214,7 @@ void PCB_EDIT_FRAME::doReCreateMenuBar() editMenu->AppendSeparator(); editMenu->Add( PCB_ACTIONS::zoneFillAll ); editMenu->Add( PCB_ACTIONS::zoneUnfillAll ); + editMenu->Add( PCB_ACTIONS::regenerateAllTuning ); editMenu->AppendSeparator(); editMenu->Add( ACTIONS::deleteTool ); @@ -400,7 +401,6 @@ void PCB_EDIT_FRAME::doReCreateMenuBar() toolsMenu->AppendSeparator(); toolsMenu->Add( PCB_ACTIONS::generatorsShowManager ); toolsMenu->Add( PCB_ACTIONS::regenerateAll ); - toolsMenu->Add( PCB_ACTIONS::regenerateOutdated ); toolsMenu->Add( PCB_ACTIONS::regenerateSelected ); } diff --git a/pcbnew/pcb_generator.cpp b/pcbnew/pcb_generator.cpp index c51f351b99..91cc28fece 100644 --- a/pcbnew/pcb_generator.cpp +++ b/pcbnew/pcb_generator.cpp @@ -23,7 +23,6 @@ */ #include -#include PCB_GENERATOR::PCB_GENERATOR( BOARD_ITEM* aParent, PCB_LAYER_ID aLayer ) : @@ -86,12 +85,6 @@ bool PCB_GENERATOR::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_ } -bool PCB_GENERATOR::NeedsUpdate() -{ - return true; -} - - bool PCB_GENERATOR::MakeEditPoints( std::shared_ptr aEditPoints ) const { return true; @@ -160,7 +153,10 @@ const STRING_ANY_MAP PCB_GENERATOR::GetProperties() const { STRING_ANY_MAP props( pcbIUScale.IU_PER_MM ); +#ifdef GENERATOR_ORDER props.set( "update_order", m_updateOrder ); +#endif + props.set( "origin", m_origin ); return props; @@ -169,14 +165,21 @@ const STRING_ANY_MAP PCB_GENERATOR::GetProperties() const void PCB_GENERATOR::SetProperties( const STRING_ANY_MAP& aProps ) { +#ifdef GENERATOR_ORDER aProps.get_to( "update_order", m_updateOrder ); +#endif + aProps.get_to( "origin", m_origin ); } std::vector> PCB_GENERATOR::GetRowData() { +#ifdef GENERATOR_ORDER return { { _HKI( "Update order" ), wxString::FromCDouble( GetUpdateOrder() ) } }; +#else + return { {} }; +#endif } @@ -198,6 +201,7 @@ bool PCB_GENERATOR::ClassOf( const EDA_ITEM* aItem ) } +#ifdef GENERATOR_ORDER static struct PCB_GENERATOR_DESC { PCB_GENERATOR_DESC() @@ -214,4 +218,5 @@ static struct PCB_GENERATOR_DESC &PCB_GENERATOR::GetUpdateOrder ), groupTab ); } -} _PCB_GENERATOR_DESC; \ No newline at end of file +} _PCB_GENERATOR_DESC; +#endif \ No newline at end of file diff --git a/pcbnew/pcb_generator.h b/pcbnew/pcb_generator.h index a5fb6c6151..553cea1ac7 100644 --- a/pcbnew/pcb_generator.h +++ b/pcbnew/pcb_generator.h @@ -63,8 +63,6 @@ public: virtual bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit ); - virtual bool NeedsUpdate(); - virtual bool MakeEditPoints( std::shared_ptr aEditPoints ) const; virtual bool UpdateFromEditPoints( std::shared_ptr aEditPoints, @@ -100,6 +98,8 @@ public: wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; + virtual wxString GetPluralName() const = 0; + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif @@ -108,18 +108,21 @@ public: static inline bool ClassOf( const EDA_ITEM* aItem ); +#ifdef GENERATOR_ORDER int GetUpdateOrder() const { return m_updateOrder; } void SetUpdateOrder( int aValue ) { m_updateOrder = aValue; } +#endif protected: wxString m_generatorType; VECTOR2I m_origin; + +#ifdef GENERATOR_ORDER int m_updateOrder = 0; +#endif friend class GENERATORS_MGR; - void setGeneratorType( const wxString& aGenType ) { m_generatorType = aGenType; } - }; #endif /* GENERATOR_H_ */ diff --git a/pcbnew/tools/generator_tool.cpp b/pcbnew/tools/generator_tool.cpp index a73c7a961d..30930212cf 100644 --- a/pcbnew/tools/generator_tool.cpp +++ b/pcbnew/tools/generator_tool.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -50,6 +51,49 @@ void GENERATOR_TOOL::Reset( RESET_REASON aReason ) } +bool GENERATOR_TOOL::Init() +{ + auto tuningPatternCondition = + []( const SELECTION& aSel ) + { + for( EDA_ITEM* item : aSel ) + { + if( PCB_GENERATOR* generator = dynamic_cast( item ) ) + { + if( generator->GetGeneratorType() == wxS( "tuning_pattern" ) ) + return true; + } + } + + return false; + }; + + // Add the generator control menus to relevant other tools + + PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + + if( selTool ) + { + TOOL_MENU& toolMenu = selTool->GetToolMenu(); + CONDITIONAL_MENU& menu = toolMenu.GetMenu(); + + menu.AddItem( PCB_ACTIONS::regenerateAllTuning, tuningPatternCondition, 100 ); + } + + ROUTER_TOOL* routerTool = m_toolMgr->GetTool(); + + if( routerTool ) + { + TOOL_MENU& toolMenu = routerTool->GetToolMenu(); + CONDITIONAL_MENU& menu = toolMenu.GetMenu(); + + menu.AddItem( PCB_ACTIONS::regenerateAllTuning, SELECTION_CONDITIONS::ShowAlways, 100 ); + } + + return true; +} + + void GENERATOR_TOOL::DestroyManagerDialog() { if( m_mgrDialog ) @@ -82,67 +126,40 @@ int GENERATOR_TOOL::ShowGeneratorsManager( const TOOL_EVENT& aEvent ) } -int GENERATOR_TOOL::RegenerateAll( const TOOL_EVENT& aEvent ) +int GENERATOR_TOOL::RegenerateAllOfType( const TOOL_EVENT& aEvent ) { - BOARD_COMMIT localCommit( this ); - BOARD_COMMIT* commit = dynamic_cast( aEvent.Commit() ); + wxString generatorType = aEvent.Parameter(); + BOARD_COMMIT commit( this ); + wxString commitMsg; + int commitFlags = 0; - if( !commit ) - commit = &localCommit; + if( generatorType == wxS( "*" ) ) + commitMsg = _( "Regenerate All" ); - GENERATORS generators = board()->Generators(); - - std::sort( generators.begin(), generators.end(), - []( const PCB_GENERATOR* a, const PCB_GENERATOR* b ) -> bool - { - return a->GetUpdateOrder() < b->GetUpdateOrder(); - } ); - - for( PCB_GENERATOR* gen : generators ) + for( PCB_GENERATOR* generator : board()->Generators() ) { - gen->EditStart( this, board(), frame(), commit ); - gen->Update( this, board(), frame(), commit ); - gen->EditPush( this, board(), frame(), commit, _( "Regenerate" ), APPEND_UNDO ); - } - - return 0; -} - - -int GENERATOR_TOOL::RegenerateOutdated( const TOOL_EVENT& aEvent ) -{ - BOARD_COMMIT localCommit( this ); - BOARD_COMMIT* commit = dynamic_cast( aEvent.Commit() ); - - if( !commit ) - commit = &localCommit; - - GENERATORS generators = board()->Generators(); - - std::sort( generators.begin(), generators.end(), - []( const PCB_GENERATOR* a, const PCB_GENERATOR* b ) -> bool - { - return a->GetUpdateOrder() < b->GetUpdateOrder(); - } ); - - for( PCB_GENERATOR* gen : generators ) - { - gen->EditStart( this, board(), frame(), commit ); - gen->Update( this, board(), frame(), commit ); - gen->EditPush( this, board(), frame(), commit, _( "Regenerate Outdated" ), APPEND_UNDO ); + if( generatorType == wxS( "*" ) || generator->GetGeneratorType() == generatorType ) + { + if( commitMsg.IsEmpty() ) + commitMsg.Printf( _( "Update %s" ), generator->GetPluralName() ); + + generator->EditStart( this, board(), frame(), &commit ); + generator->Update( this, board(), frame(), &commit ); + generator->EditPush( this, board(), frame(), &commit, commitMsg, commitFlags ); + + commitFlags |= APPEND_UNDO; + } } + frame()->RefreshCanvas(); return 0; } int GENERATOR_TOOL::RegenerateSelected( const TOOL_EVENT& aEvent ) { - BOARD_COMMIT localCommit( this ); - BOARD_COMMIT* commit = dynamic_cast( aEvent.Commit() ); - - if( !commit ) - commit = &localCommit; + BOARD_COMMIT commit( this ); + int commitFlags = 0; PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); @@ -167,37 +184,40 @@ int GENERATOR_TOOL::RegenerateSelected( const TOOL_EVENT& aEvent ) generators.push_back( gen ); } +#ifdef GENERATOR_ORDER std::sort( generators.begin(), generators.end(), []( const PCB_GENERATOR* a, const PCB_GENERATOR* b ) -> bool { return a->GetUpdateOrder() < b->GetUpdateOrder(); } ); +#endif for( PCB_GENERATOR* gen : generators ) { - gen->EditStart( this, board(), frame(), commit ); - gen->Update( this, board(), frame(), commit ); - gen->EditPush( this, board(), frame(), commit, _( "Regenerate Selected" ), APPEND_UNDO ); + gen->EditStart( this, board(), frame(), &commit ); + gen->Update( this, board(), frame(), &commit ); + gen->EditPush( this, board(), frame(), &commit, _( "Regenerate Selected" ), commitFlags ); + + commitFlags |= APPEND_UNDO; } + frame()->RefreshCanvas(); return 0; } int GENERATOR_TOOL::RegenerateItem( const TOOL_EVENT& aEvent ) { - BOARD_COMMIT localCommit( this ); - BOARD_COMMIT* commit = dynamic_cast( aEvent.Commit() ); - - if( !commit ) - commit = &localCommit; + BOARD_COMMIT commit( this ); + int commitFlags = 0; PCB_GENERATOR* gen = aEvent.Parameter(); - gen->EditStart( this, board(), frame(), commit ); - gen->Update( this, board(), frame(), commit ); - gen->EditPush( this, board(), frame(), commit, _( "Regenerate Item" ) ); + gen->EditStart( this, board(), frame(), &commit ); + gen->Update( this, board(), frame(), &commit ); + gen->EditPush( this, board(), frame(), &commit, _( "Regenerate Item" ), commitFlags ); + frame()->RefreshCanvas(); return 0; } @@ -282,14 +302,14 @@ void GENERATOR_TOOL::setTransitions() // Generator actions Go( &GENERATOR_TOOL::ShowGeneratorsManager, PCB_ACTIONS::generatorsShowManager.MakeEvent() ); - Go( &GENERATOR_TOOL::RegenerateAll, PCB_ACTIONS::regenerateAll.MakeEvent() ); - Go( &GENERATOR_TOOL::RegenerateOutdated, PCB_ACTIONS::regenerateOutdated.MakeEvent() ); - Go( &GENERATOR_TOOL::RegenerateSelected, PCB_ACTIONS::regenerateSelected.MakeEvent() ); - Go( &GENERATOR_TOOL::RegenerateItem, PCB_ACTIONS::regenerateItem.MakeEvent() ); + 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() ); - Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genPushEdit.MakeEvent() ); - Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRevertEdit.MakeEvent() ); - Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRemove.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genStartEdit.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genUpdateEdit.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genPushEdit.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRevertEdit.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRemove.MakeEvent() ); } diff --git a/pcbnew/tools/generator_tool.h b/pcbnew/tools/generator_tool.h index 194bbe0f87..21a751c03f 100644 --- a/pcbnew/tools/generator_tool.h +++ b/pcbnew/tools/generator_tool.h @@ -47,12 +47,15 @@ public: /// @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ) override; + /// @copydoc TOOL_INTERACTIVE::Init() + bool Init() override; + void DestroyManagerDialog(); int ShowGeneratorsManager( const TOOL_EVENT& aEvent ); int RegenerateSelected( const TOOL_EVENT& aEvent ); - int RegenerateAll( const TOOL_EVENT& aEvent ); + int RegenerateAllOfType( const TOOL_EVENT& aEvent ); int RegenerateOutdated( const TOOL_EVENT& aEvent ); int RegenerateItem( const TOOL_EVENT& aEvent ); int GenEditAction( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index ee9c66b749..edbe605d26 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -2391,19 +2391,21 @@ TOOL_ACTION PCB_ACTIONS::dragFreeAngle( TOOL_ACTION_ARGS() // GENERATOR_TOOL // -TOOL_ACTION PCB_ACTIONS::regenerateOutdated( TOOL_ACTION_ARGS() - .Name( "pcbnew.Generator.regenerateOutdated" ) +TOOL_ACTION PCB_ACTIONS::regenerateAllTuning( TOOL_ACTION_ARGS() + .Name( "pcbnew.Generator.regenerateAllTuning" ) .Scope( AS_GLOBAL ) - .MenuText( _( "Rebuild Outdated Generators" ) ) - .Tooltip( _( "Rebuilds geometry of outdated generators" ) ) - .Icon( BITMAPS::refresh ) ); + .MenuText( _( "Update All Tuning Patterns" ) ) + .Tooltip( _( "Attempt to re-tune existing tuning patterns within their bounds" ) ) + .Icon( BITMAPS::router_len_tuner ) + .Parameter( wxString( wxS( "tuning_pattern" ) ) ) ); TOOL_ACTION PCB_ACTIONS::regenerateAll( TOOL_ACTION_ARGS() .Name( "pcbnew.Generator.regenerateAll" ) .Scope( AS_GLOBAL ) .MenuText( _( "Rebuild All Generators" ) ) .Tooltip( _( "Rebuilds geometry of all generators" ) ) - .Icon( BITMAPS::refresh ) ); + .Icon( BITMAPS::refresh ) + .Parameter( wxString( wxS( "*" ) ) ) ); TOOL_ACTION PCB_ACTIONS::regenerateSelected( TOOL_ACTION_ARGS() .Name( "pcbnew.Generator.regenerateSelected" ) diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index a811d1d5fd..08de720025 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -269,7 +269,7 @@ public: static TOOL_ACTION routerInlineDrag; /// Generator tool - static TOOL_ACTION regenerateOutdated; + static TOOL_ACTION regenerateAllTuning; static TOOL_ACTION regenerateAll; static TOOL_ACTION regenerateSelected; static TOOL_ACTION regenerateItem;