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.

203 lines
6.2 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 The 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_
  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, COORD_TYPES_T aCoordType ) const override;
  35. virtual double ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const override;
  36. using ORIGIN_TRANSFORMS::FromDisplay;
  37. virtual long long int FromDisplay( long long int aValue, COORD_TYPES_T aCoordType ) const override;
  38. virtual double FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const override;
  39. /**
  40. * Transform a 2-D coordinate point referenced to the internal origin
  41. * to the equivalent point referenced to the user-selected display origin.
  42. *
  43. * @param aValue a point referenced to the internal origin
  44. * @returns the point re-referenced to the user-selected display origin
  45. */
  46. /**
  47. * Transform a 2-D coordinate point referenced to the user-selected
  48. * display origin to the equivalent point referenced to the internal origin.
  49. *
  50. * @param aValue a point referenced to the user-selected display origin
  51. * @returns the point re-referenced to the internal origin
  52. */
  53. /**
  54. * Transform a relative 2-D coordinate delta referenced to the user-selected
  55. * display origin to the equivalent delta referenced to the internal origin.
  56. *
  57. * This is initially intended to handle axis inversion of a delta between
  58. * two display points, but could be extended to handle other transforms.
  59. *
  60. * @param aValue a delta referenced to the internal origin
  61. * @returns the delta re-referenced to the user-selected display origin
  62. */
  63. /**
  64. * Transform a relative 2-D coordinate delta referenced to the user-selected
  65. * display origin to the equivalent delta referenced to the internal origin.
  66. *
  67. * This is initially intended to handle axis inversion of a delta between
  68. * two display points, but could be extended to handle other transforms.
  69. *
  70. * @param aValue a delta referenced to the user-selected display origin
  71. * @returns the delta re-referenced to the internal origin
  72. */
  73. // =============== Single-axis Relative Transforms ===============
  74. template<typename T>
  75. T ToDisplayRelX( T aInternalValue ) const
  76. {
  77. return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertXAxis() );
  78. }
  79. template<typename T>
  80. T ToDisplayRelY( T aInternalValue ) const
  81. {
  82. return ORIGIN_TRANSFORMS::ToDisplayRel( aInternalValue, invertYAxis() );
  83. }
  84. template<typename T>
  85. T FromDisplayRelX( T aDisplayValue ) const
  86. {
  87. return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertXAxis() );
  88. }
  89. template<typename T>
  90. T FromDisplayRelY( T aDisplayValue ) const
  91. {
  92. return ORIGIN_TRANSFORMS::FromDisplayRel( aDisplayValue, invertYAxis() );
  93. }
  94. // =============== Single-axis Absolute Transforms ===============
  95. template<typename T>
  96. T ToDisplayAbsX( T aInternalValue ) const
  97. {
  98. return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserXOrigin(), invertXAxis() );
  99. }
  100. template<typename T>
  101. T ToDisplayAbsY( T aInternalValue ) const
  102. {
  103. return ORIGIN_TRANSFORMS::ToDisplayAbs( aInternalValue, getUserYOrigin(), invertYAxis() );
  104. }
  105. template<typename T>
  106. T FromDisplayAbsX( T aDisplayValue ) const
  107. {
  108. return ORIGIN_TRANSFORMS::FromDisplayAbs( aDisplayValue, getUserXOrigin(), invertXAxis() );
  109. }
  110. template<typename T>
  111. T FromDisplayAbsY( T aDisplayValue ) const
  112. {
  113. return ORIGIN_TRANSFORMS::FromDisplayAbs( aDisplayValue, getUserYOrigin(), invertYAxis() );
  114. }
  115. // =============== Two-axis Transforms ===============
  116. template<typename T>
  117. T ToDisplayAbs( T aInternalValue ) const
  118. {
  119. T displayValue;
  120. displayValue.x = ToDisplayAbsX( aInternalValue.x );
  121. displayValue.y = ToDisplayAbsY( aInternalValue.y );
  122. return displayValue;
  123. }
  124. template<typename T>
  125. T FromDisplayAbs( T aDisplayValue ) const
  126. {
  127. T internalValue;
  128. internalValue.x = FromDisplayAbsX( aDisplayValue.x );
  129. internalValue.y = FromDisplayAbsY( aDisplayValue.y );
  130. return internalValue;
  131. }
  132. template<typename T>
  133. T ToDisplayRel( T aInternalValue ) const
  134. {
  135. T displayValue;
  136. displayValue.x = ToDisplayRelX( aInternalValue.x );
  137. displayValue.y = ToDisplayRelY( aInternalValue.y );
  138. return displayValue;
  139. }
  140. template<typename T>
  141. T FromDisplayRel( T aDisplayValue ) const
  142. {
  143. T internalValue;
  144. internalValue.x = FromDisplayRelX( aDisplayValue.x );
  145. internalValue.y = FromDisplayRelY( aDisplayValue.y );
  146. return internalValue;
  147. }
  148. protected:
  149. int getUserXOrigin() const;
  150. int getUserYOrigin() const;
  151. bool invertXAxis() const;
  152. bool invertYAxis() const;
  153. protected:
  154. const PCB_BASE_FRAME& m_pcbBaseFrame;
  155. };
  156. #endif // PCB_ORIGIN_TRANSFORMS_H_