diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 9eb0731c18..acf3c1853b 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -572,7 +572,8 @@ void TOOL_MANAGER::DeactivateTool() void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason ) { - DeactivateTool(); + if( aReason != TOOL_BASE::REDRAW ) + DeactivateTool(); for( auto& state : m_toolState ) { diff --git a/include/tool/tool_base.h b/include/tool/tool_base.h index 5b5f0a516c..52003f2c99 100644 --- a/include/tool/tool_base.h +++ b/include/tool/tool_base.h @@ -78,7 +78,8 @@ public: { RUN, ///< Tool is invoked after being inactive MODEL_RELOAD, ///< Model changes (required full reload) - GAL_SWITCH ///< Rendering engine changes + GAL_SWITCH, ///< Rendering engine changes + REDRAW ///< Full drawing refresh }; /** diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 6893813ffc..48561bcbef 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -107,6 +107,11 @@ public: void HardRedraw() override; + /** + * Rebuilds board connectivity, refreshes canvas. + */ + void RebuildAndRefresh(); + /** * Execute a remote command send by Eeschema via a socket, port KICAD_PCB_PORT_SERVICE_NUMBER * (currently 4242). diff --git a/pcbnew/python/scripting/pcbnew_action_plugins.cpp b/pcbnew/python/scripting/pcbnew_action_plugins.cpp index e9d499a07e..a6fcc5abe4 100644 --- a/pcbnew/python/scripting/pcbnew_action_plugins.cpp +++ b/pcbnew/python/scripting/pcbnew_action_plugins.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,8 @@ #include #include #include +#include +#include #include #include "../../scripting/python_scripting.h" @@ -372,7 +375,32 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) // Apply changes, UndoList already handled commit.Push( _( "Apply action script" ), SKIP_UNDO | SKIP_SET_DIRTY ); - ActivateGalCanvas(); + + RebuildAndRefresh(); +} + + +void PCB_EDIT_FRAME::RebuildAndRefresh() +{ + m_pcb->BuildConnectivity(); + + PCB_DRAW_PANEL_GAL* canvas = GetCanvas(); + + canvas->GetView()->Clear(); + canvas->GetView()->InitPreview(); + canvas->GetGAL()->SetGridOrigin( VECTOR2D( m_pcb->GetDesignSettings().GetGridOrigin() ) ); + canvas->DisplayBoard( m_pcb ); + + // allow tools to re-add their view items (selection previews, grids, etc.) + if( m_toolManager ) + m_toolManager->ResetTools( TOOL_BASE::REDRAW ); + + // reload the drawing-sheet + SetPageSettings( m_pcb->GetPageSettings() ); + + canvas->SyncLayersVisibility( m_pcb ); + + canvas->Refresh(); } diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index 4248c1cf8e..e8a7ebe1d2 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -32,7 +32,6 @@ #include "pcbnew_scripting_helpers.h" -#include #include #include #include @@ -398,27 +397,7 @@ void Refresh() { if( s_PcbEditFrame ) { - TOOL_MANAGER* toolMgr = s_PcbEditFrame->GetToolManager(); - BOARD* board = s_PcbEditFrame->GetBoard(); - PCB_DRAW_PANEL_GAL* canvas = s_PcbEditFrame->GetCanvas(); - - canvas->SyncLayersVisibility( board ); - - canvas->GetView()->Clear(); - canvas->GetView()->InitPreview(); - canvas->GetGAL()->SetGridOrigin( VECTOR2D( board->GetDesignSettings().GetGridOrigin() ) ); - canvas->DisplayBoard( board ); - - // allow tools to re-add their view items (selection previews, grids, etc.) - if( toolMgr ) - toolMgr->ResetTools( TOOL_BASE::GAL_SWITCH ); - - // reload the drawing-sheet - s_PcbEditFrame->SetPageSettings( board->GetPageSettings() ); - - board->BuildConnectivity(); - - canvas->Refresh(); + s_PcbEditFrame->RebuildAndRefresh(); } } diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 81e8e7f4ca..409785b620 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -149,7 +149,7 @@ void BOARD_EDITOR_CONTROL::Reset( RESET_REASON aReason ) { m_frame = getEditFrame(); - if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH ) + if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH || aReason == REDRAW ) { m_placeOrigin->SetPosition( getModel()->GetDesignSettings().GetAuxOrigin() ); getView()->Remove( m_placeOrigin.get() ); diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 2cea7976b6..531f0a6d0c 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -89,7 +89,7 @@ void PCB_CONTROL::Reset( RESET_REASON aReason ) { m_frame = getEditFrame(); - if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH ) + if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH || aReason == REDRAW ) { m_gridOrigin->SetPosition( board()->GetDesignSettings().GetGridOrigin() ); m_gridOrigin->SetColor( m_frame->GetGridColor() ); diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index a8de5549b6..bd8bd427ea 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -224,7 +224,7 @@ void PCB_SELECTION_TOOL::Reset( RESET_REASON aReason ) getView()->GetPainter()->GetSettings()->SetHighlight( false ); } - else + else if ( aReason != TOOL_BASE::REDRAW ) { // Restore previous properties of selected items and remove them from containers ClearSelection( true );