From 8c15ecf8e45b91a81bff9442c8980befed3d364a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 8 Jul 2020 18:20:31 +0200 Subject: [PATCH] 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. --- common/settings/color_settings.cpp | 2 +- gerbview/gerbview_draw_panel_gal.cpp | 2 ++ gerbview/gerbview_draw_panel_gal.h | 5 +++++ gerbview/gerbview_frame.cpp | 19 +++++++++++++++++-- gerbview/gerbview_frame.h | 5 +++++ gerbview/gerbview_layer_widget.cpp | 6 ++---- gerbview/gerbview_painter.cpp | 4 ++++ 7 files changed, 36 insertions(+), 7 deletions(-) diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index fec8511786..0e6b4de1f4 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -110,7 +110,7 @@ COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) : CLR( "gerbview.dcodes", LAYER_DCODES, COLOR4D( WHITE ) ); CLR( "gerbview.grid", LAYER_GERBVIEW_GRID, COLOR4D( MAGENTA ) ); 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 for( int i = 0, id = GERBVIEW_LAYER_ID_START; diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 09d55fc78a..28b541c806 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -205,6 +205,8 @@ void GERBVIEW_DRAW_PANEL_GAL::SetTopLayer( int aLayer ) 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 ) ) return m_worksheet->ViewBBox(); diff --git a/gerbview/gerbview_draw_panel_gal.h b/gerbview/gerbview_draw_panel_gal.h index f8868d1bd4..e66b955ef2 100644 --- a/gerbview/gerbview_draw_panel_gal.h +++ b/gerbview/gerbview_draw_panel_gal.h @@ -62,6 +62,11 @@ public: */ void SetWorksheet( KIGFX::WS_PROXY_VIEW_ITEM* aWorksheet ); + /** + * @return the current worksheet + */ + KIGFX::WS_PROXY_VIEW_ITEM* GetWorksheet() const { return m_worksheet.get(); } + protected: ///> Sets rendering targets & dependencies for layers. void setDefaultLayerDeps(); diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index b4635026a5..5973e001b6 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -807,6 +807,7 @@ bool GERBVIEW_FRAME::IsLayerVisible( int aLayer ) const COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID ) { COLOR4D color = COLOR4D::UNSPECIFIED; + COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings(); switch( aLayerID ) { @@ -814,7 +815,7 @@ COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID ) case LAYER_DCODES: case LAYER_GERBVIEW_WORKSHEET: case LAYER_GERBVIEW_BACKGROUND: - color = Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayerID ); + color = settings->GetColor( aLayerID ); break; case LAYER_GERBVIEW_GRID: @@ -844,10 +845,17 @@ void GERBVIEW_FRAME::SetVisibleElementColor( int aLayerID, COLOR4D aColor ) { case LAYER_NEGATIVE_OBJECTS: case LAYER_DCODES: - case LAYER_GERBVIEW_WORKSHEET: settings->SetColor( aLayerID, aColor ); 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: SetGridColor( 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 ) { + Pgm().GetSettingsManager().GetColorSettings()->SetColor( LAYER_GRID, aColor ); GetCanvas()->GetGAL()->SetGridColor( aColor ); m_gridColor = aColor; } diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 05b6de1ccb..26ecf1c404 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -129,6 +129,11 @@ public: */ int SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount ); + /** + * @return the color of the grid + */ + COLOR4D GetGridColor() override; + ///> @copydoc EDA_DRAW_FRAME::SetGridColor() virtual void SetGridColor( COLOR4D aColor ) override; diff --git a/gerbview/gerbview_layer_widget.cpp b/gerbview/gerbview_layer_widget.cpp index 8077f357c4..eff1b8319f 100644 --- a/gerbview/gerbview_layer_widget.cpp +++ b/gerbview/gerbview_layer_widget.cpp @@ -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 // stored according to the GERBER_DRAW_LAYER() offset. - myframe->SetLayerColor( GERBER_DRAW_LAYER( aLayer ), aColor ); myframe->m_SelLayerBox->ResyncBitmapOnly(); @@ -294,17 +293,16 @@ void GERBER_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFin myframe->GetCanvas()->Refresh(); } - +#include "gerbview_draw_panel_gal.h" void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor ) { myframe->SetVisibleElementColor( aId, aColor ); auto view = myframe->GetCanvas()->GetView(); - auto settings = Pgm().GetSettingsManager().GetColorSettings(); + COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings(); view->GetPainter()->GetSettings()->LoadColors( settings ); view->UpdateLayerColor( aId ); - view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); view->UpdateAllItems( KIGFX::COLOR ); myframe->GetCanvas()->Refresh(); diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index 389008b852..b8ee35bb25 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -55,6 +55,7 @@ void GERBVIEW_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings ) size_t palette_size = aSettings->m_Palette.size(); size_t palette_idx = 0; + // Layers to draw gerber data read from gerber files: for( int i = GERBVIEW_LAYER_ID_START; 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 ); } + // 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++ ) m_layerColors[i] = aSettings->GetColor( i );