From 9dae57ae9d9fd0286c0ac161bb2556ecdf022fbb Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 13 Dec 2020 22:42:29 +0000 Subject: [PATCH] Fix several bugs in SCH color printing and plotting. Fixes https://gitlab.com/kicad/code/kicad/issues/6723 --- eeschema/dialogs/dialog_plot_schematic.cpp | 8 +-- eeschema/dialogs/dialog_plot_schematic.h | 2 +- eeschema/plotters/plot_schematic_PDF.cpp | 19 ++--- eeschema/sch_sheet.cpp | 82 +++++++++++----------- eeschema/sch_text.cpp | 38 +++++----- 5 files changed, 78 insertions(+), 71 deletions(-) diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index ab00b05ad6..5e48c31716 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -289,10 +289,10 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions( RENDER_SETTINGS* aSettings ) aSettings->LoadColors( colors ); aSettings->SetDefaultPenWidth( (int) m_defaultLineWidth.GetValue() ); - if( m_plotBackgroundColor->GetValue() ) - aSettings->SetBackgroundColor( colors->GetColor( LAYER_SCHEMATIC_BACKGROUND ) ); - else - aSettings->SetBackgroundColor( COLOR4D::UNSPECIFIED ); + if( m_plotBackgroundColor->GetValue() ) + aSettings->SetBackgroundColor( colors->GetColor( LAYER_SCHEMATIC_BACKGROUND ) ); + else + aSettings->SetBackgroundColor( COLOR4D::UNSPECIFIED ); // Plot directory wxString path = m_outputDirectoryName->GetValue(); diff --git a/eeschema/dialogs/dialog_plot_schematic.h b/eeschema/dialogs/dialog_plot_schematic.h index 765030b181..ab0c9cc686 100644 --- a/eeschema/dialogs/dialog_plot_schematic.h +++ b/eeschema/dialogs/dialog_plot_schematic.h @@ -95,7 +95,7 @@ private: // PDF void createPDFFile( bool aPlotAll, bool aPlotFrameRef, RENDER_SETTINGS* aRenderSettings ); - void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, bool aPlotFrameRef); + void plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, bool aPlotWorksheet); void setupPlotPagePDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen ); /** diff --git a/eeschema/plotters/plot_schematic_PDF.cpp b/eeschema/plotters/plot_schematic_PDF.cpp index 755bb1a17e..08f43626dd 100644 --- a/eeschema/plotters/plot_schematic_PDF.cpp +++ b/eeschema/plotters/plot_schematic_PDF.cpp @@ -155,9 +155,8 @@ void DIALOG_PLOT_SCHEMATIC::restoreEnvironment( PDF_PLOTTER* aPlotter, } -void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter, - SCH_SCREEN* aScreen, - bool aPlotFrameRef ) +void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter, SCH_SCREEN* aScreen, + bool aPlotWorksheet ) { if( m_plotBackgroundColor->GetValue() ) { @@ -167,15 +166,17 @@ void DIALOG_PLOT_SCHEMATIC::plotOneSheetPDF( PLOTTER* aPlotter, aPlotter->Rect( wxPoint( 0, 0 ), end, FILL_TYPE::FILLED_SHAPE, 1.0 ); } - if( aPlotFrameRef ) + if( aPlotWorksheet ) { + COLOR4D color = COLOR4D::BLACK; + + if( aPlotter->GetColorMode() ) + color = aPlotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_WORKSHEET ); + PlotWorkSheet( aPlotter, &aScreen->Schematic()->Prj(), m_parent->GetTitleBlock(), m_parent->GetPageSettings(), aScreen->GetPageNumber(), - aScreen->GetPageCount(), m_parent->GetScreenDesc(), - aScreen->GetFileName(), - aPlotter->GetColorMode() ? - aPlotter->RenderSettings()->GetLayerColor( LAYER_SCHEMATIC_WORKSHEET ) : - COLOR4D::BLACK, aScreen->GetVirtualPageNumber() == 1 ); + aScreen->GetPageCount(), m_parent->GetScreenDesc(), aScreen->GetFileName(), + color, aScreen->GetVirtualPageNumber() == 1 ); } aScreen->Plot( aPlotter ); diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 6b1da2eb86..d7716c40cf 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -549,34 +549,6 @@ void SCH_SHEET::ViewGetLayers( int aLayers[], int& aCount ) const } -void SCH_SHEET::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) -{ - wxDC* DC = aSettings->GetPrintDC(); - wxPoint pos = m_pos + aOffset; - int lineWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() ); - COLOR4D background = GetBackgroundColor(); - COLOR4D border = GetBorderColor(); - - if( background == COLOR4D::UNSPECIFIED ) - background = aSettings->GetLayerColor( LAYER_SHEET_BACKGROUND ); - - if( border == COLOR4D::UNSPECIFIED ) - border = aSettings->GetLayerColor( LAYER_SHEET ); - - if( background != COLOR4D::UNSPECIFIED && background != COLOR4D::WHITE ) - GRRect( nullptr, DC, pos.x, pos.y, pos.x + m_size.x, pos.y + m_size.y, background ); - - GRRect( nullptr, DC, pos.x, pos.y, pos.x + m_size.x, pos.y + m_size.y, lineWidth, border ); - - for( SCH_FIELD& field : m_fields ) - field.Print( aSettings, aOffset ); - - /* Draw text : SheetLabel */ - for( SCH_SHEET_PIN* sheetPin : m_pins ) - sheetPin->Print( aSettings, aOffset ); -} - - const EDA_RECT SCH_SHEET::GetBodyBoundingBox() const { wxPoint end; @@ -959,17 +931,12 @@ bool SCH_SHEET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) void SCH_SHEET::Plot( PLOTTER* aPlotter ) { - wxString Text; - wxPoint pos; - - bool override = false; - - if( KIGFX::SCH_RENDER_SETTINGS* settings = - dynamic_cast( aPlotter->RenderSettings() ) ) - override = settings->m_OverrideItemColors; - - COLOR4D borderColor = GetBorderColor(); - COLOR4D backgroundColor = GetBackgroundColor(); + wxString msg; + wxPoint pos; + auto* settings = dynamic_cast( aPlotter->RenderSettings() ); + bool override = settings ? settings->m_OverrideItemColors : false; + COLOR4D borderColor = GetBorderColor(); + COLOR4D backgroundColor = GetBackgroundColor(); if( override || borderColor == COLOR4D::UNSPECIFIED ) borderColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_SHEET ); @@ -980,7 +947,9 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter ) aPlotter->SetColor( backgroundColor ); // Do not fill shape in B&W mode, otherwise texts are unreadable bool fill = aPlotter->GetColorMode(); - aPlotter->Rect( m_pos, m_pos + m_size, fill ? FILL_TYPE::FILLED_SHAPE : FILL_TYPE::NO_FILL, 1.0 ); + + aPlotter->Rect( m_pos, m_pos + m_size, fill ? FILL_TYPE::FILLED_SHAPE : FILL_TYPE::NO_FILL, + 1.0 ); aPlotter->SetColor( borderColor ); @@ -1010,6 +979,39 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter ) } +void SCH_SHEET::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) +{ + wxDC* DC = aSettings->GetPrintDC(); + wxPoint pos = m_pos + aOffset; + int lineWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() ); + auto* settings = dynamic_cast( aSettings ); + bool override = settings ? settings->m_OverrideItemColors : false; + COLOR4D border = GetBorderColor(); + COLOR4D background = GetBackgroundColor(); + + if( override || border == COLOR4D::UNSPECIFIED ) + border = aSettings->GetLayerColor( LAYER_SHEET ); + + if( override || background == COLOR4D::UNSPECIFIED ) + background = aSettings->GetLayerColor( LAYER_SHEET_BACKGROUND ); + + if( background != COLOR4D::UNSPECIFIED ) + { + GRFilledRect( nullptr, DC, pos.x, pos.y, pos.x + m_size.x, pos.y + m_size.y, 0, + background, background ); + } + + GRRect( nullptr, DC, pos.x, pos.y, pos.x + m_size.x, pos.y + m_size.y, lineWidth, border ); + + for( SCH_FIELD& field : m_fields ) + field.Print( aSettings, aOffset ); + + /* Draw text : SheetLabel */ + for( SCH_SHEET_PIN* sheetPin : m_pins ) + sheetPin->Print( aSettings, aOffset ); +} + + SCH_SHEET& SCH_SHEET::operator=( const SCH_ITEM& aItem ) { wxCHECK_MSG( Type() == aItem.Type(), *this, diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 44e00637d9..06eeb59ec2 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -602,11 +602,15 @@ bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) void SCH_TEXT::Plot( PLOTTER* aPlotter ) { - static std::vector Poly; - COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( GetLayer() ); - int penWidth = GetEffectiveTextPenWidth( aPlotter->RenderSettings()->GetDefaultPenWidth() ); + static std::vector s_poly; - penWidth = std::max( penWidth, aPlotter->RenderSettings()->GetMinPenWidth() ); + RENDER_SETTINGS* settings = aPlotter->RenderSettings(); + SCH_CONNECTION* connection = Connection(); + int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; + COLOR4D color = settings->GetLayerColor( layer ); + int penWidth = GetEffectiveTextPenWidth( settings->GetDefaultPenWidth() ); + + penWidth = std::max( penWidth, settings->GetMinPenWidth() ); aPlotter->SetCurrentLineWidth( penWidth ); if( IsMultilineAllowed() ) @@ -635,10 +639,10 @@ void SCH_TEXT::Plot( PLOTTER* aPlotter ) } // Draw graphic symbol for global or hierarchical labels - CreateGraphicShape( aPlotter->RenderSettings(), Poly, GetTextPos() ); + CreateGraphicShape( aPlotter->RenderSettings(), s_poly, GetTextPos() ); - if( Poly.size() ) - aPlotter->PlotPoly( Poly, FILL_TYPE::NO_FILL, penWidth ); + if( s_poly.size() ) + aPlotter->PlotPoly( s_poly, FILL_TYPE::NO_FILL, penWidth ); } @@ -1152,21 +1156,21 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const void SCH_GLOBALLABEL::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) { - static std::vector Poly; + static std::vector s_poly; - wxDC* DC = aSettings->GetPrintDC(); - COLOR4D color = aSettings->GetLayerColor( m_layer ); - int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() ); - wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings ); + SCH_CONNECTION* connection = Connection(); + int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; + wxDC* DC = aSettings->GetPrintDC(); + COLOR4D color = aSettings->GetLayerColor( layer ); + int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() ); + wxPoint text_offset = aOffset + GetSchematicTextOffset( aSettings ); EDA_TEXT::Print( aSettings, text_offset, color ); - CreateGraphicShape( aSettings, Poly, GetTextPos() + aOffset ); - GRPoly( nullptr, DC, Poly.size(), &Poly[0], false, penWidth, color, color ); + CreateGraphicShape( aSettings, s_poly, GetTextPos() + aOffset ); + GRPoly( nullptr, DC, s_poly.size(), &s_poly[0], false, penWidth, color, color ); - bool show = Schematic()->Settings().m_IntersheetRefsShow; - - if ( show ) + if( Schematic()->Settings().m_IntersheetRefsShow ) m_intersheetRefsField.Print( aSettings, aOffset ); }