KiCad PCB EDA Suite
ORIGIN_TRANSFORMS Class Reference

A class to perform either relative or absolute display origin transforms for a single axis of a point. More...

#include <origin_transforms.h>

Inheritance diagram for ORIGIN_TRANSFORMS:
PCB_ORIGIN_TRANSFORMS

Public Types

enum  COORD_TYPES_T {
  NOT_A_COORD, ABS_X_COORD, ABS_Y_COORD, REL_X_COORD,
  REL_Y_COORD
}
 The supported Display Origin Transform types. More...
 

Public Member Functions

 ORIGIN_TRANSFORMS ()
 
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
 
template<class T >
ToDisplayAbs (const T &aValue) const
 
template<class T >
ToDisplayRel (const T &aValue) const
 
template<class T >
FromDisplayAbs (const T &aValue) const
 
template<class T >
FromDisplayRel (const T &aValue) const
 

Static Protected Member Functions

template<class T >
static T ToDisplayRel (T aInternalValue, bool aInvertAxis)
 
template<class T >
static T FromDisplayRel (T aDisplayValue, bool aInvertAxis)
 
template<class T >
static T ToDisplayAbs (T aInternalValue, int aUserOrigin, bool aInvertAxis)
 
template<class T >
static T FromDisplayAbs (T aDisplayValue, int aUserOrigin, bool aInvertAxis)
 

Detailed Description

A class to perform either relative or absolute display origin transforms for a single axis of a point.

The coordinate argument is transformed between an offset from the internal origin and an offset from the user-specified origin and coordinate direction.

The functions are templated to allow use with any size scalar parameter: an int, a long long int, or a double.

Definition at line 39 of file origin_transforms.h.

Member Enumeration Documentation

◆ COORD_TYPES_T

The supported Display Origin Transform types.

Absolute coordinates require both translation and direction inversion. Relative coordinates require only direction inversion.

Enumerator
NOT_A_COORD 
ABS_X_COORD 
ABS_Y_COORD 
REL_X_COORD 
REL_Y_COORD 

Definition at line 48 of file origin_transforms.h.

48  {
49  NOT_A_COORD, //< A non-coordinate value, never transformed
50  ABS_X_COORD, //< An absolute X coordinate
51  ABS_Y_COORD, //< An absolute Y coordinate
52  REL_X_COORD, //< A relative X coordinate
53  REL_Y_COORD, //< A relative Y coordinate
54  };

Constructor & Destructor Documentation

◆ ORIGIN_TRANSFORMS()

ORIGIN_TRANSFORMS::ORIGIN_TRANSFORMS ( )

Definition at line 28 of file origin_transforms.cpp.

29 {}

◆ ~ORIGIN_TRANSFORMS()

ORIGIN_TRANSFORMS::~ORIGIN_TRANSFORMS ( )
virtual

Definition at line 31 of file origin_transforms.cpp.

32 {}

Member Function Documentation

◆ FromDisplay() [1/3]

int ORIGIN_TRANSFORMS::FromDisplay ( int  aValue,
COORD_TYPES_T  aCoordType 
) const
virtual

Definition at line 53 of file origin_transforms.cpp.

55 {
56  return static_cast<int>( FromDisplay( static_cast<long long int>( aValue ), aCoordType ) );
57 }
virtual int FromDisplay(int aValue, COORD_TYPES_T aCoordType) const

Referenced by FromDisplayAbs(), FromDisplayRel(), UNIT_BINDER::GetDoubleValue(), and UNIT_BINDER::GetValue().

◆ FromDisplay() [2/3]

long long int ORIGIN_TRANSFORMS::FromDisplay ( long long int  aValue,
COORD_TYPES_T  aCoordType 
) const
virtual

Reimplemented in PCB_ORIGIN_TRANSFORMS.

Definition at line 59 of file origin_transforms.cpp.

61 {
62  return aValue;
63 }

◆ FromDisplay() [3/3]

double ORIGIN_TRANSFORMS::FromDisplay ( double  aValue,
COORD_TYPES_T  aCoordType 
) const
virtual

Reimplemented in PCB_ORIGIN_TRANSFORMS.

Definition at line 65 of file origin_transforms.cpp.

67 {
68  return aValue;
69 }

◆ FromDisplayAbs() [1/2]

template<class T >
T ORIGIN_TRANSFORMS::FromDisplayAbs ( const T &  aValue) const
inline

Definition at line 101 of file origin_transforms.h.

102  {
103  T displayValue;
104 
105  displayValue.x = FromDisplay( aValue.x, ABS_X_COORD );
106  displayValue.y = FromDisplay( aValue.y, ABS_Y_COORD );
107  return displayValue;
108  }
virtual int FromDisplay(int aValue, COORD_TYPES_T aCoordType) const

References ABS_X_COORD, ABS_Y_COORD, and FromDisplay().

Referenced by PCB_ORIGIN_TRANSFORMS::FromDisplayAbsX(), and PCB_ORIGIN_TRANSFORMS::FromDisplayAbsY().

◆ FromDisplayAbs() [2/2]

template<class T >
static T ORIGIN_TRANSFORMS::FromDisplayAbs ( aDisplayValue,
int  aUserOrigin,
bool  aInvertAxis 
)
inlinestaticprotected

Definition at line 167 of file origin_transforms.h.

170  {
171  T internalValue = aDisplayValue;
172 
173  // Invert the direction if needed
174  if( aInvertAxis && (internalValue != static_cast<T>(0)) )
175  internalValue = -internalValue;
176 
177  // Make the value relative to the internal origin
178  internalValue += aUserOrigin;
179 
180  return internalValue;
181  }

◆ FromDisplayRel() [1/2]

template<class T >
T ORIGIN_TRANSFORMS::FromDisplayRel ( const T &  aValue) const
inline

Definition at line 111 of file origin_transforms.h.

112  {
113  T displayValue;
114 
115  displayValue.x = FromDisplay( aValue.x, REL_X_COORD );
116  displayValue.y = FromDisplay( aValue.y, REL_Y_COORD );
117  return displayValue;
118  }
virtual int FromDisplay(int aValue, COORD_TYPES_T aCoordType) const

References FromDisplay(), REL_X_COORD, and REL_Y_COORD.

Referenced by PCB_ORIGIN_TRANSFORMS::FromDisplayRelX(), and PCB_ORIGIN_TRANSFORMS::FromDisplayRelY().

◆ FromDisplayRel() [2/2]

template<class T >
static T ORIGIN_TRANSFORMS::FromDisplayRel ( aDisplayValue,
bool  aInvertAxis 
)
inlinestaticprotected

Definition at line 137 of file origin_transforms.h.

139  {
140  T internalValue = aDisplayValue;
141 
142  // Invert the direction if needed
143  if( aInvertAxis && (internalValue != static_cast<T>(0)) )
144  internalValue = -internalValue;
145 
146  return internalValue;
147  }

◆ ToDisplay() [1/3]

int ORIGIN_TRANSFORMS::ToDisplay ( int  aValue,
COORD_TYPES_T  aCoordType 
) const
virtual

Definition at line 35 of file origin_transforms.cpp.

37 {
38  return static_cast<int>( ToDisplay( static_cast<long long int>( aValue ), aCoordType ) );
39 }
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const

Referenced by UNIT_BINDER::ChangeValue(), UNIT_BINDER::SetDoubleValue(), UNIT_BINDER::SetValue(), ToDisplayAbs(), and ToDisplayRel().

◆ ToDisplay() [2/3]

long long int ORIGIN_TRANSFORMS::ToDisplay ( long long int  aValue,
COORD_TYPES_T  aCoordType 
) const
virtual

Reimplemented in PCB_ORIGIN_TRANSFORMS.

Definition at line 41 of file origin_transforms.cpp.

43 {
44  return aValue;
45 }

◆ ToDisplay() [3/3]

double ORIGIN_TRANSFORMS::ToDisplay ( double  aValue,
COORD_TYPES_T  aCoordType 
) const
virtual

Reimplemented in PCB_ORIGIN_TRANSFORMS.

Definition at line 47 of file origin_transforms.cpp.

49 {
50  return aValue;
51 }

◆ ToDisplayAbs() [1/2]

template<class T >
T ORIGIN_TRANSFORMS::ToDisplayAbs ( const T &  aValue) const
inline

Definition at line 80 of file origin_transforms.h.

81  {
82  T displayValue;
83 
84  displayValue.x = ToDisplay( aValue.x, ABS_X_COORD );
85  displayValue.y = ToDisplay( aValue.y, ABS_Y_COORD );
86  return displayValue;
87  }
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const

References ABS_X_COORD, ABS_Y_COORD, and ToDisplay().

Referenced by DIMENSION_BASE::GetMsgPanelInfo(), LEADER::GetMsgPanelInfo(), PCB_ORIGIN_TRANSFORMS::ToDisplayAbsX(), and PCB_ORIGIN_TRANSFORMS::ToDisplayAbsY().

◆ ToDisplayAbs() [2/2]

template<class T >
static T ORIGIN_TRANSFORMS::ToDisplayAbs ( aInternalValue,
int  aUserOrigin,
bool  aInvertAxis 
)
inlinestaticprotected

Definition at line 150 of file origin_transforms.h.

153  {
154  T displayValue = aInternalValue;
155 
156  // Make the value relative to the internal origin
157  displayValue -= aUserOrigin;
158 
159  // Invert the direction if needed
160  if( aInvertAxis && (displayValue != static_cast<T>(0)) )
161  displayValue = -displayValue;
162 
163  return displayValue;
164  }

◆ ToDisplayRel() [1/2]

template<class T >
T ORIGIN_TRANSFORMS::ToDisplayRel ( const T &  aValue) const
inline

Definition at line 90 of file origin_transforms.h.

91  {
92  T displayValue;
93 
94  displayValue.x = ToDisplay( aValue.x, REL_X_COORD );
95  displayValue.y = ToDisplay( aValue.y, REL_Y_COORD );
96  return displayValue;
97  }
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const

References REL_X_COORD, REL_Y_COORD, and ToDisplay().

Referenced by PCB_ORIGIN_TRANSFORMS::ToDisplayRelX(), and PCB_ORIGIN_TRANSFORMS::ToDisplayRelY().

◆ ToDisplayRel() [2/2]

template<class T >
static T ORIGIN_TRANSFORMS::ToDisplayRel ( aInternalValue,
bool  aInvertAxis 
)
inlinestaticprotected

Definition at line 123 of file origin_transforms.h.

125  {
126  T displayValue = aInternalValue;
127 
128  // Invert the direction if needed
129  if( aInvertAxis && (displayValue != static_cast<T>(0)) )
130  displayValue = -displayValue;
131 
132  return displayValue;
133  }

The documentation for this class was generated from the following files: