From ab67d2f81a2f992fe4e0cf1d81078a8b9964980f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 10 Oct 2018 10:48:16 +0100 Subject: [PATCH] Another go at fixing units changes for rulers. The previous fix only worked for hot-key changes. This should include using the toolbar, menu, etc. --- pcbnew/pcb_base_edit_frame.cpp | 14 ++++++++++++++ pcbnew/pcb_base_edit_frame.h | 2 ++ pcbnew/pcb_edit_frame.cpp | 14 +++----------- pcbnew/pcb_edit_frame.h | 2 -- pcbnew/tools/edit_tool.cpp | 20 ++++++++++++++------ pcbnew/tools/pcb_actions.h | 1 + 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 28efcd0b6f..d69b6b465e 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -30,6 +30,7 @@ #include #include "footprint_info_impl.h" #include +#include PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle, @@ -103,3 +104,16 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard ) m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); } } + + +void PCB_BASE_EDIT_FRAME::unitsChangeRefresh() +{ + PCB_BASE_FRAME::unitsChangeRefresh(); + + ReCreateAuxiliaryToolbar(); + + if( m_toolManager ) + m_toolManager->RunAction( PCB_ACTIONS::updateUnits, true ); +} + + diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 2705c8bbca..b3de5c28ce 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -209,6 +209,8 @@ protected: * duplicateItem(BOARD_ITEM*, bool) above */ virtual void duplicateItems( bool aIncrement ) = 0; + + void unitsChangeRefresh() override; }; #endif diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index a51c9aca60..f80e78eb41 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -908,14 +908,6 @@ void PCB_EDIT_FRAME::OnUpdateLayerAlpha( wxUpdateUIEvent & ) } -void PCB_EDIT_FRAME::unitsChangeRefresh() -{ - PCB_BASE_EDIT_FRAME::unitsChangeRefresh(); // Update the grid size select box. - - ReCreateAuxiliaryToolbar(); -} - - bool PCB_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const { return GetBoard()->IsElementVisible( aElement ); @@ -1271,10 +1263,10 @@ void PCB_EDIT_FRAME::InstallFootprintPropertiesDialog( MODULE* Module, wxDC* DC int retvalue = dlg->ShowModal(); /* retvalue = - * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_ABORT if abort, - * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_WANT_EXCHANGE_FP if exchange module, - * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_EDIT_OK for normal edit + * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_WANT_UPDATE_FP if update footprint + * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_WANT_EXCHANGE_FP if change footprint * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_WANT_MODEDIT for a goto editor command + * FP_PRM_EDITOR_RETVALUE::PRM_EDITOR_EDIT_OK for normal edit */ dlg->Close(); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index aacd757420..3578236208 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -209,8 +209,6 @@ protected: */ void syncLayerVisibilities(); - virtual void unitsChangeRefresh() override; - /** * Function doAutoSave * performs auto save when the board has been modified and not saved within the diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index a137b0014e..e7d322267c 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -165,6 +165,10 @@ TOOL_ACTION PCB_ACTIONS::cutToClipboard( "pcbnew.InteractiveEdit.CutToClipboard" _( "Cut" ), _( "Cut selected content to clipboard" ), cut_xpm ); +TOOL_ACTION PCB_ACTIONS::updateUnits( "pcbnew.InteractiveEdit.updateUnits", + AS_GLOBAL, 0, + "", "" ); + void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags ) { @@ -1196,8 +1200,9 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) Activate(); frame()->SetToolID( toolID, wxCURSOR_PENCIL, _( "Measure distance" ) ); + EDA_UNITS_T units = frame()->GetUserUnits(); KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; - KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, frame()->GetUserUnits() ); + KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units ); view.Add( &ruler ); view.SetVisible( &ruler, false ); @@ -1252,12 +1257,15 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) view.Update( &ruler, KIGFX::GEOMETRY ); } - else if( evt->IsAction( &PCB_ACTIONS::switchUnits ) ) + else if( evt->IsAction( &PCB_ACTIONS::switchUnits ) + || evt->IsAction( &PCB_ACTIONS::updateUnits ) ) { - ruler.SwitchUnits(); - - view.SetVisible( &ruler, true ); - view.Update( &ruler, KIGFX::GEOMETRY ); + if( frame()->GetUserUnits() != units ) + { + units = frame()->GetUserUnits(); + ruler.SwitchUnits(); + view.Update( &ruler, KIGFX::GEOMETRY ); + } } else if( evt->IsClick( BUT_RIGHT ) ) diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index e49c916b17..fba36706dd 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -365,6 +365,7 @@ public: static TOOL_ACTION measureTool; static TOOL_ACTION switchCursor; static TOOL_ACTION switchUnits; + static TOOL_ACTION updateUnits; static TOOL_ACTION deleteItemCursor; static TOOL_ACTION clearHighlight; static TOOL_ACTION highlightNet;