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 <developer@lura.sk>
5  * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
6  * Copyright (C) 2012 KiCad Developers, see CHANGELOG.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 
30 #include <wx/wx.h>
31 #include <wx/config.h>
32 
33 #include <common.h>
34 #include <math/util.h> // for KiROUND
35 #include <trigo.h>
36 
37 #include <pcb_arc.h>
38 
39 namespace PCAD2KICAD {
40 
41 PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, aBoard )
42 {
43  m_objType = wxT( 'A' );
44  m_startX = 0;
45  m_startY = 0;
46  m_angle = 0;
47  m_width = 0;
48 }
49 
50 
52 {
53 }
54 
55 
56 void PCB_ARC::Parse( XNODE* aNode,
57  int aLayer,
58  const wxString& aDefaultMeasurementUnit,
59  const wxString& aActualConversion )
60 {
61  XNODE* lNode;
62  double a = 0.0;
63  int r = 0;
64  int endX = 0;
65  int endY = 0;
66 
67  m_PCadLayer = aLayer;
69 
70  if( FindNode( aNode, wxT( "width" ) ) )
71  SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(),
72  aDefaultMeasurementUnit, &m_width, aActualConversion );
73 
74  if( aNode->GetName() == wxT( "triplePointArc" ) )
75  {
76  // center point
77  lNode = FindNode( aNode, wxT( "pt" ) );
78 
79  if( lNode )
80  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
81  &m_positionX, &m_positionY, aActualConversion );
82 
83  // start point
84  if( lNode )
85  lNode = lNode->GetNext();
86 
87  if( lNode )
88  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
89  &m_startX, &m_startY, aActualConversion );
90 
91  // end point
92  if( lNode )
93  lNode = lNode->GetNext();
94 
95  if( lNode )
96  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
97  &endX, &endY, aActualConversion );
98 
99  if( m_startX == endX && m_startY == endY )
100  {
101  m_angle = 3600;
102  }
103  else
104  {
105  double alpha1 = ArcTangente( m_startY - m_positionY, m_startX - m_positionX );
106  double alpha2 = ArcTangente( endY - m_positionY, endX - m_positionX );
107  m_angle = alpha1 - alpha2;
108 
110  }
111  }
112  else if( aNode->GetName() == wxT( "arc" ) )
113  {
114  lNode = FindNode( aNode, wxT( "pt" ) );
115 
116  if( lNode )
117  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
118  &m_positionX, &m_positionY, aActualConversion );
119 
120  lNode = FindNode( aNode, wxT( "radius" ) );
121  if( lNode)
122  SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(),
123  aDefaultMeasurementUnit, &r, aActualConversion );
124 
125 
126  lNode = FindNode( aNode, wxT( "startAngle" ) );
127  if( lNode )
128  a = StrToInt1Units( lNode->GetNodeContent() );
129 
130  lNode = FindNode( aNode, wxT( "sweepAngle" ) );
131  if( lNode )
132  m_angle = StrToInt1Units( lNode->GetNodeContent() );
133 
134  m_startX = m_positionX + KiROUND( cosdecideg( r, a ) );
135  m_startY = m_positionY - KiROUND( sindecideg( r, a ) );
136  }
137 }
138 
139 
140 void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs )
141 {
142  PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
143 
144  m_startX += aX_offs;
145  m_startY += aY_offs;
146 }
147 
148 
150 {
152 
153  m_startX = -m_startX;
154  m_angle = -m_angle;
155 
157 }
158 
159 
160 void PCB_ARC::AddToModule( MODULE* aModule )
161 {
163  {
164  EDGE_MODULE* arc = new EDGE_MODULE( aModule, ( IsCircle() ? S_CIRCLE : S_ARC ) );
165  aModule->Add( arc );
166 
167  arc->SetAngle( -m_angle );
169  arc->m_End0 = wxPoint( m_startX, m_startY );
170 
171  arc->SetWidth( m_width );
172  arc->SetLayer( m_KiCadLayer );
173 
174  arc->SetDrawCoord();
175  }
176 }
177 
178 
180 {
181  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
182 
183  m_board->Add( dseg, ADD_MODE::APPEND );
184 
185  dseg->SetShape( IsCircle() ? S_CIRCLE : S_ARC );
186  dseg->SetTimeStamp( m_timestamp );
187  dseg->SetLayer( m_KiCadLayer );
189  dseg->SetEnd( wxPoint( m_startX, m_startY ) );
190  dseg->SetAngle( -m_angle );
191  dseg->SetWidth( m_width );
192 }
193 
194 
196 {
197  return ( m_angle == 3600 );
198 }
199 
200 } // namespace PCAD2KICAD
void SetShape(STROKE_T aShape)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:485
void SetWidth(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
PCB_ARC(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_arc.cpp:41
void AddToBoard() override
Definition: pcb_arc.cpp:179
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:252
PCB_LAYER_ID GetKiCadLayer()
Definition: pcb_component.h:73
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
wxPoint m_End0
End point, relative to module origin, orient 0.
virtual void SetPosOffset(int aX_offs, int aY_offs)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Arcs (with rounded ends)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
void SetStart(const wxPoint &aStart)
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
double cosdecideg(double r, double a)
Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:365
XNODE * GetNext() const
Definition: xnode.h:68
double sindecideg(double r, double a)
Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:356
virtual void Parse(XNODE *aNode, int aLayer, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion)
Definition: pcb_arc.cpp:56
virtual void Flip() override
Definition: pcb_arc.cpp:149
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
void AddToModule(MODULE *aModule) override
Definition: pcb_arc.cpp:160
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
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:61
The common library.
void SetEnd(const wxPoint &aEnd)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_arc.cpp:140
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:162
wxPoint m_Start0
Start point or center, relative to module origin, orient 0.
int StrToInt1Units(const wxString &aStr)
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212
void SetWidth(int aWidth)