From 34aee50ae194bbca3d9ba414703c6e43a131e1f5 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 29 Mar 2020 21:43:18 -0400 Subject: [PATCH] Rework plotting colors to ensure color settings are always available --- pcbnew/pcb_plot_params.cpp | 12 ++++++++++-- pcbnew/pcb_plot_params.h | 3 +++ pcbnew/pcbplot.h | 18 +----------------- pcbnew/plot_brditems_plotter.cpp | 4 ++-- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/pcbnew/pcb_plot_params.cpp b/pcbnew/pcb_plot_params.cpp index 48bfe8c6eb..8dda7a725c 100644 --- a/pcbnew/pcb_plot_params.cpp +++ b/pcbnew/pcb_plot_params.cpp @@ -138,8 +138,16 @@ PCB_PLOT_PARAMS::PCB_PLOT_PARAMS() // it is a "local" parameter m_skipNPTH_Pads = false; - // TODO(JE) Is it an issue for this to be tied to Pgm()? - m_colors = PgmOrNull() ? Pgm().GetSettingsManager().GetColorSettings() : nullptr; + if( PgmOrNull() ) + { + m_default_colors = nullptr; + m_colors = Pgm().GetSettingsManager().GetColorSettings(); + } + else + { + m_default_colors = std::make_shared(); + m_colors = m_default_colors.get(); + } } void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision ) diff --git a/pcbnew/pcb_plot_params.h b/pcbnew/pcb_plot_params.h index b98396c387..9c05b8fe94 100644 --- a/pcbnew/pcb_plot_params.h +++ b/pcbnew/pcb_plot_params.h @@ -175,6 +175,9 @@ private: /// Pointer to active color settings to be used for plotting COLOR_SETTINGS* m_colors; + /// Dummy colors object that can be created if there is no Pgm context + std::shared_ptr m_default_colors; + public: PCB_PLOT_PARAMS(); diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h index b797d058c0..7a3bc8e7b7 100644 --- a/pcbnew/pcbplot.h +++ b/pcbnew/pcbplot.h @@ -67,28 +67,12 @@ class BRDITEMS_PLOTTER : public PCB_PLOT_PARAMS BOARD* m_board; LSET m_layerMask; - /// Pointer to color settings that should be used for plotting - COLOR_SETTINGS* m_colors; - - /// Dummy colors object that can be created if there is no Pgm context - std::unique_ptr m_default_colors; - public: BRDITEMS_PLOTTER( PLOTTER* aPlotter, BOARD* aBoard, const PCB_PLOT_PARAMS& aPlotOpts ) - : PCB_PLOT_PARAMS( aPlotOpts ), m_default_colors() + : PCB_PLOT_PARAMS( aPlotOpts ) { m_plotter = aPlotter; m_board = aBoard; - - if( PgmOrNull() ) - { - m_colors = Pgm().GetSettingsManager().GetColorSettings(); - } - else - { - m_default_colors = std::make_unique(); - m_colors = m_default_colors.get(); - } } /** diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 1338688f74..30b9e4b8f4 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -73,7 +73,7 @@ COLOR4D BRDITEMS_PLOTTER::getColor( LAYER_NUM aLayer ) { - COLOR4D color = m_colors->GetColor( aLayer ); + COLOR4D color = ColorSettings()->GetColor( aLayer ); // A hack to avoid plotting a white item in white color, expecting the paper // is also white: use a non white color: @@ -393,7 +393,7 @@ void BRDITEMS_PLOTTER::PlotDimension( DIMENSION* aDim ) draw.SetWidth( aDim->GetWidth() ); draw.SetLayer( aDim->GetLayer() ); - COLOR4D color = m_colors->GetColor( aDim->GetLayer() ); + COLOR4D color = ColorSettings()->GetColor( aDim->GetLayer() ); // Set plot color (change WHITE to LIGHTGRAY because // the white items are not seen on a white paper or screen