1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2019 CERN
5  * Author: Seth Hillbrand <hillbrand@ucdavis.edu>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __PNS_ARC_H
22 #define __PNS_ARC_H
23 
24 #include <math/vector2d.h>
25 
26 #include <geometry/shape_arc.h>
27 #include <geometry/shape_line_chain.h>
28 
29 #include "pns_line.h"
30 #include "pns_linked_item.h"
31 
32 namespace PNS {
33 
34 class NODE;
35 
36 class ARC : public LINKED_ITEM
37 {
38 public:
ARC()39     ARC() :
40         LINKED_ITEM( ARC_T )
41     {}
42 
ARC(const SHAPE_ARC & aArc,int aNet)43     ARC( const SHAPE_ARC& aArc, int aNet ) :
44         LINKED_ITEM( ARC_T ),
45         m_arc( aArc )
46     {
47         m_net = aNet;
48     }
49 
ARC(const ARC & aParentArc,const SHAPE_ARC & aArc)50     ARC( const ARC& aParentArc, const SHAPE_ARC& aArc ) :
51         LINKED_ITEM( ARC_T ),
52         m_arc( aArc )
53     {
54         m_net = aParentArc.Net();
55         m_layers = aParentArc.Layers();
56         m_marker = aParentArc.Marker();
57         m_rank = aParentArc.Rank();
58     }
59 
ARC(const LINE & aParentLine,const SHAPE_ARC & aArc)60     ARC( const LINE& aParentLine, const SHAPE_ARC& aArc ) :
61         LINKED_ITEM( ARC_T ),
62         m_arc( aArc.GetP0(), aArc.GetArcMid(), aArc.GetP1(), aParentLine.Width() )
63     {
64         m_net = aParentLine.Net();
65         m_layers = aParentLine.Layers();
66         m_marker = aParentLine.Marker();
67         m_rank = aParentLine.Rank();
68     }
69 
ClassOf(const ITEM * aItem)70     static inline bool ClassOf( const ITEM* aItem )
71     {
72         return aItem && ARC_T == aItem->Kind();
73     }
74 
75     ARC* Clone() const override;
76 
Shape()77     const SHAPE* Shape() const override
78     {
79         return static_cast<const SHAPE*>( &m_arc );
80     }
81 
SetWidth(int aWidth)82     void SetWidth( int aWidth ) override
83     {
84         m_arc.SetWidth(aWidth);
85     }
86 
Width()87     int Width() const override
88     {
89         return m_arc.GetWidth();
90     }
91 
CLine()92     const SHAPE_LINE_CHAIN CLine() const
93     {
94         return SHAPE_LINE_CHAIN( m_arc );
95     }
96 
97     const SHAPE_LINE_CHAIN Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const override;
98 
Anchor(int n)99     virtual VECTOR2I Anchor( int n ) const override
100     {
101         if( n == 0 )
102             return m_arc.GetP0();
103         else
104             return m_arc.GetP1();
105     }
106 
AnchorCount()107     virtual int AnchorCount() const override
108     {
109         return 2;
110     }
111 
112     OPT_BOX2I ChangedArea( const ARC* aOther ) const;
113 
Arc()114     SHAPE_ARC& Arc() { return m_arc; }
CArc()115     const SHAPE_ARC& CArc() const { return m_arc; }
116 
117 private:
118     SHAPE_ARC m_arc;
119 };
120 
121 }
122 
123 #endif
124