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, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26#include "pcb_point.h"
27
28#include <base_units.h>
29#include <bitmaps.h>
30#include <board.h>
31#include <eda_draw_frame.h>
34#include <geometry/shape_rect.h>
35#include <pcb_shape.h>
38#include <view/view.h>
39#include <properties/property.h>
41
42
43static const double DEFAULT_PT_SIZE_MM = 1.0;
44
45
47 BOARD_ITEM( aParent, PCB_POINT_T ),
48 m_pos( 0, 0 ),
50{
51}
52
53
54PCB_POINT::PCB_POINT( BOARD_ITEM* aParent, const VECTOR2I& aPos, int aSize ) :
55 BOARD_ITEM( aParent, PCB_POINT_T ),
56 m_pos( aPos ),
57 m_size( aSize )
58{
59}
60
61
63{
64 if( a->GetLayer() != b->GetLayer() )
65 return a->GetLayer() < b->GetLayer();
66
67 if( a->GetPosition().x != b->GetPosition().x )
68 return a->GetPosition().x < b->GetPosition().x;
69
70 if( a->GetPosition().y != b->GetPosition().y )
71 return a->GetPosition().y < b->GetPosition().y;
72
73 if( a->GetSize() != b->GetSize() )
74 return a->GetSize() < b->GetSize();
75
76 if( a->m_Uuid != b->m_Uuid )
77 return a->m_Uuid < b->m_Uuid;
78
79 return a < b;
80}
81
82
83bool PCB_POINT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
84{
85 // Compute the hit on the bars of the X
86 const int size = GetSize() / 2;
87 const SEG loc = SEG( aPosition, aPosition );
88
89 const SEG seg1 = SEG( m_pos - VECTOR2I{ size, size }, m_pos + VECTOR2I{ size, size } );
90 const SEG seg2 = SEG( m_pos - VECTOR2I{ size, -size }, m_pos + VECTOR2I{ size, -size } );
91 const SHAPE_CIRCLE circle( m_pos, size / 2 );
92
93 bool hit = seg1.Collide( loc, aAccuracy ) || seg2.Collide( loc, aAccuracy ) || circle.Collide( loc, aAccuracy );
94
95 return hit;
96}
97
98
99bool PCB_POINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
100{
101 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
102}
103
104
105std::vector<int> PCB_POINT::ViewGetLayers() const
106{
107 const PCB_LAYER_ID layer = GetLayer();
108
109 std::vector<int> layers = {
110 POINT_LAYER_FOR( layer ),
111 };
112
113 if( IsLocked() )
114 layers.push_back( LAYER_LOCKED_ITEM_SHADOW );
115
116 return layers;
117}
118
119
120double PCB_POINT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
121{
122 // All points hidden
123 if( !aView->IsLayerVisible( LAYER_POINTS ) )
124 return LOD_HIDE;
125
126 // Hide if the "main" layer is not shown
127 if( !aView->IsLayerVisible( m_layer ) )
128 return LOD_HIDE;
129
130 return LOD_SHOW;
131}
132
133
134void PCB_POINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
135{
136 RotatePoint( m_pos, aRotCentre, aAngle );
137}
138
139
140void PCB_POINT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
141{
142 MIRROR(m_pos, aCentre, aFlipDirection);
143
145}
146
147
149{
151 return bbox;
152}
153
154
155std::shared_ptr<SHAPE> PCB_POINT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
156{
157 return std::make_shared<SHAPE_RECT>( GetBoundingBox() );
158}
159
160
161wxString PCB_POINT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
162{
163 return _( "Point" );
164}
165
166
171
172
174{
175 return new PCB_POINT( *this );
176}
177
178
180{
181 assert( aOther->Type() == PCB_POINT_T );
182
183 std::swap( *((PCB_POINT*) this), *((PCB_POINT*) aOther) );
184}
185
186
187void PCB_POINT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
188{
189 aList.emplace_back( _( "PCB Point" ), wxEmptyString );
190
191 aList.emplace_back( _( "Position X" ), aFrame->MessageTextFromValue( GetPosition().x ) );
192 aList.emplace_back( _( "Position Y" ), aFrame->MessageTextFromValue( GetPosition().y ) );
193 aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetSize() ) );
194 aList.emplace_back( _( "Layer" ), GetLayerName() );
195}
196
197
199 int aClearance, int aError, ERROR_LOC aErrorLoc,
200 bool ignoreLineWidth ) const
201{
202}
203
204
205bool PCB_POINT::operator==( const BOARD_ITEM& aBoardItem ) const
206{
207 if( aBoardItem.Type() != Type() )
208 return false;
209
210 const PCB_POINT& other = static_cast<const PCB_POINT&>( aBoardItem );
211
212 return *this == other;
213}
214
215
216bool PCB_POINT::operator==( const PCB_POINT& aOther ) const
217{
218 return m_pos == aOther.m_pos && m_size == aOther.m_size;
219}
220
221
222double PCB_POINT::Similarity( const BOARD_ITEM& aOther ) const
223{
224 if( aOther.Type() != Type() )
225 return 0.0;
226
227 const PCB_POINT& other = static_cast<const PCB_POINT&>( aOther );
228
229 double similarity = 1.0;
230
231 if( m_pos == other.m_pos )
232 similarity *= 0.9;
233
234 if( m_size != other.m_size )
235 similarity *= 0.9;
236
237 if( GetLayer() != other.GetLayer() )
238 similarity *= 0.9;
239
240 return similarity;
241}
242
243static struct PCB_POINT_DESC
244{
245 // clang-format off
247 {
249 // PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
252
253 propMgr.AddProperty( new PROPERTY<PCB_POINT, int>( _HKI( "Size" ),
256 }
257 // 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:112
BITMAPS
A list of all bitmap identifiers.
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
PCB_LAYER_ID m_layer
Definition board_item.h:459
bool IsLocked() const override
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.
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:75
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:527
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
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
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:43
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:46
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:133
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:67
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition pcb_point.cpp:83
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:66
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetPosition() const override
Definition pcb_point.h:64
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:42
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
Definition seg.cpp:542
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:172
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:184
#define POINT_LAYER_FOR(boardLayer)
Definition layer_ids.h:372
@ LAYER_POINTS
PCB reference/manual snap points visibility.
Definition layer_ids.h:321
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:307
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:45
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 const double DEFAULT_PT_SIZE_MM
Definition pcb_point.cpp:43
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:62
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:229
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:113
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695