Add PCB_ACTIONS::regenerateAllTuning....

... and move GENERATOR_TOOL to RegenerateAllOfType().
This commit is contained in:
Jeff Young 2023-10-19 01:31:01 +01:00
parent 7447700735
commit 24ddc728e8
8 changed files with 131 additions and 91 deletions

View File

@ -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;
}
}

View File

@ -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 );
}

View File

@ -23,7 +23,6 @@
*/
#include <pcb_generator.h>
#include <i18n_utility.h>
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<EDIT_POINTS> 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<std::pair<wxString, wxVariant>> 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;
} _PCB_GENERATOR_DESC;
#endif

View File

@ -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<EDIT_POINTS> aEditPoints ) const;
virtual bool UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> 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_ */

View File

@ -28,6 +28,7 @@
#include <tool/tool_manager.h>
#include <tools/pcb_selection_tool.h>
#include <tools/pcb_actions.h>
#include <router/router_tool.h>
#include <dialog_generators.h>
@ -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<PCB_GENERATOR*>( 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<PCB_SELECTION_TOOL>();
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<ROUTER_TOOL>();
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<BOARD_COMMIT*>( aEvent.Commit() );
wxString generatorType = aEvent.Parameter<wxString>();
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<BOARD_COMMIT*>( 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<BOARD_COMMIT*>( aEvent.Commit() );
if( !commit )
commit = &localCommit;
BOARD_COMMIT commit( this );
int commitFlags = 0;
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
@ -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<BOARD_COMMIT*>( aEvent.Commit() );
if( !commit )
commit = &localCommit;
BOARD_COMMIT commit( this );
int commitFlags = 0;
PCB_GENERATOR* gen = aEvent.Parameter<PCB_GENERATOR*>();
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() );
}

View File

@ -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 );

View File

@ -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" )

View File

@ -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;