Add grid line thickness control to Display Options Dialog

This adds a user-settable control for the grid line thickness on GAL
canvases to the display options dialog.

The thickness settings now comes in, along with other GAL display
settings, as part of GAL_DISPLAY_OPTIONS observer functionality. To this
end, the setter in GAL interface is removed, as an external user should
be setting this parameter via the GAL_DISPLAY_OPTIONS interface.

Fixes: lp:1662482
* https://bugs.launchpad.net/kicad/+bug/1662482
This commit is contained in:
John Beard 2017-02-14 23:31:21 +08:00 committed by Maciej Suminski
parent 061d659bb1
commit 970e4f8eb4
10 changed files with 357 additions and 17 deletions

View File

@ -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<long*>( &m_gridStyle ),
static_cast<long>( 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<long>( m_gridStyle ) );
aCfg->Write( aBaseName + GalGridLineWidthConfig,
m_gridLineWidth );
}

View File

@ -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<double>( 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,

View File

@ -848,6 +848,10 @@ void OPENGL_GAL::DrawGrid()
int gridScreenSizeDense = KiROUND( gridSize.x * worldScale );
int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast<double>( 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 )

View File

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

View File

@ -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();

View File

@ -32,6 +32,7 @@
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <pcbstruct.h>
#include <incremental_text_ctrl.h>
#include <pcbnew_id.h>
@ -43,6 +44,13 @@
#include <pcb_painter.h>
#include <gal/gal_display_options.h>
/*
* 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<SPIN_INCREMENTAL_TEXT_CTRL>(
*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

View File

@ -27,11 +27,15 @@
*/
#include <dialog_display_options_base.h>
class INCREMENTAL_TEXT_CTRL;
class DIALOG_DISPLAY_OPTIONS : public DIALOG_DISPLAY_OPTIONS_BASE
{
private:
PCB_EDIT_FRAME* m_Parent;
std::unique_ptr<INCREMENTAL_TEXT_CTRL> m_gridSizeIncrementer;
void init();
public:

View File

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

View File

@ -508,6 +508,282 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">3</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols">1</property>
<property name="growablerows"></property>
<property name="hgap">0</property>
<property name="minimum_size"></property>
<property name="name">sGridSettingsGrid</property>
<property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property>
<property name="permission">none</property>
<property name="rows">0</property>
<property name="vgap">0</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Grid thickness:</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">l_gridLineWidth</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">0</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_gridLineWidth</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value">0.5</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnText"></event>
<event name="OnTextEnter"></event>
<event name="OnTextMaxLen"></event>
<event name="OnTextURL"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">0</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxSpinButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_gridLineWidthSpinBtn</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxSP_ARROW_KEYS</property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnSpin"></event>
<event name="OnSpinDown"></event>
<event name="OnSpinUp"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
</object>
</object>
</object>

View File

@ -24,6 +24,9 @@ class DIALOG_SHIM;
#include <wx/statbox.h>
#include <wx/choice.h>
#include <wx/radiobox.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/spinbutt.h>
#include <wx/statline.h>
#include <wx/button.h>
#include <wx/dialog.h>
@ -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;