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.

156 lines
5.2 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) 2022 Mike Williams
  6. * Copyright (C) 2011-2023 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef PCB_REFERENCE_IMAGE_H
  26. #define PCB_REFERENCE_IMAGE_H
  27. #include <board_item.h>
  28. #include <bitmap_base.h>
  29. /**
  30. * Object to handle a bitmap image that can be inserted in a PCB.
  31. */
  32. class PCB_REFERENCE_IMAGE : public BOARD_ITEM
  33. {
  34. public:
  35. PCB_REFERENCE_IMAGE( BOARD_ITEM* aParent, const VECTOR2I& pos = VECTOR2I( 0, 0 ),
  36. PCB_LAYER_ID aLayer = F_Cu );
  37. PCB_REFERENCE_IMAGE( const PCB_REFERENCE_IMAGE& aPcbBitmap );
  38. ~PCB_REFERENCE_IMAGE() { delete m_bitmapBase; }
  39. PCB_REFERENCE_IMAGE& operator=( const BOARD_ITEM& aItem );
  40. const BITMAP_BASE* GetImage() const
  41. {
  42. wxCHECK_MSG( m_bitmapBase != nullptr, nullptr,
  43. wxS( "Invalid PCB_REFERENCE_IMAGE init, m_bitmapBase is NULL." ) );
  44. return m_bitmapBase;
  45. }
  46. /**
  47. * Only use this if you really need to modify the underlying image
  48. */
  49. BITMAP_BASE* MutableImage() const
  50. {
  51. return m_bitmapBase;
  52. }
  53. /**
  54. * @return the image "zoom" value.
  55. * scale = 1.0 = original size of bitmap.
  56. * scale < 1.0 = the bitmap is drawn smaller than its original size.
  57. * scale > 1.0 = the bitmap is drawn bigger than its original size.
  58. */
  59. double GetImageScale() const { return m_bitmapBase->GetScale(); }
  60. void SetImageScale( double aScale ) { m_bitmapBase->SetScale( aScale ); }
  61. static inline bool ClassOf( const EDA_ITEM* aItem )
  62. {
  63. return aItem && PCB_REFERENCE_IMAGE_T == aItem->Type();
  64. }
  65. wxString GetClass() const override { return wxT( "PCB_REFERENCE_IMAGE" ); }
  66. /**
  67. * @return the actual size (in user units, not in pixels) of the image.
  68. */
  69. const VECTOR2I GetSize() const;
  70. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  71. const BOX2I GetBoundingBox() const override;
  72. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  73. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  74. //void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
  75. /// @copydoc VIEW_ITEM::ViewGetLayers()
  76. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  77. /**
  78. * Read and store an image file.
  79. *
  80. * Initialize the bitmap used to draw this item format.
  81. *
  82. * @param aFullFilename is the full filename of the image file to read.
  83. * @return true if success reading else false.
  84. */
  85. bool ReadImageFile( const wxString& aFullFilename );
  86. /**
  87. * Read and store an image file.
  88. *
  89. * Initialize the bitmap used to draw this item format.
  90. *
  91. * @param aBuf is the memory buffer containing the image file to read.
  92. * @return true if success reading else false.
  93. */
  94. bool ReadImageFile( wxMemoryBuffer& aBuf );
  95. void Move( const VECTOR2I& aMoveVector ) override { m_pos += aMoveVector; }
  96. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  97. void Rotate( const VECTOR2I& aCenter, const EDA_ANGLE& aAngle ) override;
  98. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
  99. {
  100. return wxString( _( "Reference Image" ) );
  101. }
  102. BITMAPS GetMenuImage() const override;
  103. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  104. VECTOR2I GetPosition() const override { return m_pos; }
  105. void SetPosition( const VECTOR2I& aPosition ) override { m_pos = aPosition; }
  106. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  107. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  108. EDA_ITEM* Clone() const override;
  109. double Similarity( const BOARD_ITEM& aBoardItem ) const override;
  110. bool operator==( const BOARD_ITEM& aBoardItem ) const override;
  111. #if defined( DEBUG )
  112. void Show( int nestLevel, std::ostream& os ) const override;
  113. #endif
  114. protected:
  115. void swapData( BOARD_ITEM* aItem ) override;
  116. private:
  117. VECTOR2I m_pos; // XY coordinates of center of the bitmap
  118. BITMAP_BASE* m_bitmapBase; // the BITMAP_BASE item
  119. };
  120. #endif // PCB_REFERENCE_IMAGE_H