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.

102 lines
3.5 KiB

  1. /**
  2. * @file transform.h
  3. */
  4. /*
  5. * This program source code file is part of KiCad, a free EDA CAD application.
  6. *
  7. * Copyright (C) 2007-2010 Wayne Stambaugh <stambaughw@gmail.com>
  8. * Copyright (C) 2007-2021 KiCad Developers, see AUTHORS.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #ifndef _TRANSFORM_H_
  28. #define _TRANSFORM_H_
  29. #include <wx/gdicmn.h>
  30. #include <geometry/eda_angle.h>
  31. #include <math/box2.h>
  32. /**
  33. * for transforming drawing coordinates for a wxDC device context.
  34. *
  35. * This probably should be a base class with all pure virtual methods and a WXDC_TRANSFORM
  36. * derived class. Then in the future if some new device context is used, a new transform could
  37. * be derived from the base class and all the drawable objects would have to do is provide
  38. * overloaded draw methods to use the new transform.
  39. */
  40. class TRANSFORM
  41. {
  42. public:
  43. int x1;
  44. int y1;
  45. int x2;
  46. int y2;
  47. /**
  48. * The default construct creates a transform that draws object is the normal orientation.
  49. */
  50. TRANSFORM() : x1( 1 ), y1( 0 ), x2( 0 ), y2( -1 ) {}
  51. TRANSFORM( int ax1, int ay1, int ax2, int ay2 ) : x1( ax1 ), y1( ay1 ), x2( ax2 ), y2( ay2 ) {}
  52. bool operator==( const TRANSFORM& aTransform ) const;
  53. bool operator!=( const TRANSFORM& aTransform ) const { return !( *this == aTransform ); }
  54. /**
  55. * Calculate a new coordinate according to the mirror/rotation transform.
  56. * Useful to calculate actual coordinates of a point from coordinates relative to a symbol,
  57. * which are given for a non-rotated,-non mirrored item.
  58. * @param aPoint = The position to transform
  59. * @return The transformed coordinate.
  60. */
  61. VECTOR2I TransformCoordinate( const VECTOR2I& aPoint ) const;
  62. /**
  63. * Calculate a new rect according to the mirror/rotation transform.
  64. * Useful to calculate actual coordinates of a point from coordinates relative to a symbol,
  65. * which are given for a non-rotated,-non mirrored item.
  66. * @param aRect = The rectangle to transform
  67. * @return The transformed rectangle.
  68. */
  69. BOX2I TransformCoordinate( const BOX2I& aRect ) const;
  70. /**
  71. * Calculate the Inverse mirror/rotation transform.
  72. * Useful to calculate coordinates relative to a symbol, which must be for a non-rotated,
  73. * non-mirrored item from the actual coordinate.
  74. * @return The inverse transform.
  75. */
  76. TRANSFORM InverseTransform( ) const;
  77. /**
  78. * Calculate new angles according to the transform.
  79. *
  80. * @param aAngle1 = The first angle to transform
  81. * @param aAngle2 = The second angle to transform
  82. * @return True if the angles were swapped during the transform.
  83. */
  84. bool MapAngles( EDA_ANGLE* aAngle1, EDA_ANGLE* aAngle2 ) const;
  85. };
  86. #endif // _TRANSFORM_H_