KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_reference_image.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) 2022 Mike Williams
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include "pcb_reference_image.h"
27
28#include <base_units.h>
29#include <bitmaps.h>
30#include <board.h>
31#include <common.h>
32#include <core/mirror.h>
33#include <eda_draw_frame.h>
34#include <pcb_draw_panel_gal.h>
35#include <pcb_painter.h>
36#include <plotters/plotter.h>
38#include <geometry/shape_rect.h>
40#include <trigo.h>
41
42#include <wx/mstream.h>
43
46
47
49 PCB_LAYER_ID aLayer ) :
50 BOARD_ITEM( aParent, PCB_REFERENCE_IMAGE_T, aLayer ), m_referenceImage( pcbIUScale )
51{
53}
54
55
57 BOARD_ITEM( aPCBBitmap ), m_referenceImage( aPCBBitmap.m_referenceImage )
58{
59}
60
61
63{
64}
65
66
68{
69 wxCHECK_MSG( Type() == aItem.Type(), *this,
70 wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " )
71 + GetClass() );
72
73 if( &aItem != this )
74 {
75 BOARD_ITEM::operator=( aItem );
76 const PCB_REFERENCE_IMAGE& refImg = static_cast<const PCB_REFERENCE_IMAGE&>( aItem );
78 }
79
80 return *this;
81}
82
83
85{
86 return new PCB_REFERENCE_IMAGE( *this );
87}
88
89
91{
92 wxCHECK_RET( aItem->Type() == PCB_REFERENCE_IMAGE_T,
93 wxString::Format( wxT( "% object cannot swap data with %s object." ),
94 GetClass(), aItem->GetClass() ) );
95
97 std::swap( m_layer, item->m_layer );
98 std::swap( m_isKnockout, item->m_isKnockout );
99 std::swap( m_isLocked, item->m_isLocked );
100 std::swap( m_flags, item->m_flags );
101 std::swap( m_parent, item->m_parent );
102 std::swap( m_forceVisible, item->m_forceVisible );
104}
105
106
107double PCB_REFERENCE_IMAGE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
108{
109 PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
110 PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
111
112 // All bitmaps are drawn on LAYER_DRAW_BITMAPS, but their
113 // associated board layer controls their visibility.
114 if( !GetBoard()->IsLayerVisible( m_layer ) )
115 return LOD_HIDE;
116
117 if( renderSettings->GetHighContrast()
118 && renderSettings->m_ContrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN
119 && !renderSettings->GetLayerIsHighContrast( m_layer ) )
120 {
121 return LOD_HIDE;
122 }
123
124 if( aView->IsLayerVisible( LAYER_DRAW_BITMAPS ) )
125 return LOD_SHOW;
126
127 return LOD_HIDE;
128}
129
130
132{
134}
135
136
138 FLASHING aFlash ) const
139{
140 const BOX2I box = GetBoundingBox();
141 return std::make_shared<SHAPE_RECT>( box.GetPosition(), box.GetWidth(), box.GetHeight() );
142}
143
144
146{
148}
149
150
152{
154}
155
156
157void PCB_REFERENCE_IMAGE::Move( const VECTOR2I& aMoveVector )
158{
159 // Defer to SetPosition to check the new position overflow
160 SetPosition( GetPosition() + aMoveVector );
161}
162
163
164void PCB_REFERENCE_IMAGE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
165{
166 m_referenceImage.Flip( aCentre, aFlipDirection );
167}
168
169void PCB_REFERENCE_IMAGE::Rotate( const VECTOR2I& aCenter, const EDA_ANGLE& aAngle )
170{
171 m_referenceImage.Rotate( aCenter, aAngle );
172}
173
174
175#if defined( DEBUG )
176void PCB_REFERENCE_IMAGE::Show( int nestLevel, std::ostream& os ) const
177{
178 // XML output:
179 wxString s = GetClass();
180
181 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_referenceImage.GetPosition()
182 << "/>\n";
183}
184#endif
185
186
187bool PCB_REFERENCE_IMAGE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
188{
189 return KIGEOM::BoxHitTest( aPosition, GetBoundingBox(), aAccuracy );
190}
191
192
193bool PCB_REFERENCE_IMAGE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
194{
195 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
196}
197
198
200{
201 return BITMAPS::image;
202}
203
204
206 std::vector<MSG_PANEL_ITEM>& aList )
207{
208 aList.emplace_back( _( "Reference Image" ), wxEmptyString );
209
210 aList.emplace_back( _( "PPI" ),
211 wxString::Format( wxT( "%d " ), m_referenceImage.GetImage().GetPPI() ) );
212 aList.emplace_back( _( "Scale" ),
213 wxString::Format( wxT( "%f " ), m_referenceImage.GetImageScale() ) );
214
215 aList.emplace_back( _( "Width" ),
217 aList.emplace_back( _( "Height" ),
219 aList.emplace_back( _( "Layer" ), LayerName( m_layer ) );
220}
221
222
224{
225 return { BITMAP_LAYER_FOR( m_layer ) };
226}
227
228
229bool PCB_REFERENCE_IMAGE::operator==( const BOARD_ITEM& aBoardItem ) const
230{
231 if( aBoardItem.Type() != Type() )
232 return false;
233
234 const PCB_REFERENCE_IMAGE& other = static_cast<const PCB_REFERENCE_IMAGE&>( aBoardItem );
235
236 return *this == other;
237}
238
239
241{
242 if( m_layer != aOther.m_layer )
243 return false;
244
245 if( m_referenceImage != aOther.m_referenceImage )
246 return false;
247
248 return true;
249}
250
251
252double PCB_REFERENCE_IMAGE::Similarity( const BOARD_ITEM& aOther ) const
253{
254 if( aOther.Type() != Type() )
255 return 0.0;
256
257 const PCB_REFERENCE_IMAGE& other = static_cast<const PCB_REFERENCE_IMAGE&>( aOther );
258
259 double similarity = 1.0;
260
261 if( m_layer != other.m_layer )
262 similarity *= 0.9;
263
264 similarity *= m_referenceImage.Similarity( other.m_referenceImage );
265
266 return similarity;
267}
268
269
271{
273}
274
275
277{
279 offset.x = aX;
281}
282
283
285{
287}
288
289
291{
293 offset.y = aY;
295}
296
297
299{
301}
302
303
305{
307}
308
309
311{
313}
314
315
317{
318 m_referenceImage.SetWidth( aWidth );
319}
320
321
323{
325}
326
327
329{
330 m_referenceImage.SetHeight( aHeight );
331}
332
333
335{
337 {
341
342 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ),
345
346 const wxString groupImage = _HKI( "Image Properties" );
347
351 groupImage );
352
354 _HKI( "Transform Offset X" ),
357 PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_X_COORD ),
358 groupImage );
359
361 _HKI( "Transform Offset Y" ),
364 PROPERTY_DISPLAY::PT_COORD, ORIGIN_TRANSFORMS::ABS_Y_COORD ),
365 groupImage );
366
368 _HKI( "Width" ),
371 PROPERTY_DISPLAY::PT_COORD ),
372 groupImage );
373
375 _HKI( "Height" ),
378 PROPERTY_DISPLAY::PT_COORD ),
379 groupImage );
380
381 // For future use
382 const wxString greyscale = _HKI( "Greyscale" );
383 }
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
int GetPPI() const
Definition: bitmap_base.h:118
VECTOR2I GetSize() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:239
bool m_isKnockout
Definition: board_item.h:439
PCB_LAYER_ID m_layer
Definition: board_item.h:438
bool m_isLocked
Definition: board_item.h:441
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:290
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:823
constexpr const Vec & GetPosition() const
Definition: box2.h:211
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr size_type GetHeight() const
Definition: box2.h:215
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
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:261
bool m_forceVisible
Definition: eda_item.h:503
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:501
virtual wxString GetClass() const =0
Return the class name.
EDA_ITEM * m_parent
Linked list: Link (parent struct).
Definition: eda_item.h:502
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:180
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:185
PCB specific render settings.
Definition: pcb_painter.h:78
HIGH_CONTRAST_MODE m_ContrastModeDisplay
Definition: pcb_painter.h:146
bool GetHighContrast() const
bool GetLayerIsHighContrast(int aLayerId) const
Return information whether the queried layer is marked as high-contrast.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition: view_item.h:174
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition: view_item.h:179
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:418
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:216
Object to handle a bitmap image that can be inserted in a PCB.
void SetTransformOriginOffsetY(int aY)
void swapData(BOARD_ITEM *aItem) override
VECTOR2I GetPosition() const override
Get the position of the image (this is the center of the image).
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
virtual std::vector< int > ViewGetLayers() const override
int GetTransformOriginOffsetY() const
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
void SetTransformOriginOffsetX(int aX)
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool operator==(const PCB_REFERENCE_IMAGE &aOther) const
void SetImageScale(double aScale)
int GetTransformOriginOffsetX() const
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
wxString GetClass() const override
Return the class name.
void Rotate(const VECTOR2I &aCenter, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetPosition(const VECTOR2I &aPosition) override
Set the position of the image.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
PCB_REFERENCE_IMAGE(BOARD_ITEM *aParent, const VECTOR2I &pos=VECTOR2I(0, 0), PCB_LAYER_ID aLayer=F_Cu)
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.
REFERENCE_IMAGE m_referenceImage
void SetHeight(int aHeight)
PCB_REFERENCE_IMAGE & operator=(const BOARD_ITEM &aItem)
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.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
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
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)
a few functions useful in geometry calculations.
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:31
#define BITMAP_LAYER_FOR(boardLayer)
Macros for getting the extra layers for a given board layer.
Definition: layer_ids.h:320
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
@ LAYER_DRAW_BITMAPS
Draw images.
Definition: layer_ids.h:246
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
FLIP_DIRECTION
Definition: mirror.h:27
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
static struct PCB_REFERENCE_IMAGE_DESC _PCB_REFERENCE_IMAGE_DESC
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition: typeinfo.h:89