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 The 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 SHAPE_SEGMENT& aSeg, NET_HANDLE aNet ) :
54 m_seg( aSeg )
55 {
56 m_net = aNet;
57 }
58
59
60 SEGMENT( const LINE& aParentLine, const SEG& aSeg ) :
62 m_seg( aSeg, aParentLine.Width() )
63 {
64 m_parent = nullptr;
65 m_sourceItem = aParentLine.GetSourceItem();
66
67 m_net = aParentLine.Net();
68 m_layers = aParentLine.Layers();
69 m_marker = aParentLine.Marker();
70 m_rank = aParentLine.Rank();
71 }
72
73 explicit SEGMENT( const LINKED_ITEM& aParent ) :
74 LINKED_ITEM( aParent )
75 {
76 assert( aParent.Kind() == SEGMENT_T );
77 }
78
79 static inline bool ClassOf( const ITEM* aItem )
80 {
81 return aItem && SEGMENT_T == aItem->Kind();
82 }
83
84 SEGMENT* Clone() const override;
85
86 const SHAPE* Shape( int aLayer ) const override
87 {
88 return static_cast<const SHAPE*>( &m_seg );
89 }
90
91 void SetWidth( int aWidth ) override
92 {
93 m_seg.SetWidth(aWidth);
94 }
95
96 int Width() const override
97 {
98 return m_seg.GetWidth();
99 }
100
101 const SEG& Seg() const
102 {
103 return m_seg.GetSeg();
104 }
105
107 {
108 return SHAPE_LINE_CHAIN( { m_seg.GetSeg().A, m_seg.GetSeg().B } );
109 }
110
111 void SetEnds( const VECTOR2I& a, const VECTOR2I& b )
112 {
113 m_seg.SetSeg( SEG ( a, b ) );
114 }
115
116 void SwapEnds()
117 {
118 SEG tmp = m_seg.GetSeg();
119 m_seg.SetSeg( SEG (tmp.B , tmp.A ) );
120 }
121
122 const SHAPE_LINE_CHAIN Hull( int aClearance, int aWalkaroundThickness,
123 int aLayer = -1 ) const override;
124
125 virtual VECTOR2I Anchor( int n ) const override
126 {
127 if( n == 0 )
128 return m_seg.GetSeg().A;
129 else
130 return m_seg.GetSeg().B;
131 }
132
133 virtual int AnchorCount() const override
134 {
135 return 2;
136 }
137
138 virtual const std::string Format() const override;
139
140 void SetShape( const SHAPE_SEGMENT& aShape )
141 {
142 m_seg = aShape;
143 }
144
145private:
147};
148
149}
150
151#endif
Base class for PNS router board items.
Definition pns_item.h:98
BOARD_ITEM * m_sourceItem
Definition pns_item.h:319
const PNS_LAYER_RANGE & Layers() const
Definition pns_item.h:212
virtual NET_HANDLE Net() const
Definition pns_item.h:210
PNS_LAYER_RANGE m_layers
Definition pns_item.h:323
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:173
BOARD_ITEM * GetSourceItem() const
Definition pns_item.h:202
NET_HANDLE m_net
Definition pns_item.h:326
int m_marker
Definition pns_item.h:327
BOARD_ITEM * m_parent
Definition pns_item.h:317
int m_rank
Definition pns_item.h:328
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
int Rank() const override
virtual int Marker() const override
Definition pns_line.cpp:189
LINKED_ITEM(PnsKind aKind)
Keep the router "world" - i.e.
Definition pns_node.h:240
SEGMENT(const LINKED_ITEM &aParent)
Definition pns_segment.h:73
virtual const std::string Format() const override
const SEG & Seg() const
const SHAPE_LINE_CHAIN CLine() const
static bool ClassOf(const ITEM *aItem)
Definition pns_segment.h:79
void SetShape(const SHAPE_SEGMENT &aShape)
const SHAPE * Shape(int aLayer) const override
Return the geometrical shape of the item.
Definition pns_segment.h:86
void SetEnds(const VECTOR2I &a, const VECTOR2I &b)
SEGMENT(const SHAPE_SEGMENT &aSeg, NET_HANDLE aNet)
Definition pns_segment.h:52
SEGMENT * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:200
virtual VECTOR2I Anchor(int n) const override
SEGMENT(const SEG &aSeg, NET_HANDLE aNet)
Definition pns_segment.h:45
SEGMENT(const LINE &aParentLine, const SEG &aSeg)
Definition pns_segment.h:60
int Width() const override
Definition pns_segment.h:96
const SHAPE_LINE_CHAIN Hull(int aClearance, int aWalkaroundThickness, int aLayer=-1) const override
Definition pns_line.cpp:616
virtual int AnchorCount() const override
void SwapEnds()
void SetWidth(int aWidth) override
Definition pns_segment.h:91
SHAPE_SEGMENT m_seg
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...
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:55
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687