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.

123 lines
4.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. #include <wx/debug.h> // for wxASSERT
  25. #include <pcb_base_frame.h>
  26. #include <pcb_display_options.h>
  27. #include <pcb_origin_transforms.h>
  28. using COORD_TYPE = ORIGIN_TRANSFORMS::COORD_TYPES_T;
  29. PCB_ORIGIN_TRANSFORMS::PCB_ORIGIN_TRANSFORMS( PCB_BASE_FRAME& aPcbBaseFrame )
  30. : m_pcbBaseFrame( aPcbBaseFrame ),
  31. m_invertXAxis( aPcbBaseFrame.GetDisplayOptions().m_DisplayInvertXAxis ),
  32. m_invertYAxis( aPcbBaseFrame.GetDisplayOptions().m_DisplayInvertYAxis )
  33. {}
  34. PCB_ORIGIN_TRANSFORMS::~PCB_ORIGIN_TRANSFORMS()
  35. {}
  36. long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue,
  37. COORD_TYPES_T aCoordType ) const
  38. {
  39. long long int value = aValue;
  40. switch( aCoordType )
  41. {
  42. case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
  43. case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
  44. case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
  45. case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
  46. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  47. default: wxASSERT( false ); break;
  48. };
  49. return value;
  50. }
  51. double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue,
  52. COORD_TYPES_T aCoordType ) const
  53. {
  54. double value = aValue;
  55. switch( aCoordType )
  56. {
  57. case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
  58. case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
  59. case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
  60. case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
  61. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  62. default: wxASSERT( false ); break;
  63. };
  64. return value;
  65. }
  66. long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue,
  67. COORD_TYPES_T aCoordType ) const
  68. {
  69. long long value = aValue;
  70. switch( aCoordType )
  71. {
  72. case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
  73. case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
  74. case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
  75. case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
  76. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  77. default: wxASSERT( false ); break;
  78. };
  79. return value;
  80. }
  81. double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue,
  82. COORD_TYPES_T aCoordType ) const
  83. {
  84. double value = aValue;
  85. switch( aCoordType )
  86. {
  87. case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
  88. case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
  89. case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
  90. case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
  91. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  92. default: wxASSERT( false ); break;
  93. };
  94. return value;
  95. }
  96. int PCB_ORIGIN_TRANSFORMS::GetUserXOrigin() const
  97. {
  98. return m_pcbBaseFrame.GetUserOrigin().x;
  99. }
  100. int PCB_ORIGIN_TRANSFORMS::GetUserYOrigin() const
  101. {
  102. return m_pcbBaseFrame.GetUserOrigin().y;
  103. }