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
40
41static const double DEFAULT_PT_SIZE_MM = 1.0;
42
43
45 BOARD_ITEM( aParent, PCB_POINT_T ),
46 m_pos( 0, 0 ),
48{
49}
50
51
52PCB_POINT::PCB_POINT( BOARD_ITEM* aParent, const VECTOR2I& aPos, int aSize ) :
53 BOARD_ITEM( aParent, PCB_POINT_T ),
54 m_pos( aPos ),
55 m_size( aSize )
56{
57}
58
59
60bool PCB_POINT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
61{
62 // Compute the hit on the bars of the X
63 const int size = GetSize() / 2;
64 const SEG loc = SEG( aPosition, aPosition );
65
66 const SEG seg1 = SEG( m_pos - VECTOR2I{ size, size }, m_pos + VECTOR2I{ size, size } );
67 const SEG seg2 = SEG( m_pos - VECTOR2I{ size, -size }, m_pos + VECTOR2I{ size, -size } );
68 const SHAPE_CIRCLE circle( m_pos, size / 2 );
69
70 bool hit = seg1.Collide( loc, aAccuracy ) || seg2.Collide( loc, aAccuracy ) || circle.Collide( loc, aAccuracy );
71
72 return hit;
73}
74
75
76bool PCB_POINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
77{
78 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
79}
80
81
82std::vector<int> PCB_POINT::ViewGetLayers() const
83{
84 const PCB_LAYER_ID layer = GetLayer();
85
86 std::vector<int> layers = {
87 POINT_LAYER_FOR( layer ),
88 };
89
90 if( IsLocked() )
91 layers.push_back( LAYER_LOCKED_ITEM_SHADOW );
92
93 return layers;
94}
95
96
97double PCB_POINT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
98{
99 // All points hidden
100 if( !aView->IsLayerVisible( LAYER_POINTS ) )
101 return LOD_HIDE;
102
103 // Hide if the "main" layer is not shown
104 if( !aView->IsLayerVisible( m_layer ) )
105 return LOD_HIDE;
106
107 return LOD_SHOW;
108}
109
110
111void PCB_POINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
112{
113 RotatePoint( m_pos, aRotCentre, aAngle );
114}
115
116
117void PCB_POINT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
118{
119 MIRROR(m_pos, aCentre, aFlipDirection);
120
122}
123
124
126{
128 return bbox;
129}
130
131
132std::shared_ptr<SHAPE> PCB_POINT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
133{
134 return std::make_shared<SHAPE_RECT>( GetBoundingBox() );
135}
136
137
138wxString PCB_POINT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
139{
140 return _( "Point" );
141}
142
143
148
149
151{
152 return new PCB_POINT( *this );
153}
154
155
157{
158 assert( aOther->Type() == PCB_POINT_T );
159
160 std::swap( *((PCB_POINT*) this), *((PCB_POINT*) aOther) );
161}
162
163
164void PCB_POINT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
165{
166 aList.emplace_back( _( "PCB Point" ), wxEmptyString );
167
168 aList.emplace_back( _( "Position X" ), aFrame->MessageTextFromValue( GetPosition().x ) );
169 aList.emplace_back( _( "Position Y" ), aFrame->MessageTextFromValue( GetPosition().y ) );
170 aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetSize() ) );
171 aList.emplace_back( _( "Layer" ), GetLayerName() );
172}
173
174
176 int aClearance, int aError, ERROR_LOC aErrorLoc,
177 bool ignoreLineWidth ) const
178{
179}
180
181
182bool PCB_POINT::operator==( const BOARD_ITEM& aBoardItem ) const
183{
184 if( aBoardItem.Type() != Type() )
185 return false;
186
187 const PCB_POINT& other = static_cast<const PCB_POINT&>( aBoardItem );
188
189 return *this == other;
190}
191
192
193bool PCB_POINT::operator==( const PCB_POINT& aOther ) const
194{
195 return m_pos == aOther.m_pos && m_size == aOther.m_size;
196}
197
198
199double PCB_POINT::Similarity( const BOARD_ITEM& aOther ) const
200{
201 if( aOther.Type() != Type() )
202 return 0.0;
203
204 const PCB_POINT& other = static_cast<const PCB_POINT&>( aOther );
205
206 double similarity = 1.0;
207
208 if( m_pos == other.m_pos )
209 similarity *= 0.9;
210
211 if( m_size != other.m_size )
212 similarity *= 0.9;
213
214 if( GetLayer() != other.GetLayer() )
215 similarity *= 0.9;
216
217 return similarity;
218}
219
220static struct PCB_POINT_DESC
221{
222 // clang-format off
224 {
226 // PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
229
230 propMgr.AddProperty( new PROPERTY<PCB_POINT, int>( _HKI( "Size" ),
233 }
234 // 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:79
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:81
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:232
PCB_LAYER_ID m_layer
Definition board_item.h:453
bool IsLocked() const override
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:280
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.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
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:66
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition view.h:422
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: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:128
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition pcb_point.cpp:82
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:62
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition pcb_point.cpp:97
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:60
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:61
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:59
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:536
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:170
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:371
@ LAYER_POINTS
PCB reference/manual snap points visibility.
Definition layer_ids.h:320
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:306
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:41
static struct PCB_POINT_DESC _PCB_POINT_DESC
#define TYPE_HASH(x)
Definition property.h:73
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:62
#define REGISTER_TYPE(x)
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:112
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695