From f75266d130968e1cc1a50976122305654663e6fc Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 20 Sep 2022 22:06:11 +0300 Subject: [PATCH] Keep selection order in SCH->PCB cross-selection. --- eeschema/cross-probing.cpp | 14 +++++++------- eeschema/sch_edit_frame.h | 4 ++-- eeschema/tools/sch_editor_control.cpp | 2 +- pcbnew/cross-probing.cpp | 25 ++++++++++++++++++++----- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index c24f3b0c34..4d9e4122f1 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -274,9 +274,9 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) } -void SCH_EDIT_FRAME::SendSelectItemsToPcb( const std::deque& aItems, bool aForce ) +void SCH_EDIT_FRAME::SendSelectItemsToPcb( const std::vector& aItems, bool aForce ) { - std::set parts; + std::vector parts; for( EDA_ITEM* item : aItems ) { @@ -288,7 +288,7 @@ void SCH_EDIT_FRAME::SendSelectItemsToPcb( const std::deque& aItems, wxString ref = symbol->GetField( REFERENCE_FIELD )->GetText(); - parts.emplace( wxT( "F" ) + EscapeString( ref, CTX_IPC ) ); + parts.push_back( wxT( "F" ) + EscapeString( ref, CTX_IPC ) ); break; } @@ -300,7 +300,7 @@ void SCH_EDIT_FRAME::SendSelectItemsToPcb( const std::deque& aItems, wxString full_path = GetCurrentSheet().PathAsString() + item->m_Uuid.AsString(); - parts.emplace( wxT( "S" ) + full_path ); + parts.push_back( wxT( "S" ) + full_path ); break; } @@ -312,8 +312,8 @@ void SCH_EDIT_FRAME::SendSelectItemsToPcb( const std::deque& aItems, wxString ref = symbol->GetField( REFERENCE_FIELD )->GetText(); - parts.insert( wxT( "P" ) + EscapeString( ref, CTX_IPC ) + wxT( "/" ) - + EscapeString( pin->GetShownNumber(), CTX_IPC ) ); + parts.push_back( wxT( "P" ) + EscapeString( ref, CTX_IPC ) + wxT( "/" ) + + EscapeString( pin->GetShownNumber(), CTX_IPC ) ); break; } @@ -347,7 +347,7 @@ void SCH_EDIT_FRAME::SendSelectItemsToPcb( const std::deque& aItems, // we have existing interpreter of the selection packet on the other // side in place, we use that here. Kiway().ExpressMail( FRAME_PCB_EDITOR, aForce ? MAIL_SELECTION_FORCE : MAIL_SELECTION, - command, this ); + command, this ); } } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index b8a6b69303..9fc6b7d2c1 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -263,11 +263,11 @@ public: /** * Sends items to Pcbnew for selection * - * @param aElements are the items to select + * @param aItems are the items to select * @param aForce select the element in pcbnew whether or not the user has the select option chosen * This is used for when the eeschema user is using the cross-probe tool */ - void SendSelectItemsToPcb( const std::deque& aElements, bool aForce ); + void SendSelectItemsToPcb( const std::vector& aItems, bool aForce ); /** * Sends a net name to Pcbnew for highlighting diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index eb0bb9e66b..2da394ca4b 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -739,7 +739,7 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF EE_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection(); - m_frame->SendSelectItemsToPcb( selection.GetItems(), aForce ); + m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce ); } diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index 912a1926c9..4a6870fa10 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -432,7 +432,7 @@ std::vector PCB_EDIT_FRAME::FindItemsFromSyncSelection( std::string { wxArrayString syncArray = wxStringTokenize( syncStr, "," ); - std::vector items; + std::vector> orderPairs; for( FOOTPRINT* footprint : GetBoard()->Footprints() ) { @@ -450,8 +450,10 @@ std::vector PCB_EDIT_FRAME::FindItemsFromSyncSelection( std::string wxString fpRefEscaped = EscapeString( footprint->GetReference(), CTX_IPC ); - for( wxString syncEntry : syncArray ) + for( unsigned index = 0; index < syncArray.size(); ++index ) { + wxString syncEntry = syncArray[index]; + if( syncEntry.empty() ) continue; @@ -462,13 +464,13 @@ std::vector PCB_EDIT_FRAME::FindItemsFromSyncSelection( std::string case 'S': // Select sheet with subsheets: S if( fpSheetPath.StartsWith( syncData ) ) { - items.push_back( footprint ); + orderPairs.emplace_back( index, footprint ); } break; case 'F': // Select footprint: F if( syncData == fpRefEscaped ) { - items.push_back( footprint ); + orderPairs.emplace_back( index, footprint ); } break; case 'P': // Select pad: P/ @@ -484,7 +486,7 @@ std::vector PCB_EDIT_FRAME::FindItemsFromSyncSelection( std::string { if( selectPadNumber == pad->GetNumber() ) { - items.push_back( pad ); + orderPairs.emplace_back( index, pad ); } } } @@ -495,6 +497,19 @@ std::vector PCB_EDIT_FRAME::FindItemsFromSyncSelection( std::string } } + std::sort( + orderPairs.begin(), orderPairs.end(), + []( const std::pair& a, const std::pair& b ) -> bool + { + return a.first < b.first; + } ); + + std::vector items; + items.reserve( orderPairs.size() ); + + for( const std::pair& pair : orderPairs ) + items.push_back( pair.second ); + return items; }