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
4.5 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-2019 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.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_BITMAP& operator=( const SCH_ITEM& aItem );
  47. BITMAP_BASE* GetImage()
  48. {
  49. wxCHECK_MSG( m_image != NULL, NULL, "Invalid SCH_BITMAP init, m_image is NULL." );
  50. return m_image;
  51. }
  52. /**
  53. * @return the image "zoom" value
  54. * scale = 1.0 = original size of bitmap.
  55. * scale < 1.0 = the bitmap is drawn smaller than its original size.
  56. * scale > 1.0 = the bitmap is drawn bigger than its original size.
  57. */
  58. double GetImageScale() const
  59. {
  60. return m_image->GetScale();
  61. }
  62. void SetImageScale( double aScale )
  63. {
  64. m_image->SetScale( aScale );
  65. }
  66. static inline bool ClassOf( const EDA_ITEM* aItem )
  67. {
  68. return aItem && SCH_BITMAP_T == aItem->Type();
  69. }
  70. wxString GetClass() const override
  71. {
  72. return wxT( "SCH_BITMAP" );
  73. }
  74. /**
  75. * @return the actual size (in user units, not in pixels) of the image
  76. */
  77. wxSize GetSize() const;
  78. const EDA_RECT GetBoundingBox() const override;
  79. void SwapData( SCH_ITEM* aItem ) override;
  80. void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
  81. /// @copydoc VIEW_ITEM::ViewGetLayers()
  82. virtual void ViewGetLayers( int aLayers[], int& aCount ) const 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. /**
  96. * Virtual function IsMovableFromAnchorPoint
  97. * Return true for items which are moved with the anchor point at mouse cursor
  98. * and false for items moved with no reference to anchor
  99. * @return false for a bus entry
  100. */
  101. bool IsMovableFromAnchorPoint() override { return false; }
  102. void MirrorY( int aYaxis_position ) override;
  103. void MirrorX( int aXaxis_position ) override;
  104. void Rotate( wxPoint aPosition ) override;
  105. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override
  106. {
  107. return wxString( _( "Image" ) );
  108. }
  109. BITMAP_DEF GetMenuImage() const override;
  110. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  111. wxPoint GetPosition() const override { return m_pos; }
  112. void SetPosition( const wxPoint& aPosition ) override { m_pos = aPosition; }
  113. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  114. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  115. void Plot( PLOTTER* aPlotter ) override;
  116. EDA_ITEM* Clone() const override;
  117. #if defined(DEBUG)
  118. void Show( int nestLevel, std::ostream& os ) const override;
  119. #endif
  120. };
  121. #endif // _SCH_BITMAP_H_