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 (C) 2024 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <memory>
27
28#include <base_units.h>
29#include <core/mirror.h>
30#include <math/box2.h>
31#include <math/vector2d.h>
32
33class BITMAP_BASE;
34
35class wxMemoryBuffer;
36class wxImage;
37
43{
44public:
45 REFERENCE_IMAGE( const EDA_IU_SCALE& aIuScale );
46 REFERENCE_IMAGE( const REFERENCE_IMAGE& aOther );
48
50
51 bool operator==( const REFERENCE_IMAGE& aOther ) const;
52
53 double Similarity( const REFERENCE_IMAGE& aOther ) const;
54
55 BOX2I GetBoundingBox() const;
56
57 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const;
58
59 VECTOR2I GetPosition() const;
60 void SetPosition( const VECTOR2I& aPos );
61
62 VECTOR2I GetSize() const;
63
70 double GetImageScale() const;
71
81 void SetImageScale( double aScale );
82
83 void SetWidth( int aWidth );
84 void SetHeight( int aHeight );
85
86 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
87
88 void Rotate( const VECTOR2I& aCenter, const EDA_ANGLE& aAngle );
89
98 bool ReadImageFile( const wxString& aFullFilename );
99
108 bool ReadImageFile( wxMemoryBuffer& aBuf );
109
113 bool SetImage( const wxImage& aImage );
114
115 void SwapData( REFERENCE_IMAGE& aItem );
116
122 const BITMAP_BASE& GetImage() const;
123
127 BITMAP_BASE& MutableImage() const;
128
129
134 void SetTransformOriginOffset( const VECTOR2I& aCenter );
135
136private:
137 void scaleBy( double ratio );
138
139 void updatePixelSizeInIU();
140
142
143 VECTOR2I m_pos; // XY coordinates of center of the bitmap
146
147 std::unique_ptr<BITMAP_BASE> m_bitmapBase;
148};
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:49
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
void SwapData(REFERENCE_IMAGE &aItem)
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
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 Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
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)
void SetHeight(int aHeight)
VECTOR2I GetSize() const
VECTOR2I m_transformOriginOffset
< Center of scaling, etc, relative to the image center
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.
BOX2I GetBoundingBox() const
void scaleBy(double ratio)
bool operator==(const REFERENCE_IMAGE &aOther) const
FLIP_DIRECTION
Definition: mirror.h:27