Show "natural" angles even in inverted coord systems.

This commit is contained in:
Jeff Young
2025-10-25 18:08:00 +01:00
parent 5a4aacc1ea
commit 258c0b50be
6 changed files with 77 additions and 84 deletions
+19 -20
View File
@@ -23,53 +23,52 @@
*/
#include <origin_transforms.h>
#include <geometry/eda_angle.h>
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<int>( ToDisplay( static_cast<long long int>( 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<int>( FromDisplay( static_cast<long long int>( 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;
}
+3 -3
View File
@@ -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 );
}
+24 -45
View File
@@ -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<class T>
T ToDisplayAbs( const T& aValue ) const
@@ -96,7 +86,6 @@ public:
return displayValue;
}
template<class T>
T FromDisplayAbs( const T& aValue ) const
{
@@ -117,39 +106,33 @@ public:
return displayValue;
}
protected:
template<class T> inline static
T ToDisplayRel( T aInternalValue,
bool aInvertAxis )
template<class T>
inline static T ToDisplayRel( T aInternalValue, bool aInvertAxis )
{
T displayValue = aInternalValue;
// Invert the direction if needed
if( aInvertAxis && (displayValue != static_cast<T>(0)) )
if( aInvertAxis && ( displayValue != static_cast<T>( 0 ) ) )
displayValue = -displayValue;
return displayValue;
}
template<class T> inline static
T FromDisplayRel( T aDisplayValue,
bool aInvertAxis )
template<class T>
inline static T FromDisplayRel( T aDisplayValue, bool aInvertAxis )
{
T internalValue = aDisplayValue;
// Invert the direction if needed
if( aInvertAxis && (internalValue != static_cast<T>(0)) )
if( aInvertAxis && ( internalValue != static_cast<T>( 0 ) ) )
internalValue = -internalValue;
return internalValue;
}
template<class T> inline static
T ToDisplayAbs( T aInternalValue,
int aUserOrigin,
bool aInvertAxis )
template<class T>
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<T>(0)) )
if( aInvertAxis && ( displayValue != static_cast<T>( 0 ) ) )
displayValue = -displayValue;
return displayValue;
}
template<class T> inline static
T FromDisplayAbs( T aDisplayValue,
int aUserOrigin,
bool aInvertAxis )
template<class T>
inline static T FromDisplayAbs( T aDisplayValue, int aUserOrigin, bool aInvertAxis )
{
T internalValue = aDisplayValue;
// Invert the direction if needed
if( aInvertAxis && (internalValue != static_cast<T>(0)) )
if( aInvertAxis && ( internalValue != static_cast<T>( 0 ) ) )
internalValue = -internalValue;
// Make the value relative to the internal origin
@@ -180,5 +161,3 @@ protected:
return internalValue;
}
};
#endif // ORIGIN_TRANSFORMS_H
+1 -1
View File
@@ -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() );
+26 -6
View File
@@ -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 )
+4 -9
View File
@@ -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 <origin_transforms.h>
@@ -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_