From c3479154ca973c8a551c11e2af193910aa8607a9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 31 Aug 2018 22:39:11 +0100 Subject: [PATCH] Fix draw order issues in eeschema and libedit. Eeschema (where only the parent component is in the view) uses draw order. LibEdit (where the individual items are in the view) uses the viewPriority setting. --- eeschema/libedit/lib_edit_frame.cpp | 1 + eeschema/sch_painter.cpp | 31 +++++++++++++++++------------ eeschema/sch_view.cpp | 11 +++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 3a2bb01027..b02bdaf45f 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -287,6 +287,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SyncView(); GetGalCanvas()->GetViewControls()->SetSnapping( true ); + GetGalCanvas()->GetView()->UseDrawPriority( true ); } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 3727bd46de..44274dce99 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -164,7 +164,6 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) //printf("bkgd2 %.02f %.02f %.02f %.02f\n", c2.r, c2.g, c2.b, c2.a); m_gal->EnableDepthTest( false ); - m_gal->AdvanceDepth(); /* m_gal->SetLineWidth( 10 ); m_gal->SetIsFill( false ); @@ -215,16 +214,19 @@ void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit { size_t pinIndex = 0; - for( auto& item : aComp->GetDrawItems() ) + auto visitItem = [&]( LIB_ITEM& item, bool aBackground ) { - if( !aDrawFields && item.Type() == LIB_FIELD_T ) - continue; + if( aBackground != ( item.GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) ) + return; + + if( !aDrawFields && item.Type() == LIB_FIELD_T ) + return; if( aUnit && item.GetUnit() && aUnit != item.GetUnit() ) - continue; + return; if( aConvert && item.GetConvert() && aConvert != item.GetConvert() ) - continue; + return; if( item.Type() == LIB_PIN_T ) { @@ -239,7 +241,16 @@ void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit } else Draw( &item, aLayer ); - } + }; + + // Apply a z-order heuristic (because we don't yet let the user edit it): + // draw body-filled objects first. + + for( auto& item : aComp->GetDrawItems() ) + visitItem( item, true ); + + for( auto& item : aComp->GetDrawItems() ) + visitItem( item, false ); } @@ -1040,7 +1051,6 @@ void SCH_PAINTER::draw ( SCH_GLOBALLABEL *aLabel, int aLayer ) m_gal->SetIsStroke( true ); m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_GLOBLABEL ) ); m_gal->DrawPolyline( pts2 ); - m_gal->AdvanceDepth(); // fixme draw( static_cast( aLabel ), aLayer ); } @@ -1060,7 +1070,6 @@ void SCH_PAINTER::draw ( SCH_HIERLABEL *aLabel, int aLayer ) m_gal->SetIsStroke( true ); m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEETLABEL ) ); m_gal->DrawPolyline( pts2 ); - m_gal->AdvanceDepth(); // fixme draw( static_cast( aLabel ), aLayer ); } @@ -1108,11 +1117,7 @@ void SCH_PAINTER::draw ( SCH_SHEET *aSheet, int aLayer ) for( auto& sheetPin : aSheet->GetPins() ) - { - m_gal->AdvanceDepth(); draw( static_cast( &sheetPin ), aLayer ); - } - } void SCH_PAINTER::draw ( SCH_NO_CONNECT *aNC, int aLayer ) diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index ecaf72ab65..b3f0e8f270 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -116,10 +116,19 @@ void SCH_VIEW::DisplayComponent( LIB_PART *aPart ) { Clear(); + int fgPriority = INT_MAX / 2; + int bgPriority = 0; + for ( auto &item : aPart->GetDrawItems() ) { //printf("-- ADD %p\n", &item ); - Add( &item ); + + // Apply a z-order heuristic (because we don't yet let the user edit it): + // push body-filled objects to the back. + if( item.GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) + Add( &item, bgPriority++ ); + else + Add( &item, fgPriority++ ); } m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA( ) );