KiCad PCB EDA Suite
bitmap_base.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 jean-pierre.charras jp.charras at wanadoo.fr
5  * Copyright (C) 2013-2020 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 #ifndef BITMAP_BASE_H
26 #define BITMAP_BASE_H
27 
28 #include <eda_rect.h>
29 
30 #include <wx/bitmap.h>
31 #include <wx/image.h>
32 
33 namespace KIGFX
34 {
35 class COLOR4D;
36 }
37 
38 class LINE_READER;
39 class PLOTTER;
40 
41 
52 {
53 public:
54  BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
55 
56  BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
57 
59  {
60  delete m_bitmap;
61  delete m_image;
62  }
63 
64  /*
65  * Accessors:
66  */
67  double GetPixelSizeIu() const { return m_pixelSizeIu; }
68  void SetPixelSizeIu( double aPixSize ) { m_pixelSizeIu = aPixSize; }
69 
70  wxImage* GetImageData() { return m_image; }
71  const wxImage* GetImageData() const { return m_image; }
72 
73  void SetImage( wxImage* aImage )
74  {
75  delete m_image;
76  m_image = aImage;
77  }
78 
79  double GetScale() const { return m_scale; }
80  void SetScale( double aScale ) { m_scale = aScale; }
81 
82  /*
83  * Rebuild the internal bitmap used to draw/plot image.
84  *
85  * This must be called after a #m_image change.
86  */
87  void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
88 
89  void SetBitmap( wxBitmap* aBitMap )
90  {
91  delete m_bitmap;
92  m_bitmap = aBitMap;
93  }
94 
98  void ImportData( BITMAP_BASE* aItem );
99 
111  double GetScalingFactor() const
112  {
113  return m_pixelSizeIu * m_scale;
114  }
115 
119  wxSize GetSize() const;
120 
124  wxSize GetSizePixels() const
125  {
126  if( m_image )
127  return wxSize( m_image->GetWidth(), m_image->GetHeight() );
128  else
129  return wxSize( 0, 0 );
130  }
131 
135  int GetPPI() const
136  {
137  return m_ppi;
138  }
139 
147  const EDA_RECT GetBoundingBox() const;
148 
149  void DrawBitmap( wxDC* aDC, const wxPoint& aPos );
150 
161  bool ReadImageFile( const wxString& aFullFilename );
162 
174  bool ReadImageFile( wxInputStream& aInStream );
175 
185  bool SaveData( FILE* aFile ) const;
186 
195  void SaveData( wxArrayString& aPngStrings ) const;
196 
207  bool LoadData( LINE_READER& aLine, wxString& aErrorMsg );
208 
214  void Mirror( bool aVertically );
215 
221  void Rotate( bool aRotateCCW );
222 
233  void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos,
234  KIGFX::COLOR4D aDefaultColor, int aDefaultPensize ) const;
235 
236 private:
237  double m_scale; // The scaling factor of the bitmap
238  // With m_pixelSizeIu, controls the actual draw size
239  wxImage* m_image; // the raw image data (png format)
240  wxBitmap* m_bitmap; // the bitmap used to draw/plot image
241  double m_pixelSizeIu; // The scaling factor of the bitmap
242  // to convert the bitmap size (in pixels)
243  // to internal KiCad units
244  // Usually does not change
245  int m_ppi; // the bitmap definition. the default is 300PPI
246 };
247 
248 
249 #endif // BITMAP_BASE_H
double GetScalingFactor() const
This scaling factor depends on m_pixelSizeIu and m_scale.
Definition: bitmap_base.h:111
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
BITMAP_BASE(const wxPoint &pos=wxPoint(0, 0))
Definition: bitmap_base.cpp:45
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
bool SaveData(FILE *aFile) const
Write the bitmap data to aFile.
void SetScale(double aScale)
Definition: bitmap_base.h:80
void RebuildBitmap()
Definition: bitmap_base.h:87
double GetScale() const
Definition: bitmap_base.h:79
wxImage * GetImageData()
Definition: bitmap_base.h:70
const wxImage * GetImageData() const
Definition: bitmap_base.h:71
void Mirror(bool aVertically)
Mirror image vertically (i.e.
const EDA_RECT GetBoundingBox() const
Return the orthogonal, bounding box of this object for display purposes.
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:51
double m_scale
Definition: bitmap_base.h:237
void SetBitmap(wxBitmap *aBitMap)
Definition: bitmap_base.h:89
wxSize GetSize() const
wxBitmap * m_bitmap
Definition: bitmap_base.h:240
void SetPixelSizeIu(double aPixSize)
Definition: bitmap_base.h:68
double GetPixelSizeIu() const
Definition: bitmap_base.h:67
Base plotter engine class.
Definition: plotter.h:121
void ImportData(BITMAP_BASE *aItem)
Copy aItem image to this object and update m_bitmap.
Definition: bitmap_base.cpp:77
Handle the component boundary box.
Definition: eda_rect.h:42
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData.
wxSize GetSizePixels() const
Definition: bitmap_base.h:124
void DrawBitmap(wxDC *aDC, const wxPoint &aPos)
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, KIGFX::COLOR4D aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
void Rotate(bool aRotateCCW)
Rotate image CW or CCW.
double m_pixelSizeIu
Definition: bitmap_base.h:241
int GetPPI() const
Definition: bitmap_base.h:135
wxImage * m_image
Definition: bitmap_base.h:239
void SetImage(wxImage *aImage)
Definition: bitmap_base.h:73
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98