You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
6.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019-2020 Reece R. Pollack <reece@his.com>
  5. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef PCB_ORIGIN_TRANSFORM_H_
  25. #define PCB_ORIGIN_TRANSFORM_H_ 1
  26. #include <origin_transforms.h>
  27. class PCB_BASE_FRAME;
  28. class PCB_ORIGIN_TRANSFORMS : public ORIGIN_TRANSFORMS
  29. {
  30. public:
  31. PCB_ORIGIN_TRANSFORMS( PCB_BASE_FRAME& aPcbBaseFrame );
  32. virtual ~PCB_ORIGIN_TRANSFORMS() override;
  33. using ORIGIN_TRANSFORMS::ToDisplay;
  34. virtual long long int ToDisplay( long long int aValue,
  35. COORD_TYPES_T aCoordType ) override;
  36. virtual double ToDisplay( double aValue,
  37. COORD_TYPES_T aCoordType ) override;
  38. using ORIGIN_TRANSFORMS::FromDisplay;
  39. virtual long long int FromDisplay( long long int aValue,
  40. COORD_TYPES_T aCoordType ) override;
  41. virtual double FromDisplay( double aValue,
  42. COORD_TYPES_T aCoordType ) override;
  43. /**
  44. * Transform a 2-D coordinate point referenced to the internal origin
  45. * to the equivalent point referenced to the user-selected display origin.
  46. *
  47. * @param aValue a point referenced to the internal origin
  48. * @returns the point re-referenced to the user-selected display origin
  49. */
  50. /**
  51. * Transform a 2-D coordinate point referenced to the user-selected
  52. * display origin to the equivalent point referenced to the internal origin.
  53. *
  54. * @param aValue a point referenced to the user-selected display origin
  55. * @returns the point re-referenced to the internal origin
  56. */
  57. /**
  58. * Transform a relative 2-D coordinate delta referenced to the user-selected
  59. * display origin to the equivalent delta referenced to the internal origin.
  60. *
  61. * This is initially intended to handle axis inversion of a delta between
  62. * two display points, but could be extended to handle other transforms.
  63. *
  64. * @param aValue a delta referenced to the internal origin
  65. * @returns the delta re-referenced to the user-selected display origin
  66. */
  67. /**
  68. * Transform a relative 2-D coordinate delta referenced to the user-selected
  69. * display origin to the equivalent delta referenced to the internal origin.
  70. *
  71. * This is initially intended to handle axis inversion of a delta between
  72. * two display points, but could be extended to handle other transforms.
  73. *
  74. * @param aValue a delta referenced to the user-selected display origin
  75. * @returns the delta re-referenced to the internal origin
  76. */
  77. // =============== Single-axis Relative Transforms ===============
  78. template<typename T>
  79. T ToDisplayRelX( T aInternalValue ) const
  80. {
  81. return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, m_invertXAxis );
  82. }
  83. template<typename T>
  84. T ToDisplayRelY( T aInternalValue ) const
  85. {
  86. return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, m_invertYAxis );
  87. }
  88. template<typename T>
  89. T FromDisplayRelX( T aDisplayValue ) const
  90. {
  91. return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, m_invertXAxis );
  92. }
  93. template<typename T>
  94. T FromDisplayRelY( T aDisplayValue ) const
  95. {
  96. return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, m_invertYAxis );
  97. }
  98. // =============== Single-axis Absolute Transforms ===============
  99. template<typename T>
  100. T ToDisplayAbsX( T aInternalValue ) const
  101. {
  102. return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, GetUserXOrigin(), m_invertXAxis );
  103. }
  104. template<typename T>
  105. T ToDisplayAbsY( T aInternalValue ) const
  106. {
  107. return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, GetUserYOrigin(), m_invertYAxis );
  108. }
  109. template<typename T>
  110. T FromDisplayAbsX( T aDisplayValue ) const
  111. {
  112. return ORIGIN_TRANSFORMS::FromDisplayAbs( aDisplayValue, GetUserXOrigin(), m_invertXAxis );
  113. }
  114. template<typename T>
  115. T FromDisplayAbsY( T aDisplayValue ) const
  116. {
  117. return ORIGIN_TRANSFORMS::FromDisplayAbs( aDisplayValue, GetUserYOrigin(), m_invertYAxis );
  118. }
  119. // =============== Two-axis Transforms ===============
  120. template<typename T>
  121. T ToDisplayAbs( T aInternalValue ) const
  122. {
  123. T displayValue;
  124. displayValue.x = ToDisplayAbsX( aInternalValue.x );
  125. displayValue.y = ToDisplayAbsY( aInternalValue.y );
  126. return displayValue;
  127. }
  128. template<typename T>
  129. T FromDisplayAbs( T aDisplayValue ) const
  130. {
  131. T internalValue;
  132. internalValue.x = FromDisplayAbsX( aDisplayValue.x );
  133. internalValue.y = FromDisplayAbsY( aDisplayValue.y );
  134. return internalValue;
  135. }
  136. template<typename T>
  137. T ToDisplayRel( T aInternalValue ) const
  138. {
  139. T displayValue;
  140. displayValue.x = ToDisplayRelX( aInternalValue.x );
  141. displayValue.y = ToDisplayRelY( aInternalValue.y );
  142. return displayValue;
  143. }
  144. template<typename T>
  145. T FromDisplayRel( T aDisplayValue ) const
  146. {
  147. T internalValue;
  148. internalValue.x = FromDisplayRelX( aDisplayValue.x );
  149. internalValue.y = FromDisplayRelY( aDisplayValue.y );
  150. return internalValue;
  151. }
  152. protected:
  153. const PCB_BASE_FRAME& m_pcbBaseFrame;
  154. const bool& m_invertXAxis;
  155. const bool& m_invertYAxis;
  156. int GetUserXOrigin() const;
  157. int GetUserYOrigin() const;
  158. };
  159. #endif // PCB_ORIGIN_TRANSFORMS_H_