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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <pcad/pcad_arc.h>
23
24#include <board.h>
25#include <footprint.h>
26#include <math/util.h> // for KiROUND
27#include <pcb_shape.h>
28#include <trigo.h>
29#include <xnode.h>
30
31#include <wx/string.h>
32
33namespace PCAD2KICAD {
34
35PCAD_ARC::PCAD_ARC( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
36 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
37{
38 m_ObjType = wxT( 'A' );
39 m_StartX = 0;
40 m_StartY = 0;
42 m_Width = 0;
43}
44
45
49
50
51void PCAD_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
52 const wxString& aActualConversion )
53{
54 XNODE* lNode;
55 int r = 0;
57
58 m_PCadLayer = aLayer;
60
61 if( FindNode( aNode, wxT( "width" ) ) )
62 {
63 SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(), aDefaultUnits, &m_Width,
64 aActualConversion );
65 }
66
67 if( aNode->GetName() == wxT( "triplePointArc" ) )
68 {
69 // center point
70 lNode = FindNode( aNode, wxT( "pt" ) );
71
72 if( lNode )
73 {
74 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
75 aActualConversion );
76 }
77
78 // start point
79 if( lNode )
80 lNode = lNode->GetNext();
81
82 if( lNode )
83 {
84 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_StartX, &m_StartY,
85 aActualConversion );
86 }
87
88 // end point
89 if( lNode )
90 lNode = lNode->GetNext();
91
92 if( lNode )
93 {
94 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &end.x, &end.y,
95 aActualConversion );
96 }
97
98 VECTOR2I position( m_PositionX, m_PositionY );
99 VECTOR2I start( m_StartX, m_StartY );
100
101 if( start == end )
102 {
104 }
105 else
106 {
107 EDA_ANGLE alpha1( start - position );
108 EDA_ANGLE alpha2( end - position );
109 m_Angle = alpha1 - alpha2;
110
111 m_Angle.Normalize();
112 }
113 }
114 else if( aNode->GetName() == wxT( "arc" ) )
115 {
116 lNode = FindNode( aNode, wxT( "pt" ) );
117
118 if( lNode )
119 {
120 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
121 aActualConversion );
122 }
123
124 lNode = FindNode( aNode, wxT( "radius" ) );
125
126 if( lNode)
127 {
128 SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(), aDefaultUnits, &r,
129 aActualConversion );
130 }
131
132
133 lNode = FindNode( aNode, wxT( "startAngle" ) );
134
135 EDA_ANGLE a = ANGLE_0;
136
137 if( lNode )
138 a = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
139
140 lNode = FindNode( aNode, wxT( "sweepAngle" ) );
141
142 if( lNode )
143 m_Angle = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
144
145 m_StartX = m_PositionX + KiROUND( r * a.Cos() );
146 m_StartY = m_PositionY - KiROUND( r * a.Sin() );
147 }
148}
149
150
151void PCAD_ARC::SetPosOffset( int aX_offs, int aY_offs )
152{
153 PCAD_PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
154
155 m_StartX += aX_offs;
156 m_StartY += aY_offs;
157}
158
159
161{
163
165 m_Angle = -m_Angle;
166
167 m_KiCadLayer = m_board->FlipLayer( m_KiCadLayer );
168}
169
170
172{
173 PCB_SHAPE* arc = new PCB_SHAPE( aFootprint, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC );
174
177 arc->SetArcAngleAndEnd( -m_Angle, true );
178
180 arc->SetLayer( m_KiCadLayer );
181
182 if( aFootprint )
183 {
184 aFootprint->Add( arc );
185 arc->Rotate( { 0, 0 }, aFootprint->GetOrientation() );
186 arc->Move( aFootprint->GetPosition() );
187 }
188 else
189 m_board->Add( arc );
190}
191
192
194{
195 return ( m_Angle == ANGLE_360 );
196}
197
198} // namespace PCAD2KICAD
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
double Sin() const
Definition eda_angle.h:178
double Cos() const
Definition eda_angle.h:197
void SetCenter(const VECTOR2I &aCenter)
EDA_ANGLE GetOrientation() const
Definition footprint.h:406
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
VECTOR2I GetPosition() const override
Definition footprint.h:403
PCAD_ARC(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition pcad_arc.cpp:35
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition pcad_arc.cpp:151
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultUnits, const wxString &aActualConversion)
Definition pcad_arc.cpp:51
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
Definition pcad_arc.cpp:171
virtual void Flip() override
Definition pcad_arc.cpp:160
EDA_ANGLE m_Angle
Definition pcad_arc.h:55
virtual void SetPosOffset(int aX_offs, int aY_offs)
PCAD_PCB_COMPONENT(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Definition pcb_shape.h:107
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void SetStart(const VECTOR2I &aStart) override
void SetStroke(const STROKE_PARAMS &aStroke) override
Simple container to manage line stroke parameters.
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
XNODE * GetNext() const
Definition xnode.h:102
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
@ TENTHS_OF_A_DEGREE_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:417
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)
VECTOR2I end
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683