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

View File

@ -19,11 +19,11 @@ DIALOG_PASTE_SPECIAL_BASE::DIALOG_PASTE_SPECIAL_BASE( wxWindow* parent, wxWindow
wxBoxSizer* optionsSizer; wxBoxSizer* optionsSizer;
optionsSizer = new wxBoxSizer( wxVERTICAL ); 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") }; 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_pasteOptionsNChoices = sizeof( m_pasteOptionsChoices ) / sizeof( wxString ); int m_optionsNChoices = sizeof( m_optionsChoices ) / sizeof( wxString );
m_pasteOptions = new wxRadioBox( this, wxID_ANY, _("Reference Designators"), wxDefaultPosition, wxDefaultSize, m_pasteOptionsNChoices, m_pasteOptionsChoices, 1, wxRA_SPECIFY_COLS ); m_options = new wxRadioBox( this, wxID_ANY, _("Reference Designators"), wxDefaultPosition, wxDefaultSize, m_optionsNChoices, m_optionsChoices, 1, wxRA_SPECIFY_COLS );
m_pasteOptions->SetSelection( 1 ); m_options->SetSelection( 1 );
optionsSizer->Add( m_pasteOptions, 0, wxALL, 5 ); optionsSizer->Add( m_options, 0, wxALL, 5 );
m_clearNetsCB = new wxCheckBox( this, wxID_ANY, _("Clear net assignments"), wxDefaultPosition, wxDefaultSize, 0 ); 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") ); 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 ); this->Centre( wxBOTH );
// Connect Events // 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() DIALOG_PASTE_SPECIAL_BASE::~DIALOG_PASTE_SPECIAL_BASE()
{ {
// Disconnect Events // 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="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</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_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>

View File

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

View File

@ -32,10 +32,9 @@ class SCH_SHEET_PIN;
enum class PASTE_MODE enum class PASTE_MODE
{ {
UNIQUE_ANNOTATIONS = 0, UNIQUE_ANNOTATIONS,
KEEP_ANNOTATIONS = 1, KEEP_ANNOTATIONS,
REMOVE_ANNOTATIONS = 2, REMOVE_ANNOTATIONS
RESPECT_OPTIONS = 3,
}; };
@ -43,7 +42,7 @@ class DIALOG_PASTE_SPECIAL : public DIALOG_PASTE_SPECIAL_BASE
{ {
public: 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 TransferDataToWindow() override;
bool TransferDataFromWindow() override; bool TransferDataFromWindow() override;

View File

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