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 47 of file origin_transforms.h.

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

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 106 of file origin_transforms.h.

107  {
108  T displayValue;
109 
110  displayValue.x = FromDisplay( aValue.x, ABS_X_COORD );
111  displayValue.y = FromDisplay( aValue.y, ABS_Y_COORD );
112  return displayValue;
113  }
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 178 of file origin_transforms.h.

181  {
182  T internalValue = aDisplayValue;
183 
184  // Invert the direction if needed
185  if( aInvertAxis && (internalValue != static_cast<T>(0)) )
186  internalValue = -internalValue;
187 
188  // Make the value relative to the internal origin
189  internalValue += aUserOrigin;
190 
191  return internalValue;
192  }

◆ FromDisplayRel() [1/2]

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

Definition at line 116 of file origin_transforms.h.

117  {
118  T displayValue;
119 
120  displayValue.x = FromDisplay( aValue.x, REL_X_COORD );
121  displayValue.y = FromDisplay( aValue.y, REL_Y_COORD );
122  return displayValue;
123  }
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 145 of file origin_transforms.h.

147  {
148  T internalValue = aDisplayValue;
149 
150  // Invert the direction if needed
151  if( aInvertAxis && (internalValue != static_cast<T>(0)) )
152  internalValue = -internalValue;
153 
154  return internalValue;
155  }

◆ 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 85 of file origin_transforms.h.

86  {
87  T displayValue;
88 
89  displayValue.x = ToDisplay( aValue.x, ABS_X_COORD );
90  displayValue.y = ToDisplay( aValue.y, ABS_Y_COORD );
91  return displayValue;
92  }
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const

References ABS_X_COORD, ABS_Y_COORD, and ToDisplay().

Referenced by DIMENSION::GetMsgPanelInfo(), PCB_SHAPE::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 161 of file origin_transforms.h.

164  {
165  T displayValue = aInternalValue;
166 
167  // Make the value relative to the internal origin
168  displayValue -= aUserOrigin;
169 
170  // Invert the direction if needed
171  if( aInvertAxis && (displayValue != static_cast<T>(0)) )
172  displayValue = -displayValue;
173 
174  return displayValue;
175  }

◆ ToDisplayRel() [1/2]

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

Definition at line 95 of file origin_transforms.h.

96  {
97  T displayValue;
98 
99  displayValue.x = ToDisplay( aValue.x, REL_X_COORD );
100  displayValue.y = ToDisplay( aValue.y, REL_Y_COORD );
101  return displayValue;
102  }
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 131 of file origin_transforms.h.

133  {
134  T displayValue = aInternalValue;
135 
136  // Invert the direction if needed
137  if( aInvertAxis && (displayValue != static_cast<T>(0)) )
138  displayValue = -displayValue;
139 
140  return displayValue;
141  }

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