Remove unreachable PASTE_MODE.

Also, don't depend on enum order.

Fixes KICAD-YJ8.
This commit is contained in:
Jeff Young 2025-08-21 11:23:33 +01:00
parent d636eec643
commit 42735b775d
7 changed files with 60 additions and 68 deletions

View File

@ -24,23 +24,21 @@
#include <dialogs/dialog_paste_special.h>
DIALOG_PASTE_SPECIAL::DIALOG_PASTE_SPECIAL( wxWindow* aParent, PASTE_MODE* aMode,
const wxString& aReplacement ) :
DIALOG_PASTE_SPECIAL::DIALOG_PASTE_SPECIAL( wxWindow* aParent, PASTE_MODE* aMode, const wxString& aDefaultRef ) :
DIALOG_PASTE_SPECIAL_BASE( aParent ),
m_mode( aMode )
{
m_pasteOptions->SetItemToolTip( static_cast<int>( PASTE_MODE::UNIQUE_ANNOTATIONS ),
_( "Finds the next available reference designator for "
"any designators that already exist in the design." ) );
m_options->SetItemToolTip( static_cast<int>( PASTE_MODE::UNIQUE_ANNOTATIONS ),
_( "Finds the next available reference designator for any designators that already "
"exist in the design." ) );
m_pasteOptions->SetItemToolTip( static_cast<int>( PASTE_MODE::KEEP_ANNOTATIONS ),
wxT( "" ) ); // Self explanatory
m_options->SetItemToolTip( static_cast<int>( PASTE_MODE::KEEP_ANNOTATIONS ),
wxT( "" ) ); // Self explanatory
m_pasteOptions->SetItemToolTip( static_cast<int>( PASTE_MODE::REMOVE_ANNOTATIONS ),
wxString::Format( _( "Replaces reference designators with '%s'." ),
aReplacement ) );
m_options->SetItemToolTip( static_cast<int>( PASTE_MODE::REMOVE_ANNOTATIONS ),
wxString::Format( _( "Replaces reference designators with '%s'." ), aDefaultRef ) );
m_pasteOptions->SetFocus();
m_options->SetFocus();
// Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings();
@ -49,14 +47,26 @@ DIALOG_PASTE_SPECIAL::DIALOG_PASTE_SPECIAL( wxWindow* aParent, PASTE_MODE* aMode
bool DIALOG_PASTE_SPECIAL::TransferDataToWindow()
{
m_pasteOptions->SetSelection( static_cast<int>( *m_mode ) );
switch( *m_mode )
{
case PASTE_MODE::UNIQUE_ANNOTATIONS: m_options->SetSelection( 0 ); break;
case PASTE_MODE::KEEP_ANNOTATIONS: m_options->SetSelection( 1 ); break;
case PASTE_MODE::REMOVE_ANNOTATIONS: m_options->SetSelection( 2 ); break;
}
return true;
}
bool DIALOG_PASTE_SPECIAL::TransferDataFromWindow()
{
*m_mode = static_cast<PASTE_MODE>( m_pasteOptions->GetSelection() );
switch( m_options->GetSelection() )
{
case 0: *m_mode = PASTE_MODE::UNIQUE_ANNOTATIONS; break;
case 1: *m_mode = PASTE_MODE::KEEP_ANNOTATIONS; break;
case 2: *m_mode = PASTE_MODE::REMOVE_ANNOTATIONS; break;
}
return true;
}

View File

@ -19,11 +19,11 @@ DIALOG_PASTE_SPECIAL_BASE::DIALOG_PASTE_SPECIAL_BASE( wxWindow* parent, wxWindow
wxBoxSizer* optionsSizer;
optionsSizer = new wxBoxSizer( wxVERTICAL );
wxString m_pasteOptionsChoices[] = { _("Assign unique reference designators to pasted symbols"), _("Keep existing reference designators, even if they are duplicated"), _("Clear reference designators on all pasted symbols") };
int m_pasteOptionsNChoices = sizeof( m_pasteOptionsChoices ) / sizeof( wxString );
m_pasteOptions = new wxRadioBox( this, wxID_ANY, _("Reference Designators"), wxDefaultPosition, wxDefaultSize, m_pasteOptionsNChoices, m_pasteOptionsChoices, 1, wxRA_SPECIFY_COLS );
m_pasteOptions->SetSelection( 1 );
optionsSizer->Add( m_pasteOptions, 0, wxALL, 5 );
wxString m_optionsChoices[] = { _("Assign unique reference designators to pasted symbols"), _("Keep existing reference designators, even if they are duplicated"), _("Clear reference designators on all pasted symbols") };
int m_optionsNChoices = sizeof( m_optionsChoices ) / sizeof( wxString );
m_options = new wxRadioBox( this, wxID_ANY, _("Reference Designators"), wxDefaultPosition, wxDefaultSize, m_optionsNChoices, m_optionsChoices, 1, wxRA_SPECIFY_COLS );
m_options->SetSelection( 1 );
optionsSizer->Add( m_options, 0, wxALL, 5 );
m_clearNetsCB = new wxCheckBox( this, wxID_ANY, _("Clear net assignments"), wxDefaultPosition, wxDefaultSize, 0 );
m_clearNetsCB->SetToolTip( _("Remove the net information from all connected items before pasting") );
@ -50,12 +50,12 @@ DIALOG_PASTE_SPECIAL_BASE::DIALOG_PASTE_SPECIAL_BASE( wxWindow* parent, wxWindow
this->Centre( wxBOTH );
// Connect Events
m_pasteOptions->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_PASTE_SPECIAL_BASE::onRadioBoxEvent ), NULL, this );
m_options->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_PASTE_SPECIAL_BASE::onRadioBoxEvent ), NULL, this );
}
DIALOG_PASTE_SPECIAL_BASE::~DIALOG_PASTE_SPECIAL_BASE()
{
// Disconnect Events
m_pasteOptions->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_PASTE_SPECIAL_BASE::onRadioBoxEvent ), NULL, this );
m_options->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_PASTE_SPECIAL_BASE::onRadioBoxEvent ), NULL, this );
}

View File

@ -116,7 +116,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_pasteOptions</property>
<property name="name">m_options</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>

View File

@ -32,7 +32,7 @@ class DIALOG_PASTE_SPECIAL_BASE : public DIALOG_SHIM
private:
protected:
wxRadioBox* m_pasteOptions;
wxRadioBox* m_options;
wxCheckBox* m_clearNetsCB;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;

View File

@ -1714,20 +1714,19 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
SCHEMATIC_SETTINGS& schematicSettings = m_frame->Schematic().Settings();
int annotateStartNum = schematicSettings.m_AnnotateStartNum;
PASTE_MODE pasteMode = annotateAutomatic ? PASTE_MODE::RESPECT_OPTIONS : PASTE_MODE::REMOVE_ANNOTATIONS;
PASTE_MODE pasteMode = annotateAutomatic ? PASTE_MODE::UNIQUE_ANNOTATIONS : PASTE_MODE::REMOVE_ANNOTATIONS;
bool forceRemoveAnnotations = false;
if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
{
PASTE_MODE pasteModeSpecial = pasteMode;
DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteModeSpecial );
PASTE_MODE defaultPasteMode = pasteMode;
DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
if( dlg.ShowModal() == wxID_CANCEL )
return 0;
// We have to distinguish if removing was explicit
forceRemoveAnnotations = ( pasteModeSpecial == PASTE_MODE::REMOVE_ANNOTATIONS );
pasteMode = pasteModeSpecial;
forceRemoveAnnotations = pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS && pasteMode != defaultPasteMode;
}
bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
@ -1866,8 +1865,8 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
symbol->SetLibSymbol( libSymbol );
}
// If the symbol is already in the schematic we have to always keep the
// annotations. The exception is if the user has chosen to remove them.
// If the symbol is already in the schematic we have to always keep the annotations. The exception
// is if the user has chosen to remove them.
for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
{
if( !existingRefsSet.contains( instance.m_Reference ) )
@ -1880,11 +1879,10 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
updatePastedSymbol( symbol, sheetPath, clipPath, forceKeepAnnotations );
// Most modes will need new KIIDs for the symbol and its pins
// However, if we are pasting unique annotations, we need to check if the symbol
// is not already in the hierarchy. If we don't already have a copy of the
// symbol, we just keep the existing KIID data as it is likely the same symbol
// being moved around the schematic
// Most modes will need new KIIDs for the symbol and its pins. However, if we are pasting
// unique annotations, we need to check if the symbol is not already in the hierarchy. If we
// don't already have a copy of the symbol, we just keep the existing KIID data as it is likely
// the same symbol being moved around the schematic.
bool needsNewKiid = ( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
@ -1955,13 +1953,11 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
if( !fn.IsAbsolute() )
{
wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
currentSheetFileName.GetPath() );
fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS, currentSheetFileName.GetPath() );
}
// Try to find the screen for the pasted sheet by several means
if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
&existingScreen ) )
if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ), &existingScreen ) )
{
if( loadedScreens.count( sheet->GetFileName() ) > 0 )
existingScreen = loadedScreens.at( sheet->GetFileName() );
@ -2003,8 +1999,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
{
SCH_SHEET_PATH subPath = updatePastedSheet( sheet, sheetPath, clipPath,
( forceKeepAnnotations && annotateAutomatic ),
&pastedSheets[sheetPath],
pastedSymbols );
&pastedSheets[sheetPath], pastedSymbols );
}
}
else
@ -2099,24 +2094,16 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
{
for( size_t i = 0; i < pastedSymbols[sheetPath].GetCount(); i++ )
{
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
|| pasteMode == PASTE_MODE::RESPECT_OPTIONS
|| pastedSymbols[sheetPath][i].AlwaysAnnotate() )
{
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS || pastedSymbols[sheetPath][i].AlwaysAnnotate() )
annotatedSymbols[sheetPath].AddItem( pastedSymbols[sheetPath][i] );
}
}
for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[sheetPath] )
{
for( size_t i = 0; i < pastedSymbols[pastedSheetPath].GetCount(); i++ )
{
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
|| pasteMode == PASTE_MODE::RESPECT_OPTIONS
|| pastedSymbols[pastedSheetPath][i].AlwaysAnnotate() )
{
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS || pastedSymbols[pastedSheetPath][i].AlwaysAnnotate() )
annotatedSymbols[pastedSheetPath].AddItem( pastedSymbols[pastedSheetPath][i] );
}
}
}
}
@ -2137,10 +2124,8 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
}
else
{
annotatedSymbols[path].ReannotateByOptions( annotateOrder,
annotateAlgo,
annotateStartNum, existingRefs, false,
&hierarchy );
annotatedSymbols[path].ReannotateByOptions( annotateOrder, annotateAlgo, annotateStartNum,
existingRefs, false, &hierarchy );
}
annotatedSymbols[path].UpdateAnnotation();
@ -2160,11 +2145,9 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
}
else
{
annotatedSymbols[pastedSheetPath].ReannotateByOptions( annotateOrder,
annotateAlgo,
annotatedSymbols[pastedSheetPath].ReannotateByOptions( annotateOrder, annotateAlgo,
annotateStartNum, existingRefs,
false,
&hierarchy );
false, &hierarchy );
}
annotatedSymbols[pastedSheetPath].UpdateAnnotation();

View File

@ -32,10 +32,9 @@ class SCH_SHEET_PIN;
enum class PASTE_MODE
{
UNIQUE_ANNOTATIONS = 0,
KEEP_ANNOTATIONS = 1,
REMOVE_ANNOTATIONS = 2,
RESPECT_OPTIONS = 3,
UNIQUE_ANNOTATIONS,
KEEP_ANNOTATIONS,
REMOVE_ANNOTATIONS
};
@ -43,7 +42,7 @@ class DIALOG_PASTE_SPECIAL : public DIALOG_PASTE_SPECIAL_BASE
{
public:
DIALOG_PASTE_SPECIAL( wxWindow* aParent, PASTE_MODE* aMode, const wxString& aReplacement = wxS( "?" ) );
DIALOG_PASTE_SPECIAL( wxWindow* aParent, PASTE_MODE* aMode, const wxString& aDefaultRef = wxS( "?" ) );
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;

View File

@ -1266,7 +1266,8 @@ int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent )
fp->SetReference( defaultRef );
}
cancelled = !placeBoardItems( &commit, clipBoard, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS, false );
cancelled = !placeBoardItems( &commit, clipBoard, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS,
false );
}
break;
@ -1288,16 +1289,15 @@ int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent )
clipFootprint->SetReference( defaultRef );
clipFootprint->SetParent( board() );
clipFootprint->ResolveComponentClassNames(
board(), clipFootprint->GetTransientComponentClassNames() );
clipFootprint->ResolveComponentClassNames( board(), clipFootprint->GetTransientComponentClassNames() );
clipFootprint->ClearTransientComponentClassNames();
pastedItems.push_back( clipFootprint );
}
pruneItemLayers( pastedItems );
cancelled =
!placeBoardItems( &commit, pastedItems, true, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS, false );
cancelled = !placeBoardItems( &commit, pastedItems, true, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS,
false );
break;
}