Gerbview: fix issues when setting the grid color and the worksheet color.

The issue for the grid color was due to the fact there are 2 places to
store the color: the color settings and the m_gridColor GERBVIEW_FRAME member.
The worksheet color (color set to RED after a color change in layer render)
is a bit strange: looks like LAYER_GERBVIEW_WORKSHEET and LAYER_WORKSHEET
are both used to draw the worksheet.
This commit is contained in:
jean-pierre charras 2020-07-08 18:20:31 +02:00
parent 3dd2dc89ad
commit 8c15ecf8e4
7 changed files with 36 additions and 7 deletions

View File

@ -110,7 +110,7 @@ COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) :
CLR( "gerbview.dcodes", LAYER_DCODES, COLOR4D( WHITE ) ); CLR( "gerbview.dcodes", LAYER_DCODES, COLOR4D( WHITE ) );
CLR( "gerbview.grid", LAYER_GERBVIEW_GRID, COLOR4D( MAGENTA ) ); CLR( "gerbview.grid", LAYER_GERBVIEW_GRID, COLOR4D( MAGENTA ) );
CLR( "gerbview.negative_objects", LAYER_NEGATIVE_OBJECTS, COLOR4D( DARKGRAY ) ); CLR( "gerbview.negative_objects", LAYER_NEGATIVE_OBJECTS, COLOR4D( DARKGRAY ) );
CLR( "gerbview.worksheet", LAYER_GERBVIEW_WORKSHEET, COLOR4D( BLUE ) ); CLR( "gerbview.worksheet", LAYER_GERBVIEW_WORKSHEET, COLOR4D( RED ) );
// TODO(JE) New default scheme for GerbView // TODO(JE) New default scheme for GerbView
for( int i = 0, id = GERBVIEW_LAYER_ID_START; for( int i = 0, id = GERBVIEW_LAYER_ID_START;

View File

@ -205,6 +205,8 @@ void GERBVIEW_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
BOX2I GERBVIEW_DRAW_PANEL_GAL::GetDefaultViewBBox() const BOX2I GERBVIEW_DRAW_PANEL_GAL::GetDefaultViewBBox() const
{ {
// Even in Gervbview, this is the LAYER_WORKSHEET that controls the visibility
// of the worksheet
if( m_worksheet && m_view->IsLayerVisible( LAYER_WORKSHEET ) ) if( m_worksheet && m_view->IsLayerVisible( LAYER_WORKSHEET ) )
return m_worksheet->ViewBBox(); return m_worksheet->ViewBBox();

View File

@ -62,6 +62,11 @@ public:
*/ */
void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet );
/**
* @return the current worksheet
*/
KIGFX::WS_PROXY_VIEW_ITEM* GetWorksheet() const { return m_worksheet.get(); }
protected: protected:
///> Sets rendering targets & dependencies for layers. ///> Sets rendering targets & dependencies for layers.
void setDefaultLayerDeps(); void setDefaultLayerDeps();

View File

@ -807,6 +807,7 @@ bool GERBVIEW_FRAME::IsLayerVisible( int aLayer ) const
COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID ) COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID )
{ {
COLOR4D color = COLOR4D::UNSPECIFIED; COLOR4D color = COLOR4D::UNSPECIFIED;
COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings();
switch( aLayerID ) switch( aLayerID )
{ {
@ -814,7 +815,7 @@ COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID )
case LAYER_DCODES: case LAYER_DCODES:
case LAYER_GERBVIEW_WORKSHEET: case LAYER_GERBVIEW_WORKSHEET:
case LAYER_GERBVIEW_BACKGROUND: case LAYER_GERBVIEW_BACKGROUND:
color = Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayerID ); color = settings->GetColor( aLayerID );
break; break;
case LAYER_GERBVIEW_GRID: case LAYER_GERBVIEW_GRID:
@ -844,10 +845,17 @@ void GERBVIEW_FRAME::SetVisibleElementColor( int aLayerID, COLOR4D aColor )
{ {
case LAYER_NEGATIVE_OBJECTS: case LAYER_NEGATIVE_OBJECTS:
case LAYER_DCODES: case LAYER_DCODES:
case LAYER_GERBVIEW_WORKSHEET:
settings->SetColor( aLayerID, aColor ); settings->SetColor( aLayerID, aColor );
break; break;
case LAYER_GERBVIEW_WORKSHEET:
settings->SetColor( LAYER_GERBVIEW_WORKSHEET, aColor );
// LAYER_WORKSHEET color is alsu used to draw the worksheet
// FIX ME: why LAYER_WORKSHEET must be set, although LAYER_GERBVIEW_WORKSHEET
// is used to initialize the worksheet color layer.
settings->SetColor( LAYER_WORKSHEET, aColor );
break;
case LAYER_GERBVIEW_GRID: case LAYER_GERBVIEW_GRID:
SetGridColor( aColor ); SetGridColor( aColor );
settings->SetColor( aLayerID, aColor ); settings->SetColor( aLayerID, aColor );
@ -958,8 +966,15 @@ void GERBVIEW_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
} }
COLOR4D GERBVIEW_FRAME::GetGridColor()
{
return Pgm().GetSettingsManager().GetColorSettings()->GetColor( LAYER_GRID );
}
void GERBVIEW_FRAME::SetGridColor( COLOR4D aColor ) void GERBVIEW_FRAME::SetGridColor( COLOR4D aColor )
{ {
Pgm().GetSettingsManager().GetColorSettings()->SetColor( LAYER_GRID, aColor );
GetCanvas()->GetGAL()->SetGridColor( aColor ); GetCanvas()->GetGAL()->SetGridColor( aColor );
m_gridColor = aColor; m_gridColor = aColor;
} }

View File

@ -129,6 +129,11 @@ public:
*/ */
int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount ); int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount );
/**
* @return the color of the grid
*/
COLOR4D GetGridColor() override;
///> @copydoc EDA_DRAW_FRAME::SetGridColor() ///> @copydoc EDA_DRAW_FRAME::SetGridColor()
virtual void SetGridColor( COLOR4D aColor ) override; virtual void SetGridColor( COLOR4D aColor ) override;

View File

@ -250,7 +250,6 @@ void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, COLOR4D aColor )
{ {
// NOTE: Active layer in GerbView is stored as 0-indexed, but layer color is // NOTE: Active layer in GerbView is stored as 0-indexed, but layer color is
// stored according to the GERBER_DRAW_LAYER() offset. // stored according to the GERBER_DRAW_LAYER() offset.
myframe->SetLayerColor( GERBER_DRAW_LAYER( aLayer ), aColor ); myframe->SetLayerColor( GERBER_DRAW_LAYER( aLayer ), aColor );
myframe->m_SelLayerBox->ResyncBitmapOnly(); myframe->m_SelLayerBox->ResyncBitmapOnly();
@ -294,17 +293,16 @@ void GERBER_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFin
myframe->GetCanvas()->Refresh(); myframe->GetCanvas()->Refresh();
} }
#include "gerbview_draw_panel_gal.h"
void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor ) void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor )
{ {
myframe->SetVisibleElementColor( aId, aColor ); myframe->SetVisibleElementColor( aId, aColor );
auto view = myframe->GetCanvas()->GetView(); auto view = myframe->GetCanvas()->GetView();
auto settings = Pgm().GetSettingsManager().GetColorSettings(); COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings();
view->GetPainter()->GetSettings()->LoadColors( settings ); view->GetPainter()->GetSettings()->LoadColors( settings );
view->UpdateLayerColor( aId ); view->UpdateLayerColor( aId );
view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
view->UpdateAllItems( KIGFX::COLOR ); view->UpdateAllItems( KIGFX::COLOR );
myframe->GetCanvas()->Refresh(); myframe->GetCanvas()->Refresh();

View File

@ -55,6 +55,7 @@ void GERBVIEW_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings )
size_t palette_size = aSettings->m_Palette.size(); size_t palette_size = aSettings->m_Palette.size();
size_t palette_idx = 0; size_t palette_idx = 0;
// Layers to draw gerber data read from gerber files:
for( int i = GERBVIEW_LAYER_ID_START; for( int i = GERBVIEW_LAYER_ID_START;
i < GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT; i++ ) i < GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT; i++ )
{ {
@ -72,6 +73,9 @@ void GERBVIEW_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings )
m_layerColorsDark[i] = baseColor.Darkened( 0.25 ); m_layerColorsDark[i] = baseColor.Darkened( 0.25 );
} }
// Draw layers specific to Gerbview:
// LAYER_DCODES, LAYER_NEGATIVE_OBJECTS, LAYER_GERBVIEW_GRID,
// LAYER_GERBVIEW_AXES, LAYER_GERBVIEW_BACKGROUND, LAYER_GERBVIEW_WORKSHEET,
for( int i = LAYER_DCODES; i < GERBVIEW_LAYER_ID_END; i++ ) for( int i = LAYER_DCODES; i < GERBVIEW_LAYER_ID_END; i++ )
m_layerColors[i] = aSettings->GetColor( i ); m_layerColors[i] = aSettings->GetColor( i );