Horizon
Loading...
Searching...
No Matches
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_line.h"
32#include "pns_linked_item.h"
33
34namespace PNS {
35
36class NODE;
37
38class SEGMENT : public LINKED_ITEM
39{
40public:
41 SEGMENT() :
42 LINKED_ITEM( SEGMENT_T )
43 {}
44
45 SEGMENT( const SEG& aSeg, int aNet ) :
46 LINKED_ITEM( SEGMENT_T ),
47 m_seg( aSeg, 0 )
48 {
49 m_net = aNet;
50 }
51
52 SEGMENT( const LINE& aParentLine, const SEG& aSeg ) :
53 LINKED_ITEM( SEGMENT_T ),
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 static inline bool ClassOf( const ITEM* aItem )
63 {
64 return aItem && SEGMENT_T == aItem->Kind();
65 }
66
67 SEGMENT* Clone() const override;
68
69 const SHAPE* Shape() const override
70 {
71 return static_cast<const SHAPE*>( &m_seg );
72 }
73
74 void SetWidth( int aWidth ) override
75 {
76 m_seg.SetWidth(aWidth);
77 }
78
79 int Width() const override
80 {
81 return m_seg.GetWidth();
82 }
83
84 const SEG& Seg() const
85 {
86 return m_seg.GetSeg();
87 }
88
89 const SHAPE_LINE_CHAIN CLine() const
90 {
91 return SHAPE_LINE_CHAIN( { m_seg.GetSeg().A, m_seg.GetSeg().B } );
92 }
93
94 void SetEnds( const VECTOR2I& a, const VECTOR2I& b )
95 {
96 m_seg.SetSeg( SEG ( a, b ) );
97 }
98
99 void SwapEnds()
100 {
101 SEG tmp = m_seg.GetSeg();
102 m_seg.SetSeg( SEG (tmp.B , tmp.A ) );
103 }
104
105 const SHAPE_LINE_CHAIN Hull( int aClearance, int aWalkaroundThickness, int aLayer = -1 ) const override;
106
107 virtual VECTOR2I Anchor( int n ) const override
108 {
109 if( n == 0 )
110 return m_seg.GetSeg().A;
111 else
112 return m_seg.GetSeg().B;
113 }
114
115 virtual int AnchorCount() const override
116 {
117 return 2;
118 }
119
120private:
121 SHAPE_SEGMENT m_seg;
122};
123
124}
125
126#endif
Base class for PNS router board items.
Definition pns_item.h:57
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:131
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:61
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition pns_line.h:156
Definition pns_linked_item.h:30
Definition pns_segment.h:39
SEGMENT * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:121
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition pns_segment.h:69
Definition seg.h:41
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition shape_line_chain.h:81
Definition shape_segment.h:36
An abstract shape on 2D plane.
Definition shape.h:117