Fix broken pasted sheet page numbering.
This change no longer sorts pasted sheets by page number. This was done
because pasted sheets may not be numbered. When sheets are not numbered
they are sorted by UUID path which results in some unexpected results.
Since the pasted sheet code uses recursion, pages will be numbered in the
order they are added.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/16580
(cherry picked from commit 4cf22e428c
)
This commit is contained in:
parent
efa99b1e71
commit
add2215e5a
|
@ -1466,7 +1466,8 @@ void SCH_EDITOR_CONTROL::updatePastedSymbol( SCH_SYMBOL* aSymbol, SCH_SCREEN* aP
|
||||||
|
|
||||||
|
|
||||||
SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPastePath,
|
SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPastePath,
|
||||||
const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
|
const KIID_PATH& aClipPath,
|
||||||
|
SCH_SHEET* aSheet,
|
||||||
bool aForceKeepAnnotations,
|
bool aForceKeepAnnotations,
|
||||||
SCH_SHEET_LIST* aPastedSheetsSoFar,
|
SCH_SHEET_LIST* aPastedSheetsSoFar,
|
||||||
SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
|
SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
|
||||||
|
@ -1477,6 +1478,8 @@ SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPas
|
||||||
sheetPath.push_back( aSheet );
|
sheetPath.push_back( aSheet );
|
||||||
|
|
||||||
aPastedSheetsSoFar->push_back( sheetPath );
|
aPastedSheetsSoFar->push_back( sheetPath );
|
||||||
|
wxLogDebug( wxS( "Adding pasted sheet path: %s from clipboard path: %s." ),
|
||||||
|
sheetPath.Path().AsString(), aClipPath.AsString() );
|
||||||
|
|
||||||
if( aSheet->GetScreen() == nullptr )
|
if( aSheet->GetScreen() == nullptr )
|
||||||
return sheetPath; // We can only really set the page number but not load any items
|
return sheetPath; // We can only really set the page number but not load any items
|
||||||
|
@ -1922,16 +1925,12 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
||||||
getView()->Hide( item, true );
|
getView()->Hide( item, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
pasteInstances.SortByPageNumbers();
|
|
||||||
|
|
||||||
if( sheetsPasted )
|
if( sheetsPasted )
|
||||||
{
|
{
|
||||||
// Update page numbers: Find next free numeric page number
|
// Update page numbers: Find next free numeric page number
|
||||||
for( SCH_SHEET_PATH& instance : pasteInstances )
|
for( SCH_SHEET_PATH& sheetPath : pasteInstances )
|
||||||
{
|
{
|
||||||
pastedSheets[instance].SortByPageNumbers();
|
for( SCH_SHEET_PATH& pastedSheet : pastedSheets[sheetPath] )
|
||||||
|
|
||||||
for( SCH_SHEET_PATH& pastedSheet : pastedSheets[instance] )
|
|
||||||
{
|
{
|
||||||
int page = 1;
|
int page = 1;
|
||||||
wxString pageNum = wxString::Format( "%d", page );
|
wxString pageNum = wxString::Format( "%d", page );
|
||||||
|
@ -1939,14 +1938,27 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
||||||
while( hierarchy.PageNumberExists( pageNum ) )
|
while( hierarchy.PageNumberExists( pageNum ) )
|
||||||
pageNum = wxString::Format( "%d", ++page );
|
pageNum = wxString::Format( "%d", ++page );
|
||||||
|
|
||||||
pastedSheet.SetPageNumber( pageNum );
|
wxLogDebug( wxS( "Setting sheet path %s instance." ),
|
||||||
|
pastedSheet.Path().AsString() );
|
||||||
|
|
||||||
|
SCH_SHEET_INSTANCE sheetInstance;
|
||||||
|
|
||||||
|
sheetInstance.m_Path = pastedSheet.Path();
|
||||||
|
|
||||||
|
// Don't include the actual sheet in the instance path.
|
||||||
|
sheetInstance.m_Path.pop_back();
|
||||||
|
sheetInstance.m_PageNumber = pageNum;
|
||||||
|
sheetInstance.m_ProjectName = m_frame->Prj().GetProjectName();
|
||||||
|
|
||||||
|
SCH_SHEET* sheet = pastedSheet.Last();
|
||||||
|
|
||||||
|
wxCHECK2( sheet, continue );
|
||||||
|
|
||||||
|
sheet->AddInstance( sheetInstance );
|
||||||
hierarchy.push_back( pastedSheet );
|
hierarchy.push_back( pastedSheet );
|
||||||
|
|
||||||
// Remove all pasted sheet instance data that is not part of the current project.
|
// Remove all pasted sheet instance data that is not part of the current project.
|
||||||
std::vector<KIID_PATH> instancesToRemove;
|
std::vector<KIID_PATH> instancesToRemove;
|
||||||
SCH_SHEET* sheet = pastedSheet.Last();
|
|
||||||
|
|
||||||
wxCHECK2( sheet, continue );
|
|
||||||
|
|
||||||
for( const SCH_SHEET_INSTANCE& pastedInstance : sheet->GetInstances() )
|
for( const SCH_SHEET_INSTANCE& pastedInstance : sheet->GetInstances() )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue