From 9d5322cfdf5706df67948a0242f9c8934c02ae8c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 19 Jan 2022 13:24:02 +0000 Subject: [PATCH] Move rotation angle increments to UNIT_BINDER and EDA_ANGLE. --- common/eda_rect.cpp | 22 ++++++------ include/footprint_editor_settings.h | 2 +- pcbnew/dialogs/panel_edit_options.cpp | 15 ++++---- pcbnew/dialogs/panel_edit_options.h | 8 +++-- pcbnew/dialogs/panel_edit_options_base.cpp | 20 +++++------ pcbnew/dialogs/panel_edit_options_base.fbp | 6 ++-- pcbnew/dialogs/panel_edit_options_base.h | 6 ++-- pcbnew/footprint_editor_settings.cpp | 14 ++++++-- pcbnew/pcb_edit_frame.cpp | 4 +-- pcbnew/pcbnew.cpp | 41 ++++++++++++++++------ pcbnew/pcbnew_settings.cpp | 14 ++++++-- pcbnew/pcbnew_settings.h | 5 +-- 12 files changed, 99 insertions(+), 58 deletions(-) diff --git a/common/eda_rect.cpp b/common/eda_rect.cpp index 5daefa9b10..7c10679c86 100644 --- a/common/eda_rect.cpp +++ b/common/eda_rect.cpp @@ -186,7 +186,8 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c if( !m_init ) return false; - double rotation = aRotation.AsTenthsOfADegree(); + EDA_ANGLE rotation = aRotation; + rotation.Normalize(); /* * Most rectangles will be axis aligned. It is quicker to check for this case and pass @@ -196,22 +197,20 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c // Prevent floating point comparison errors static const double ROT_EPS = 0.000000001; - static const double ROT_PARALLEL[] = { -3600, -1800, 0, 1800, 3600 }; - static const double ROT_PERPENDICULAR[] = { -2700, -900, 0, 900, 2700 }; - - NORMALIZE_ANGLE_POS( rotation ); + static const double ROT_PARALLEL[] = { 0.0, 180.0, 360.0 }; + static const double ROT_PERPENDICULAR[] = { 0.0, 90.0, 270.0 }; // Test for non-rotated rectangle - for( int ii = 0; ii < 5; ii++ ) + for( double ii : ROT_PARALLEL ) { - if( std::fabs( rotation - ROT_PARALLEL[ii] ) < ROT_EPS ) + if( std::fabs( rotation.AsDegrees() - ii ) < ROT_EPS ) return Intersects( aRect ); } // Test for rectangle rotated by multiple of 90 degrees - for( int jj = 0; jj < 4; jj++ ) + for( double jj : ROT_PERPENDICULAR ) { - if( std::fabs( rotation - ROT_PERPENDICULAR[jj] ) < ROT_EPS ) + if( std::fabs( rotation.AsDegrees() - jj ) < ROT_EPS ) { EDA_RECT rotRect; @@ -242,7 +241,7 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c for( int i = 0; i < 4; i++ ) { VECTOR2I delta = corners[i] - rCentre; - RotatePoint( delta, -EDA_ANGLE( rotation, TENTHS_OF_A_DEGREE_T ) ); + RotatePoint( delta, -rotation ); delta += rCentre; if( aRect.Contains( delta ) ) @@ -262,7 +261,7 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c // Rotate and test each corner for( int j = 0; j < 4; j++ ) { - RotatePoint( corners[j], EDA_ANGLE( rotation, TENTHS_OF_A_DEGREE_T ) ); + RotatePoint( corners[j], rotation ); corners[j] += rCentre; if( Contains( corners[j] ) ) @@ -276,7 +275,6 @@ bool EDA_RECT::Intersects( const EDA_RECT& aRect, const EDA_ANGLE& aRotation ) c return true; } - return false; } diff --git a/include/footprint_editor_settings.h b/include/footprint_editor_settings.h index f335b6ed86..95613a253d 100644 --- a/include/footprint_editor_settings.h +++ b/include/footprint_editor_settings.h @@ -65,7 +65,7 @@ public: bool m_PolarCoords; - int m_RotationAngle; + EDA_ANGLE m_RotationAngle; bool m_Use45Limit; diff --git a/pcbnew/dialogs/panel_edit_options.cpp b/pcbnew/dialogs/panel_edit_options.cpp index e828b88ab8..b28c731566 100644 --- a/pcbnew/dialogs/panel_edit_options.cpp +++ b/pcbnew/dialogs/panel_edit_options.cpp @@ -30,9 +30,12 @@ #include -PANEL_EDIT_OPTIONS::PANEL_EDIT_OPTIONS( wxWindow* aParent, bool isFootprintEditor ) : +PANEL_EDIT_OPTIONS::PANEL_EDIT_OPTIONS( wxWindow* aParent, EDA_BASE_FRAME* aUnitsProvider, + bool isFootprintEditor ) : PANEL_EDIT_OPTIONS_BASE( aParent ), - m_isFootprintEditor( isFootprintEditor ) + m_isFootprintEditor( isFootprintEditor ), + m_rotationAngle( aUnitsProvider, m_rotationAngleLabel, m_rotationAngleCtrl, + m_rotationAngleUnits ) { m_magneticPads->Show( m_isFootprintEditor ); m_magneticGraphics->Show( m_isFootprintEditor ); @@ -53,7 +56,7 @@ PANEL_EDIT_OPTIONS::PANEL_EDIT_OPTIONS( wxWindow* aParent, bool isFootprintEdito void PANEL_EDIT_OPTIONS::loadPCBSettings( PCBNEW_SETTINGS* aCfg ) { - m_rotationAngle->SetValue( AngleToStringDegrees( (double) aCfg->m_RotationAngle ) ); + m_rotationAngle.SetAngleValue( aCfg->m_RotationAngle ); m_magneticPadChoice->SetSelection( static_cast( aCfg->m_MagneticItems.pads ) ); m_magneticTrackChoice->SetSelection( static_cast( aCfg->m_MagneticItems.tracks ) ); m_magneticGraphicsChoice->SetSelection( !aCfg->m_MagneticItems.graphics ); @@ -79,7 +82,7 @@ void PANEL_EDIT_OPTIONS::loadPCBSettings( PCBNEW_SETTINGS* aCfg ) void PANEL_EDIT_OPTIONS::loadFPSettings( FOOTPRINT_EDITOR_SETTINGS* aCfg ) { - m_rotationAngle->SetValue( AngleToStringDegrees( (double) aCfg->m_RotationAngle ) ); + m_rotationAngle.SetAngleValue( aCfg->m_RotationAngle ); m_magneticPads->SetValue( aCfg->m_MagneticItems.pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); m_magneticGraphics->SetValue( aCfg->m_MagneticItems.graphics ); m_cbFpGraphic45Mode->SetValue( aCfg->m_Use45Limit ); @@ -115,7 +118,7 @@ bool PANEL_EDIT_OPTIONS::TransferDataFromWindow() { FOOTPRINT_EDITOR_SETTINGS* cfg = mgr.GetAppSettings(); - cfg->m_RotationAngle = wxRound( 10.0 * wxAtof( m_rotationAngle->GetValue() ) ); + cfg->m_RotationAngle = m_rotationAngle.GetAngleValue(); cfg->m_MagneticItems.pads = m_magneticPads->GetValue() ? MAGNETIC_OPTIONS::CAPTURE_ALWAYS : MAGNETIC_OPTIONS::NO_EFFECT; @@ -130,7 +133,7 @@ bool PANEL_EDIT_OPTIONS::TransferDataFromWindow() cfg->m_Display.m_DisplayRatsnestLinesCurved = m_OptDisplayCurvedRatsnestLines->GetValue(); cfg->m_Display.m_ShowModuleRatsnest = m_showSelectedRatsnest->GetValue(); - cfg->m_RotationAngle = wxRound( 10.0 * wxAtof( m_rotationAngle->GetValue() ) ); + cfg->m_RotationAngle = m_rotationAngle.GetAngleValue(); cfg->m_MagneticItems.pads = static_cast( m_magneticPadChoice->GetSelection() ); cfg->m_MagneticItems.tracks = static_cast( m_magneticTrackChoice->GetSelection() ); diff --git a/pcbnew/dialogs/panel_edit_options.h b/pcbnew/dialogs/panel_edit_options.h index 8f2670e102..b74e2105fd 100644 --- a/pcbnew/dialogs/panel_edit_options.h +++ b/pcbnew/dialogs/panel_edit_options.h @@ -25,17 +25,19 @@ #ifndef PANEL_EDIT_OPTIONS_H #define PANEL_EDIT_OPTIONS_H +#include #include "panel_edit_options_base.h" class FOOTPRINT_EDITOR_SETTINGS; class PCBNEW_SETTINGS; +class EDA_BASE_FRAME; class PANEL_EDIT_OPTIONS : public PANEL_EDIT_OPTIONS_BASE { public: - PANEL_EDIT_OPTIONS( wxWindow* aParent, bool isFootprintEditor ); + PANEL_EDIT_OPTIONS( wxWindow* aParent, EDA_BASE_FRAME* aUnitsProvider, bool isFootprintEditor ); bool TransferDataToWindow() override; bool TransferDataFromWindow() override; @@ -47,7 +49,9 @@ private: void loadPCBSettings( PCBNEW_SETTINGS* aCfg ); private: - bool m_isFootprintEditor; + bool m_isFootprintEditor; + + UNIT_BINDER m_rotationAngle; }; diff --git a/pcbnew/dialogs/panel_edit_options_base.cpp b/pcbnew/dialogs/panel_edit_options_base.cpp index cf9ee15d9c..571926cba3 100644 --- a/pcbnew/dialogs/panel_edit_options_base.cpp +++ b/pcbnew/dialogs/panel_edit_options_base.cpp @@ -50,19 +50,19 @@ PANEL_EDIT_OPTIONS_BASE::PANEL_EDIT_OPTIONS_BASE( wxWindow* parent, wxWindowID i wxBoxSizer* bSizerRotationStep; bSizerRotationStep = new wxBoxSizer( wxHORIZONTAL ); - m_staticTextRotationAngle = new wxStaticText( bOptionsSizer->GetStaticBox(), wxID_ANY, _("Step for &rotate commands:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticTextRotationAngle->Wrap( -1 ); - bSizerRotationStep->Add( m_staticTextRotationAngle, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); + m_rotationAngleLabel = new wxStaticText( bOptionsSizer->GetStaticBox(), wxID_ANY, _("Step for &rotate commands:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_rotationAngleLabel->Wrap( -1 ); + bSizerRotationStep->Add( m_rotationAngleLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); - m_rotationAngle = new wxTextCtrl( bOptionsSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - m_rotationAngle->SetToolTip( _("Set increment (in degrees) for context menu and hotkey rotation.") ); - m_rotationAngle->SetMinSize( wxSize( 60,-1 ) ); + m_rotationAngleCtrl = new wxTextCtrl( bOptionsSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_rotationAngleCtrl->SetToolTip( _("Set increment (in degrees) for context menu and hotkey rotation.") ); + m_rotationAngleCtrl->SetMinSize( wxSize( 60,-1 ) ); - bSizerRotationStep->Add( m_rotationAngle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + bSizerRotationStep->Add( m_rotationAngleCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - m_staticText32 = new wxStaticText( bOptionsSizer->GetStaticBox(), wxID_ANY, _("deg"), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText32->Wrap( -1 ); - bSizerRotationStep->Add( m_staticText32, 0, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); + m_rotationAngleUnits = new wxStaticText( bOptionsSizer->GetStaticBox(), wxID_ANY, _("deg"), wxDefaultPosition, wxDefaultSize, 0 ); + m_rotationAngleUnits->Wrap( -1 ); + bSizerRotationStep->Add( m_rotationAngleUnits, 0, wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); bSizerUniversal->Add( bSizerRotationStep, 0, wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/panel_edit_options_base.fbp b/pcbnew/dialogs/panel_edit_options_base.fbp index 7152192c5c..f87be3b6bc 100644 --- a/pcbnew/dialogs/panel_edit_options_base.fbp +++ b/pcbnew/dialogs/panel_edit_options_base.fbp @@ -357,7 +357,7 @@ 0 1 - m_staticTextRotationAngle + m_rotationAngleLabel 1 @@ -417,7 +417,7 @@ 0 60,-1 1 - m_rotationAngle + m_rotationAngleCtrl 1 @@ -482,7 +482,7 @@ 0 1 - m_staticText32 + m_rotationAngleUnits 1 diff --git a/pcbnew/dialogs/panel_edit_options_base.h b/pcbnew/dialogs/panel_edit_options_base.h index 7769f8a5b4..13d32c8372 100644 --- a/pcbnew/dialogs/panel_edit_options_base.h +++ b/pcbnew/dialogs/panel_edit_options_base.h @@ -40,9 +40,9 @@ class PANEL_EDIT_OPTIONS_BASE : public RESETTABLE_PANEL wxCheckBox* m_magneticPads; wxCheckBox* m_magneticGraphics; wxCheckBox* m_flipLeftRight; - wxStaticText* m_staticTextRotationAngle; - wxTextCtrl* m_rotationAngle; - wxStaticText* m_staticText32; + wxStaticText* m_rotationAngleLabel; + wxTextCtrl* m_rotationAngleCtrl; + wxStaticText* m_rotationAngleUnits; wxCheckBox* m_allowFreePads; wxStaticBoxSizer* m_mouseCmdsWinLin; wxStaticText* m_staticText181; diff --git a/pcbnew/footprint_editor_settings.cpp b/pcbnew/footprint_editor_settings.cpp index 651302974b..3f48a519ea 100644 --- a/pcbnew/footprint_editor_settings.cpp +++ b/pcbnew/footprint_editor_settings.cpp @@ -44,7 +44,7 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_Display(), m_UserGrid(), m_PolarCoords( false ), - m_RotationAngle( 900 ), + m_RotationAngle( ANGLE_90 ), m_Use45Limit( true ), m_LibWidth( 250 ), m_LastImportExportPath(), @@ -86,8 +86,16 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_params.emplace_back( new PARAM( "editing.polar_coords", &m_PolarCoords, false ) ); - m_params.emplace_back( new PARAM( "editing.rotation_angle", - &m_RotationAngle, 900, 1, 900 ) ); + m_params.emplace_back( new PARAM_LAMBDA( "editing.rotation_angle", + [this] () -> int + { + return m_RotationAngle.AsTenthsOfADegree(); + }, + [this] ( int aVal ) + { + m_RotationAngle = EDA_ANGLE( aVal, TENTHS_OF_A_DEGREE_T ); + }, + 900 ) ); m_params.emplace_back( new PARAM( "editing.fp_use_45_degree_limit", &m_Use45Limit, false ) ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 41de505793..94da052d17 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -1054,7 +1054,7 @@ void PCB_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) if( cfg ) { - m_rotationAngle = EDA_ANGLE( cfg->m_RotationAngle, TENTHS_OF_A_DEGREE_T ); + m_rotationAngle = cfg->m_RotationAngle; m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager; } } @@ -1069,7 +1069,7 @@ void PCB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) if( cfg ) { - cfg->m_RotationAngle = m_rotationAngle.AsTenthsOfADegree(); + cfg->m_RotationAngle = m_rotationAngle; 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/pcbnew.cpp b/pcbnew/pcbnew.cpp index 8270bafd3e..9a6a621b7c 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-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 @@ -23,11 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pcbnew.cpp - * @brief Pcbnew main program. - */ - #include #include #include @@ -42,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -151,8 +145,6 @@ static struct IFACE : public KIFACE_BASE } case PANEL_FP_EDIT_OPTIONS: - return new PANEL_EDIT_OPTIONS( aParent, true ); - case PANEL_FP_DEFAULT_VALUES: { EDA_BASE_FRAME* unitsProvider = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false ); @@ -177,7 +169,10 @@ static struct IFACE : public KIFACE_BASE unitsProvider = static_cast( manager ); } - return new PANEL_FP_EDITOR_DEFAULTS( aParent, unitsProvider ); + if( aClassId == PANEL_FP_EDIT_OPTIONS ) + return new PANEL_EDIT_OPTIONS( aParent, unitsProvider, true ); + else + return new PANEL_FP_EDITOR_DEFAULTS( aParent, unitsProvider ); } case PANEL_FP_COLORS: @@ -192,7 +187,31 @@ static struct IFACE : public KIFACE_BASE } case PANEL_PCB_EDIT_OPTIONS: - return new PANEL_EDIT_OPTIONS( aParent, false ); + { + EDA_BASE_FRAME* unitsProvider = aKiway->Player( FRAME_PCB_EDITOR, false ); + + if( !unitsProvider ) + unitsProvider = aKiway->Player( FRAME_FOOTPRINT_EDITOR, false ); + + if( !unitsProvider ) + unitsProvider = aKiway->Player( FRAME_FOOTPRINT_VIEWER, false ); + + if( !unitsProvider ) + { + // If we can't find an eeschema frame we'll have to make do with the units + // defined in whatever FRAME we _can_ find. + for( unsigned i = 0; !unitsProvider && i < KIWAY_PLAYER_COUNT; ++i ) + unitsProvider = aKiway->Player( (FRAME_T) i, false ); + } + + if( !unitsProvider ) + { + wxWindow* manager = wxFindWindowByName( KICAD_MANAGER_FRAME_NAME ); + unitsProvider = static_cast( manager ); + } + + return new PANEL_EDIT_OPTIONS( aParent, unitsProvider, false ); + } case PANEL_PCB_COLORS: { diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index 8db339dc08..5018ed886a 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -70,7 +70,7 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_Use45DegreeLimit( false ), m_FlipLeftRight( false ), m_PolarCoords( false ), - m_RotationAngle( 900 ), + m_RotationAngle( ANGLE_90 ), m_ShowPageLimits( true ), m_AutoRefillZones( true ), m_AllowFreePads( false ), @@ -132,8 +132,16 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_params.emplace_back( new PARAM( "editing.allow_free_pads", &m_AllowFreePads, false ) ); - m_params.emplace_back( new PARAM( "editing.rotation_angle", - &m_RotationAngle, 900, 1, 900 ) ); + m_params.emplace_back( new PARAM_LAMBDA( "editing.rotation_angle", + [this] () -> int + { + return m_RotationAngle.AsTenthsOfADegree(); + }, + [this] ( int aVal ) + { + m_RotationAngle = EDA_ANGLE( aVal, TENTHS_OF_A_DEGREE_T ); + }, + 900 ) ); m_params.emplace_back( new PARAM( "pcb_display.graphic_items_fill", &m_Display.m_DisplayGraphicsFill, true ) ); diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index fef61f96b1..168848c5eb 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jon Evans - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-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 as published by the @@ -21,6 +21,7 @@ #ifndef PCBNEW_SETTINGS_H_ #define PCBNEW_SETTINGS_H_ +#include #include #include @@ -331,7 +332,7 @@ public: bool m_PolarCoords; - int m_RotationAngle; + EDA_ANGLE m_RotationAngle; bool m_ShowPageLimits;