KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_pad_shape.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 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_pad_shape.h>
23
24#include <common.h>
25#include <xnode.h>
26
27#include <wx/string.h>
28
29namespace PCAD2KICAD {
30
32 PCAD_PCB_COMPONENT( aCallbacks, aBoard )
33{
34 m_Shape = wxEmptyString;
35 m_Width = 0;
36 m_Height = 0;
37}
38
39
43
44
45void PCAD_PAD_SHAPE::Parse( XNODE* aNode, const wxString& aDefaultUnits,
46 const wxString& aActualConversion )
47{
48 wxString str, s;
49 long num;
50 int minX, maxX, minY, maxY, x, y;
51 XNODE* lNode;
52
53 lNode = FindNode( aNode, wxT( "padShapeType" ) );
54
55 if( lNode )
56 {
57 str = lNode->GetNodeContent();
58 str.Trim( false );
59 m_Shape = str;
60 }
61
62 lNode = FindNode( aNode, wxT( "layerNumRef" ) );
63
64 if( lNode )
65 {
66 lNode->GetNodeContent().ToLong( &num );
67 m_PCadLayer = (int) num;
68 }
69
71
72 if( m_Shape == wxT( "Oval" )
73 || m_Shape == wxT( "Rect" )
74 || m_Shape == wxT( "Ellipse" )
75 || m_Shape == wxT( "MtHole" )
76 || m_Shape == wxT( "RndRect" ) )
77 {
78 lNode = FindNode( aNode, wxT( "shapeWidth" ) );
79
80 if( lNode )
81 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Width, aActualConversion );
82
83 lNode = FindNode( aNode, wxT( "shapeHeight" ) );
84
85 if( lNode )
86 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Height, aActualConversion );
87 }
88 else if( m_Shape == wxT( "Polygon" ) )
89 {
90 // approximation to simpler pad shape .....
91 lNode = FindNode( aNode, wxT( "shapeOutline" ) );
92
93 if( lNode )
94 lNode = FindNode( lNode, wxT( "pt" ) );
95
96 minX = 0;
97 maxX = 0;
98 minY = 0;
99 maxY = 0;
100
101 while( lNode )
102 {
103 s = lNode->GetNodeContent();
104 SetPosition( s, aDefaultUnits, &x, &y, aActualConversion );
105
106 if( minX > x )
107 minX = x;
108
109 if( maxX < x )
110 maxX = x;
111
112 if( minY > y )
113 minY = y;
114
115 if( maxY < y )
116 maxY = y;
117
118 lNode = lNode->GetNext();
119 }
120
121 m_Width = maxX - minX;
122 m_Height = maxY - minY;
123 }
124}
125
126
127} // namespace PCAD2KICAD
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
PCAD_PAD_SHAPE(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
virtual void Parse(XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion)
PCAD_PCB_COMPONENT(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
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
The common library.
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)