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#include <properties/property.h>
45
48
49
51 PCB_LAYER_ID aLayer ) :
53{
54 m_referenceImage.SetPosition( aPos );
55}
56
57
62
63
67
68
70{
71 wxCHECK_MSG( Type() == aItem.Type(), *this,
72 wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " )
73 + GetClass() );
74
75 if( &aItem != this )
76 {
77 BOARD_ITEM::operator=( aItem );
78 const PCB_REFERENCE_IMAGE& refImg = static_cast<const PCB_REFERENCE_IMAGE&>( aItem );
80 }
81
82 return *this;
83}
84
85
87{
88 wxCHECK( aOther && aOther->Type() == PCB_REFERENCE_IMAGE_T, /* void */ );
89 *this = *static_cast<const PCB_REFERENCE_IMAGE*>( aOther );
90}
91
92
94{
95 return new PCB_REFERENCE_IMAGE( *this );
96}
97
98
100{
101 wxCHECK_RET( aItem->Type() == PCB_REFERENCE_IMAGE_T,
102 wxString::Format( wxT( "% object cannot swap data with %s object." ),
103 GetClass(), aItem->GetClass() ) );
104
106 std::swap( m_layer, item->m_layer );
107 std::swap( m_isKnockout, item->m_isKnockout );
108 std::swap( m_isLocked, item->m_isLocked );
109 std::swap( m_flags, item->m_flags );
110 std::swap( m_parent, item->m_parent );
111 std::swap( m_forceVisible, item->m_forceVisible );
112 m_referenceImage.SwapData( item->m_referenceImage );
113}
114
115
116double PCB_REFERENCE_IMAGE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
117{
118 PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
119 PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
120
121 // All bitmaps are drawn on LAYER_DRAW_BITMAPS, but their
122 // associated board layer controls their visibility.
123 if( !GetBoard()->IsLayerVisible( m_layer ) )
124 return LOD_HIDE;
125
126 if( renderSettings->GetHighContrast()
128 && !renderSettings->GetLayerIsHighContrast( m_layer ) )
129 {
130 return LOD_HIDE;
131 }
132
133 if( aView->IsLayerVisible( LAYER_DRAW_BITMAPS ) )
134 return LOD_SHOW;
135
136 return LOD_HIDE;
137}
138
139
141{
142 return m_referenceImage.GetBoundingBox();
143}
144
145
147 FLASHING aFlash ) const
148{
149 const BOX2I box = GetBoundingBox();
150 return std::make_shared<SHAPE_RECT>( box.GetPosition(), box.GetWidth(), box.GetHeight() );
151}
152
153
155{
156 return m_referenceImage.GetPosition();
157}
158
159
161{
162 m_referenceImage.SetPosition( aPos );
163}
164
165
166void PCB_REFERENCE_IMAGE::Move( const VECTOR2I& aMoveVector )
167{
168 // Defer to SetPosition to check the new position overflow
169 SetPosition( GetPosition() + aMoveVector );
170}
171
172
173void PCB_REFERENCE_IMAGE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
174{
175 m_referenceImage.Flip( aCentre, aFlipDirection );
176
177 if( GetBoard() )
179 else
181}
182
183
184void PCB_REFERENCE_IMAGE::Rotate( const VECTOR2I& aCenter, const EDA_ANGLE& aAngle )
185{
186 m_referenceImage.Rotate( aCenter, aAngle );
187}
188
189
190#if defined( DEBUG )
191void PCB_REFERENCE_IMAGE::Show( int nestLevel, std::ostream& os ) const
192{
193 // XML output:
194 wxString s = GetClass();
195
196 NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_referenceImage.GetPosition()
197 << "/>\n";
198}
199#endif
200
201
202bool PCB_REFERENCE_IMAGE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
203{
204 return KIGEOM::BoxHitTest( aPosition, GetBoundingBox(), aAccuracy );
205}
206
207
208bool PCB_REFERENCE_IMAGE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
209{
210 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
211}
212
213
214bool PCB_REFERENCE_IMAGE::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
215{
216 return KIGEOM::BoxHitTest( aPoly, GetBoundingBox(), aContained );
217}
218
219
224
225
227 std::vector<MSG_PANEL_ITEM>& aList )
228{
229 aList.emplace_back( _( "Reference Image" ), wxEmptyString );
230
231 aList.emplace_back( _( "PPI" ),
232 wxString::Format( wxT( "%d " ), m_referenceImage.GetImage().GetPPI() ) );
233 aList.emplace_back( _( "Scale" ),
234 wxString::Format( wxT( "%f " ), m_referenceImage.GetImageScale() ) );
235
236 aList.emplace_back( _( "Width" ),
237 aFrame->MessageTextFromValue( m_referenceImage.GetSize().x ) );
238 aList.emplace_back( _( "Height" ),
239 aFrame->MessageTextFromValue( m_referenceImage.GetSize().y ) );
240 aList.emplace_back( _( "Layer" ), LayerName( m_layer ) );
241}
242
243
245{
246 return { BITMAP_LAYER_FOR( m_layer ) };
247}
248
249
250bool PCB_REFERENCE_IMAGE::operator==( const BOARD_ITEM& aBoardItem ) const
251{
252 if( aBoardItem.Type() != Type() )
253 return false;
254
255 const PCB_REFERENCE_IMAGE& other = static_cast<const PCB_REFERENCE_IMAGE&>( aBoardItem );
256
257 return *this == other;
258}
259
260
262{
263 if( m_layer != aOther.m_layer )
264 return false;
265
266 if( m_referenceImage != aOther.m_referenceImage )
267 return false;
268
269 return true;
270}
271
272
273double PCB_REFERENCE_IMAGE::Similarity( const BOARD_ITEM& aOther ) const
274{
275 if( aOther.Type() != Type() )
276 return 0.0;
277
278 const PCB_REFERENCE_IMAGE& other = static_cast<const PCB_REFERENCE_IMAGE&>( aOther );
279
280 double similarity = 1.0;
281
282 if( m_layer != other.m_layer )
283 similarity *= 0.9;
284
285 similarity *= m_referenceImage.Similarity( other.m_referenceImage );
286
287 return similarity;
288}
289
290
292{
293 return m_referenceImage.GetTransformOriginOffset().x;
294}
295
296
298{
299 VECTOR2I offset = m_referenceImage.GetTransformOriginOffset();
300 offset.x = aX;
301 m_referenceImage.SetTransformOriginOffset( offset );
302}
303
304
306{
307 return m_referenceImage.GetTransformOriginOffset().y;
308}
309
310
312{
313 VECTOR2I offset = m_referenceImage.GetTransformOriginOffset();
314 offset.y = aY;
315 m_referenceImage.SetTransformOriginOffset( offset );
316}
317
318
320{
321 return m_referenceImage.GetImageScale();
322}
323
324
326{
327 m_referenceImage.SetImageScale( aScale );
328}
329
330
332{
333 return m_referenceImage.GetImage().GetSize().x;
334}
335
336
338{
339 m_referenceImage.SetWidth( aWidth );
340}
341
342
344{
345 return m_referenceImage.GetImage().GetSize().y;
346}
347
348
350{
351 m_referenceImage.SetHeight( aHeight );
352}
353
354
356{
358 {
362
363 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ),
366
367 const wxString groupImage = _HKI( "Image Properties" );
368
372 groupImage );
373
374 propMgr.AddProperty( new PROPERTY<PCB_REFERENCE_IMAGE, int>( _HKI( "Transform Offset X" ),
378 groupImage );
379
380 propMgr.AddProperty( new PROPERTY<PCB_REFERENCE_IMAGE, int>( _HKI( "Transform Offset Y" ),
384 groupImage );
385
386 propMgr.AddProperty( new PROPERTY<PCB_REFERENCE_IMAGE, int>( _HKI( "Width" ),
389 groupImage );
390
391 propMgr.AddProperty( new PROPERTY<PCB_REFERENCE_IMAGE, int>( _HKI( "Height" ),
394 groupImage );
395
396 // For future use
397 const wxString greyscale = _HKI( "Greyscale" );
398 }
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
BITMAPS
A list of all bitmap identifiers.
@ HIDDEN
Inactive layers are hidden.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:237
bool m_isKnockout
Definition board_item.h:460
PCB_LAYER_ID m_layer
Definition board_item.h:459
bool m_isLocked
Definition board_item.h:462
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:285
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
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.
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition eda_item.cpp:338
bool m_forceVisible
Definition eda_item.h:539
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:533
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:534
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:82
HIGH_CONTRAST_MODE m_ContrastModeDisplay
bool GetLayerIsHighContrast(int aLayerId) const
Return information whether the queried layer is marked as high-contrast.
virtual wxString GetClass() const =0
Return the class name.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:180
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:185
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:423
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:221
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
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)
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)
void CopyFrom(const BOARD_ITEM *aOther) override
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
PROPERTY_BASE & ReplaceProperty(PROPERTY_BASE *aProperty, const wxString &aGroup)
Replace an existing property.
VECTOR2I GetPosition() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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 _(s)
a few functions useful in geometry calculations.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition layer_id.cpp:172
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:367
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:184
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:284
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.
#define _HKI(x)
Definition page_info.cpp:44
static struct PCB_REFERENCE_IMAGE_DESC _PCB_REFERENCE_IMAGE_DESC
#define TYPE_HASH(x)
Definition property.h:74
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
#define REGISTER_TYPE(x)
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:89
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695