KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_bitmap.cpp
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) 2011 jean-pierre.charras
5 * Copyright (C) 2011-2023 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
28#include "sch_bitmap.h"
29
30#include <bitmap_base.h>
31#include <bitmaps.h>
32#include <base_units.h>
33#include <common.h>
34#include <core/mirror.h>
35#include <eda_draw_frame.h>
37#include <plotters/plotter.h>
38#include <sch_draw_panel.h>
40#include <trigo.h>
41
42#include <wx/mstream.h>
43
44
46 SCH_ITEM( nullptr, SCH_BITMAP_T ),
47 m_referenceImage( schIUScale)
48{
50 m_layer = LAYER_NOTES; // used only to draw/plot a rectangle,
51 // when a bitmap cannot be drawn or plotted
52}
53
54
55SCH_BITMAP::SCH_BITMAP( const SCH_BITMAP& aSchBitmap ) :
56 SCH_ITEM( aSchBitmap ),
57 m_referenceImage( aSchBitmap.m_referenceImage )
58{
59}
60
61
63{
64 wxCHECK_MSG( Type() == aItem.Type(), *this,
65 wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
66 GetClass() );
67
68 if( &aItem != this )
69 {
70 SCH_ITEM::operator=( aItem );
71
72 const SCH_BITMAP& bitmap = static_cast<const SCH_BITMAP&>( aItem );
74 }
75
76 return *this;
77}
78
79
81{
82 return new SCH_BITMAP( *this );
83}
84
85
87{
88 SCH_ITEM::SwapFlags( aItem );
89
90 wxCHECK_RET( aItem->Type() == SCH_BITMAP_T,
91 wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ),
92 aItem->GetClass() ) );
93
94 SCH_BITMAP* item = (SCH_BITMAP*) aItem;
96}
97
98
100{
102}
103
104
105void SCH_BITMAP::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
106 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
107{
108 VECTOR2I pos = GetPosition() + aOffset;
109
110 m_referenceImage.GetImage().DrawBitmap( aSettings->GetPrintDC(), pos,
111 aSettings->GetBackgroundColor() );
112}
113
114
116{
118}
119
120
121void SCH_BITMAP::SetPosition( const VECTOR2I& aPosition )
122{
123 m_referenceImage.SetPosition( aPosition );
124}
125
126
127void SCH_BITMAP::Move( const VECTOR2I& aMoveVector )
128{
129 SetPosition( GetPosition() + aMoveVector );
130}
131
132
134{
135 m_referenceImage.Flip( VECTOR2I( 0, aCenter ), FLIP_DIRECTION::TOP_BOTTOM );
136}
137
138
140{
141 m_referenceImage.Flip( VECTOR2I( aCenter, 0 ), FLIP_DIRECTION::LEFT_RIGHT );
142}
143
144
145void SCH_BITMAP::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
146{
147 m_referenceImage.Rotate( aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
148}
149
150
151#if defined(DEBUG)
152void SCH_BITMAP::Show( int nestLevel, std::ostream& os ) const
153{
154 // XML output:
155 wxString s = GetClass();
156
157 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << GetPosition() << "/>\n";
158}
159#endif
160
161
162bool SCH_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
163{
164 return KIGEOM::BoxHitTest( aPosition, GetBoundingBox(), aAccuracy );
165}
166
167
168bool SCH_BITMAP::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
169{
170 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
171}
172
173
174void SCH_BITMAP::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
175 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
176{
177 if( aBackground )
178 {
180 aPlotter, GetPosition(), aPlotter->RenderSettings()->GetLayerColor( GetLayer() ),
181 aPlotter->RenderSettings()->GetDefaultPenWidth() );
182 }
183}
184
185
187{
188 return BITMAPS::image;
189}
190
191
192void SCH_BITMAP::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
193{
194 aList.emplace_back( _( "Bitmap" ), wxEmptyString );
195
196 aList.emplace_back( _( "PPI" ),
197 wxString::Format( wxT( "%d " ), m_referenceImage.GetImage().GetPPI() ) );
198 aList.emplace_back( _( "Scale" ),
199 wxString::Format( wxT( "%f " ), m_referenceImage.GetImageScale() ) );
200
201 aList.emplace_back( _( "Width" ),
203 aList.emplace_back( _( "Height" ),
205}
206
207
208void SCH_BITMAP::ViewGetLayers( int aLayers[], int& aCount ) const
209{
210 aCount = 2;
211 aLayers[0] = LAYER_DRAW_BITMAPS;
212 aLayers[1] = LAYER_SELECTION_SHADOWS;
213}
214
215
216bool SCH_BITMAP::operator==( const SCH_ITEM& aItem ) const
217{
218 if( Type() != aItem.Type() )
219 return false;
220
221 const SCH_BITMAP& bitmap = static_cast<const SCH_BITMAP&>( aItem );
222 return m_referenceImage == bitmap.m_referenceImage;
223}
224
225
226double SCH_BITMAP::Similarity( const SCH_ITEM& aItem ) const
227{
228 if( Type() != aItem.Type() )
229 return 0.0;
230
231 if( m_Uuid == aItem.m_Uuid )
232 return 1.0;
233
234 const SCH_BITMAP& bitmap = static_cast<const SCH_BITMAP&>( aItem );
236}
237
238
240{
242}
243
244
246{
248 offset.x = aX;
250}
251
252
254{
256}
257
258
260{
262 offset.y = aY;
264}
265
266
268{
270}
271
272
273void SCH_BITMAP::SetImageScale( double aScale )
274{
276}
277
278
280{
282}
283
284
285void SCH_BITMAP::SetWidth( int aWidth )
286{
287 m_referenceImage.SetWidth( aWidth );
288}
289
290
292{
294}
295
296
297void SCH_BITMAP::SetHeight( int aHeight )
298{
299 m_referenceImage.SetHeight( aHeight );
300}
301
302
303static struct SCH_BITMAP_DESC
304{
306 {
310
311 propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>( _HKI( "Position X" ), &SCH_BITMAP::SetX,
313 PROPERTY_DISPLAY::PT_COORD ) );
314
315
316 propMgr.AddProperty( new PROPERTY<SCH_BITMAP, int>( _HKI( "Position Y" ), &SCH_BITMAP::SetY,
318 PROPERTY_DISPLAY::PT_COORD ) );
319
320 const wxString groupImage = _HKI( "Image Properties" );
321
322 propMgr.AddProperty( new PROPERTY<SCH_BITMAP, double>( _HKI( "Scale" ),
325 groupImage );
326
328 _HKI( "Transform Offset X" ),
331 PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_X_COORD ),
332 groupImage );
333
335 _HKI( "Transform Offset Y" ),
338 PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_Y_COORD ),
339 groupImage );
340
342 _HKI( "Width" ),
345 PROPERTY_DISPLAY::PT_COORD ),
346 groupImage );
347
349 _HKI( "Height" ),
352 PROPERTY_DISPLAY::PT_COORD ),
353 groupImage );
354 }
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
void PlotImage(PLOTTER *aPlotter, const VECTOR2I &aPos, const KIGFX::COLOR4D &aDefaultColor, int aDefaultPensize) const
Plot bitmap on plotter.
int GetPPI() const
Definition: bitmap_base.h:118
void DrawBitmap(wxDC *aDC, const VECTOR2I &aPos, const KIGFX::COLOR4D &aBackgroundColor=KIGFX::COLOR4D::UNSPECIFIED) const
VECTOR2I GetSize() const
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
int GetDefaultPenWidth() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
Base plotter engine class.
Definition: plotter.h:105
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:136
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void SwapData(REFERENCE_IMAGE &aItem)
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle)
void SetTransformOriginOffset(const VECTOR2I &aCenter)
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)
void SetHeight(int aHeight)
VECTOR2I GetSize() const
void SetPosition(const VECTOR2I &aPos)
void SetWidth(int aWidth)
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
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_bitmap.cpp:145
double GetImageScale() const
Definition: sch_bitmap.cpp:267
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_bitmap.cpp:80
SCH_BITMAP(const VECTOR2I &pos=VECTOR2I(0, 0))
Definition: sch_bitmap.cpp:45
void SetWidth(int aWidth)
Definition: sch_bitmap.cpp:285
VECTOR2I GetPosition() const override
Definition: sch_bitmap.cpp:115
int GetTransformOriginOffsetY() const
Definition: sch_bitmap.cpp:253
void SetHeight(int aHeight)
Definition: sch_bitmap.cpp:297
int GetWidth() const
Definition: sch_bitmap.cpp:279
int GetY() const
Definition: sch_bitmap.h:57
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: sch_bitmap.cpp:174
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Definition: sch_bitmap.cpp:208
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_bitmap.cpp:99
wxString GetClass() const override
Return the class name.
Definition: sch_bitmap.h:65
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_bitmap.cpp:133
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_bitmap.cpp:192
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_bitmap.cpp:226
int GetHeight() const
Definition: sch_bitmap.cpp:291
void SetY(int aY)
Definition: sch_bitmap.h:58
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_bitmap.cpp:186
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_bitmap.cpp:162
int GetX() const
Definition: sch_bitmap.h:54
void SetTransformOriginOffsetX(int aX)
Definition: sch_bitmap.cpp:245
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_bitmap.cpp:121
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_bitmap.cpp:127
SCH_BITMAP & operator=(const SCH_ITEM &aItem)
Definition: sch_bitmap.cpp:62
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_bitmap.cpp:86
void SetX(int aX)
Definition: sch_bitmap.h:55
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_bitmap.cpp:139
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_bitmap.cpp:216
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_bitmap.cpp:105
REFERENCE_IMAGE m_referenceImage
Definition: sch_bitmap.h:138
int GetTransformOriginOffsetX() const
Definition: sch_bitmap.cpp:239
void SetTransformOriginOffsetY(int aY)
Definition: sch_bitmap.cpp:259
void SetImageScale(double aScale)
Definition: sch_bitmap.cpp:273
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:101
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:281
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:354
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:176
SCH_LAYER_ID m_layer
Definition: sch_item.h:723
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
The common library.
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:406
a few functions useful in geometry calculations.
@ LAYER_DRAW_BITMAPS
to handle and draw images bitmaps
Definition: layer_ids.h:225
@ LAYER_NOTES
Definition: layer_ids.h:372
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:398
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static struct SCH_BITMAP_DESC _SCH_BITMAP_DESC
@ SCH_BITMAP_T
Definition: typeinfo.h:164
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691