KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_hole.cpp
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * @author Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "pns_item.h"
23#include "pns_hole.h"
24#include "pns_node.h"
25#include "pns_utils.h"
26
31
32namespace PNS
33{
34
36{
37 delete m_holeShape;
38}
39
40
42{
43 HOLE* h = new HOLE( m_holeShape->Clone() );
44
45 h->SetLayers( Layers() );
46 h->SetOwner( nullptr );
47
48 h->m_rank = m_rank;
49 h->m_marker = m_marker;
50 h->m_parent = m_parent;
52
53 return h;
54}
55
56
57const SHAPE_LINE_CHAIN HOLE::Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const
58{
59 if( !m_holeShape )
60 return SHAPE_LINE_CHAIN();
61
62 if( m_holeShape->Type() == SH_CIRCLE )
63 {
64 auto cir = static_cast<SHAPE_CIRCLE*>( m_holeShape );
65 int cl = ( aClearance + aWalkaroundThickness / 2 );
66 int width = cir->GetRadius() * 2;
67
68 // Chamfer = width * ( 1 - sqrt(2)/2 ) for equilateral octagon
69 return OctagonalHull( cir->GetCenter() - VECTOR2I( width / 2, width / 2 ),
70 VECTOR2I( width, width ), cl,
71 ( 2 * cl + width ) * ( 1.0 - M_SQRT1_2 ) );
72 }
73 else if( m_holeShape->Type() == SH_COMPOUND )
74 {
75 SHAPE_COMPOUND* cmpnd = static_cast<SHAPE_COMPOUND*>( m_holeShape );
76
77 if( cmpnd->Shapes().size() == 1 )
78 {
79 return BuildHullForPrimitiveShape( cmpnd->Shapes()[0], aClearance,
80 aWalkaroundThickness );
81 }
82 else
83 {
84 SHAPE_POLY_SET hullSet;
85
86 for( SHAPE* shape : cmpnd->Shapes() )
87 {
88 hullSet.AddOutline(
89 BuildHullForPrimitiveShape( shape, aClearance, aWalkaroundThickness ) );
90 }
91
93 return hullSet.Outline( 0 );
94 }
95 }
96 else
97 {
98 return BuildHullForPrimitiveShape( m_holeShape, aClearance, aWalkaroundThickness );
99 }
100}
101
102
103int HOLE::Radius() const
104{
105 assert( m_holeShape->Type() == SH_CIRCLE );
106
107 return static_cast<const SHAPE_CIRCLE*>( m_holeShape )->GetRadius();
108}
109
110
111void HOLE::SetCenter( const VECTOR2I& aCenter )
112{
113 assert( m_holeShape->Type() == SH_CIRCLE );
114 static_cast<SHAPE_CIRCLE*>( m_holeShape )->SetCenter( aCenter );
115}
116
117
118void HOLE::SetRadius( int aRadius )
119{
120 assert( m_holeShape->Type() == SH_CIRCLE );
121 static_cast<SHAPE_CIRCLE*>( m_holeShape )->SetRadius( aRadius );
122}
123
124
126{
128}
129
130
131HOLE* HOLE::MakeCircularHole( const VECTOR2I& pos, int radius )
132{
133 SHAPE_CIRCLE* circle = new SHAPE_CIRCLE( pos, radius );
134 HOLE* hole = new HOLE( circle );
135
136 hole->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
137 return hole;
138}
139
140}; // namespace PNS
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
void Move(const VECTOR2I &delta)
Definition: pns_hole.cpp:125
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_hole.cpp:57
int Radius() const
Definition: pns_hole.cpp:103
void SetCenter(const VECTOR2I &aCenter)
Definition: pns_hole.cpp:111
void SetRadius(int aRadius)
Definition: pns_hole.cpp:118
static HOLE * MakeCircularHole(const VECTOR2I &pos, int radius)
Definition: pns_hole.cpp:131
virtual HOLE * Clone() const override
Return a deep copy of the item.
Definition: pns_hole.cpp:41
SHAPE * m_holeShape
Definition: pns_hole.h:94
virtual ~HOLE()
Definition: pns_hole.cpp:35
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:196
bool m_isVirtual
Definition: pns_item.h:294
const LAYER_RANGE & Layers() const
Definition: pns_item.h:195
int m_marker
Definition: pns_item.h:291
BOARD_ITEM * m_parent
Definition: pns_item.h:286
int m_rank
Definition: pns_item.h:292
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition: pns_item.h:76
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:98
int GetRadius() const
Definition: shape_circle.h:108
const std::vector< SHAPE * > & Shapes() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
An abstract shape on 2D plane.
Definition: shape.h:126
virtual void Move(const VECTOR2I &aVector)=0
virtual SHAPE * Clone() const
Return a dynamically allocated copy of the shape.
Definition: shape.h:148
@ B_Cu
Definition: layer_ids.h:95
@ F_Cu
Definition: layer_ids.h:64
Push and Shove diff pair dimensions (gap) settings dialog.
const SHAPE_LINE_CHAIN BuildHullForPrimitiveShape(const SHAPE *aShape, int aClearance, int aWalkaroundThickness)
Definition: pns_utils.cpp:467
const SHAPE_LINE_CHAIN OctagonalHull(const VECTOR2I &aP0, const VECTOR2I &aSize, int aClearance, int aChamfer)
Definition: pns_utils.cpp:36
@ SH_CIRCLE
circle
Definition: shape.h:50
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
Definition: shape.h:53
constexpr int delta
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588