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 <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>
30 
31 #include "pns_line.h"
32 #include "pns_linked_item.h"
33 
34 namespace PNS {
35 
36 class NODE;
37 
38 class SEGMENT : public LINKED_ITEM
39 {
40 public:
41  SEGMENT() :
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 
120 private:
122 };
123 
124 }
125 
126 #endif
Base class for PNS router board items.
Definition: pns_item.h:55
virtual int AnchorCount() const override
Definition: pns_segment.h:115
SHAPE_SEGMENT m_seg
Definition: pns_segment.h:121
void SetSeg(const SEG &aSeg)
int Rank() const override
Definition: pns_line.cpp:1053
int Width() const override
Definition: pns_segment.h:79
SEGMENT * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:121
const SHAPE_LINE_CHAIN CLine() const
Definition: pns_segment.h:89
static bool ClassOf(const ITEM *aItem)
Definition: pns_segment.h:62
LAYER_RANGE m_layers
Definition: pns_item.h:246
int m_rank
Definition: pns_item.h:251
const SEG & Seg() const
Definition: pns_segment.h:84
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:60
const SHAPE_LINE_CHAIN Hull(int aClearance, int aWalkaroundThickness, int aLayer=-1) const override
Definition: pns_line.cpp:531
const SEG & GetSeg() const
int m_marker
Definition: pns_item.h:250
SEGMENT(const LINE &aParentLine, const SEG &aSeg)
Definition: pns_segment.h:52
virtual VECTOR2I Anchor(int n) const override
Definition: pns_segment.h:107
void SetWidth(int aWidth) override
Definition: pns_segment.h:74
int Net() const
Definition: pns_item.h:150
An abstract shape on 2D plane.
Definition: shape.h:116
SEGMENT(const SEG &aSeg, int aNet)
Definition: pns_segment.h:45
int m_net
Definition: pns_item.h:249
Definition: seg.h:40
virtual int Marker() const override
Definition: pns_line.cpp:108
Represent a polyline (an zero-thickness chain of connected line segments).
VECTOR2I A
Definition: seg.h:48
void SwapEnds()
Definition: pns_segment.h:99
void SetEnds(const VECTOR2I &a, const VECTOR2I &b)
Definition: pns_segment.h:94
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:128
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_segment.h:69
Push and Shove diff pair dimensions (gap) settings dialog.
int GetWidth() const
const LAYER_RANGE & Layers() const
Definition: pns_item.h:152
void SetWidth(int aWidth)
VECTOR2I B
Definition: seg.h:49