KiCad PCB EDA Suite
class_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) 2013 jean-pierre.charras jp.charras at wanadoo.fr
5  * Copyright (C) 2013-2016 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 #ifndef _BITMAP_BASE_H_
26 #define _BITMAP_BASE_H_
27 
33 class PLOTTER;
34 
45 {
46 private:
47  double m_scale; // The scaling factor of the bitmap
48  // With m_pixelScaleFactor, controls the actual draw size
49  wxImage* m_image; // the raw image data (png format)
50  wxBitmap* m_bitmap; // the bitmap used to draw/plot image
51  double m_pixelScaleFactor; // The scaling factor of the bitmap
52  // to convert the bitmap size (in pixels)
53  // to internal KiCad units
54  // Usually does not change
55  int m_ppi; // the bitmap definition. the default is 300PPI
56 
57 
58 public:
59  BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
60 
61  BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
62 
64  {
65  delete m_bitmap;
66  delete m_image;
67  }
68 
69 
70  /*
71  * Accessors:
72  */
73  double GetPixelScaleFactor() const { return m_pixelScaleFactor; }
74  void SetPixelScaleFactor( double aSF ) { m_pixelScaleFactor = aSF; }
75  wxImage* GetImageData() { return m_image; }
76  void SetImage( wxImage* aImage )
77  {
78  delete m_image;
79  m_image = aImage;
80  }
81 
82  double GetScale() const { return m_scale; }
83  void SetScale( double aScale ) { m_scale = aScale; }
84 
85  /*
86  * Function RebuildBitmap
87  * Rebuild the internal bitmap used to draw/plot image
88  * must be called after a m_image change
89  */
90  void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
91 
92  void SetBitmap( wxBitmap* aBitMap )
93  {
94  delete m_bitmap;
95  m_bitmap = aBitMap;
96  }
97 
102  void ImportData( BITMAP_BASE* aItem );
103 
115  double GetScalingFactor() const
116  {
117  return m_pixelScaleFactor * m_scale;
118  }
119 
120 
125  wxSize GetSize() const;
126 
131  wxSize GetSizePixels() const
132  {
133  if( m_image )
134  return wxSize( m_image->GetWidth(), m_image->GetHeight() );
135  else
136  return wxSize( 0, 0 );
137  }
138 
143  int GetPPI() const
144  {
145  return m_ppi;
146  }
147 
156  const EDA_RECT GetBoundingBox() const;
157 
158  void DrawBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPos );
159 
170  bool ReadImageFile( const wxString& aFullFilename );
171 
179  bool SaveData( FILE* aFile ) const;
180 
187  void SaveData( wxArrayString& aPngStrings ) const;
188 
196  bool LoadData( LINE_READER& aLine, wxString& aErrorMsg );
197 
198 
206  void Mirror( bool aVertically );
207 
213  void Rotate( bool aRotateCCW );
214 
224  void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos,
225  COLOR4D aDefaultColor, int aDefaultPensize );
226 };
227 
228 
229 #endif // _BITMAP_BASE_H_
double GetPixelScaleFactor() const
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))
bool SaveData(FILE *aFile) const
writes the bitmap data to aFile The format is png, in Hexadecimal form: If the hexadecimal data is co...
wxSize GetSize() const
Function GetSize.
void SetScale(double aScale)
void RebuildBitmap()
wxImage * GetImageData()
void PlotImage(PLOTTER *aPlotter, const wxPoint &aPos, COLOR4D aDefaultColor, int aDefaultPensize)
Function PlotImage Plot bitmap on plotter.
const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
void Mirror(bool aVertically)
Function Mirror Mirror image vertically (i.e.
This class handle bitmap images in KiCad.
void SetBitmap(wxBitmap *aBitMap)
wxBitmap * m_bitmap
wxSize GetSizePixels() const
Function GetSizePixels.
double GetScale() const
double m_pixelScaleFactor
void SetPixelScaleFactor(double aSF)
Base plotter engine class.
Definition: plot_common.h:86
void ImportData(BITMAP_BASE *aItem)
Function ImportData Copy aItem image to me and update m_bitmap.
int GetPPI() const
Class EDA_RECT handles the component boundary box.
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData (png, in Hexadecimal form)
double GetScalingFactor() const
Function GetScalingFactor.
bool ReadImageFile(const wxString &aFullFilename)
Function ReadImageFile Reads and stores in memory an image file.
void DrawBitmap(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPos)
void Rotate(bool aRotateCCW)
Function Rotate Rotate image CW or CCW.
wxImage * m_image
void SetImage(wxImage *aImage)