2011-08-31 14:59:20 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-08-31 14:59:20 +00:00
|
|
|
*
|
2018-01-29 08:39:13 +00:00
|
|
|
* Copyright (C) 2018 jean-pierre.charras jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2013-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-08-31 14:59:20 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2018-01-29 08:39:13 +00:00
|
|
|
#ifndef BITMAP_BASE_H
|
|
|
|
#define BITMAP_BASE_H
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2018-08-03 09:04:57 +00:00
|
|
|
#include <eda_rect.h>
|
|
|
|
|
2019-04-24 15:35:01 +00:00
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/image.h>
|
|
|
|
|
2019-05-23 18:31:15 +00:00
|
|
|
namespace KIGFX
|
|
|
|
{
|
2019-04-24 15:35:01 +00:00
|
|
|
class COLOR4D;
|
2019-05-23 18:31:15 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 15:35:01 +00:00
|
|
|
class LINE_READER;
|
2013-10-04 08:42:09 +00:00
|
|
|
class PLOTTER;
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2019-04-24 15:35:01 +00:00
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/**
|
2011-09-30 18:15:37 +00:00
|
|
|
* This class handle bitmap images in KiCad.
|
2018-04-08 10:28:59 +00:00
|
|
|
* It is not intended to be used alone, but inside another class,
|
2011-08-31 14:59:20 +00:00
|
|
|
* so all methods are protected ( or private )
|
2013-10-04 08:42:09 +00:00
|
|
|
* It is used in SCH_BITMAP class and WS_DRAW_ITEM_BITMAP (and other in future)
|
2011-08-31 14:59:20 +00:00
|
|
|
*
|
|
|
|
* Remember not all plotters are able to plot a bitmap
|
|
|
|
* Mainly GERBER plotters cannot.
|
|
|
|
*/
|
|
|
|
class BITMAP_BASE
|
|
|
|
{
|
|
|
|
private:
|
2016-07-11 19:48:46 +00:00
|
|
|
double m_scale; // The scaling factor of the bitmap
|
2020-11-28 09:53:26 +00:00
|
|
|
// With m_pixelSizeIu, controls the actual draw size
|
2011-08-31 14:59:20 +00:00
|
|
|
wxImage* m_image; // the raw image data (png format)
|
|
|
|
wxBitmap* m_bitmap; // the bitmap used to draw/plot image
|
2020-11-28 09:53:26 +00:00
|
|
|
double m_pixelSizeIu; // The scaling factor of the bitmap
|
2011-08-31 14:59:20 +00:00
|
|
|
// to convert the bitmap size (in pixels)
|
2011-09-30 18:15:37 +00:00
|
|
|
// to internal KiCad units
|
2011-08-31 14:59:20 +00:00
|
|
|
// Usually does not change
|
2013-10-19 10:29:54 +00:00
|
|
|
int m_ppi; // the bitmap definition. the default is 300PPI
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
public:
|
|
|
|
BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
BITMAP_BASE( const BITMAP_BASE& aSchBitmap );
|
|
|
|
|
|
|
|
~BITMAP_BASE()
|
|
|
|
{
|
|
|
|
delete m_bitmap;
|
|
|
|
delete m_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Accessors:
|
|
|
|
*/
|
2020-11-28 09:53:26 +00:00
|
|
|
double GetPixelSizeIu() const { return m_pixelSizeIu; }
|
|
|
|
void SetPixelSizeIu( double aPixSize ) { m_pixelSizeIu = aPixSize; }
|
2019-04-24 09:50:18 +00:00
|
|
|
|
2011-09-02 19:43:56 +00:00
|
|
|
wxImage* GetImageData() { return m_image; }
|
2019-04-24 09:50:18 +00:00
|
|
|
const wxImage* GetImageData() const { return m_image; }
|
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
void SetImage( wxImage* aImage )
|
|
|
|
{
|
|
|
|
delete m_image;
|
|
|
|
m_image = aImage;
|
|
|
|
}
|
2011-09-02 19:43:56 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
double GetScale() const { return m_scale; }
|
|
|
|
void SetScale( double aScale ) { m_scale = aScale; }
|
|
|
|
|
2011-09-02 19:43:56 +00:00
|
|
|
/*
|
|
|
|
* Function RebuildBitmap
|
|
|
|
* Rebuild the internal bitmap used to draw/plot image
|
|
|
|
* must be called after a m_image change
|
|
|
|
*/
|
|
|
|
void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2016-07-06 09:22:56 +00:00
|
|
|
void SetBitmap( wxBitmap* aBitMap )
|
|
|
|
{
|
|
|
|
delete m_bitmap;
|
|
|
|
m_bitmap = aBitMap;
|
|
|
|
}
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/**
|
|
|
|
* Function ImportData
|
|
|
|
* Copy aItem image to me and update m_bitmap
|
|
|
|
*/
|
|
|
|
void ImportData( BITMAP_BASE* aItem );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetScalingFactor
|
|
|
|
* @return the scaling factor from pixel size to actual draw size
|
2020-11-28 09:53:26 +00:00
|
|
|
* this scaling factor depends on m_pixelSizeIu and m_scale
|
|
|
|
* m_pixelSizeIu gives the scaling factor between a pixel size and
|
2011-08-31 14:59:20 +00:00
|
|
|
* the internal schematic units
|
2016-07-11 19:48:46 +00:00
|
|
|
* m_scale is an user dependant value, and gives the "zoom" value
|
|
|
|
* m_scale = 1.0 = original size of bitmap.
|
|
|
|
* m_scale < 1.0 = the bitmap is drawn smaller than its original size.
|
|
|
|
* m_scale > 1.0 = the bitmap is drawn bigger than its original size.
|
2011-08-31 14:59:20 +00:00
|
|
|
*/
|
|
|
|
double GetScalingFactor() const
|
|
|
|
{
|
2020-11-28 09:53:26 +00:00
|
|
|
return m_pixelSizeIu * m_scale;
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetSize
|
2013-10-04 08:42:09 +00:00
|
|
|
* @return the actual size (in user units, not in pixels) of the image
|
2011-08-31 14:59:20 +00:00
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
wxSize GetSize() const;
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2011-09-02 19:43:56 +00:00
|
|
|
/**
|
|
|
|
* Function GetSizePixels
|
2013-10-04 08:42:09 +00:00
|
|
|
* @return the size in pixels of the image
|
2011-09-02 19:43:56 +00:00
|
|
|
*/
|
|
|
|
wxSize GetSizePixels() const
|
|
|
|
{
|
|
|
|
if( m_image )
|
|
|
|
return wxSize( m_image->GetWidth(), m_image->GetHeight() );
|
|
|
|
else
|
2016-07-11 19:48:46 +00:00
|
|
|
return wxSize( 0, 0 );
|
2011-09-02 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
/**
|
|
|
|
* @return the bitmap definition in ppi
|
|
|
|
* the default is 300 ppi
|
|
|
|
*/
|
|
|
|
int GetPPI() const
|
|
|
|
{
|
2013-10-19 10:29:54 +00:00
|
|
|
return m_ppi;
|
2013-10-18 17:38:03 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/**
|
|
|
|
* Function GetBoundingBox
|
|
|
|
* returns the orthogonal, bounding box of this object for display
|
|
|
|
* purposes. This box should be an enclosing perimeter for visible
|
|
|
|
* components of this object, and the units should be in the pcb or
|
|
|
|
* schematic coordinate system. It is OK to overestimate the size
|
|
|
|
* by a few counts.
|
|
|
|
*/
|
2015-01-18 17:28:14 +00:00
|
|
|
const EDA_RECT GetBoundingBox() const;
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2018-08-03 09:04:57 +00:00
|
|
|
void DrawBitmap( wxDC* aDC, const wxPoint& aPos );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-04 08:42:09 +00:00
|
|
|
* Reads and stores in memory an image file.
|
2019-04-24 15:35:01 +00:00
|
|
|
*
|
2013-10-04 08:42:09 +00:00
|
|
|
* Init the bitmap format used to draw this item.
|
2011-08-31 14:59:20 +00:00
|
|
|
* supported images formats are format supported by wxImage
|
|
|
|
* if all handlers are loaded
|
2019-04-24 15:35:01 +00:00
|
|
|
* by default, .png, .jpeg are always loaded
|
|
|
|
*
|
2011-08-31 14:59:20 +00:00
|
|
|
* @param aFullFilename The full filename of the image file to read.
|
|
|
|
* @return bool - true if success reading else false.
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
bool ReadImageFile( const wxString& aFullFilename );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2019-04-24 15:35:01 +00:00
|
|
|
/**
|
|
|
|
* Reads and stores in memory an image file.
|
|
|
|
*
|
|
|
|
* Init the bitmap format used to draw this item.
|
|
|
|
* supported images formats are format supported by wxImage
|
|
|
|
* if all handlers are loaded
|
|
|
|
* by default, .png, .jpeg are always loaded
|
|
|
|
*
|
|
|
|
* @param aInStream an input stream containing the file data
|
|
|
|
* @return bool - true if success reading else false.
|
|
|
|
*/
|
|
|
|
bool ReadImageFile( wxInputStream& aInStream );
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/**
|
|
|
|
* writes the bitmap data to aFile
|
|
|
|
* The format is png, in Hexadecimal form:
|
|
|
|
* If the hexadecimal data is converted to binary it gives exactly a .png image data
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
bool SaveData( FILE* aFile ) const;
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
/**
|
|
|
|
* writes the bitmap data to an array string
|
|
|
|
* The format is png, in Hexadecimal form:
|
|
|
|
* If the hexadecimal data is converted to binary it gives exactly a .png image data
|
|
|
|
* @param aPngStrings The wxArrayString to write to.
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
void SaveData( wxArrayString& aPngStrings ) const;
|
2013-10-18 17:38:03 +00:00
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/**
|
|
|
|
* Load an image data saved by SaveData (png, in Hexadecimal form)
|
2013-10-18 17:38:03 +00:00
|
|
|
* @param aLine - the LINE_READER used to read the data file.
|
2011-08-31 14:59:20 +00:00
|
|
|
* @param aErrorMsg - Description of the error if an error occurs while loading the
|
|
|
|
* png bimap data.
|
|
|
|
* @return true if the bitmap loaded successfully.
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
bool LoadData( LINE_READER& aLine, wxString& aErrorMsg );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Mirror
|
|
|
|
* Mirror image vertically (i.e. relative to its horizontal X axis )
|
|
|
|
* or horizontally (i.e relative to its vertical Y axis)
|
|
|
|
* @param aVertically = false to mirror horizontally
|
|
|
|
* or true to mirror vertically
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
void Mirror( bool aVertically );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Rotate
|
|
|
|
* Rotate image CW or CCW.
|
|
|
|
* @param aRotateCCW = true to rotate CCW
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
void Rotate( bool aRotateCCW );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function PlotImage
|
|
|
|
* Plot bitmap on plotter.
|
|
|
|
* If the plotter does not support bitmaps, plot a
|
|
|
|
* @param aPlotter = the plotter to use
|
|
|
|
* @param aPos = the position od the center of the bitmap
|
|
|
|
* @param aDefaultColor = the color used to plot the rectangle when bitmap is not supported
|
|
|
|
* @param aDefaultPensize = the pen size used to plot the rectangle when bitmap is not supported
|
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos,
|
2019-05-23 18:31:15 +00:00
|
|
|
KIGFX::COLOR4D aDefaultColor, int aDefaultPensize );
|
2011-08-31 14:59:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-01-29 08:39:13 +00:00
|
|
|
#endif // BITMAP_BASE_H
|