From e82795ba58b479d77024a34c5edb86648eacaf22 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 23 Nov 2019 22:43:54 +0000 Subject: [PATCH] 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 --- cvpcb/display_footprints_frame.cpp | 17 +++------------- cvpcb/display_footprints_frame.h | 13 ------------ include/pcb_base_frame.h | 17 ++++++++++++++++ include/pcb_display_options.h | 1 + pcbnew/footprint_edit_frame.cpp | 16 --------------- pcbnew/footprint_edit_frame.h | 14 ------------- pcbnew/pcb_base_edit_frame.cpp | 19 ++++++++++++++++++ pcbnew/pcb_base_edit_frame.h | 13 ++++++++++++ pcbnew/pcb_base_frame.cpp | 30 ++++++++++++++++++++++++++++ pcbnew/pcb_display_options.cpp | 3 ++- pcbnew/pcb_edit_frame.cpp | 15 +------------- pcbnew/pcb_edit_frame.h | 16 --------------- pcbnew/pcb_layer_widget.cpp | 17 ++++++++-------- pcbnew/toolbars_footprint_editor.cpp | 3 +++ pcbnew/toolbars_pcb_editor.cpp | 3 +++ 15 files changed, 101 insertions(+), 96 deletions(-) diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 038dd22a30..3ec3f71971 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -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,9 +432,10 @@ 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 ); + m_optionsToolBar->Toggle( ACTIONS::measureTool, IsCurrentTool( ACTIONS::measureTool ) ); + m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != INCHES ); m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == INCHES ); m_optionsToolBar->Refresh(); } diff --git a/cvpcb/display_footprints_frame.h b/cvpcb/display_footprints_frame.h index 50f709e69a..d30c83aa80 100644 --- a/cvpcb/display_footprints_frame.h +++ b/cvpcb/display_footprints_frame.h @@ -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 diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 8793e7b9f1..43daf84aea 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -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() * diff --git a/include/pcb_display_options.h b/include/pcb_display_options.h index 76e018c3ad..add072c691 100644 --- a/include/pcb_display_options.h +++ b/include/pcb_display_options.h @@ -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) diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 2703e5eece..133cd5295e 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -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: diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 46dca334c9..c03fcd9464 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -27,7 +27,6 @@ #include 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. /** diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 003098889e..a1d4cfcf75 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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(); +} diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index fc47839c42..d34f5f32d6 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -28,6 +28,7 @@ #include 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 diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 4816ce1725..c5462af23a 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -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( 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() ); } diff --git a/pcbnew/pcb_display_options.cpp b/pcbnew/pcb_display_options.cpp index 687585208a..784c8b38c7 100644 --- a/pcbnew/pcb_display_options.cpp +++ b/pcbnew/pcb_display_options.cpp @@ -55,5 +55,6 @@ PCB_DISPLAY_OPTIONS::PCB_DISPLAY_OPTIONS() m_MaxLinksShowed = 3; // in track creation: number of hairwires shown m_ShowModuleRatsnest = true; // When moving a footprint: allows displaying a ratsnest m_DisplayRatsnestLinesCurved = false; - m_ShowGlobalRatsnest = true; + m_ShowGlobalRatsnest = true; + m_ShowGrid = true; } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index a738d8567f..5ceacb0188 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -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(); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 9f91dddfe9..d243ce278f 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -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 diff --git a/pcbnew/pcb_layer_widget.cpp b/pcbnew/pcb_layer_widget.cpp index 3a6dc29998..a9023a7619 100644 --- a/pcbnew/pcb_layer_widget.cpp +++ b/pcbnew/pcb_layer_widget.cpp @@ -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( renderRow.id ) ); @@ -692,14 +694,13 @@ void PCB_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled ) myframe->OnModify(); } - brd->SetElementVisibility( static_cast( aId ), isEnabled ); - + // Grid is not set through the board visibility if( aId == LAYER_GRID ) - { - myframe->GetCanvas()->GetGAL()->SetGridVisibility( myframe->IsGridVisible() ); - myframe->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - } - else if( aId == LAYER_RATSNEST ) + myframe->SetGridVisibility( isEnabled ); + else + brd->SetElementVisibility( static_cast( aId ), isEnabled ); + + 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(); diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index e32cfcb1b6..693d1112f9 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -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() ) diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 71a62d104e..563a748a8f 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -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;