Move rotation angle increments to UNIT_BINDER and EDA_ANGLE.

This commit is contained in:
Jeff Young 2022-01-19 13:24:02 +00:00
parent ef721f051a
commit 9d5322cfdf
12 changed files with 99 additions and 58 deletions

View File

@ -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<double>( 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;
}

View File

@ -65,7 +65,7 @@ public:
bool m_PolarCoords;
int m_RotationAngle;
EDA_ANGLE m_RotationAngle;
bool m_Use45Limit;

View File

@ -30,9 +30,12 @@
#include <panel_edit_options.h>
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<int>( aCfg->m_MagneticItems.pads ) );
m_magneticTrackChoice->SetSelection( static_cast<int>( 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<FOOTPRINT_EDITOR_SETTINGS>();
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<MAGNETIC_OPTIONS>( m_magneticPadChoice->GetSelection() );
cfg->m_MagneticItems.tracks = static_cast<MAGNETIC_OPTIONS>( m_magneticTrackChoice->GetSelection() );

View File

@ -25,17 +25,19 @@
#ifndef PANEL_EDIT_OPTIONS_H
#define PANEL_EDIT_OPTIONS_H
#include <widgets/unit_binder.h>
#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;
};

View File

@ -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 );

View File

@ -357,7 +357,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticTextRotationAngle</property>
<property name="name">m_rotationAngleLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -417,7 +417,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size">60,-1</property>
<property name="moveable">1</property>
<property name="name">m_rotationAngle</property>
<property name="name">m_rotationAngleCtrl</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -482,7 +482,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText32</property>
<property name="name">m_rotationAngleUnits</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>

View File

@ -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;

View File

@ -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<bool>( "editing.polar_coords",
&m_PolarCoords, false ) );
m_params.emplace_back( new PARAM<int>( "editing.rotation_angle",
&m_RotationAngle, 900, 1, 900 ) );
m_params.emplace_back( new PARAM_LAMBDA<int>( "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<bool>( "editing.fp_use_45_degree_limit",
&m_Use45Limit, false ) );

View File

@ -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();

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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 <pcbnew_scripting_helpers.h>
#include <pgm_base.h>
#include <kiface_base.h>
@ -42,7 +37,6 @@
#include <pcbnew_settings.h>
#include <footprint_editor_settings.h>
#include <settings/settings_manager.h>
#include <class_draw_panel_gal.h>
#include <fp_lib_table.h>
#include <footprint_edit_frame.h>
#include <footprint_viewer_frame.h>
@ -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<EDA_BASE_FRAME*>( 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<EDA_BASE_FRAME*>( manager );
}
return new PANEL_EDIT_OPTIONS( aParent, unitsProvider, false );
}
case PANEL_PCB_COLORS:
{

View File

@ -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<bool>( "editing.allow_free_pads",
&m_AllowFreePads, false ) );
m_params.emplace_back( new PARAM<int>( "editing.rotation_angle",
&m_RotationAngle, 900, 1, 900 ) );
m_params.emplace_back( new PARAM_LAMBDA<int>( "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<bool>( "pcb_display.graphic_items_fill",
&m_Display.m_DisplayGraphicsFill, true ) );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* 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 <geometry/eda_angle.h>
#include <settings/app_settings.h>
#include <pcb_display_options.h>
@ -331,7 +332,7 @@ public:
bool m_PolarCoords;
int m_RotationAngle;
EDA_ANGLE m_RotationAngle;
bool m_ShowPageLimits;