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 <trigo.h>
35 
36 #include <pcb_arc.h>
37 
38 namespace PCAD2KICAD {
39 
40 PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, aBoard )
41 {
42  m_objType = wxT( 'A' );
43  m_startX = 0;
44  m_startY = 0;
45  m_angle = 0;
46  m_width = 0;
47 }
48 
49 
51 {
52 }
53 
54 
55 void PCB_ARC::Parse( XNODE* aNode,
56  int aLayer,
57  wxString aDefaultMeasurementUnit,
58  wxString aActualConversion )
59 {
60  XNODE* lNode;
61  double a = 0.0;
62  int r = 0;
63  int endX = 0;
64  int endY = 0;
65 
66  m_PCadLayer = aLayer;
68 
69  if( FindNode( aNode, wxT( "width" ) ) )
70  SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(),
71  aDefaultMeasurementUnit, &m_width, aActualConversion );
72 
73  if( aNode->GetName() == wxT( "triplePointArc" ) )
74  {
75  // center point
76  lNode = FindNode( aNode, wxT( "pt" ) );
77 
78  if( lNode )
79  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
80  &m_positionX, &m_positionY, aActualConversion );
81 
82  // start point
83  if( lNode )
84  lNode = lNode->GetNext();
85 
86  if( lNode )
87  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
88  &m_startX, &m_startY, aActualConversion );
89 
90  // end point
91  if( lNode )
92  lNode = lNode->GetNext();
93 
94  if( lNode )
95  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
96  &endX, &endY, aActualConversion );
97 
98  if( m_startX == endX && m_startY == endY )
99  {
100  m_angle = 3600;
101  }
102  else
103  {
104  double alpha1 = ArcTangente( m_startY - m_positionY, m_startX - m_positionX );
105  double alpha2 = ArcTangente( endY - m_positionY, endX - m_positionX );
106  m_angle = alpha1 - alpha2;
107 
109  }
110  }
111  else if( aNode->GetName() == wxT( "arc" ) )
112  {
113  lNode = FindNode( aNode, wxT( "pt" ) );
114 
115  if( lNode )
116  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
117  &m_positionX, &m_positionY, aActualConversion );
118 
119  lNode = FindNode( aNode, wxT( "radius" ) );
120  if( lNode)
121  SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(),
122  aDefaultMeasurementUnit, &r, aActualConversion );
123 
124 
125  lNode = FindNode( aNode, wxT( "startAngle" ) );
126  if( lNode )
127  a = StrToInt1Units( lNode->GetNodeContent() );
128 
129  lNode = FindNode( aNode, wxT( "sweepAngle" ) );
130  if( lNode )
131  m_angle = StrToInt1Units( lNode->GetNodeContent() );
132 
133  m_startX = m_positionX + KiROUND( cosdecideg( r, a ) );
134  m_startY = m_positionY - KiROUND( sindecideg( r, a ) );
135  }
136 }
137 
138 
139 void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs )
140 {
141  PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
142 
143  m_startX += aX_offs;
144  m_startY += aY_offs;
145 }
146 
147 
149 {
151 
152  m_startX = -m_startX;
153  m_angle = -m_angle;
154 
156 }
157 
158 
159 void PCB_ARC::AddToModule( MODULE* aModule )
160 {
162  {
163  EDGE_MODULE* arc = new EDGE_MODULE( aModule, S_ARC );
164  aModule->GraphicalItems().PushBack( arc );
165 
166  arc->SetAngle( -m_angle );
168  arc->m_End0 = wxPoint( m_startX, m_startY );
169 
170  arc->SetWidth( m_width );
171  arc->SetLayer( m_KiCadLayer );
172 
173  arc->SetDrawCoord();
174  }
175 }
176 
177 
179 {
180  DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
181 
182  m_board->Add( dseg, ADD_APPEND );
183 
184  dseg->SetShape( S_ARC );
185  dseg->SetTimeStamp( m_timestamp );
186  dseg->SetLayer( m_KiCadLayer );
188  dseg->SetEnd( wxPoint( m_startX, m_startY ) );
189  dseg->SetAngle( -m_angle );
190  dseg->SetWidth( m_width );
191 }
192 
193 } // namespace PCAD2KICAD
void SetWidth(wxString aStr, wxString aDefaultMeasurementUnit, int *aWidth, wxString aActualConversion)
void SetShape(STROKE_T aShape)
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
int StrToInt1Units(wxString aStr)
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
PCB_ARC(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_arc.cpp:40
void AddToBoard() override
Definition: pcb_arc.cpp:178
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:222
DLIST< BOARD_ITEM > & GraphicalItems()
Definition: class_module.h:136
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
bool IsNonCopperLayer(LAYER_NUM aLayerId)
Function IsNonCopperLayer tests whether a layer is a non copper layer.
wxPoint m_End0
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
virtual void SetPosOffset(int aX_offs, int aY_offs)
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:271
Arcs (with rounded ends)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
void SetPosition(wxString aStr, wxString aDefaultMeasurementUnit, int *aX, int *aY, wxString aActualConversion)
virtual void Parse(XNODE *aNode, int aLayer, wxString aDefaultMeasurementUnit, wxString aActualConversion)
Definition: pcb_arc.cpp:55
void SetStart(const wxPoint &aStart)
Class 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:311
double sindecideg(double r, double a)
Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:302
virtual void Flip() override
Definition: pcb_arc.cpp:148
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
LAYER_ID FlipLayer(LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:444
void AddToModule(MODULE *aModule) override
Definition: pcb_arc.cpp:159
void SetDrawCoord()
Set draw coordinates (absolute values ) from relative coordinates.
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...
XNODE * FindNode(XNODE *aChild, wxString aTag)
virtual void SetPosOffset(int aX_offs, int aY_offs) override
Definition: pcb_arc.cpp:139
wxPoint m_Start0
XNODE * GetNext() const
Definition: xnode.h:68
void SetWidth(int aWidth)