KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_solid.cpp
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
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 <math/vector2d.h>
23
24#include <geometry/shape.h>
29
30#include <wx/log.h>
31
32#include "pns_router.h"
33#include "pns_solid.h"
34#include "pns_utils.h"
35
36namespace PNS {
37
38
39const SHAPE_LINE_CHAIN SOLID::Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const
40{
41 if( !m_shape )
42 return SHAPE_LINE_CHAIN();
43
44 if( m_shape->Type() == SH_COMPOUND )
45 {
46 SHAPE_COMPOUND* cmpnd = static_cast<SHAPE_COMPOUND*>( m_shape );
47
48 if ( cmpnd->Shapes().size() == 1 )
49 {
50 return BuildHullForPrimitiveShape( cmpnd->Shapes()[0], aClearance,
51 aWalkaroundThickness );
52 }
53 else
54 {
55 SHAPE_POLY_SET hullSet;
56
57 for( SHAPE* shape : cmpnd->Shapes() )
58 {
59 hullSet.AddOutline( BuildHullForPrimitiveShape( shape, aClearance,
60 aWalkaroundThickness ) );
61 }
62
64 return hullSet.Outline( 0 );
65 }
66 }
67 else
68 {
69 return BuildHullForPrimitiveShape( m_shape, aClearance, aWalkaroundThickness );
70 }
71}
72
73
75{
76 ITEM* solid = new SOLID( *this );
77 return solid;
78}
79
80
81void SOLID::SetPos( const VECTOR2I& aCenter )
82{
83 VECTOR2I delta = aCenter - m_pos;
84
85 if( m_shape )
86 m_shape->Move( delta );
87
88 if( m_hole )
89 m_hole->Move( delta );
90
91 m_pos = aCenter;
92}
93
94
95VECTOR2I SOLID::Anchor( int aN ) const
96{
97 return m_anchorPoints.empty() ? m_pos : m_anchorPoints[aN];
98}
99
101{
102 return m_anchorPoints.empty() ? 1 : m_anchorPoints.size();
103}
104
105
106}
void Move(const VECTOR2I &delta)
Definition: pns_hole.cpp:125
Base class for PNS router board items.
Definition: pns_item.h:97
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_solid.cpp:39
VECTOR2I m_pos
Definition: pns_solid.h:139
void SetPos(const VECTOR2I &aCenter)
Definition: pns_solid.cpp:81
SHAPE * m_shape
Definition: pns_solid.h:140
ITEM * Clone() const override
Return a deep copy of the item.
Definition: pns_solid.cpp:74
std::vector< VECTOR2I > m_anchorPoints
Definition: pns_solid.h:145
virtual VECTOR2I Anchor(int aN) const override
Definition: pns_solid.cpp:95
virtual int AnchorCount() const override
Definition: pns_solid.cpp:100
HOLE * m_hole
Definition: pns_solid.h:144
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:98
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
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:477
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
Definition: shape.h:53
constexpr int delta