From afd80c3cdb675327c8cc7e8577dfb27bfaeba557 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 23 Jul 2018 12:37:01 +0100 Subject: [PATCH] Fix botched attempt to have ruler adjust to unit changes. Also fixes the context menu so there's a specific one for the measurement tool, allowing zooming for instance without cancelling the tool. --- include/preview_items/ruler_item.h | 7 +++++-- pcbnew/pcb_base_edit_frame.cpp | 12 +----------- pcbnew/pcb_base_edit_frame.h | 2 -- pcbnew/tools/edit_tool.cpp | 19 +++++++++++++++---- pcbnew/tools/edit_tool.h | 3 +++ 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/preview_items/ruler_item.h b/include/preview_items/ruler_item.h index 46fd3317ca..2f5474d692 100644 --- a/include/preview_items/ruler_item.h +++ b/include/preview_items/ruler_item.h @@ -71,9 +71,12 @@ public: return wxT( "RULER_ITEM" ); } - void UpdateUserUnits( EDA_UNITS_T aUserUnits ) + void SwitchUnits() { - m_userUnits = aUserUnits; + if( m_userUnits == INCHES ) + m_userUnits = MILLIMETRES; + else + m_userUnits = INCHES; } private: diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 129a861cf9..7f44568cbd 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -28,7 +28,7 @@ #include #include #include -#include + void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle ) { @@ -81,13 +81,3 @@ 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(); // Update the status bar. - - GetToolManager()->RunAction( PCB_ACTIONS::switchUnits, true ); // Notify tools. -} - - diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 7ac61a7d73..0417bbc75a 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -204,8 +204,6 @@ protected: * duplicateItem(BOARD_ITEM*, bool) above */ virtual void duplicateItems( bool aIncrement ) = 0; - - void unitsChangeRefresh() override; }; #endif diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index d783798768..ec54ab184b 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -237,7 +237,8 @@ void EnsureEditableFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector ) EDIT_TOOL::EDIT_TOOL() : PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), - m_dragging( false ) + m_dragging( false ), + m_measureMenu( *this ) { } @@ -318,6 +319,16 @@ bool EDIT_TOOL::Init() menu.AddItem( PCB_ACTIONS::updateFootprints, singleModuleCondition ); menu.AddItem( PCB_ACTIONS::exchangeFootprints, singleModuleCondition ); + // Initialize menu for Measurement Tool + auto& ctxMenu = m_measureMenu.GetMenu(); + + // cancel current toool goes in main context menu at the top if present + ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1000 ); + ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); + + // Finally, add the standard zoom/grid items + m_measureMenu.AddStandardSubMenus( *getEditFrame() ); + return true; } @@ -1201,7 +1212,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) const VECTOR2I cursorPos = controls.GetCursorPosition(); - if( evt->IsCancel() || evt->IsActivate() ) + if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { break; } @@ -1255,7 +1266,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) else if( evt->IsAction( &PCB_ACTIONS::switchUnits ) ) { - ruler.UpdateUserUnits( frame()->GetUserUnits() ); + ruler.SwitchUnits(); view.SetVisible( &ruler, true ); view.Update( &ruler, KIGFX::GEOMETRY ); @@ -1263,7 +1274,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_RIGHT ) ) { - GetManager()->PassEvent(); + m_measureMenu.ShowContextMenu(); } } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 2b620baae6..e081308206 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -194,6 +194,9 @@ private: ///> of edit reference point). VECTOR2I m_cursor; + ///> A context menu for the Measurement Tool + TOOL_MENU m_measureMenu; + ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. bool updateModificationPoint( SELECTION& aSelection );