Allow selected RefDes as proxy to selected symbol for annotate selection.

Also fixes some likely bugs regarding collection of power symbols and symbols
with no lib link for annotation.

Fixes https://gitlab.com/kicad/code/kicad/issues/12259
This commit is contained in:
Jeff Young 2022-08-24 11:30:27 +01:00
parent ae86c6f3a7
commit 9657b23139
3 changed files with 56 additions and 73 deletions

View File

@ -160,6 +160,37 @@ void SCH_EDIT_FRAME::DeleteAnnotation( ANNOTATE_SCOPE_T aAnnotateScope, bool aRe
}
std::unordered_set<SCH_SYMBOL*> getInferredSymbols( const EE_SELECTION& aSelection )
{
std::unordered_set<SCH_SYMBOL*> symbols;
for( EDA_ITEM* item : aSelection )
{
switch( item->Type() )
{
case SCH_FIELD_T:
{
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
if( field->GetId() == REFERENCE_FIELD && field->GetParent()->Type() == SCH_SYMBOL_T )
symbols.insert( static_cast<SCH_SYMBOL*>( field->GetParent() ) );
break;
}
case SCH_SYMBOL_T:
symbols.insert( static_cast<SCH_SYMBOL*>( item ) );
break;
default:
break;
}
}
return symbols;
}
void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
ANNOTATE_ORDER_T aSortOption,
ANNOTATE_ALGO_T aAlgoOption,
@ -179,8 +210,7 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
SCH_SHEET_PATH currentSheet = GetCurrentSheet();
// Store the selected sheets relative to the full hierarchy so we
// get the correct sheet numbers
// Store the selected sheets relative to the full hierarchy so we get the correct sheet numbers
SCH_SHEET_LIST selectedSheets;
for( EDA_ITEM* item : selection )
@ -195,8 +225,8 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
}
// Like above, store subsheets relative to full hierarchy for
// recursive annotation from current sheet
// Like above, store subsheets relative to full hierarchy for recursive annotation from current
// sheet
SCH_SHEET_LIST subSheets;
std::vector<SCH_ITEM*> tempSubSheets;
@ -211,15 +241,20 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
}
std::unordered_set<SCH_SYMBOL*> selectedSymbols;
if( aAnnotateScope == ANNOTATE_SELECTION )
selectedSymbols = getInferredSymbols( selection );
// Map of locked symbols
SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
// Map of previous annotation for building info messages
std::map<wxString, wxString> previousAnnotation;
// Test for and replace duplicate time stamps in symbols and sheets. Duplicate
// time stamps can happen with old schematics, schematic conversions, or manual
// editing of files.
// Test for and replace duplicate time stamps in symbols and sheets. Duplicate time stamps
// can happen with old schematics, schematic conversions, or manual editing of files.
if( aRepairTimestamps )
{
int count = screens.ReplaceDuplicateTimeStamps();
@ -244,7 +279,9 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
break;
case ANNOTATE_SELECTION:
selection.GetMultiUnitSymbols( lockedSymbols, currentSheet );
for( SCH_SYMBOL* symbol : selectedSymbols )
currentSheet.AppendMultiUnitSymbol( lockedSymbols, symbol );
break;
}
@ -262,18 +299,19 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope,
break;
case ANNOTATE_CURRENT_SHEET:
GetCurrentSheet().GetSymbols( references );
currentSheet.GetSymbols( references );
if( aRecursive )
subSheets.GetSymbolsWithinPath( references, currentSheet, true, true );
subSheets.GetSymbolsWithinPath( references, currentSheet, false, true );
break;
case ANNOTATE_SELECTION:
selection.GetSymbols( references, currentSheet );
for( SCH_SYMBOL* symbol : selectedSymbols )
currentSheet.AppendSymbol( references, symbol, false, true );
if( aRecursive )
selectedSheets.GetSymbolsWithinPath( references, currentSheet, true, true );
selectedSheets.GetSymbolsWithinPath( references, currentSheet, false, true );
break;
}
@ -443,7 +481,9 @@ int SCH_EDIT_FRAME::CheckAnnotate( ANNOTATION_ERROR_HANDLER aErrorHandler,
case ANNOTATE_SELECTION:
EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
EE_SELECTION& selection = selTool->RequestSelection();
selection.GetSymbols( referenceList, GetCurrentSheet(), includePowerSymbols );
for( SCH_SYMBOL* symbol : getInferredSymbols( selection ) )
GetCurrentSheet().AppendSymbol( referenceList, symbol, false, true );
if( aRecursive )
{
@ -464,7 +504,6 @@ int SCH_EDIT_FRAME::CheckAnnotate( ANNOTATION_ERROR_HANDLER aErrorHandler,
sheet.GetSymbols( referenceList, includePowerSymbols );
}
break;
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 CERN
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.TXT for contributors.
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -115,33 +115,3 @@ EDA_RECT EE_SELECTION::GetBoundingBox() const
}
void EE_SELECTION::GetSymbols( SCH_REFERENCE_LIST& aReferences,
const SCH_SHEET_PATH& aSelectionPath,
bool aIncludePowerSymbols,
bool aForceIncludeOrphanSymbols )
{
for( EDA_ITEM* item : Items() )
{
if( item->Type() != SCH_SYMBOL_T )
continue;
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
aSelectionPath.AppendSymbol( aReferences, symbol, aIncludePowerSymbols,
aForceIncludeOrphanSymbols );
}
}
void EE_SELECTION::GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP& aRefList,
const SCH_SHEET_PATH& aSelectionPath,
bool aIncludePowerSymbols )
{
for( EDA_ITEM* item : Items() )
{
if( item->Type() != SCH_SYMBOL_T )
continue;
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
aSelectionPath.AppendMultiUnitSymbol( aRefList, symbol, aIncludePowerSymbols );
}
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 CERN
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.TXT for contributors.
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -29,6 +29,7 @@ class SCH_REFERENCE_LIST;
class SCH_SCREEN;
class SCH_SHEET_PATH;
#include <unordered_set>
#include <tool/selection.h>
#include <sch_sheet_path.h> // SCH_MULTI_UNIT_REFERENCE_MAP
@ -49,33 +50,6 @@ public:
void SetScreen( SCH_SCREEN* aScreen ) { m_screen = aScreen; }
SCH_SCREEN* GetScreen() { return m_screen; }
/**
* Adds #SCH_REFERENCE object to \a aReferences for each symbol in the selection.
*
* @param aReferences List of references to populate.
* @param aSelectionPath The path to the sheet containing this selection.
* @param aIncludePowerSymbols set to false to only get normal symbols.
* @param aForceIncludeOrphanSymbols set to true to include symbols having no symbol found
* in lib. The normal option is false, and set to true
* only to build the full list of symbols.
*/
void GetSymbols( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSelectionPath,
bool aIncludePowerSymbols = true, bool aForceIncludeOrphanSymbols = false );
/**
* Add a #SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of
* multi-unit parts in the selection.
*
* The map key for each element will be the reference designator.
*
* @param aRefList Map of reference designators to reference lists
* @param aSelectionPath The path to the sheet containing this selection.
* @param aIncludePowerSymbols Set to false to only get normal symbols.
*/
void GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP& aRefList,
const SCH_SHEET_PATH& aSelectionPath,
bool aIncludePowerSymbols = true );
};
#endif // EE_SELECTION_H