Sym edit: next/prev unit actions

Trivial small part of making large multi-unit symbol handling possibly a
little bit easier.

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/9346
This commit is contained in:
John Beard 2024-10-01 16:05:04 +01:00
parent a4cbd0adb4
commit 1effaf83c3
6 changed files with 64 additions and 10 deletions

View File

@ -763,17 +763,10 @@ void SYMBOL_EDIT_FRAME::OnSelectUnit( wxCommandEvent& event )
{
int i = event.GetSelection();
if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == m_unit ) )
if( i == wxNOT_FOUND )
return;
m_toolManager->RunAction( ACTIONS::cancelInteractive );
m_toolManager->RunAction( EE_ACTIONS::clearSelection );
m_unit = i + 1;
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
RebuildView();
UpdateSymbolMsgPanelInfo();
SetUnit( i + 1 );
}
@ -953,6 +946,27 @@ void SYMBOL_EDIT_FRAME::OnModify()
}
void SYMBOL_EDIT_FRAME::SetUnit( int aUnit )
{
wxCHECK( aUnit > 0 && aUnit <= GetCurSymbol()->GetUnitCount(), /* void*/ );
if( m_unit == aUnit )
return;
m_toolManager->RunAction( ACTIONS::cancelInteractive );
m_toolManager->RunAction( EE_ACTIONS::clearSelection );
m_unit = aUnit;
if( m_unitSelectBox->GetSelection() != ( m_unit - 1 ) )
m_unitSelectBox->SetSelection( m_unit - 1 );
m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
RebuildView();
UpdateSymbolMsgPanelInfo();
}
bool SYMBOL_EDIT_FRAME::SynchronizePins()
{
return m_SyncPinEdit && m_symbol && m_symbol->IsMulti() && !m_symbol->UnitsLocked();

View File

@ -233,7 +233,7 @@ public:
void OnModify() override;
int GetUnit() const { return m_unit; }
void SetUnit( int aUnit ) { m_unit = aUnit; }
void SetUnit( int aUnit );
int GetBodyStyle() const { return m_bodyStyle; }
void SetBodyStyle( int aBodyStyle ) { m_bodyStyle = aBodyStyle; }

View File

@ -1272,6 +1272,20 @@ TOOL_ACTION EE_ACTIONS::repairSchematic( TOOL_ACTION_ARGS()
.Tooltip( _( "Run various diagnostics and attempt to repair schematic" ) )
.Icon( BITMAPS::rescue ) );
TOOL_ACTION EE_ACTIONS::previousUnit( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.previousUnit" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Previous Unit" ) )
.Tooltip( _( "Open the previous unit of the symbol" ) )
.Parameter<int>( -1 ) );
TOOL_ACTION EE_ACTIONS::nextUnit( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.nextUnit" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Next Unit" ) )
.Tooltip( _( "Open the next unit of the symbol" ) )
.Parameter<int>( 1 ) );
// Python Console
TOOL_ACTION EE_ACTIONS::showPythonConsole( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.showPythonConsole" )

View File

@ -267,6 +267,8 @@ public:
static TOOL_ACTION exportSymbolAsSVG;
static TOOL_ACTION showPythonConsole;
static TOOL_ACTION repairSchematic;
static TOOL_ACTION previousUnit;
static TOOL_ACTION nextUnit;
// Line modes
static TOOL_ACTION lineModeFree;

View File

@ -759,8 +759,26 @@ int SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic( const TOOL_EVENT& aEvent )
}
int SYMBOL_EDITOR_CONTROL::ChangeUnit( const TOOL_EVENT& aEvent )
{
if( !m_isSymbolEditor )
return 0;
SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
const int deltaUnit = aEvent.Parameter<int>();
const int nUnits = editFrame->GetCurSymbol()->GetUnitCount();
const int newUnit = ( ( editFrame->GetUnit() - 1 + deltaUnit + nUnits ) % nUnits ) + 1;
editFrame->SetUnit( newUnit );
return 0;
}
void SYMBOL_EDITOR_CONTROL::setTransitions()
{
// clang-format off
Go( &SYMBOL_EDITOR_CONTROL::AddLibrary, ACTIONS::newLibrary.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::AddLibrary, ACTIONS::addLibrary.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::AddSymbol, EE_ACTIONS::newSymbol.MakeEvent() );
@ -800,4 +818,8 @@ void SYMBOL_EDITOR_CONTROL::setTransitions()
Go( &SYMBOL_EDITOR_CONTROL::ToggleProperties, ACTIONS::showProperties.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::ToggleHiddenPins, EE_ACTIONS::showHiddenPins.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::ToggleHiddenFields, EE_ACTIONS::showHiddenFields.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::ChangeUnit, EE_ACTIONS::previousUnit.MakeEvent() );
Go( &SYMBOL_EDITOR_CONTROL::ChangeUnit, EE_ACTIONS::nextUnit.MakeEvent() );
// clang-format on
}

View File

@ -70,6 +70,8 @@ public:
int ToggleHiddenPins( const TOOL_EVENT& aEvent );
int ToggleHiddenFields( const TOOL_EVENT& aEvent );
int ChangeUnit( const TOOL_EVENT& aEvent );
int DdAddLibrary( const TOOL_EVENT& aEvent );
private: