From 8f7278e34f72c7b9e2d0aa11c106642bc269b527 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 19 Jun 2019 07:48:35 -0700 Subject: [PATCH] Eeschema: Normalize layer ordering between plot and screen Fixes: lp:1833428 * https://bugs.launchpad.net/kicad/+bug/1833428 --- eeschema/sch_bitmap.cpp | 3 +- eeschema/sch_painter.cpp | 10 ++-- eeschema/sch_screen.cpp | 65 ++++++++--------------- eeschema/sch_view.h | 9 ++-- include/core/typeinfo.h | 13 +++-- include/layers_id_colors_and_visibility.h | 1 + 6 files changed, 40 insertions(+), 61 deletions(-) diff --git a/eeschema/sch_bitmap.cpp b/eeschema/sch_bitmap.cpp index 6bdc9fe122..fe3e9149d6 100644 --- a/eeschema/sch_bitmap.cpp +++ b/eeschema/sch_bitmap.cpp @@ -41,8 +41,7 @@ SCH_BITMAP::SCH_BITMAP( const wxPoint& pos ) : SCH_ITEM( NULL, SCH_BITMAP_T ) { m_pos = pos; - m_Layer = LAYER_NOTES; // used only to draw/plot a rectangle, - // when a bitmap cannot be drawn or plotted + m_Layer = LAYER_SCHEMATIC_BITMAPS; m_image = new BITMAP_BASE(); } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 9cb3203c6e..0592ffb5b0 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -167,11 +167,11 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) m_schSettings.ImportLegacyColors( nullptr ); - switch( item->Type() ) - { - HANDLE_ITEM(LIB_ALIAS_T, LIB_ALIAS); - HANDLE_ITEM(LIB_PART_T, LIB_PART); - HANDLE_ITEM(LIB_RECTANGLE_T, LIB_RECTANGLE); + switch( item->Type() ) + { + HANDLE_ITEM(LIB_ALIAS_T, LIB_ALIAS); + HANDLE_ITEM(LIB_PART_T, LIB_PART); + HANDLE_ITEM(LIB_RECTANGLE_T, LIB_RECTANGLE); HANDLE_ITEM(LIB_POLYLINE_T, LIB_POLYLINE); HANDLE_ITEM(LIB_CIRCLE_T, LIB_CIRCLE); HANDLE_ITEM(LIB_PIN_T, LIB_PIN); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index acf9e386ef..5a913a6b1f 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -509,9 +509,11 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode * library editor and library viewer do not use m_drawList, and therefore * their SCH_SCREEN::Draw() draws nothing */ - std::vector< SCH_ITEM* > junctions; - std::vector< SCH_ITEM* > bitmaps; - std::vector< SCH_ITEM* > other; + std::vector< SCH_ITEM* > items; + + + // Ensure links are up to date, even if a library was reloaded for some reason: + UpdateSymbolLinks(); // Ensure links are up to date, even if a library was reloaded for some reason: UpdateSymbolLinks(); @@ -521,36 +523,25 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode if( item->IsMoving() || item->IsResized() ) continue; - if( item->Type() == SCH_JUNCTION_T ) - junctions.push_back( item ); - 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 ); + items.push_back( item ); } - // 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 - for( auto item : bitmaps ) - item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), aDrawMode, aColor ); + std::sort( items.begin(), items.end(), [] ( const SCH_ITEM* a, const SCH_ITEM* b ) + { + if( a->Type() == b->Type() ) + return a->GetLayer() > b->GetLayer(); - for( auto item : other ) - item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), aDrawMode, aColor ); + return a->Type() > b->Type(); + } ); - for( auto item : junctions ) + for( auto item : items ) item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), aDrawMode, aColor ); } void SCH_SCREEN::Plot( PLOTTER* aPlotter ) { - // Ensure links are up to date, even if a library was reloaded for some reason: - std::vector< SCH_ITEM* > junctions; - std::vector< SCH_ITEM* > bitmaps; - std::vector< SCH_ITEM* > other; + std::vector< SCH_ITEM* > items; // Ensure links are up to date, even if a library was reloaded for some reason: UpdateSymbolLinks(); @@ -560,32 +551,18 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter ) if( item->IsMoving() || item->IsResized() ) continue; - if( item->Type() == SCH_JUNCTION_T ) - junctions.push_back( item ); - 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 ); + items.push_back( item ); } - // 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 - for( auto item : bitmaps ) + std::sort( items.begin(), items.end(), [] ( const SCH_ITEM* a, const SCH_ITEM* b ) { - aPlotter->SetCurrentLineWidth( item->GetPenSize() ); - item->Plot( aPlotter ); - } + if( a->Type() == b->Type() ) + return a->GetLayer() > b->GetLayer(); - for( auto item : other ) - { - aPlotter->SetCurrentLineWidth( item->GetPenSize() ); - item->Plot( aPlotter ); - } + return a->Type() > b->Type(); + } ); - for( auto item : junctions ) + for( auto item : items ) { aPlotter->SetCurrentLineWidth( item->GetPenSize() ); item->Plot( aPlotter ); diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index 12695199c4..9f524f1c75 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -46,14 +46,17 @@ static const LAYER_NUM SCH_LAYER_ORDER[] = LAYER_GP_OVERLAY, LAYER_SELECT_OVERLAY, LAYER_ERC_ERR, LAYER_ERC_WARN, LAYER_REFERENCEPART, LAYER_VALUEPART, LAYER_FIELDS, - LAYER_JUNCTION, LAYER_NOCONNECT, + LAYER_NOCONNECT, + LAYER_JUNCTION, LAYER_HIERLABEL, - LAYER_WIRE, LAYER_BUS, + LAYER_WIRE, + LAYER_BUS, + LAYER_NOTES, LAYER_DEVICE, LAYER_DEVICE_BACKGROUND, - LAYER_NOTES, LAYER_SHEET, LAYER_SHEET_BACKGROUND, + LAYER_SCHEMATIC_BITMAPS, LAYER_WORKSHEET }; diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 178e522b59..008e5df0c7 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -104,23 +104,22 @@ enum KICAD_T PCB_NETINFO_T, ///< class NETINFO_ITEM, a description of a net // Schematic draw Items. The order of these items effects the sort order. - // It is currently ordered to mimic the old Eeschema locate behavior where - // the smallest item is the selected item. + // The SCH_MARKER_T is drawn last (on top of others) SCH_MARKER_T, - SCH_JUNCTION_T, SCH_NO_CONNECT_T, - SCH_BUS_WIRE_ENTRY_T, - SCH_BUS_BUS_ENTRY_T, - SCH_LINE_T, - SCH_BITMAP_T, + SCH_JUNCTION_T, SCH_TEXT_T, SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIERARCHICAL_LABEL_T, + SCH_BUS_WIRE_ENTRY_T, + SCH_BUS_BUS_ENTRY_T, + SCH_LINE_T, SCH_FIELD_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T, SCH_SHEET_T, + SCH_BITMAP_T, // Be prudent with these 3 types: // they should be used only to locate a specific field type diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index 0467c9a086..d78d2cfc5f 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -257,6 +257,7 @@ enum SCH_LAYER_ID: int LAYER_ERC_ERR, LAYER_DEVICE_BACKGROUND, LAYER_SHEET_BACKGROUND, + LAYER_SCHEMATIC_BITMAPS, LAYER_SCHEMATIC_GRID, LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_CURSOR,