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.

104 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@verizon.net>
  8. * Copyright (C) 2007-2017 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. class EDA_RECT;
  31. /**
  32. * Class for tranforming drawing coordinates for a wxDC device context.
  33. *
  34. * This probably should be a base class with all pure methods and a derived class
  35. * named WXDC_TRANFORM be created. Then in the future if some new device context
  36. * is used, a new transform could be derived from the base class and all the drawable
  37. * objects would have to do is provide overloaded draw methods to use the new transorm.
  38. */
  39. class TRANSFORM
  40. {
  41. public:
  42. int x1;
  43. int y1;
  44. int x2;
  45. int y2;
  46. /**
  47. * The default construct creates a tranform that draws object is the normal orientation.
  48. */
  49. TRANSFORM() : x1( 1 ), y1( 0 ), x2( 0 ), y2( -1 ) {}
  50. TRANSFORM( int ax1, int ay1, int ax2, int ay2 ) : x1( ax1 ), y1( ay1 ), x2( ax2 ), y2( ay2 ) {}
  51. bool operator==( const TRANSFORM& aTransform ) const;
  52. bool operator!=( const TRANSFORM& aTransform ) const { return !( *this == aTransform ); }
  53. /**
  54. * Calculate a new coordinate according to the mirror/rotation transform.
  55. * Useful to calculate actual coordinates of a point
  56. * from coordinates relative to a component
  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. wxPoint TransformCoordinate( const wxPoint& aPoint ) const;
  62. /**
  63. * Calculate a new rect according to the mirror/rotation transform.
  64. * Useful to calculate actual coordinates of a point
  65. * from coordinates relative to a component
  66. * which are given for a non rotated, non mirrored item
  67. * @param aRect = The rectangle to transform
  68. * @return The transformed rectangle.
  69. */
  70. EDA_RECT TransformCoordinate( const EDA_RECT& aRect ) const;
  71. /**
  72. * Calculate the Inverse mirror/rotation transform.
  73. * Useful to calculate coordinates relative to a component
  74. * which must be for a non rotated, non mirrored item
  75. * from the actual coordinate.
  76. * @return The inverse transform.
  77. */
  78. TRANSFORM InverseTransform( ) const;
  79. /**
  80. * Calculate new angles according to the transform.
  81. *
  82. * @param aAngle1 = The first angle to transform
  83. * @param aAngle2 = The second angle to transform
  84. * @return True if the angles were swapped during the transform.
  85. */
  86. bool MapAngles( int* aAngle1, int* aAngle2 ) const;
  87. };
  88. #endif // _TRANSFORM_H_