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
62bool PCB_POINT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
63{
64 // Compute the hit on the bars of the X
65 const int size = GetSize() / 2;
66 const SEG loc = SEG( aPosition, aPosition );
67
68 const SEG seg1 = SEG( m_pos - VECTOR2I{ size, size }, m_pos + VECTOR2I{ size, size } );
69 const SEG seg2 = SEG( m_pos - VECTOR2I{ size, -size }, m_pos + VECTOR2I{ size, -size } );
70 const SHAPE_CIRCLE circle( m_pos, size / 2 );
71
72 bool hit = seg1.Collide( loc, aAccuracy ) || seg2.Collide( loc, aAccuracy ) || circle.Collide( loc, aAccuracy );
73
74 return hit;
75}
76
77
78bool PCB_POINT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
79{
80 return KIGEOM::BoxHitTest( aRect, GetBoundingBox(), aContained, aAccuracy );
81}
82
83
84std::vector<int> PCB_POINT::ViewGetLayers() const
85{
86 const PCB_LAYER_ID layer = GetLayer();
87
88 std::vector<int> layers = {
89 POINT_LAYER_FOR( layer ),
90 };
91
92 if( IsLocked() )
93 layers.push_back( LAYER_LOCKED_ITEM_SHADOW );
94
95 return layers;
96}
97
98
99double PCB_POINT::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
100{
101 // All points hidden
102 if( !aView->IsLayerVisible( LAYER_POINTS ) )
103 return LOD_HIDE;
104
105 // Hide if the "main" layer is not shown
106 if( !aView->IsLayerVisible( m_layer ) )
107 return LOD_HIDE;
108
109 return LOD_SHOW;
110}
111
112
113void PCB_POINT::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
114{
115 RotatePoint( m_pos, aRotCentre, aAngle );
116}
117
118
119void PCB_POINT::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
120{
121 MIRROR(m_pos, aCentre, aFlipDirection);
122
124}
125
126
128{
130 return bbox;
131}
132
133
134std::shared_ptr<SHAPE> PCB_POINT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
135{
136 return std::make_shared<SHAPE_RECT>( GetBoundingBox() );
137}
138
139
140wxString PCB_POINT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
141{
142 return _( "Point" );
143}
144
145
150
151
153{
154 return new PCB_POINT( *this );
155}
156
157
159{
160 assert( aOther->Type() == PCB_POINT_T );
161
162 std::swap( *((PCB_POINT*) this), *((PCB_POINT*) aOther) );
163}
164
165
166void PCB_POINT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
167{
168 aList.emplace_back( _( "PCB Point" ), wxEmptyString );
169
170 aList.emplace_back( _( "Position X" ), aFrame->MessageTextFromValue( GetPosition().x ) );
171 aList.emplace_back( _( "Position Y" ), aFrame->MessageTextFromValue( GetPosition().y ) );
172 aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetSize() ) );
173 aList.emplace_back( _( "Layer" ), GetLayerName() );
174}
175
176
178 int aClearance, int aError, ERROR_LOC aErrorLoc,
179 bool ignoreLineWidth ) const
180{
181}
182
183
184bool PCB_POINT::operator==( const BOARD_ITEM& aBoardItem ) const
185{
186 if( aBoardItem.Type() != Type() )
187 return false;
188
189 const PCB_POINT& other = static_cast<const PCB_POINT&>( aBoardItem );
190
191 return *this == other;
192}
193
194
195bool PCB_POINT::operator==( const PCB_POINT& aOther ) const
196{
197 return m_pos == aOther.m_pos && m_size == aOther.m_size;
198}
199
200
201double PCB_POINT::Similarity( const BOARD_ITEM& aOther ) const
202{
203 if( aOther.Type() != Type() )
204 return 0.0;
205
206 const PCB_POINT& other = static_cast<const PCB_POINT&>( aOther );
207
208 double similarity = 1.0;
209
210 if( m_pos == other.m_pos )
211 similarity *= 0.9;
212
213 if( m_size != other.m_size )
214 similarity *= 0.9;
215
216 if( GetLayer() != other.GetLayer() )
217 similarity *= 0.9;
218
219 return similarity;
220}
221
222static struct PCB_POINT_DESC
223{
224 // clang-format off
226 {
228 // PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
231
232 propMgr.AddProperty( new PROPERTY<PCB_POINT, int>( _HKI( "Size" ),
235 }
236 // 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.
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:128
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition pcb_point.cpp:84
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:99
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:62
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: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)
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