Rework plotting colors to ensure color settings are always available

This commit is contained in:
Jon Evans 2020-03-29 21:43:18 -04:00
parent 570ea62b64
commit 34aee50ae1
4 changed files with 16 additions and 21 deletions

View File

@ -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<COLOR_SETTINGS>();
m_colors = m_default_colors.get();
}
}
void PCB_PLOT_PARAMS::SetGerberPrecision( int aPrecision )

View File

@ -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<COLOR_SETTINGS> m_default_colors;
public:
PCB_PLOT_PARAMS();

View File

@ -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<COLOR_SETTINGS> 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<COLOR_SETTINGS>();
m_colors = m_default_colors.get();
}
}
/**

View File

@ -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