Horizon
pns_segment.h
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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>
28#include <geometry/shape_segment.h>
29#include <geometry/shape_line_chain.h>
30
31#include "pns_item.h"
32#include "pns_line.h"
33
34namespace PNS {
35
36class NODE;
37
38class SEGMENT : public ITEM
39{
40public:
41 SEGMENT() :
42 ITEM( SEGMENT_T )
43 {}
44
45 SEGMENT( const SEG& aSeg, int aNet ) :
46 ITEM( SEGMENT_T ), m_seg( aSeg, 0 )
47 {
48 m_net = aNet;
49 }
50
51 SEGMENT( const LINE& aParentLine, const SEG& aSeg ) :
52 ITEM( SEGMENT_T ),
53 m_seg( aSeg, aParentLine.Width() )
54 {
55 m_net = aParentLine.Net();
56 m_layers = aParentLine.Layers();
57 m_marker = aParentLine.Marker();
58 m_rank = aParentLine.Rank();
59 }
60
61 static inline bool ClassOf( const ITEM* aItem )
62 {
63 return aItem && SEGMENT_T == aItem->Kind();
64 }
65
66 SEGMENT* Clone() const override;
67
68 const SHAPE* Shape() const override
69 {
70 return static_cast<const SHAPE*>( &m_seg );
71 }
72
73 void SetLayer( int aLayer )
74 {
75 SetLayers( LAYER_RANGE( aLayer ) );
76 }
77
78 int Layer() const override
79 {
80 return Layers().Start();
81 }
82
83 void SetWidth( int aWidth )
84 {
85 m_seg.SetWidth(aWidth);
86 }
87
88 int Width() const
89 {
90 return m_seg.GetWidth();
91 }
92
93 const SEG& Seg() const
94 {
95 return m_seg.GetSeg();
96 }
97
98 const SHAPE_LINE_CHAIN CLine() const
99 {
100 return SHAPE_LINE_CHAIN( m_seg.GetSeg().A, m_seg.GetSeg().B );
101 }
102
103 void SetEnds( const VECTOR2I& a, const VECTOR2I& b )
104 {
105 m_seg.SetSeg( SEG ( a, b ) );
106 }
107
108 void SwapEnds()
109 {
110 SEG tmp = m_seg.GetSeg();
111 m_seg.SetSeg( SEG (tmp.B , tmp.A ) );
112 }
113
114 const SHAPE_LINE_CHAIN Hull( int aClearance, int aWalkaroundThickness ) const override;
115
116 virtual VECTOR2I Anchor( int n ) const override
117 {
118 if( n == 0 )
119 return m_seg.GetSeg().A;
120 else
121 return m_seg.GetSeg().B;
122 }
123
124 virtual int AnchorCount() const override
125 {
126 return 2;
127 }
128
129private:
130 SHAPE_SEGMENT m_seg;
131};
132
133}
134
135#endif
Class LAYER_RANGE.
Definition: pns_layerset.h:33
Class ITEM.
Definition: pns_item.h:55
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:195
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:215
int Net() const
Function Net()
Definition: pns_item.h:180
Definition: pns_line.h:61
int Width() const
‍Returns line width
Definition: pns_line.h:161
Definition: pns_segment.h:39
int Layer() const override
Function Layer()
Definition: pns_segment.h:78
SEGMENT * Clone() const override
Function Clone()
Definition: pns_line.cpp:122
const SHAPE * Shape() const override
Function Shape()
Definition: pns_segment.h:68
Definition: seg.h:37
Class SHAPE_LINE_CHAIN.
Definition: shape_line_chain.h:50
Definition: shape_segment.h:31
Class SHAPE.
Definition: shape.h:59