Fix grid settings in pcbnew/modedit/cvpcb

* Make the grid display settings separate from the board object
* Ensure that the grid is initialized on creation in all the frames

Fixes: lp:1843169
* https://bugs.launchpad.net/kicad/+bug/1843169
This commit is contained in:
Ian McInerney 2019-11-23 22:43:54 +00:00
parent 99b9354a51
commit e82795ba58
15 changed files with 101 additions and 96 deletions

View File

@ -304,18 +304,6 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int )
}
bool DISPLAY_FOOTPRINTS_FRAME::IsGridVisible() const
{
return m_drawGrid;
}
void DISPLAY_FOOTPRINTS_FRAME::SetGridVisibility(bool aVisible)
{
m_drawGrid = aVisible;
}
COLOR4D DISPLAY_FOOTPRINTS_FRAME::GetGridColor()
{
return COLOR4D( DARKGRAY );
@ -444,6 +432,7 @@ void DISPLAY_FOOTPRINTS_FRAME::SyncToolbars()
m_mainToolBar->Toggle( ACTIONS::zoomTool, IsCurrentTool( ACTIONS::zoomTool ) );
m_mainToolBar->Refresh();
m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() );
m_optionsToolBar->Toggle( ACTIONS::selectionTool, IsCurrentTool( ACTIONS::selectionTool ) );
m_optionsToolBar->Toggle( ACTIONS::measureTool, IsCurrentTool( ACTIONS::measureTool ) );
m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != INCHES );

View File

@ -78,19 +78,6 @@ public:
bool GetAutoZoom() const { return m_autoZoom; }
void SetAutoZoom( bool aEnable ) { m_autoZoom = aEnable; }
/**
* Function IsGridVisible() , virtual
* @return true if the grid must be shown
*/
bool IsGridVisible() const override;
/**
* Function SetGridVisibility() , virtual
* It may be overloaded by derived classes
* if you want to store/retrieve the grid visibility in configuration.
* @param aVisible = true if the grid must be shown
*/
void SetGridVisibility( bool aVisible ) override;
/**
* Function GetGridColor() , virtual
* @return the color of the grid

View File

@ -414,6 +414,23 @@ public:
*/
void SetFastGrid2();
/**
* Function IsGridVisible()
*
* @return true if the grid is shown
*/
virtual bool IsGridVisible() const override;
/**
* Function SetGridVisibility()
* Turn the display of the canvas grid on/off
*
* Note: After calling, the view must be refreshed to update the grid display
*
* @param aVisible = true if the grid is shown
*/
virtual void SetGridVisibility( bool aVisible ) override;
/**
* Function DisplayGridMsg()
*

View File

@ -84,6 +84,7 @@ public:
int m_MaxLinksShowed; // in track creation: number of hairwires shown
bool m_ShowModuleRatsnest; // When moving a footprint: allows displaying a ratsnest
bool m_ShowGlobalRatsnest; // If true, show all
bool m_ShowGrid; // Show the grid on the canvas
bool m_DisplayRatsnestLinesCurved; // Airwires can be drawn as straight lines (false)
// or curved lines (true)

View File

@ -723,18 +723,6 @@ void FOOTPRINT_EDIT_FRAME::FocusOnLibID( const LIB_ID& aLibID )
}
bool FOOTPRINT_EDIT_FRAME::IsGridVisible() const
{
return IsElementVisible( LAYER_GRID );
}
void FOOTPRINT_EDIT_FRAME::SetGridVisibility(bool aVisible)
{
SetElementVisibility( LAYER_GRID, aVisible );
}
bool FOOTPRINT_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
{
return GetBoard()->IsElementVisible( aElement );
@ -815,10 +803,6 @@ void FOOTPRINT_EDIT_FRAME::ActivateGalCanvas()
// Be sure the axis are enabled
GetCanvas()->GetGAL()->SetAxesEnabled( true );
// Setup the grid
GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
updateView();
// Ensure the m_Layers settings are using the canvas type:

View File

@ -27,7 +27,6 @@
#include <fp_tree_synchronizing_adapter.h>
class PCB_LAYER_BOX_SELECTOR;
class PCB_LAYER_WIDGET;
class FP_LIB_TABLE;
class EDGE_MODULE;
class FOOTPRINT_TREE_PANE;
@ -279,18 +278,6 @@ public:
*/
void SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState );
/**
* @return true if the grid must be shown
*/
bool IsGridVisible() const override;
/**
* It may be overloaded by derived classes
* if you want to store/retrieve the grid visibility in configuration.
* @param aVisible = true if the grid must be shown
*/
void SetGridVisibility( bool aVisible ) override;
/**
* @return the color of the grid
*/
@ -358,7 +345,6 @@ protected:
FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend );
PCB_LAYER_BOX_SELECTOR* m_selLayerBox; // a combo box to display and select active layer
PCB_LAYER_WIDGET* m_Layers; // the layer manager
PARAM_CFG_ARRAY m_configParams; // List of footprint editor configuration parameters.
/**

View File

@ -25,6 +25,7 @@
#include <pcb_base_edit_frame.h>
#include <tool/tool_manager.h>
#include <pcb_draw_panel_gal.h>
#include <pcb_layer_widget.h>
#include <gal/graphics_abstraction_layer.h>
#include <class_board.h>
#include <view/view.h>
@ -113,3 +114,21 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh()
}
void PCB_BASE_EDIT_FRAME::SetGridVisibility( bool aVisible )
{
PCB_BASE_FRAME::SetGridVisibility( aVisible );
// We must notify the layer widget to refill the render view to update the grid checkbox
if( m_Layers )
{
m_Layers->Freeze();
// TODO (ISM): Implement a SyncRenderState handler inside the layer widget to use instead
// This current method redraws the entire render panel and looks bad
m_Layers->ReFillRender();
m_Layers->Thaw();
}
// TODO (ISM): Remove this by changing toolbars to use the EVT_UPDATE_UI to get the state
SyncToolbars();
}

View File

@ -28,6 +28,7 @@
#include <pcb_base_frame.h>
class BOARD_ITEM_CONTAINER;
class PCB_LAYER_WIDGET;
/**
* Common, abstract interface for edit frames.
@ -157,6 +158,15 @@ public:
m_undoRedoBlocked = aBlock;
}
/**
* Function SetGridVisibility()
*
* Override this function in the PCB_BASE_EDIT_FRAME to refill the layer widget
*
* @param aVisible = true if the grid must be shown
*/
void SetGridVisibility( bool aVisible ) override;
/**
* Function GetRotationAngle()
* Returns the angle used for rotate operations.
@ -188,6 +198,9 @@ protected:
bool m_undoRedoBlocked;
void unitsChangeRefresh() override;
/// Layer manager. It is the responsibility of the child frames to instantiate this
PCB_LAYER_WIDGET* m_Layers;
};
#endif

View File

@ -836,6 +836,32 @@ void PCB_BASE_FRAME::SetFastGrid2()
}
bool PCB_BASE_FRAME::IsGridVisible() const
{
return m_DisplayOptions.m_ShowGrid;
}
void PCB_BASE_FRAME::SetGridVisibility( bool aVisible )
{
m_DisplayOptions.m_ShowGrid = aVisible;
// Update the display with the new grid
if( GetCanvas() )
{
// Check to ensure these exist, since this function could be called before
// the GAL and View have been created
if( GetCanvas()->GetGAL() )
GetCanvas()->GetGAL()->SetGridVisibility( aVisible );
if( GetCanvas()->GetView() )
GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
GetCanvas()->Refresh();
}
}
PCB_DRAW_PANEL_GAL* PCB_BASE_FRAME::GetCanvas() const
{
return static_cast<PCB_DRAW_PANEL_GAL*>( EDA_DRAW_FRAME::GetCanvas() );
@ -868,5 +894,9 @@ void PCB_BASE_FRAME::ActivateGalCanvas()
canvas->GetView()->RecacheAllItems();
canvas->SetEventDispatcher( m_toolDispatcher );
canvas->StartDrawing();
// Initialize the grid settings
GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
}

View File

@ -56,4 +56,5 @@ PCB_DISPLAY_OPTIONS::PCB_DISPLAY_OPTIONS()
m_ShowModuleRatsnest = true; // When moving a footprint: allows displaying a ratsnest
m_DisplayRatsnestLinesCurved = false;
m_ShowGlobalRatsnest = true;
m_ShowGrid = true;
}

View File

@ -543,8 +543,6 @@ void PCB_EDIT_FRAME::ActivateGalCanvas()
PCB_BASE_EDIT_FRAME::ActivateGalCanvas();
COLORS_DESIGN_SETTINGS& cds = Settings().Colors();
GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
GetCanvas()->GetGAL()->SetGridColor( cds.GetLayerColor( LAYER_GRID ) );
GetCanvas()->GetView()->GetPainter()->GetSettings()->ImportLegacyColors( &cds );
GetCanvas()->Refresh();
@ -618,18 +616,6 @@ void PCB_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg )
}
bool PCB_EDIT_FRAME::IsGridVisible() const
{
return IsElementVisible( LAYER_GRID );
}
void PCB_EDIT_FRAME::SetGridVisibility(bool aVisible)
{
SetElementVisibility( LAYER_GRID, aVisible );
}
COLOR4D PCB_EDIT_FRAME::GetGridColor()
{
return Settings().Colors().GetItemColor( LAYER_GRID );
@ -671,6 +657,7 @@ void PCB_EDIT_FRAME::onBoardLoaded()
syncRenderStates();
SetElementVisibility( LAYER_RATSNEST, GetDisplayOptions().m_ShowGlobalRatsnest );
// Update the tracks / vias available sizes list:
ReCreateAuxiliaryToolbar();

View File

@ -102,8 +102,6 @@ class PCB_EDIT_FRAME : public PCB_BASE_EDIT_FRAME
ACTION_TOOLBAR* m_microWaveToolBar;
protected:
PCB_LAYER_WIDGET* m_Layers;
PARAM_CFG_ARRAY m_configParams; // List of Pcbnew configuration settings.
PARAM_CFG_ARRAY m_projectFileParams;
@ -348,20 +346,6 @@ public:
void UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, bool aEdit = true );
void UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool aEdit = true );
/**
* Function IsGridVisible() , virtual
* @return true if the grid must be shown
*/
bool IsGridVisible() const override;
/**
* Function SetGridVisibility() , virtual
* It may be overloaded by derived classes
* if you want to store/retrieve the grid visibility in configuration.
* @param aVisible = true if the grid must be shown
*/
void SetGridVisibility( bool aVisible ) override;
/**
* Function GetGridColor() , virtual
* @return the color of the grid

View File

@ -410,6 +410,8 @@ void PCB_LAYER_WIDGET::ReFillRender()
if( renderRow.id == LAYER_RATSNEST )
renderRow.state = myframe->GetDisplayOptions().m_ShowGlobalRatsnest;
else if( renderRow.id == LAYER_GRID )
renderRow.state = myframe->IsGridVisible();
else
renderRow.state = board->IsElementVisible(
static_cast<GAL_LAYER_ID>( renderRow.id ) );
@ -692,14 +694,13 @@ void PCB_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
myframe->OnModify();
}
// Grid is not set through the board visibility
if( aId == LAYER_GRID )
myframe->SetGridVisibility( isEnabled );
else
brd->SetElementVisibility( static_cast<GAL_LAYER_ID>( aId ), isEnabled );
if( aId == LAYER_GRID )
{
myframe->GetCanvas()->GetGAL()->SetGridVisibility( myframe->IsGridVisible() );
myframe->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
else if( aId == LAYER_RATSNEST )
if( aId == LAYER_RATSNEST )
{
// don't touch the layers. ratsnest is enabled on per-item basis.
myframe->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
@ -712,7 +713,7 @@ void PCB_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled )
myframe->GetCanvas()->GetView()->UpdateDisplayOptions( opt );
}
}
else
else if( aId != LAYER_GRID )
myframe->GetCanvas()->GetView()->SetLayerVisible( aId, isEnabled );
myframe->GetCanvas()->Refresh();

View File

@ -219,6 +219,9 @@ void FOOTPRINT_EDIT_FRAME::SyncToolbars()
{
#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
if( !m_mainToolBar || !m_optionsToolBar || !m_drawToolBar )
return;
auto& opts = GetDisplayOptions();
if( IsCurrentFPFromBoard() )

View File

@ -663,6 +663,9 @@ void PCB_EDIT_FRAME::SyncToolbars()
{
#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
if( !m_mainToolBar || !m_optionsToolBar || !m_drawToolBar || !m_microWaveToolBar )
return;
auto& opts = GetDisplayOptions();
KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions();
int zoneMode = opts.m_DisplayZonesMode;