From c2904ce7e9e76403fb586f1fcb2a2fb6262541dc Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 9 Jan 2020 20:15:46 -0800 Subject: [PATCH] Fixing drawing order when plotting/printing This is a partial re-work of a previous commit to the v5 branch (8f7278e34f72c7b9e2d0aa11c106642bc269b527) that fixes #368 --- eeschema/sch_screen.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index a3a66d28b6..e56faf07c4 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -519,7 +519,10 @@ void SCH_SCREEN::UpdateSymbolLinks( bool aForce ) void SCH_SCREEN::Print( wxDC* aDC ) { + // Ensure links are up to date, even if a library was reloaded for some reason: std::vector< SCH_ITEM* > junctions; + std::vector bitmaps; + std::vector other; // Ensure links are up to date, even if a library was reloaded for some reason: UpdateSymbolLinks(); @@ -531,10 +534,26 @@ void SCH_SCREEN::Print( wxDC* aDC ) if( item->Type() == SCH_JUNCTION_T ) junctions.push_back( item ); + else if( item->Type() == SCH_BITMAP_T ) + bitmaps.push_back( item ); else - item->Print( aDC, wxPoint( 0, 0 ) ); + other.push_back( item ); } + /// Sort to ensure plot-order consistency with screen drawing + std::sort( other.begin(), other.end(), []( const SCH_ITEM* a, const SCH_ITEM* b ) { + if( a->Type() == b->Type() ) + return a->GetLayer() > b->GetLayer(); + + return a->Type() > b->Type(); + } ); + + for( auto item : bitmaps ) + item->Print( aDC, wxPoint( 0, 0 ) ); + + for( auto item : other ) + item->Print( aDC, wxPoint( 0, 0 ) ); + for( auto item : junctions ) item->Print( aDC, wxPoint( 0, 0 ) ); } @@ -560,11 +579,17 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter ) else if( item->Type() == SCH_BITMAP_T ) bitmaps.push_back( item ); else - // uncomment line below when there is a virtual EDA_ITEM::GetBoundingBox() - // if( panel->GetClipBox().Intersects( item->GetBoundingBox() ) ) other.push_back( item ); } + /// Sort to ensure plot-order consistency with screen drawing + std::sort( other.begin(), other.end(), []( const SCH_ITEM* a, const SCH_ITEM* b ) { + if( a->Type() == b->Type() ) + return a->GetLayer() > b->GetLayer(); + + return a->Type() > b->Type(); + } ); + // Bitmaps are drawn first to ensure they are in the background // This is particularly important for the wxPostscriptDC (used in *nix printers) as // the bitmap PS command clears the screen