KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_point.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) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2012 Wayne Stambaugh <[email protected]>
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22#include "pcb_point.h"
23
24#include <base_units.h>
25#include <bitmaps.h>
26#include <board.h>
27#include <eda_draw_frame.h>
28#include <footprint.h>
31#include <geometry/shape_rect.h>
32#include <pcb_shape.h>
35#include <trigo.h>
36#include <view/view.h>
37#include <properties/property.h>
39
40
41static const double DEFAULT_PT_SIZE_MM = 1.0;
42
43
45 BOARD_ITEM( aParent, PCB_POINT_T ),
46 m_libPos( 0, 0 ),
47 m_pos( 0, 0 ),
49{
51}
52
53
54PCB_POINT::PCB_POINT( BOARD_ITEM* aParent, const VECTOR2I& aPos, int aSize ) :
55 BOARD_ITEM( aParent, PCB_POINT_T ),
56 m_libPos( 0, 0 ),
57 m_pos( 0, 0 ),
58 m_size( aSize )
59{
60 SetPosition( aPos );
61}
62
63
65{
66 if( const FOOTPRINT* fp = GetParentFootprint() )
67 m_pos = fp->GetTransform().Apply( m_libPos );
68 else
70}
71
72
74{
75 if( const FOOTPRINT* fp = GetParentFootprint() )
76 m_libPos = fp->GetTransform().InverseApply( aPos );
77 else
78 m_libPos = aPos;
79
81}
82
83
85{
86 BOARD_ITEM::SetParent( aParent );
88}
89
90
95
96
98{
99 if( a->GetLayer() != b->GetLayer() )
100 return a->GetLayer() < b->GetLayer();
101
102 if( a->GetPosition().x != b->GetPosition().x )
103 return a->GetPosition().x < b->GetPosition().x;
104
105 if( a->GetPosition().y != b->GetPosition().y )
106 return a->GetPosition().y < b->GetPosition().y;
107
108 if( a->GetSize() != b->GetSize() )
109 return a->GetSize() < b->GetSize();
110
111 if( a->m_Uuid != b->m_Uuid )
112 return a->m_Uuid < b->m_Uuid;
113
114 return a < b;
115}
116
117
118bool PCB_POINT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
119{
120 // Compute the hit on the bars of the X
121 const int size = GetSize() / 2;
122 const VECTOR2I pos = GetPosition();
123 const SEG loc = SEG( aPosition, aPosition );
124
125 const SEG seg1 = SEG( pos - VECTOR2I{ size, size }, pos + VECTOR2I{ size, size } );
126 const SEG seg2 = SEG( pos - VECTOR2I{ size, -size }, pos + VECTOR2I{ size, -size } );
127 const SHAPE_CIRCLE circle( pos, size / 2 );
128
129 bool hit = seg1.Collide( loc, aAccuracy ) || seg2.Collide( loc, aAccuracy ) || circle.Collide( loc, aAccuracy );
130
131 return hit;
132}
133
134
135bool PCB_POINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
136{
137 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
138}
139
140
141std::vector<int> PCB_POINT::ViewGetLayers() const
142{
143 const PCB_LAYER_ID layer = GetLayer();
144
145 std::vector<int> layers = {
146 POINT_LAYER_FOR( layer ),
147 };
148
149 if( IsLocked() )
150 layers.push_back( LAYER_LOCKED_ITEM_SHADOW );
151
152 return layers;
153}
154
155
156double PCB_POINT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
157{
158 // All points hidden
159 if( !aView->IsLayerVisible( LAYER_POINTS ) )
160 return LOD_HIDE;
161
162 // Hide if the "main" layer is not shown
163 if( !aView->IsLayerVisible( m_layer ) )
164 return LOD_HIDE;
165
166 return LOD_SHOW;
167}
168
169
170void PCB_POINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
171{
172 VECTOR2I newPos = GetPosition();
173 RotatePoint( newPos, aRotCentre, aAngle );
174 SetPosition( newPos );
175}
176
177
178void PCB_POINT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
179{
180 if( const FOOTPRINT* fp = GetParentFootprint() )
181 {
182 // Mirror the library-frame position (rotation-independent).
183 const VECTOR2I libAxis = fp->GetTransform().InverseApply( aCentre );
184 MIRROR( m_libPos, libAxis, aFlipDirection );
186 }
187 else
188 {
189 VECTOR2I newPos = GetPosition();
190 MIRROR( newPos, aCentre, aFlipDirection );
191 SetPosition( newPos );
192 }
193
195}
196
197
202
203
204std::shared_ptr<SHAPE> PCB_POINT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
205{
206 return std::make_shared<SHAPE_RECT>( GetBoundingBox() );
207}
208
209
210wxString PCB_POINT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
211{
212 return _( "Point" );
213}
214
215
220
221
223{
224 return new PCB_POINT( *this );
225}
226
227
229{
230 assert( aOther->Type() == PCB_POINT_T );
231
232 std::swap( *((PCB_POINT*) this), *((PCB_POINT*) aOther) );
233}
234
235
236void PCB_POINT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
237{
238 aList.emplace_back( _( "PCB Point" ), wxEmptyString );
239
240 aList.emplace_back( _( "Position X" ), aFrame->MessageTextFromValue( GetPosition().x ) );
241 aList.emplace_back( _( "Position Y" ), aFrame->MessageTextFromValue( GetPosition().y ) );
242 aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetSize() ) );
243 aList.emplace_back( _( "Layer" ), GetLayerName() );
244}
245
246
248 int aClearance, int aError, ERROR_LOC aErrorLoc,
249 bool ignoreLineWidth ) const
250{
251}
252
253
254bool PCB_POINT::operator==( const BOARD_ITEM& aBoardItem ) const
255{
256 if( aBoardItem.Type() != Type() )
257 return false;
258
259 const PCB_POINT& other = static_cast<const PCB_POINT&>( aBoardItem );
260
261 return *this == other;
262}
263
264
265bool PCB_POINT::operator==( const PCB_POINT& aOther ) const
266{
267 return GetPosition() == aOther.GetPosition() && m_size == aOther.m_size;
268}
269
270
271double PCB_POINT::Similarity( const BOARD_ITEM& aOther ) const
272{
273 if( aOther.Type() != Type() )
274 return 0.0;
275
276 const PCB_POINT& other = static_cast<const PCB_POINT&>( aOther );
277
278 double similarity = 1.0;
279
280 if( GetPosition() == other.GetPosition() )
281 similarity *= 0.9;
282
283 if( m_size != other.m_size )
284 similarity *= 0.9;
285
286 if( GetLayer() != other.GetLayer() )
287 similarity *= 0.9;
288
289 return similarity;
290}
291
292static struct PCB_POINT_DESC
293{
294 // clang-format off
296 {
298 // PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
301
302 propMgr.AddProperty( new PROPERTY<PCB_POINT, int>( _HKI( "Size" ),
305 }
306 // clang-format on
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:83
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:265
PCB_LAYER_ID m_layer
Definition board_item.h:508
bool IsLocked() const override
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:313
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
static constexpr BOX2< VECTOR2I > ByCenter(const VECTOR2I &aCenter, const SizeVec &aSize)
Definition box2.h:71
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:531
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:176
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:181
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition view.h:427
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:39
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
PCB_POINT(BOARD_ITEM *aParent)
Definition pcb_point.cpp:44
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
VECTOR2I m_pos
Definition pcb_point.h:137
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
bool operator==(const PCB_POINT &aOther) const
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
int GetSize() const
Definition pcb_point.h:69
void recomputePosition()
Recompute the cached board position from the library position and parent transform.
Definition pcb_point.cpp:64
void SetParent(EDA_ITEM *aParent) override
Definition pcb_point.cpp:84
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_point.cpp:73
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
virtual void swapData(BOARD_ITEM *aImage) override
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.
void SetSize(const int aSize)
Definition pcb_point.h:68
void OnFootprintTransformed() override
Refresh the cached board position after the parent footprint's transform changed.
Definition pcb_point.cpp:91
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
VECTOR2I m_libPos
Definition pcb_point.h:135
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetPosition() const override
Definition pcb_point.h:60
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.
Definition seg.h:38
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
Definition seg.cpp:538
Represent a set of closed polygons.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
#define _(s)
a few functions useful in geometry calculations.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition layer_id.cpp:173
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
#define POINT_LAYER_FOR(boardLayer)
Definition layer_ids.h:370
@ LAYER_POINTS
PCB reference/manual snap points visibility.
Definition layer_ids.h:317
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:303
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:41
FLIP_DIRECTION
Definition mirror.h:23
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
#define _HKI(x)
Definition page_info.cpp:40
static const double DEFAULT_PT_SIZE_MM
Definition pcb_point.cpp:41
static struct PCB_POINT_DESC _PCB_POINT_DESC
#define TYPE_HASH(x)
Definition property.h:74
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
bool operator()(const PCB_POINT *a, const PCB_POINT *b) const
Definition pcb_point.cpp:97
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:225
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:106
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683