diff --git a/common/gal/gal_display_options.cpp b/common/gal/gal_display_options.cpp index 3befa9281d..ce85aade5b 100644 --- a/common/gal/gal_display_options.cpp +++ b/common/gal/gal_display_options.cpp @@ -31,6 +31,7 @@ using namespace KIGFX; */ static const wxString GalGLAntialiasingKeyword( "OpenGLAntialiasingMode" ); static const wxString GalGridStyleConfig( "GridStyle" ); +static const wxString GalGridLineWidthConfig( "GridLineWidth" ); GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() @@ -49,6 +50,9 @@ void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, wxString aBaseName ) reinterpret_cast( &m_gridStyle ), static_cast( KIGFX::GRID_STYLE::DOTS ) ); + aCfg->Read( aBaseName + GalGridLineWidthConfig, + &m_gridLineWidth, 0.5 ); + NotifyChanged(); } @@ -60,6 +64,9 @@ void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, wxString aBaseName ) aCfg->Write( aBaseName + GalGridStyleConfig, static_cast( m_gridStyle ) ); + + aCfg->Write( aBaseName + GalGridLineWidthConfig, + m_gridLineWidth ); } diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index fe14af6eab..7e4ac5dbf2 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -60,7 +60,7 @@ GAL::GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions ) : SetGridVisibility( true ); SetGridDrawThreshold( 10 ); SetCoarseGrid( 10 ); - SetGridLineWidth( 0.5 ); + gridLineWidth = 0.5; gridStyle = GRID_STYLE::LINES; // Initialize the cursor shape @@ -98,6 +98,12 @@ bool GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) refresh = true; } + if( options.m_gridLineWidth != gridLineWidth ) + { + gridLineWidth = options.m_gridLineWidth ; + refresh = true; + } + // tell the derived class if the base class needs an update or not return refresh; } @@ -168,7 +174,10 @@ void GAL::DrawGrid() int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast( gridTick ) * worldScale ); // Compute the line marker or point radius of the grid - double marker = 2.0 * gridLineWidth / worldScale; + // Note: generic grids can't handle sub-pixel lines without + // either losing fine/course distinction or having some dots + // fail to render + double marker = std::max( 1.0, gridLineWidth ) / worldScale; double doubleMarker = 2.0 * marker; // Check if the grid would not be too dense @@ -265,7 +274,7 @@ void GAL::DrawGrid() if( tickX || tickY || gridScreenSizeDense > gridDrawThreshold ) { - double radius = ( tickX && tickY ) ? doubleMarker : marker; + double radius = ( ( tickX && tickY ) ? doubleMarker : marker ) / 2.0; DrawRectangle( VECTOR2D( i * gridSize.x - radius + gridOrigin.x, j * gridSize.y - radius + gridOrigin.y ), VECTOR2D( i * gridSize.x + radius + gridOrigin.x, diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index e6bcfcdbc1..bd50e673af 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -848,6 +848,10 @@ void OPENGL_GAL::DrawGrid() int gridScreenSizeDense = KiROUND( gridSize.x * worldScale ); int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast( gridTick ) * worldScale ); + // sub-pixel lines all render the same + double minorLineWidth = std::max( 1.0, gridLineWidth ); + double majorLineWidth = minorLineWidth * 2.0; + // Check if the grid would not be too dense if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridDrawThreshold ) return; @@ -904,9 +908,9 @@ void OPENGL_GAL::DrawGrid() for( int j = gridStartY; j != gridEndY; j += dirY ) { if( j % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold ) - glLineWidth( 2.0 ); + glLineWidth( majorLineWidth ); else - glLineWidth( 1.0 ); + glLineWidth( minorLineWidth ); if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold ) || gridScreenSizeDense > gridDrawThreshold ) @@ -928,9 +932,9 @@ void OPENGL_GAL::DrawGrid() for( int i = gridStartX; i != gridEndX; i += dirX ) { if( i % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold ) - glLineWidth( 2.0 ); + glLineWidth( majorLineWidth ); else - glLineWidth( 1.0 ); + glLineWidth( minorLineWidth ); if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold ) || gridScreenSizeDense > gridDrawThreshold ) diff --git a/include/gal/gal_display_options.h b/include/gal/gal_display_options.h index 3694853e14..b7524d2cf3 100644 --- a/include/gal/gal_display_options.h +++ b/include/gal/gal_display_options.h @@ -71,6 +71,9 @@ namespace KIGFX ///> The grid style to draw the grid in KIGFX::GRID_STYLE m_gridStyle; + + ///> Thickness to render grid lines/dots + double m_gridLineWidth; }; } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 654fc413d5..b3f78a2543 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -829,16 +829,6 @@ public: return gridLineWidth; } - /** - * @brief Set the grid line width. - * - * @param aGridLineWidth is the rid line width. - */ - inline void SetGridLineWidth( double aGridLineWidth ) - { - gridLineWidth = aGridLineWidth; - } - ///> @brief Draw the grid virtual void DrawGrid(); diff --git a/pcbnew/dialogs/dialog_display_options.cpp b/pcbnew/dialogs/dialog_display_options.cpp index 74cc93caa1..8c2ddd1ccc 100644 --- a/pcbnew/dialogs/dialog_display_options.cpp +++ b/pcbnew/dialogs/dialog_display_options.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -43,6 +44,13 @@ #include #include +/* + * Spin control parameters + */ +static const double gridThicknessMin = 0.5; +static const double gridThicknessMax = 10.0; +static const double gridThicknessStep = 0.5; + static void setRadioFromGridStyle( wxRadioBox& aRBox, KIGFX::GRID_STYLE aStyle ) @@ -198,7 +206,17 @@ DIALOG_DISPLAY_OPTIONS::DIALOG_DISPLAY_OPTIONS( PCB_EDIT_FRAME* parent ) : { m_Parent = parent; + // bind the spin button and text box + m_gridSizeIncrementer = std::make_unique( + *m_gridLineWidthSpinBtn, *m_gridLineWidth); + + m_gridSizeIncrementer->SetStep( gridThicknessMin, gridThicknessMax, + gridThicknessStep ); + m_gridSizeIncrementer->SetPrecision( 1 ); + + // load settings into controls init(); + m_sdbSizerOK->SetDefault(); // Now all widgets have the size fixed, call FinishDialogSettings @@ -234,6 +252,8 @@ void DIALOG_DISPLAY_OPTIONS::init() gal_opts.gl_antialiasing_mode ); setRadioFromGridStyle( *m_gridStyle, gal_opts.m_gridStyle ); + + m_gridSizeIncrementer->SetValue( gal_opts.m_gridLineWidth ); } @@ -278,6 +298,8 @@ void DIALOG_DISPLAY_OPTIONS::OnOkClick(wxCommandEvent& event) gal_opts.m_gridStyle = getGridStyleFromRadio( *m_gridStyle ); + gal_opts.m_gridLineWidth = m_gridSizeIncrementer->GetValue(); + gal_opts.NotifyChanged(); // Apply changes to the GAL diff --git a/pcbnew/dialogs/dialog_display_options.h b/pcbnew/dialogs/dialog_display_options.h index f02c889b78..63a34b612b 100644 --- a/pcbnew/dialogs/dialog_display_options.h +++ b/pcbnew/dialogs/dialog_display_options.h @@ -27,11 +27,15 @@ */ #include +class INCREMENTAL_TEXT_CTRL; + class DIALOG_DISPLAY_OPTIONS : public DIALOG_DISPLAY_OPTIONS_BASE { private: PCB_EDIT_FRAME* m_Parent; + std::unique_ptr m_gridSizeIncrementer; + void init(); public: diff --git a/pcbnew/dialogs/dialog_display_options_base.cpp b/pcbnew/dialogs/dialog_display_options_base.cpp index 22f6fb07c3..a508791b67 100644 --- a/pcbnew/dialogs/dialog_display_options_base.cpp +++ b/pcbnew/dialogs/dialog_display_options_base.cpp @@ -55,6 +55,25 @@ DIALOG_DISPLAY_OPTIONS_BASE::DIALOG_DISPLAY_OPTIONS_BASE( wxWindow* parent, wxWi m_gridStyle->SetSelection( 0 ); sGridSettings->Add( m_gridStyle, 0, wxALL|wxEXPAND, 5 ); + wxFlexGridSizer* sGridSettingsGrid; + sGridSettingsGrid = new wxFlexGridSizer( 0, 3, 0, 0 ); + sGridSettingsGrid->AddGrowableCol( 1 ); + sGridSettingsGrid->SetFlexibleDirection( wxBOTH ); + sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + l_gridLineWidth = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY, _("Grid thickness:"), wxDefaultPosition, wxDefaultSize, 0 ); + l_gridLineWidth->Wrap( -1 ); + sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + m_gridLineWidth = new wxTextCtrl( sGridSettings->GetStaticBox(), wxID_ANY, _("0.5"), wxDefaultPosition, wxDefaultSize, 0 ); + sGridSettingsGrid->Add( m_gridLineWidth, 0, wxEXPAND, 0 ); + + m_gridLineWidthSpinBtn = new wxSpinButton( sGridSettings->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS ); + sGridSettingsGrid->Add( m_gridLineWidthSpinBtn, 0, wxALL, 0 ); + + + sGridSettings->Add( sGridSettingsGrid, 1, wxALL|wxEXPAND, 5 ); + sLeftSizer->Add( sGridSettings, 1, wxALL|wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/dialog_display_options_base.fbp b/pcbnew/dialogs/dialog_display_options_base.fbp index 570c33ba1a..724e2692a1 100644 --- a/pcbnew/dialogs/dialog_display_options_base.fbp +++ b/pcbnew/dialogs/dialog_display_options_base.fbp @@ -508,6 +508,282 @@ + + 5 + wxALL|wxEXPAND + 1 + + 3 + wxBOTH + 1 + + 0 + + sGridSettingsGrid + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 0 + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Grid thickness: + + 0 + + + 0 + + 1 + l_gridLineWidth + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_gridLineWidth + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_gridLineWidthSpinBtn + 1 + + + protected + 1 + + Resizable + 1 + + wxSP_ARROW_KEYS + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pcbnew/dialogs/dialog_display_options_base.h b/pcbnew/dialogs/dialog_display_options_base.h index d97fd8d480..d48ad7ccfd 100644 --- a/pcbnew/dialogs/dialog_display_options_base.h +++ b/pcbnew/dialogs/dialog_display_options_base.h @@ -24,6 +24,9 @@ class DIALOG_SHIM; #include #include #include +#include +#include +#include #include #include #include @@ -47,6 +50,9 @@ class DIALOG_DISPLAY_OPTIONS_BASE : public DIALOG_SHIM wxCheckBox* m_OptDisplayVias; wxChoice* m_choiceAntialiasing; wxRadioBox* m_gridStyle; + wxStaticText* l_gridLineWidth; + wxTextCtrl* m_gridLineWidth; + wxSpinButton* m_gridLineWidthSpinBtn; wxRadioBox* m_ShowNetNamesOption; wxRadioBox* m_OptDisplayTracksClearance; wxCheckBox* m_OptDisplayModOutlines;