KiCad PCB EDA Suite
pcb_arc.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2007, 2008 Lubo Racko <[email protected]>
5 * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <[email protected]>
6 * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <pcad/pcb_arc.h>
27
28#include <board.h>
29#include <footprint.h>
30#include <fp_shape.h>
31#include <math/util.h> // for KiROUND
32#include <pcb_shape.h>
33#include <trigo.h>
34#include <xnode.h>
35
36#include <wx/string.h>
37
38namespace PCAD2KICAD {
39
40PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
41 PCB_COMPONENT( aCallbacks, aBoard )
42{
43 m_objType = wxT( 'A' );
44 m_StartX = 0;
45 m_StartY = 0;
47 m_Width = 0;
48}
49
50
52{
53}
54
55
56void PCB_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
57 const wxString& aActualConversion )
58{
59 XNODE* lNode;
60 int r = 0;
61 VECTOR2I end;
62
63 m_PCadLayer = aLayer;
65
66 if( FindNode( aNode, wxT( "width" ) ) )
67 {
68 SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(), aDefaultUnits, &m_Width,
69 aActualConversion );
70 }
71
72 if( aNode->GetName() == wxT( "triplePointArc" ) )
73 {
74 // center point
75 lNode = FindNode( aNode, wxT( "pt" ) );
76
77 if( lNode )
78 {
79 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
80 aActualConversion );
81 }
82
83 // start point
84 if( lNode )
85 lNode = lNode->GetNext();
86
87 if( lNode )
88 {
89 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_StartX, &m_StartY,
90 aActualConversion );
91 }
92
93 // end point
94 if( lNode )
95 lNode = lNode->GetNext();
96
97 if( lNode )
98 {
99 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &end.x, &end.y,
100 aActualConversion );
101 }
102
103 VECTOR2I position( m_positionX, m_positionY );
104 VECTOR2I start( m_StartX, m_StartY );
105
106 if( start == end )
107 {
109 }
110 else
111 {
112 EDA_ANGLE alpha1( start - position );
113 EDA_ANGLE alpha2( end - position );
114 m_Angle = alpha1 - alpha2;
115
117 }
118 }
119 else if( aNode->GetName() == wxT( "arc" ) )
120 {
121 lNode = FindNode( aNode, wxT( "pt" ) );
122
123 if( lNode )
124 {
125 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
126 aActualConversion );
127 }
128
129 lNode = FindNode( aNode, wxT( "radius" ) );
130
131 if( lNode)
132 {
133 SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(), aDefaultUnits, &r,
134 aActualConversion );
135 }
136
137
138 lNode = FindNode( aNode, wxT( "startAngle" ) );
139
140 EDA_ANGLE a = ANGLE_0;
141
142 if( lNode )
143 a = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
144
145 lNode = FindNode( aNode, wxT( "sweepAngle" ) );
146
147 if( lNode )
148 m_Angle = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
149
150 m_StartX = m_positionX + KiROUND( r * a.Cos() );
151 m_StartY = m_positionY - KiROUND( r * a.Sin() );
152 }
153}
154
155
156void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs )
157{
158 PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
159
160 m_StartX += aX_offs;
161 m_StartY += aY_offs;
162}
163
164
166{
168
170 m_Angle = -m_Angle;
171
173}
174
175
177{
179 {
180 FP_SHAPE* arc = new FP_SHAPE( aFootprint, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC );
181 aFootprint->Add( arc );
182
185 arc->SetArcAngleAndEnd0( -m_Angle, true );
186
188 arc->SetLayer( m_KiCadLayer );
189
190 arc->SetDrawCoord();
191 }
192}
193
194
196{
198
200
201 arc->SetFilled( false );
202 arc->SetLayer( m_KiCadLayer );
205 arc->SetArcAngleAndEnd( -m_Angle, true );
207}
208
209
211{
212 return ( m_Angle == ANGLE_360 );
213}
214
215} // namespace PCAD2KICAD
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:214
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:711
EDA_ANGLE Normalize()
Definition: eda_angle.h:249
double Sin() const
Definition: eda_angle.h:206
double Cos() const
Definition: eda_angle.h:221
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:458
void SetFilled(bool aFlag)
Definition: eda_shape.h:95
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:124
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:584
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:561
void SetStart0(const VECTOR2I &aPoint)
Definition: fp_shape.h:91
virtual void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
Definition: fp_shape.cpp:80
void SetArcAngleAndEnd0(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
Definition: fp_shape.cpp:193
void SetCenter0(const VECTOR2I &aPt)
Definition: fp_shape.cpp:161
PCB_ARC(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_arc.cpp:40
void AddToFootprint(FOOTPRINT *aFootprint) override
Definition: pcb_arc.cpp:176
virtual void Flip() override
Definition: pcb_arc.cpp:165
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition: pcb_arc.cpp:56
EDA_ANGLE m_Angle
Definition: pcb_arc.h:56
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_arc.cpp:156
void AddToBoard() override
Definition: pcb_arc.cpp:195
PCB_LAYER_ID GetKiCadLayer() const
Definition: pcb_component.h:56
virtual void SetPosOffset(int aX_offs, int aY_offs)
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: pcb_shape.h:72
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
Hold an XML or S-expression element.
Definition: xnode.h:44
XNODE * GetNext() const
Definition: xnode.h:67
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
static constexpr EDA_ANGLE & ANGLE_360
Definition: eda_angle.h:418
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
E_SERIE r
Definition: eserie.cpp:41
bool IsNonCopperLayer(int aLayerId)
Test whether a layer is a non copper layer.
Definition: layer_ids.h:836
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:544
int StrToInt1Units(const wxString &aStr)
void SetWidth(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
void SetPosition(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618