KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_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-2023 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/pcad_arc.h>
27
28#include <board.h>
29#include <footprint.h>
30#include <math/util.h> // for KiROUND
31#include <pcb_shape.h>
32#include <trigo.h>
33#include <xnode.h>
34
35#include <wx/string.h>
36
37namespace PCAD2KICAD {
38
39PCAD_ARC::PCAD_ARC( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
40 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
41{
42 m_ObjType = wxT( 'A' );
43 m_StartX = 0;
44 m_StartY = 0;
46 m_Width = 0;
47}
48
49
51{
52}
53
54
55void PCAD_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
56 const wxString& aActualConversion )
57{
58 XNODE* lNode;
59 int r = 0;
60 VECTOR2I end;
61
62 m_PCadLayer = aLayer;
64
65 if( FindNode( aNode, wxT( "width" ) ) )
66 {
67 SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(), aDefaultUnits, &m_Width,
68 aActualConversion );
69 }
70
71 if( aNode->GetName() == wxT( "triplePointArc" ) )
72 {
73 // center point
74 lNode = FindNode( aNode, wxT( "pt" ) );
75
76 if( lNode )
77 {
78 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
79 aActualConversion );
80 }
81
82 // start point
83 if( lNode )
84 lNode = lNode->GetNext();
85
86 if( lNode )
87 {
88 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_StartX, &m_StartY,
89 aActualConversion );
90 }
91
92 // end point
93 if( lNode )
94 lNode = lNode->GetNext();
95
96 if( lNode )
97 {
98 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &end.x, &end.y,
99 aActualConversion );
100 }
101
102 VECTOR2I position( m_PositionX, m_PositionY );
103 VECTOR2I start( m_StartX, m_StartY );
104
105 if( start == end )
106 {
108 }
109 else
110 {
111 EDA_ANGLE alpha1( start - position );
112 EDA_ANGLE alpha2( end - position );
113 m_Angle = alpha1 - alpha2;
114
116 }
117 }
118 else if( aNode->GetName() == wxT( "arc" ) )
119 {
120 lNode = FindNode( aNode, wxT( "pt" ) );
121
122 if( lNode )
123 {
124 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
125 aActualConversion );
126 }
127
128 lNode = FindNode( aNode, wxT( "radius" ) );
129
130 if( lNode)
131 {
132 SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(), aDefaultUnits, &r,
133 aActualConversion );
134 }
135
136
137 lNode = FindNode( aNode, wxT( "startAngle" ) );
138
139 EDA_ANGLE a = ANGLE_0;
140
141 if( lNode )
142 a = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
143
144 lNode = FindNode( aNode, wxT( "sweepAngle" ) );
145
146 if( lNode )
147 m_Angle = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
148
149 m_StartX = m_PositionX + KiROUND( r * a.Cos() );
150 m_StartY = m_PositionY - KiROUND( r * a.Sin() );
151 }
152}
153
154
155void PCAD_ARC::SetPosOffset( int aX_offs, int aY_offs )
156{
157 PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
158
159 m_StartX += aX_offs;
160 m_StartY += aY_offs;
161}
162
163
165{
167
169 m_Angle = -m_Angle;
170
172}
173
174
176{
177 PCB_SHAPE* arc = new PCB_SHAPE( aFootprint, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC );
178
181 arc->SetArcAngleAndEnd( -m_Angle, true );
182
183 arc->SetStroke( STROKE_PARAMS( m_Width, LINE_STYLE::SOLID ) );
184 arc->SetLayer( m_KiCadLayer );
185
186 if( aFootprint )
187 {
188 aFootprint->Add( arc );
189 arc->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
190 arc->Move( aFootprint->GetPosition() );
191 }
192 else
193 m_board->Add( arc );
194}
195
196
198{
199 return ( m_Angle == ANGLE_360 );
200}
201
202} // namespace PCAD2KICAD
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:882
EDA_ANGLE Normalize()
Definition: eda_angle.h:255
double Sin() const
Definition: eda_angle.h:212
double Cos() const
Definition: eda_angle.h:227
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:543
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:129
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:689
EDA_ANGLE GetOrientation() const
Definition: footprint.h:212
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:968
VECTOR2I GetPosition() const override
Definition: footprint.h:209
PCAD_ARC(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcad_arc.cpp:39
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcad_arc.cpp:155
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition: pcad_arc.cpp:55
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
Definition: pcad_arc.cpp:175
virtual void Flip() override
Definition: pcad_arc.cpp:164
EDA_ANGLE m_Angle
Definition: pcad_arc.h:59
virtual void SetPosOffset(int aX_offs, int aY_offs)
PCB_LAYER_ID GetKiCadLayer() const
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_shape.cpp:523
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_shape.cpp:314
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_shape.cpp:452
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: pcb_shape.h:86
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
Hold an XML or S-expression element.
Definition: xnode.h:44
XNODE * GetNext() const
Definition: xnode.h:67
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:441
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:634
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:588