Ensure new symbols obey the observed sheet number

Internal numerology will not make sense when annotating, so use the
observed sheet number and let the algo ensure that numbers are not
duplicated

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21637

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19138

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16632
This commit is contained in:
Seth Hillbrand
2025-09-15 16:48:48 -07:00
parent bda994c00a
commit 4fcc2ac7e2
6 changed files with 24 additions and 11 deletions
+3 -3
View File
@@ -327,7 +327,7 @@ void SCH_REFERENCE_LIST::ReannotateByOptions( ANNOTATE_ORDER_T aSort
wxS( "Attempting to annotate item on sheet not part of the "
"hierarchy?" ) );
ref.SetSheetNumber( path->GetVirtualPageNumber() );
ref.SetSheetNumber( path->GetPageNumberAsInt() );
}
// Never lock unassigned references
@@ -344,9 +344,9 @@ void SCH_REFERENCE_LIST::ReannotateByOptions( ANNOTATE_ORDER_T aSort
}
void SCH_REFERENCE_LIST::ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences )
void SCH_REFERENCE_LIST::ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences, ANNOTATE_ALGO_T aAlgoOption )
{
ReannotateByOptions( UNSORTED, INCREMENTAL_BY_REF, 0, aAdditionalReferences, true, nullptr );
ReannotateByOptions( UNSORTED, aAlgoOption, 0, aAdditionalReferences, true, nullptr );
}
+2 -2
View File
@@ -390,11 +390,11 @@ public:
* @note Do not use as a general reannotation method.
*
* Replaces any duplicate reference designators with the next available number after the
* present number regardless of configured annotation options.
* present number obeying the current annotation style.
*
* Multi-unit symbols are reannotated together.
*/
void ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences );
void ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences, ANNOTATE_ALGO_T aAlgoOption );
/**
* Annotate the references by the provided options.
+13 -2
View File
@@ -459,7 +459,7 @@ void SCH_SHEET_PATH::AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL*
{
SCH_REFERENCE schReference( aSymbol, *this );
schReference.SetSheetNumber( m_virtualPageNumber );
schReference.SetSheetNumber( GetPageNumberAsInt() );
aReferences.AddItem( schReference );
}
}
@@ -491,7 +491,7 @@ void SCH_SHEET_PATH::AppendMultiUnitSymbol( SCH_MULTI_UNIT_REFERENCE_MAP& aRefLi
if( symbol && symbol->GetUnitCount() > 1 )
{
SCH_REFERENCE schReference = SCH_REFERENCE( aSymbol, *this );
schReference.SetSheetNumber( m_virtualPageNumber );
schReference.SetSheetNumber( GetPageNumberAsInt() );
wxString reference_str = schReference.GetRef();
// Never lock unassigned references
@@ -601,6 +601,17 @@ wxString SCH_SHEET_PATH::GetPageNumber() const
return sheet->getPageNumber( tmpPath );
}
int SCH_SHEET_PATH::GetPageNumberAsInt() const
{
long page;
wxString pageStr = GetPageNumber();
if( pageStr.ToLong( &page ) )
return (int) page;
return GetVirtualPageNumber();
}
void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber )
{
+2
View File
@@ -206,6 +206,8 @@ public:
wxString GetPageNumber() const;
int GetPageNumberAsInt() const;
const SCH_SHEET* GetSheet( unsigned aIndex ) const
{
SCH_SHEET* retv = nullptr;
+3 -3
View File
@@ -1895,7 +1895,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
if( libSymbol )
{
SCH_REFERENCE schReference( symbol, sheetPath );
schReference.SetSheetNumber( sheetPath.GetVirtualPageNumber() );
schReference.SetSheetNumber( sheetPath.GetPageNumberAsInt() );
pastedSymbols[sheetPath].AddItem( schReference );
}
}
@@ -2103,7 +2103,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
{
annotatedSymbols[path].ReannotateDuplicates( existingRefs );
annotatedSymbols[path].ReannotateDuplicates( existingRefs, annotateAlgo );
}
else
{
@@ -2124,7 +2124,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
{
annotatedSymbols[pastedSheetPath].ReannotateDuplicates( existingRefs );
annotatedSymbols[pastedSheetPath].ReannotateDuplicates( existingRefs, annotateAlgo );
}
else
{
@@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE( ReannotateDuplicates )
loadTestCase( c.m_SchematicRelativePath, c.m_ExpectedReannotations );
m_refsToReannotate.SetRefDesTracker( m_schematic->Settings().m_refDesTracker );
m_refsToReannotate.ReannotateDuplicates( getAdditionalRefs() );
m_refsToReannotate.ReannotateDuplicates( getAdditionalRefs(), INCREMENTAL_BY_REF );
m_refsToReannotate.UpdateAnnotation();
checkAnnotation( c.m_ExpectedReannotations );