KiCad PCB EDA Suite
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 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, int 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 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:
122};
123
124}
125
126#endif
Base class for PNS router board items.
Definition: pns_item.h:56
int m_net
Definition: pns_item.h:254
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:130
LAYER_RANGE m_layers
Definition: pns_item.h:251
@ SEGMENT_T
Definition: pns_item.h:66
const LAYER_RANGE & Layers() const
Definition: pns_item.h:154
int m_marker
Definition: pns_item.h:255
int Net() const
Definition: pns_item.h:152
int m_rank
Definition: pns_item.h:256
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
virtual int Marker() const override
Definition: pns_line.cpp:108
int Rank() const override
Definition: pns_line.cpp:1039
const SEG & Seg() const
Definition: pns_segment.h:84
const SHAPE_LINE_CHAIN CLine() const
Definition: pns_segment.h:89
static bool ClassOf(const ITEM *aItem)
Definition: pns_segment.h:62
void SetEnds(const VECTOR2I &a, const VECTOR2I &b)
Definition: pns_segment.h:94
SEGMENT(const SEG &aSeg, int aNet)
Definition: pns_segment.h:45
SEGMENT * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:121
virtual VECTOR2I Anchor(int n) const override
Definition: pns_segment.h:107
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_segment.h:69
SEGMENT(const LINE &aParentLine, const SEG &aSeg)
Definition: pns_segment.h:52
int Width() const override
Definition: pns_segment.h:79
const SHAPE_LINE_CHAIN Hull(int aClearance, int aWalkaroundThickness, int aLayer=-1) const override
Definition: pns_line.cpp:531
virtual int AnchorCount() const override
Definition: pns_segment.h:115
void SwapEnds()
Definition: pns_segment.h:99
void SetWidth(int aWidth) override
Definition: pns_segment.h:74
SHAPE_SEGMENT m_seg
Definition: pns_segment.h:121
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:123
Push and Shove diff pair dimensions (gap) settings dialog.