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.

151 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2011 jean-pierre.charras
  5. * Copyright (C) 2011-2017 KiCad Developers, see change_log.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. /**
  25. * @file sch_bitmap.h
  26. *
  27. */
  28. #ifndef _SCH_BITMAP_H_
  29. #define _SCH_BITMAP_H_
  30. #include <sch_item_struct.h>
  31. #include <bitmap_base.h>
  32. /**
  33. * Object to handle a bitmap image that can be inserted in a schematic.
  34. */
  35. class SCH_BITMAP : public SCH_ITEM
  36. {
  37. wxPoint m_pos; // XY coordinates of center of the bitmap
  38. BITMAP_BASE* m_image; // the BITMAP_BASE item
  39. public:
  40. SCH_BITMAP( const wxPoint& pos = wxPoint( 0, 0 ) );
  41. SCH_BITMAP( const SCH_BITMAP& aSchBitmap );
  42. ~SCH_BITMAP()
  43. {
  44. delete m_image;
  45. }
  46. SCH_ITEM& operator=( const SCH_ITEM& aItem );
  47. /*
  48. * Accessors:
  49. */
  50. double GetPixelScaleFactor() const { return m_image->GetPixelScaleFactor(); }
  51. void SetPixelScaleFactor( double aSF ) { m_image->SetPixelScaleFactor( aSF ); }
  52. BITMAP_BASE* GetImage()
  53. {
  54. wxCHECK_MSG( m_image != NULL, NULL, "Invalid SCH_BITMAP initialization, m_image is NULL." );
  55. return m_image;
  56. }
  57. /**
  58. * @return the scaling factor from pixel size to actual draw size
  59. * this scaling factor depend on m_pixelScaleFactor and m_Scale
  60. * m_pixelScaleFactor gives the scaling factor between a pixel size and
  61. * the internal schematic units
  62. * m_Scale is an user dependant value, and gives the "zoom" value
  63. * m_Scale = 1.0 = original size of bitmap.
  64. * m_Scale < 1.0 = the bitmap is drawn smaller than its original size.
  65. * m_Scale > 1.0 = the bitmap is drawn bigger than its original size.
  66. */
  67. double GetScalingFactor() const
  68. {
  69. return m_image->GetScalingFactor();
  70. }
  71. wxString GetClass() const override
  72. {
  73. return wxT( "SCH_BITMAP" );
  74. }
  75. /**
  76. * @return the actual size (in user units, not in pixels) of the image
  77. */
  78. wxSize GetSize() const;
  79. const EDA_RECT GetBoundingBox() const override;
  80. void SwapData( SCH_ITEM* aItem ) override;
  81. void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  82. GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
  83. /**
  84. * Reads and stores an image file. Init the bitmap used to draw this item
  85. * format.
  86. *
  87. * @param aFullFilename The full filename of the image file to read.
  88. * @return bool - true if success reading else false.
  89. */
  90. bool ReadImageFile( const wxString& aFullFilename );
  91. void Move( const wxPoint& aMoveVector ) override
  92. {
  93. m_pos += aMoveVector;
  94. }
  95. void MirrorY( int aYaxis_position ) override;
  96. void MirrorX( int aXaxis_position ) override;
  97. void Rotate( wxPoint aPosition ) override;
  98. bool IsSelectStateChanged( const wxRect& aRect ) override;
  99. wxString GetSelectMenuText() const override { return wxString( _( "Image" ) ); }
  100. BITMAP_DEF GetMenuImage() const override;
  101. wxPoint GetPosition() const override { return m_pos; }
  102. void SetPosition( const wxPoint& aPosition ) override { m_pos = aPosition; }
  103. bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
  104. bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const override;
  105. void Plot( PLOTTER* aPlotter ) override;
  106. EDA_ITEM* Clone() const override;
  107. #if defined(DEBUG)
  108. void Show( int nestLevel, std::ostream& os ) const override;
  109. #endif
  110. };
  111. #endif // _SCH_BITMAP_H_