From 258c0b50bec8ebfa8f25f42ac23a9ac57013dac9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 25 Oct 2025 18:08:00 +0100 Subject: [PATCH] Show "natural" angles even in inverted coord systems. --- common/origin_transforms.cpp | 39 ++++++++-------- common/widgets/unit_binder.cpp | 6 +-- include/origin_transforms.h | 69 ++++++++++------------------ pcbnew/dialogs/dialog_set_offset.cpp | 2 +- pcbnew/pcb_origin_transforms.cpp | 32 ++++++++++--- pcbnew/pcb_origin_transforms.h | 13 ++---- 6 files changed, 77 insertions(+), 84 deletions(-) diff --git a/common/origin_transforms.cpp b/common/origin_transforms.cpp index fe0baee806..8ad44e4b25 100644 --- a/common/origin_transforms.cpp +++ b/common/origin_transforms.cpp @@ -23,53 +23,52 @@ */ #include +#include -ORIGIN_TRANSFORMS::ORIGIN_TRANSFORMS() -{} - - -ORIGIN_TRANSFORMS::~ORIGIN_TRANSFORMS() -{} - - -int ORIGIN_TRANSFORMS::ToDisplay( int aValue, - COORD_TYPES_T aCoordType ) const +int ORIGIN_TRANSFORMS::ToDisplay( int aValue, COORD_TYPES_T aCoordType ) const { return static_cast( ToDisplay( static_cast( aValue ), aCoordType ) ); } -long long int ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, - COORD_TYPES_T aCoordType ) const +long long int ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const { return aValue; } -double ORIGIN_TRANSFORMS::ToDisplay( double aValue, - COORD_TYPES_T aCoordType ) const +double ORIGIN_TRANSFORMS::ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const { return aValue; } -int ORIGIN_TRANSFORMS::FromDisplay( int aValue, - COORD_TYPES_T aCoordType ) const +double ORIGIN_TRANSFORMS::ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const +{ + return aValue.AsDegrees(); +} + + +int ORIGIN_TRANSFORMS::FromDisplay( int aValue, COORD_TYPES_T aCoordType ) const { return static_cast( FromDisplay( static_cast( aValue ), aCoordType ) ); } -long long int ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, - COORD_TYPES_T aCoordType ) const +long long int ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const { return aValue; } -double ORIGIN_TRANSFORMS::FromDisplay( double aValue, - COORD_TYPES_T aCoordType ) const +double ORIGIN_TRANSFORMS::FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const { return aValue; } + + +EDA_ANGLE ORIGIN_TRANSFORMS::FromDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const +{ + return aValue; +} \ No newline at end of file diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 99e0f338e0..140a5964bf 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -415,7 +415,7 @@ void UNIT_BINDER::SetDoubleValue( double aValue ) void UNIT_BINDER::SetAngleValue( const EDA_ANGLE& aValue ) { - SetDoubleValue( aValue.AsDegrees() ); + SetDoubleValue( m_originTransforms.ToDisplay( aValue, m_coordType ) ); } @@ -488,7 +488,7 @@ void UNIT_BINDER::ChangeDoubleValue( double aValue ) void UNIT_BINDER::ChangeAngleValue( const EDA_ANGLE& aValue ) { - ChangeDoubleValue( aValue.AsDegrees() ); + ChangeDoubleValue( m_originTransforms.ToDisplay( aValue, m_coordType ) ); } @@ -602,7 +602,7 @@ double UNIT_BINDER::GetDoubleValue() const EDA_ANGLE UNIT_BINDER::GetAngleValue() { - return EDA_ANGLE( GetDoubleValue(), DEGREES_T ); + return m_originTransforms.FromDisplay( EDA_ANGLE( GetDoubleValue(), DEGREES_T ), m_coordType ); } diff --git a/include/origin_transforms.h b/include/origin_transforms.h index 3d2def38b2..0b3576636a 100644 --- a/include/origin_transforms.h +++ b/include/origin_transforms.h @@ -22,8 +22,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef ORIGIN_TRANSFORMS_H_ -#define ORIGIN_TRANSFORMS_H_ +#pragma once + +class EDA_ANGLE; /** * A class to perform either relative or absolute display origin @@ -53,28 +54,17 @@ public: REL_Y_COORD, //< A relative Y coordinate }; - ORIGIN_TRANSFORMS(); + ~ORIGIN_TRANSFORMS() = default; - virtual ~ORIGIN_TRANSFORMS(); - - virtual int ToDisplay( int aValue, - COORD_TYPES_T aCoordType ) const; - - virtual long long int ToDisplay( long long int aValue, - COORD_TYPES_T aCoordType ) const; - - virtual double ToDisplay( double aValue, - COORD_TYPES_T aCoordType ) const; - - virtual int FromDisplay( int aValue, - COORD_TYPES_T aCoordType ) const; - - virtual long long int FromDisplay( long long int aValue, - COORD_TYPES_T aCoordType ) const; - - virtual double FromDisplay( double aValue, - COORD_TYPES_T aCoordType ) const; + virtual int ToDisplay( int aValue, COORD_TYPES_T aCoordType ) const; + virtual long long int ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const; + virtual double ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const; + virtual double ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const; + virtual int FromDisplay( int aValue, COORD_TYPES_T aCoordType ) const; + virtual long long int FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const; + virtual double FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const; + virtual EDA_ANGLE FromDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const; template T ToDisplayAbs( const T& aValue ) const @@ -96,7 +86,6 @@ public: return displayValue; } - template T FromDisplayAbs( const T& aValue ) const { @@ -117,39 +106,33 @@ public: return displayValue; } - protected: - template inline static - T ToDisplayRel( T aInternalValue, - bool aInvertAxis ) + template + inline static T ToDisplayRel( T aInternalValue, bool aInvertAxis ) { T displayValue = aInternalValue; // Invert the direction if needed - if( aInvertAxis && (displayValue != static_cast(0)) ) + if( aInvertAxis && ( displayValue != static_cast( 0 ) ) ) displayValue = -displayValue; return displayValue; } - - template inline static - T FromDisplayRel( T aDisplayValue, - bool aInvertAxis ) + template + inline static T FromDisplayRel( T aDisplayValue, bool aInvertAxis ) { T internalValue = aDisplayValue; // Invert the direction if needed - if( aInvertAxis && (internalValue != static_cast(0)) ) + if( aInvertAxis && ( internalValue != static_cast( 0 ) ) ) internalValue = -internalValue; return internalValue; } - template inline static - T ToDisplayAbs( T aInternalValue, - int aUserOrigin, - bool aInvertAxis ) + template + inline static T ToDisplayAbs( T aInternalValue, int aUserOrigin, bool aInvertAxis ) { T displayValue = aInternalValue; @@ -157,21 +140,19 @@ protected: displayValue -= aUserOrigin; // Invert the direction if needed - if( aInvertAxis && (displayValue != static_cast(0)) ) + if( aInvertAxis && ( displayValue != static_cast( 0 ) ) ) displayValue = -displayValue; return displayValue; } - template inline static - T FromDisplayAbs( T aDisplayValue, - int aUserOrigin, - bool aInvertAxis ) + template + inline static T FromDisplayAbs( T aDisplayValue, int aUserOrigin, bool aInvertAxis ) { T internalValue = aDisplayValue; // Invert the direction if needed - if( aInvertAxis && (internalValue != static_cast(0)) ) + if( aInvertAxis && ( internalValue != static_cast( 0 ) ) ) internalValue = -internalValue; // Make the value relative to the internal origin @@ -180,5 +161,3 @@ protected: return internalValue; } }; - -#endif // ORIGIN_TRANSFORMS_H diff --git a/pcbnew/dialogs/dialog_set_offset.cpp b/pcbnew/dialogs/dialog_set_offset.cpp index d76aac8d82..aa8ab1ef30 100644 --- a/pcbnew/dialogs/dialog_set_offset.cpp +++ b/pcbnew/dialogs/dialog_set_offset.cpp @@ -185,7 +185,7 @@ bool DIALOG_SET_OFFSET::TransferDataFromWindow() if( m_polarCoords->GetValue() ) { m_stateRadius = m_xOffset.GetDoubleValue(); - m_stateTheta = EDA_ANGLE( m_yOffset.GetDoubleValue(), DEGREES_T ); + m_stateTheta = m_yOffset.GetAngleValue(); m_updatedOffset.x = KiROUND( m_stateRadius * m_stateTheta.Cos() ); m_updatedOffset.y = KiROUND( m_stateRadius * m_stateTheta.Sin() ); diff --git a/pcbnew/pcb_origin_transforms.cpp b/pcbnew/pcb_origin_transforms.cpp index 98461e46dc..6063b7bc83 100644 --- a/pcbnew/pcb_origin_transforms.cpp +++ b/pcbnew/pcb_origin_transforms.cpp @@ -34,11 +34,8 @@ PCB_ORIGIN_TRANSFORMS::PCB_ORIGIN_TRANSFORMS( PCB_BASE_FRAME& aPcbBaseFrame ) : m_pcbBaseFrame( aPcbBaseFrame ) {} -PCB_ORIGIN_TRANSFORMS::~PCB_ORIGIN_TRANSFORMS() -{} -long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, - COORD_TYPES_T aCoordType ) const +long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const { long long int value = aValue; @@ -55,6 +52,7 @@ long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue, return value; } + double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const { double value = aValue; @@ -72,8 +70,17 @@ double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue, COORD_TYPES_T aCoordType return value; } -long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, - COORD_TYPES_T aCoordType ) const + +double PCB_ORIGIN_TRANSFORMS::ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const +{ + if( !invertYAxis() && ( aCoordType == REL_X_COORD || aCoordType == REL_Y_COORD ) ) + return -aValue.AsDegrees(); + + return aValue.AsDegrees(); +} + + +long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const { long long value = aValue; @@ -90,6 +97,7 @@ long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue, return value; } + double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const { double value = aValue; @@ -108,16 +116,27 @@ double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue, COORD_TYPES_T aCoordTy } +EDA_ANGLE PCB_ORIGIN_TRANSFORMS::FromDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const +{ + if( !invertYAxis() && ( aCoordType == REL_X_COORD || aCoordType == REL_Y_COORD ) ) + return -aValue; + + return aValue; +} + + int PCB_ORIGIN_TRANSFORMS::getUserXOrigin() const { return m_pcbBaseFrame.GetUserOrigin().x; } + int PCB_ORIGIN_TRANSFORMS::getUserYOrigin() const { return m_pcbBaseFrame.GetUserOrigin().y; } + bool PCB_ORIGIN_TRANSFORMS::invertXAxis() const { if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR ) @@ -126,6 +145,7 @@ bool PCB_ORIGIN_TRANSFORMS::invertXAxis() const return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertXAxis; } + bool PCB_ORIGIN_TRANSFORMS::invertYAxis() const { if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR ) diff --git a/pcbnew/pcb_origin_transforms.h b/pcbnew/pcb_origin_transforms.h index 1559298328..3948d2b950 100644 --- a/pcbnew/pcb_origin_transforms.h +++ b/pcbnew/pcb_origin_transforms.h @@ -22,8 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PCB_ORIGIN_TRANSFORM_H_ -#define PCB_ORIGIN_TRANSFORM_H_ +#pragma once #include @@ -34,21 +33,19 @@ class PCB_ORIGIN_TRANSFORMS : public ORIGIN_TRANSFORMS public: PCB_ORIGIN_TRANSFORMS( PCB_BASE_FRAME& aPcbBaseFrame ); - virtual ~PCB_ORIGIN_TRANSFORMS() override; + ~PCB_ORIGIN_TRANSFORMS() = default; using ORIGIN_TRANSFORMS::ToDisplay; virtual long long int ToDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override; - virtual double ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const override; - + virtual double ToDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const override; using ORIGIN_TRANSFORMS::FromDisplay; virtual long long int FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override; - virtual double FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const override; - + virtual EDA_ANGLE FromDisplay( const EDA_ANGLE& aValue, COORD_TYPES_T aCoordType ) const override; /** * Transform a 2-D coordinate point referenced to the internal origin @@ -199,5 +196,3 @@ protected: protected: const PCB_BASE_FRAME& m_pcbBaseFrame; }; - -#endif // PCB_ORIGIN_TRANSFORMS_H_