From 5176512de39030472d47cd447f9faaed22610f1d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 13 Jan 2022 20:04:14 +0000 Subject: [PATCH] Move PCBNew rotation increment to EDA_ANGLE. --- pcbnew/pcb_base_edit_frame.cpp | 8 +++++--- pcbnew/pcb_base_edit_frame.h | 6 +++--- pcbnew/pcb_edit_frame.cpp | 6 +++--- pcbnew/tools/edit_tool.cpp | 6 +++--- pcbnew/tools/pcb_tool_base.cpp | 4 ++-- pcbnew/tools/tool_event_utils.cpp | 14 ++++++++------ pcbnew/tools/tool_event_utils.h | 26 ++++++++++++-------------- 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 434ee6fe83..9d3a84b3b6 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -48,7 +48,8 @@ PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, const wxPoint& aPos, const wxSize& aSize, long aStyle, const wxString& aFrameName ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ), - m_rotationAngle( 900 ), m_undoRedoBlocked( false ), + m_rotationAngle( ANGLE_90 ), + m_undoRedoBlocked( false ), m_selectionFilterPanel( nullptr ), m_appearancePanel( nullptr ) { @@ -158,9 +159,10 @@ bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent ) } -void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle ) +void PCB_BASE_EDIT_FRAME::SetRotationAngle( EDA_ANGLE aRotationAngle ) { - wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900, + wxCHECK2_MSG( aRotationAngle > ANGLE_0 && aRotationAngle <= ANGLE_90, + aRotationAngle = ANGLE_90, wxT( "Invalid rotation angle, defaulting to 90." ) ); m_rotationAngle = aRotationAngle; diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index abb6ace727..3b3ead1c85 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -159,12 +159,12 @@ public: /** * Return the angle used for rotate operations. */ - int GetRotationAngle() const { return m_rotationAngle; } + EDA_ANGLE GetRotationAngle() const { return m_rotationAngle; } /** * Set the angle used for rotate operations. */ - void SetRotationAngle( int aRotationAngle ); + void SetRotationAngle( EDA_ANGLE aRotationAngle ); void ShowTextPropertiesDialog( BOARD_ITEM* aText ); void ShowGraphicItemPropertiesDialog( BOARD_ITEM* aItem ); @@ -226,7 +226,7 @@ protected: void unitsChangeRefresh() override; protected: - int m_rotationAngle; // Rotation step (in tenths of a degree) + EDA_ANGLE m_rotationAngle; // Rotation step (in tenths of a degree) bool m_undoRedoBlocked; PANEL_SELECTION_FILTER* m_selectionFilterPanel; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 76d1bfbf06..8f7bbfa0f6 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -192,7 +192,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : // assume dirty m_ZoneFillsDirty = true; - m_rotationAngle = 900; + m_rotationAngle = ANGLE_90; m_aboutTitle = _( "KiCad PCB Editor" ); // Must be created before the menus are created. @@ -1048,7 +1048,7 @@ void PCB_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) if( cfg ) { - m_rotationAngle = cfg->m_RotationAngle; + m_rotationAngle = EDA_ANGLE( cfg->m_RotationAngle, TENTHS_OF_A_DEGREE_T ); m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager; } } @@ -1063,7 +1063,7 @@ void PCB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) if( cfg ) { - cfg->m_RotationAngle = m_rotationAngle; + cfg->m_RotationAngle = m_rotationAngle.AsTenthsOfADegree(); cfg->m_AuiPanels.show_layer_manager = m_show_layer_manager_tools; cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x; cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex(); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 3dc70193f7..e5a7116066 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1461,8 +1461,8 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) updateModificationPoint( selection ); - VECTOR2I refPt = selection.GetReferencePoint(); - const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent ); + VECTOR2I refPt = selection.GetReferencePoint(); + EDA_ANGLE rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent ); // When editing footprints, all items have the same parent if( IsFootprintEditor() ) @@ -1484,7 +1484,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) } } - static_cast( item )->Rotate( refPt, EDA_ANGLE( rotateAngle, TENTHS_OF_A_DEGREE_T ) ); + static_cast( item )->Rotate( refPt, rotateAngle ); } if( !m_dragging ) diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index df65b22691..297a5befcb 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -217,8 +217,8 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool, */ if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) ) { - const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt ); - newItem->Rotate( newItem->GetPosition(), EDA_ANGLE( rotationAngle, TENTHS_OF_A_DEGREE_T ) ); + EDA_ANGLE rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt ); + newItem->Rotate( newItem->GetPosition(), rotationAngle ); view()->Update( &preview ); } else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) ) diff --git a/pcbnew/tools/tool_event_utils.cpp b/pcbnew/tools/tool_event_utils.cpp index 03d3364ac7..29af29822e 100644 --- a/pcbnew/tools/tool_event_utils.cpp +++ b/pcbnew/tools/tool_event_utils.cpp @@ -33,13 +33,15 @@ bool TOOL_EVT_UTILS::IsRotateToolEvt( const TOOL_EVENT& aEvt ) } -int TOOL_EVT_UTILS::GetEventRotationAngle( const PCB_BASE_EDIT_FRAME& aFrame, - const TOOL_EVENT& aEvt ) +EDA_ANGLE TOOL_EVT_UTILS::GetEventRotationAngle( const PCB_BASE_EDIT_FRAME& aFrame, + const TOOL_EVENT& aEvent ) { - wxASSERT_MSG( IsRotateToolEvt( aEvt ), "Expected rotation event" ); + wxASSERT_MSG( IsRotateToolEvt( aEvent ), "Expected rotation event" ); - const int rotAngle = aFrame.GetRotationAngle(); - const int angleMultiplier = aEvt.Parameter(); + EDA_ANGLE rotAngle = aFrame.GetRotationAngle(); + const int angleMultiplier = aEvent.Parameter(); - return rotAngle * angleMultiplier; + wxASSERT_MSG( angleMultiplier == 1 || angleMultiplier == -1, "Expected 1 or -1" ); + + return angleMultiplier > 0 ? rotAngle : -rotAngle; } diff --git a/pcbnew/tools/tool_event_utils.h b/pcbnew/tools/tool_event_utils.h index 5f104829c9..b418792693 100644 --- a/pcbnew/tools/tool_event_utils.h +++ b/pcbnew/tools/tool_event_utils.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,6 +25,7 @@ #define TOOL_EVENT_UTILS_H #include +#include class PCB_BASE_EDIT_FRAME; @@ -33,10 +34,9 @@ class PCB_BASE_EDIT_FRAME; /** * Namespace TOOL_EVT_UTILS * - * Utility functions for dealing with various tool events. These are - * free functions, so they interface with any classes exclusively via - * the public interfaces, so they don't need to be subsumed into the - * "helped" classes. + * Utility functions for dealing with various tool events. These are free functions, so they + * interface with any classes exclusively via the public interfaces, so they don't need to be + * subsumed into the "helped" classes. */ namespace TOOL_EVT_UTILS { @@ -51,18 +51,16 @@ namespace TOOL_EVT_UTILS /** * Function getEventRotationAngle() * - * Helper function to get a rotation angle based on a frame's - * configured angle and the direction indicated by a rotation action event + * Helper function to get a rotation angle based on a frame's configured angle and the + * direction indicated by a rotation action event * - * @param aFrame the PCB edit frame to use to get the base rotation - * step value from - * @param aEvt the tool event - should be a rotation action event - * and should have a rotation multiplier parameter + * @param aFrame the PCB edit frame to use to get the base rotation step value from + * @param aEvt the tool event - should be a rotation action event and should have a rotation + * multiplier parameter * - * @return the rotation angle in clockwise internal units + * @return the clockwise rotation angle */ - int GetEventRotationAngle( const PCB_BASE_EDIT_FRAME& aFrame, - const TOOL_EVENT& aEvt ); + EDA_ANGLE GetEventRotationAngle( const PCB_BASE_EDIT_FRAME& aFrame, const TOOL_EVENT& aEvent ); } #endif // TOOL_EVENT_UTILS_H