Allow users to control the order of sheets through sheet fields.

Fixes https://gitlab.com/kicad/code/kicad/issues/2394
This commit is contained in:
Jeff Young 2020-05-03 23:20:31 +01:00
parent ed3e366715
commit da1a89fc7e
2 changed files with 34 additions and 4 deletions

View File

@ -318,7 +318,11 @@ bool DIALOG_SCH_SHEET_PROPS::TransferDataFromWindow()
m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() ); m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() );
m_frame->TestDanglingEnds(); m_frame->TestDanglingEnds();
m_frame->RefreshItem( m_sheet );
// Refresh all sheets in case ordering changed.
for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
m_frame->RefreshItem( item );
m_frame->OnModify(); m_frame->OnModify();
return true; return true;

View File

@ -777,10 +777,36 @@ void SCH_SCREEN::GetSheets( std::vector<SCH_ITEM*>* aItems )
std::sort( aItems->begin(), aItems->end(), std::sort( aItems->begin(), aItems->end(),
[]( EDA_ITEM* a, EDA_ITEM* b ) -> bool []( EDA_ITEM* a, EDA_ITEM* b ) -> bool
{ {
if( a->GetPosition().x == b->GetPosition().x ) long a_order = 0;
return a->GetPosition().y < b->GetPosition().y; long b_order = 0;
else
for( const SCH_FIELD& field : static_cast<SCH_SHEET*>( a )->GetFields() )
{
if( field.GetName().CmpNoCase( wxT( "Order" ) ) == 0 )
{
field.GetText().ToLong( &a_order );
break;
}
}
for( const SCH_FIELD& field : static_cast<SCH_SHEET*>( b )->GetFields() )
{
if( field.GetName().CmpNoCase( wxT( "Order" ) ) == 0 )
{
field.GetText().ToLong( &b_order );
break;
}
}
if( a_order == b_order )
{
if( a->GetPosition().x == b->GetPosition().x )
return a->GetPosition().y < b->GetPosition().y;
return a->GetPosition().x < b->GetPosition().x; return a->GetPosition().x < b->GetPosition().x;
}
return a_order < b_order;
} ); } );
} }