KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_segment.h
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#ifndef __PNS_SEGMENT_H
23#define __PNS_SEGMENT_H
24
25#include <math/vector2d.h>
26
27#include <geometry/seg.h>
30
31#include "pns_line.h"
32#include "pns_linked_item.h"
33
34namespace PNS {
35
36class NODE;
37
38class SEGMENT : public LINKED_ITEM
39{
40public:
43 {}
44
45 SEGMENT( const SEG& aSeg, NET_HANDLE aNet ) :
47 m_seg( aSeg, 0 )
48 {
49 m_net = aNet;
50 }
51
52 SEGMENT( const LINE& aParentLine, const SEG& aSeg ) :
54 m_seg( aSeg, aParentLine.Width() )
55 {
56 m_net = aParentLine.Net();
57 m_layers = aParentLine.Layers();
58 m_marker = aParentLine.Marker();
59 m_rank = aParentLine.Rank();
60 }
61
62 explicit SEGMENT( const LINKED_ITEM& aParent ) :
63 LINKED_ITEM( aParent )
64 {
65 assert( aParent.Kind() == SEGMENT_T );
66 }
67
68 static inline bool ClassOf( const ITEM* aItem )
69 {
70 return aItem && SEGMENT_T == aItem->Kind();
71 }
72
73 SEGMENT* Clone() const override;
74
75 const SHAPE* Shape( int aLayer ) const override
76 {
77 return static_cast<const SHAPE*>( &m_seg );
78 }
79
80 void SetWidth( int aWidth ) override
81 {
82 m_seg.SetWidth(aWidth);
83 }
84
85 int Width() const override
86 {
87 return m_seg.GetWidth();
88 }
89
90 const SEG& Seg() const
91 {
92 return m_seg.GetSeg();
93 }
94
95 const SHAPE_LINE_CHAIN CLine() const
96 {
97 return SHAPE_LINE_CHAIN( { m_seg.GetSeg().A, m_seg.GetSeg().B } );
98 }
99
100 void SetEnds( const VECTOR2I& a, const VECTOR2I& b )
101 {
102 m_seg.SetSeg( SEG ( a, b ) );
103 }
104
105 void SwapEnds()
106 {
107 SEG tmp = m_seg.GetSeg();
108 m_seg.SetSeg( SEG (tmp.B , tmp.A ) );
109 }
110
111 const SHAPE_LINE_CHAIN Hull( int aClearance, int aWalkaroundThickness, int aLayer = -1 ) const override;
112
113 virtual VECTOR2I Anchor( int n ) const override
114 {
115 if( n == 0 )
116 return m_seg.GetSeg().A;
117 else
118 return m_seg.GetSeg().B;
119 }
120
121 virtual int AnchorCount() const override
122 {
123 return 2;
124 }
125
126 virtual const std::string Format() const override;
127
128 void SetShape( const SHAPE_SEGMENT& aShape )
129 {
130 m_seg = aShape;
131 }
132
133private:
135};
136
137}
138
139#endif
Base class for PNS router board items.
Definition: pns_item.h:97
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:199
virtual NET_HANDLE Net() const
Definition: pns_item.h:197
PNS_LAYER_RANGE m_layers
Definition: pns_item.h:306
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:170
NET_HANDLE m_net
Definition: pns_item.h:309
@ SEGMENT_T
Definition: pns_item.h:106
int m_marker
Definition: pns_item.h:310
int m_rank
Definition: pns_item.h:311
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:62
int Rank() const override
Definition: pns_line.cpp:1117
virtual int Marker() const override
Definition: pns_line.cpp:142
SEGMENT(const LINKED_ITEM &aParent)
Definition: pns_segment.h:62
virtual const std::string Format() const override
Definition: pns_line.cpp:1329
const SEG & Seg() const
Definition: pns_segment.h:90
const SHAPE_LINE_CHAIN CLine() const
Definition: pns_segment.h:95
static bool ClassOf(const ITEM *aItem)
Definition: pns_segment.h:68
void SetShape(const SHAPE_SEGMENT &aShape)
Definition: pns_segment.h:128
const SHAPE * Shape(int aLayer) const override
Return the geometrical shape of the item.
Definition: pns_segment.h:75
void SetEnds(const VECTOR2I &a, const VECTOR2I &b)
Definition: pns_segment.h:100
SEGMENT * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:153
virtual VECTOR2I Anchor(int n) const override
Definition: pns_segment.h:113
SEGMENT(const SEG &aSeg, NET_HANDLE aNet)
Definition: pns_segment.h:45
SEGMENT(const LINE &aParentLine, const SEG &aSeg)
Definition: pns_segment.h:52
int Width() const override
Definition: pns_segment.h:85
const SHAPE_LINE_CHAIN Hull(int aClearance, int aWalkaroundThickness, int aLayer=-1) const override
Definition: pns_line.cpp:569
virtual int AnchorCount() const override
Definition: pns_segment.h:121
void SwapEnds()
Definition: pns_segment.h:105
void SetWidth(int aWidth) override
Definition: pns_segment.h:80
SHAPE_SEGMENT m_seg
Definition: pns_segment.h:134
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SEG & GetSeg() const
int GetWidth() const
void SetSeg(const SEG &aSeg)
void SetWidth(int aWidth)
An abstract shape on 2D plane.
Definition: shape.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54