KiCad PCB EDA Suite
Loading...
Searching...
No Matches
reference_image.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <memory>
23
24#include <base_units.h>
25#include <core/mirror.h>
26#include <gal/color4d.h>
27#include <geometry/eda_angle.h>
28#include <math/box2.h>
29#include <math/vector2d.h>
30
31class BITMAP_BASE;
32class PLOTTER;
33
34class wxMemoryBuffer;
35class wxImage;
36
42{
43public:
44 REFERENCE_IMAGE( const EDA_IU_SCALE& aIuScale );
45 REFERENCE_IMAGE( const REFERENCE_IMAGE& aOther );
47
49
50 bool operator==( const REFERENCE_IMAGE& aOther ) const;
51
52 double Similarity( const REFERENCE_IMAGE& aOther ) const;
53
54 BOX2I GetBoundingBox() const;
55
56 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const;
57
58 VECTOR2I GetPosition() const;
59 void SetPosition( const VECTOR2I& aPos );
60
61 VECTOR2I GetSize() const;
62
69 double GetImageScale() const;
70
80 void SetImageScale( double aScale );
81
82 void SetWidth( int aWidth );
83 void SetHeight( int aHeight );
84
91 bool Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
92
100 void Rotate( const VECTOR2I& aCenter, const EDA_ANGLE& aAngle );
101
106
110 void SetOrientation( const EDA_ANGLE& aAngle );
111
112 double GetOpacity() const { return m_opacity; }
113 void SetOpacity( double aOpacity );
114
123 bool ReadImageFile( const wxString& aFullFilename );
124
133 bool ReadImageFile( wxMemoryBuffer& aBuf );
134
138 bool SetImage( const wxImage& aImage );
139
140 void PackToBytes( std::string& aOutputBytes ) const;
141 bool UnpackFromBytes( const std::string& aInputBytes );
142
143 void SwapData( REFERENCE_IMAGE& aItem );
144
150 const BITMAP_BASE& GetImage() const;
151
155 BITMAP_BASE& MutableImage() const;
156
167 void PlotImage( PLOTTER* aPlotter, const VECTOR2I& aPos, const KIGFX::COLOR4D& aDefaultColor,
168 int aDefaultPensize ) const;
169
170
175 void SetTransformOriginOffset( const VECTOR2I& aCenter );
176
177private:
178 void scaleBy( double ratio );
179
180 void updatePixelSizeInIU();
181
185 VECTOR2I boundingSize() const;
186
188
190
193
196
198 double m_opacity;
199
200 std::unique_ptr<BITMAP_BASE> m_bitmapBase;
201};
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
This class handle bitmap images in KiCad.
Definition bitmap_base.h:47
An "orientation", held as an angle constrained to the range [0, 360) degrees.
Definition eda_angle.h:473
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Base plotter engine class.
Definition plotter.h:138
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
BITMAP_BASE & MutableImage() const
Only use this if you really need to modify the underlying image.
const EDA_IU_SCALE & m_iuScale
EDA_ANGLE GetOrientation() const
void SwapData(REFERENCE_IMAGE &aItem)
bool Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
VECTOR2I m_pos
XY coordinates of center of the bitmap.
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
Rotate the image about aCenter.
void SetTransformOriginOffset(const VECTOR2I &aCenter)
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
VECTOR2I GetTransformOriginOffset() const
Get the center of scaling, etc, relative to the image center (GetPosition()).
VECTOR2I GetPosition() const
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot the image on a plotter, turned to its stored orientation.
EDA_ORIENTATION m_orientation
Rotation of the image content relative to the raster, in [0, 360).
bool SetImage(const wxImage &aImage)
Set the image from an existing wxImage.
std::unique_ptr< BITMAP_BASE > m_bitmapBase
REFERENCE_IMAGE & operator=(const REFERENCE_IMAGE &aOther)
double GetOpacity() const
void SetHeight(int aHeight)
VECTOR2I GetSize() const
VECTOR2I m_transformOriginOffset
Center of scaling, etc, relative to the image center.
bool UnpackFromBytes(const std::string &aInputBytes)
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation of the image content relative to the stored raster.
void SetOpacity(double aOpacity)
void SetPosition(const VECTOR2I &aPos)
void SetWidth(int aWidth)
bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy) const
const BITMAP_BASE & GetImage() const
Get the underlying image.
double Similarity(const REFERENCE_IMAGE &aOther) const
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
REFERENCE_IMAGE(const EDA_IU_SCALE &aIuScale)
VECTOR2I boundingSize() const
BOX2I GetBoundingBox() const
void scaleBy(double ratio)
void PackToBytes(std::string &aOutputBytes) const
double m_opacity
The opacity of the image, in the range [0, 1].
bool operator==(const REFERENCE_IMAGE &aOther) const
FLIP_DIRECTION
Definition mirror.h:23
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708