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.

172 lines
5.0 KiB

7 years ago
  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-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. /**
  25. * @file sch_bitmap.h
  26. */
  27. #ifndef _SCH_BITMAP_H_
  28. #define _SCH_BITMAP_H_
  29. #include <sch_item.h>
  30. #include <bitmap_base.h>
  31. /**
  32. * Object to handle a bitmap image that can be inserted in a schematic.
  33. */
  34. class SCH_BITMAP : public SCH_ITEM
  35. {
  36. public:
  37. SCH_BITMAP( const VECTOR2I& pos = VECTOR2I( 0, 0 ) );
  38. SCH_BITMAP( const SCH_BITMAP& aSchBitmap );
  39. ~SCH_BITMAP()
  40. {
  41. delete m_bitmapBase;
  42. }
  43. SCH_BITMAP& operator=( const SCH_ITEM& aItem );
  44. BITMAP_BASE* GetImage() const
  45. {
  46. wxCHECK_MSG( m_bitmapBase != nullptr, nullptr,
  47. "Invalid SCH_BITMAP init, m_bitmapBase is NULL." );
  48. return m_bitmapBase;
  49. }
  50. /**
  51. * @return the image "zoom" value.
  52. * scale = 1.0 = original size of bitmap.
  53. * scale < 1.0 = the bitmap is drawn smaller than its original size.
  54. * scale > 1.0 = the bitmap is drawn bigger than its original size.
  55. */
  56. double GetImageScale() const
  57. {
  58. return m_bitmapBase->GetScale();
  59. }
  60. void SetImageScale( double aScale )
  61. {
  62. m_bitmapBase->SetScale( aScale );
  63. }
  64. static inline bool ClassOf( const EDA_ITEM* aItem )
  65. {
  66. return aItem && SCH_BITMAP_T == aItem->Type();
  67. }
  68. wxString GetClass() const override
  69. {
  70. return wxT( "SCH_BITMAP" );
  71. }
  72. /**
  73. * @return the actual size (in user units, not in pixels) of the image.
  74. */
  75. VECTOR2I GetSize() const;
  76. const BOX2I GetBoundingBox() const override;
  77. void SwapData( SCH_ITEM* aItem ) override;
  78. void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
  79. /// @copydoc VIEW_ITEM::ViewGetLayers()
  80. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  81. /**
  82. * Read and store an image file.
  83. *
  84. * Initialize the bitmap used to draw this item format.
  85. *
  86. * @param aFullFilename is the full filename of the image file to read.
  87. * @return true if success reading else false.
  88. */
  89. bool ReadImageFile( const wxString& aFullFilename );
  90. /**
  91. * Read and store an image file.
  92. *
  93. * Initialize the bitmap used to draw this item format.
  94. *
  95. * @param aBuf is the memory buffer containing the image file to read.
  96. * @return true if success reading else false.
  97. */
  98. bool ReadImageFile( wxMemoryBuffer& aBuf );
  99. void Move( const VECTOR2I& aMoveVector ) override
  100. {
  101. m_pos += aMoveVector;
  102. }
  103. /**
  104. * Return true for items which are moved with the anchor point at mouse cursor and false
  105. * for items moved with no reference to anchor.
  106. *
  107. * @return false for a bus entry.
  108. */
  109. bool IsMovableFromAnchorPoint() const override { return false; }
  110. void MirrorHorizontally( int aCenter ) override;
  111. void MirrorVertically( int aCenter ) override;
  112. void Rotate( const VECTOR2I& aCenter ) override;
  113. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
  114. {
  115. return wxString( _( "Image" ) );
  116. }
  117. BITMAPS GetMenuImage() const override;
  118. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  119. VECTOR2I GetPosition() const override { return m_pos; }
  120. void SetPosition( const VECTOR2I& aPosition ) override { m_pos = aPosition; }
  121. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  122. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  123. void Plot( PLOTTER* aPlotter, bool aBackground,
  124. const SCH_PLOT_SETTINGS& aPlotSettings ) const override;
  125. EDA_ITEM* Clone() const override;
  126. double Similarity( const SCH_ITEM& aOther ) const override;
  127. bool operator==( const SCH_ITEM& aOther ) const override;
  128. #if defined(DEBUG)
  129. void Show( int nestLevel, std::ostream& os ) const override;
  130. #endif
  131. private:
  132. VECTOR2I m_pos; // XY coordinates of center of the bitmap
  133. BITMAP_BASE* m_bitmapBase; // the BITMAP_BASE item
  134. };
  135. #endif // _SCH_BITMAP_H_