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.

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