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.

128 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-2021 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 <pcbnew_settings.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. {}
  32. PCB_ORIGIN_TRANSFORMS::~PCB_ORIGIN_TRANSFORMS()
  33. {}
  34. long long int PCB_ORIGIN_TRANSFORMS::ToDisplay( long long int aValue,
  35. COORD_TYPES_T aCoordType ) const
  36. {
  37. long long int value = aValue;
  38. switch( aCoordType )
  39. {
  40. case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
  41. case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
  42. case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
  43. case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
  44. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  45. default: wxASSERT( false ); break;
  46. };
  47. return value;
  48. }
  49. double PCB_ORIGIN_TRANSFORMS::ToDisplay( double aValue, COORD_TYPES_T aCoordType ) const
  50. {
  51. double value = aValue;
  52. switch( aCoordType )
  53. {
  54. case COORD_TYPE::ABS_X_COORD: value = ToDisplayAbsX( value ); break;
  55. case COORD_TYPE::ABS_Y_COORD: value = ToDisplayAbsY( value ); break;
  56. case COORD_TYPE::REL_X_COORD: value = ToDisplayRelX( value ); break;
  57. case COORD_TYPE::REL_Y_COORD: value = ToDisplayRelY( value ); break;
  58. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  59. default: wxASSERT( false ); break;
  60. };
  61. return value;
  62. }
  63. long long int PCB_ORIGIN_TRANSFORMS::FromDisplay( long long int aValue,
  64. COORD_TYPES_T aCoordType ) const
  65. {
  66. long long value = aValue;
  67. switch( aCoordType )
  68. {
  69. case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
  70. case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
  71. case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
  72. case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
  73. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  74. default: wxASSERT( false ); break;
  75. };
  76. return value;
  77. }
  78. double PCB_ORIGIN_TRANSFORMS::FromDisplay( double aValue, COORD_TYPES_T aCoordType ) const
  79. {
  80. double value = aValue;
  81. switch( aCoordType )
  82. {
  83. case COORD_TYPE::ABS_X_COORD: value = FromDisplayAbsX( value ); break;
  84. case COORD_TYPE::ABS_Y_COORD: value = FromDisplayAbsY( value ); break;
  85. case COORD_TYPE::REL_X_COORD: value = FromDisplayRelX( value ); break;
  86. case COORD_TYPE::REL_Y_COORD: value = FromDisplayRelY( value ); break;
  87. case COORD_TYPE::NOT_A_COORD: /* do nothing */ ; break;
  88. default: wxASSERT( false ); break;
  89. };
  90. return value;
  91. }
  92. int PCB_ORIGIN_TRANSFORMS::getUserXOrigin() const
  93. {
  94. return m_pcbBaseFrame.GetUserOrigin().x;
  95. }
  96. int PCB_ORIGIN_TRANSFORMS::getUserYOrigin() const
  97. {
  98. return m_pcbBaseFrame.GetUserOrigin().y;
  99. }
  100. bool PCB_ORIGIN_TRANSFORMS::invertXAxis() const
  101. {
  102. return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertXAxis;
  103. }
  104. bool PCB_ORIGIN_TRANSFORMS::invertYAxis() const
  105. {
  106. return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis;
  107. }