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_item.h"
32 #include "pns_line.h"
33 
34 namespace PNS {
35 
36 class NODE;
37 
38 class SEGMENT : public ITEM
39 {
40 public:
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 
129 private:
131 };
132 
133 }
134 
135 #endif
Class ITEM.
Definition: pns_item.h:53
virtual int AnchorCount() const override
Definition: pns_segment.h:124
SHAPE_SEGMENT m_seg
Definition: pns_segment.h:130
void SetSeg(const SEG &aSeg)
Definition: shape_segment.h:65
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:207
int Rank() const override
Definition: pns_line.cpp:730
static bool ClassOf(const ITEM *aItem)
Definition: pns_segment.h:61
LAYER_RANGE m_layers
Definition: pns_item.h:350
int m_rank
Definition: pns_item.h:355
void SetWidth(int aWidth)
Definition: pns_segment.h:83
int m_marker
Definition: pns_item.h:354
SEGMENT(const LINE &aParentLine, const SEG &aSeg)
Definition: pns_segment.h:51
virtual VECTOR2I Anchor(int n) const override
Definition: pns_segment.h:116
int GetWidth() const
Definition: shape_segment.h:80
Class SHAPE.
Definition: shape.h:57
int Width() const
Definition: pns_segment.h:88
int Start() const
Definition: pns_layerset.h:83
SEGMENT(const SEG &aSeg, int aNet)
Definition: pns_segment.h:45
int Layer() const override
Function Layer()
Definition: pns_segment.h:78
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:187
int m_net
Definition: pns_item.h:353
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:120
void SetLayer(int aLayer)
Definition: pns_segment.h:73
Definition: seg.h:37
virtual int Marker() const override
Definition: pns_line.cpp:105
const SEG & GetSeg() const
Definition: shape_segment.h:70
Class SHAPE_LINE_CHAIN.
VECTOR2I A
Definition: seg.h:49
void SwapEnds()
Definition: pns_segment.h:108
void SetEnds(const VECTOR2I &a, const VECTOR2I &b)
Definition: pns_segment.h:103
int Net() const
Function Net()
Definition: pns_item.h:177
const SHAPE_LINE_CHAIN CLine() const
Definition: pns_segment.h:98
const SEG & Seg() const
Definition: pns_segment.h:93
const SHAPE_LINE_CHAIN Hull(int aClearance, int aWalkaroundThickness) const override
Definition: pns_line.cpp:267
const SHAPE * Shape() const override
Function Shape()
Definition: pns_segment.h:68
Push and Shove diff pair dimensions (gap) settings dialog.
SEGMENT * Clone() const override
Function Clone()
Definition: pns_line.cpp:124
Class LAYER_RANGE.
Definition: pns_layerset.h:32
void SetWidth(int aWidth)
Definition: shape_segment.h:75
VECTOR2I B
Definition: seg.h:50