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-2018 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 private:
54  double m_scale; // The scaling factor of the bitmap
55  // With m_pixelScaleFactor, controls the actual draw size
56  wxImage* m_image; // the raw image data (png format)
57  wxBitmap* m_bitmap; // the bitmap used to draw/plot image
58  double m_pixelScaleFactor; // The scaling factor of the bitmap
59  // to convert the bitmap size (in pixels)
60  // to internal KiCad units
61  // Usually does not change
62  int m_ppi; // the bitmap definition. the default is 300PPI
63 
64 
65 public:
66  BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
67 
68  BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
69 
71  {
72  delete m_bitmap;
73  delete m_image;
74  }
75 
76 
77  /*
78  * Accessors:
79  */
80  double GetPixelScaleFactor() const { return m_pixelScaleFactor; }
81  void SetPixelScaleFactor( double aSF ) { m_pixelScaleFactor = aSF; }
82 
83  wxImage* GetImageData() { return m_image; }
84  const wxImage* GetImageData() const { return m_image; }
85 
86  void SetImage( wxImage* aImage )
87  {
88  delete m_image;
89  m_image = aImage;
90  }
91 
92  double GetScale() const { return m_scale; }
93  void SetScale( double aScale ) { m_scale = aScale; }
94 
95  /*
96  * Function RebuildBitmap
97  * Rebuild the internal bitmap used to draw/plot image
98  * must be called after a m_image change
99  */
100  void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
101 
102  void SetBitmap( wxBitmap* aBitMap )
103  {
104  delete m_bitmap;
105  m_bitmap = aBitMap;
106  }
107 
112  void ImportData( BITMAP_BASE* aItem );
113 
125  double GetScalingFactor() const
126  {
127  return m_pixelScaleFactor * m_scale;
128  }
129 
130 
135  wxSize GetSize() const;
136 
141  wxSize GetSizePixels() const
142  {
143  if( m_image )
144  return wxSize( m_image->GetWidth(), m_image->GetHeight() );
145  else
146  return wxSize( 0, 0 );
147  }
148 
153  int GetPPI() const
154  {
155  return m_ppi;
156  }
157 
166  const EDA_RECT GetBoundingBox() const;
167 
168  void DrawBitmap( wxDC* aDC, const wxPoint& aPos );
169 
181  bool ReadImageFile( const wxString& aFullFilename );
182 
194  bool ReadImageFile( wxInputStream& aInStream );
195 
203  bool SaveData( FILE* aFile ) const;
204 
211  void SaveData( wxArrayString& aPngStrings ) const;
212 
220  bool LoadData( LINE_READER& aLine, wxString& aErrorMsg );
221 
222 
230  void Mirror( bool aVertically );
231 
237  void Rotate( bool aRotateCCW );
238 
248  void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos,
249  KIGFX::COLOR4D aDefaultColor, int aDefaultPensize );
250 };
251 
252 
253 #endif // BITMAP_BASE_H
double GetScalingFactor() const
Function GetScalingFactor.
Definition: bitmap_base.h:125
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
BITMAP_BASE(const wxPoint &pos=wxPoint(0, 0))
Definition: bitmap_base.cpp:46
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
bool SaveData(FILE *aFile) const
writes the bitmap data to aFile The format is png, in Hexadecimal form: If the hexadecimal data is co...
void SetScale(double aScale)
Definition: bitmap_base.h:93
void RebuildBitmap()
Definition: bitmap_base.h:100
double GetScale() const
Definition: bitmap_base.h:92
wxImage * GetImageData()
Definition: bitmap_base.h:83
const wxImage * GetImageData() const
Definition: bitmap_base.h:84
void Mirror(bool aVertically)
Function Mirror Mirror image vertically (i.e.
const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
double GetPixelScaleFactor() const
Definition: bitmap_base.h:80
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:51
double m_scale
Definition: bitmap_base.h:54
void SetBitmap(wxBitmap *aBitMap)
Definition: bitmap_base.h:102
wxSize GetSize() const
Function GetSize.
wxBitmap * m_bitmap
Definition: bitmap_base.h:57
double m_pixelScaleFactor
Definition: bitmap_base.h:58
void SetPixelScaleFactor(double aSF)
Definition: bitmap_base.h:81
Base plotter engine class.
Definition: plotter.h:97
void ImportData(BITMAP_BASE *aItem)
Function ImportData Copy aItem image to me and update m_bitmap.
Definition: bitmap_base.cpp:78
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, KIGFX::COLOR4D aDefaultColor, int aDefaultPensize)
Function PlotImage Plot bitmap on plotter.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData (png, in Hexadecimal form)
wxSize GetSizePixels() const
Function GetSizePixels.
Definition: bitmap_base.h:141
void DrawBitmap(wxDC *aDC, const wxPoint &aPos)
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores in memory an image file.
void Rotate(bool aRotateCCW)
Function Rotate Rotate image CW or CCW.
int GetPPI() const
Definition: bitmap_base.h:153
wxImage * m_image
Definition: bitmap_base.h:56
void SetImage(wxImage *aImage)
Definition: bitmap_base.h:86
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39