KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_via.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 (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_via.h>
27#include <pcad/pcad_via_shape.h>
28
29#include <xnode.h>
30
31#include <wx/string.h>
32#include <wx/translation.h>
33
34namespace PCAD2KICAD {
35
36PCAD_VIA::PCAD_VIA( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCAD_PAD( aCallbacks, aBoard )
37{
38 m_ObjType = wxT( 'V' );
39}
40
41
43{
44}
45
46
47void PCAD_VIA::Parse( XNODE* aNode, const wxString& aDefaultUnits,
48 const wxString& aActualConversion )
49{
50 XNODE* lNode, * tNode;
51 wxString propValue;
52 PCAD_VIA_SHAPE* viaShape;
53
55 lNode = FindNode( aNode, wxT( "viaStyleRef" ) );
56
57 if( lNode )
58 {
59 lNode->GetAttribute( wxT( "Name" ), &propValue );
60 propValue.Trim( false );
61 propValue.Trim( true );
62 m_Name.text = propValue;
63 }
64
65 lNode = FindNode( aNode, wxT( "pt" ) );
66
67 if( lNode )
68 {
69 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_PositionX, &m_PositionY,
70 aActualConversion );
71 }
72
73 lNode = FindNode( aNode, wxT( "netNameRef" ) );
74
75 if( lNode )
76 {
77 lNode->GetAttribute( wxT( "Name" ), &propValue );
78 propValue.Trim( false );
79 propValue.Trim( true );
80 m_Net = propValue;
82 }
83
84 lNode = aNode;
85
86 while( lNode && lNode->GetName() != wxT( "www.lura.sk" ) )
87 lNode = lNode->GetParent();
88
89 lNode = FindNode( lNode, wxT( "library" ) );
90
91 if ( !lNode )
92 THROW_IO_ERROR( _( "Unable to find library section." ) );
93
94 lNode = FindNode( lNode, wxT( "viaStyleDef" ) );
95
96 while( lNode )
97 {
98 lNode->GetAttribute( wxT( "Name" ), &propValue );
99
100 if( propValue.IsSameAs( m_Name.text, false ) )
101 break;
102
103 lNode = lNode->GetNext();
104 }
105
106 if ( !lNode )
107 THROW_IO_ERROR( wxString::Format( _( "Unable to find viaStyleDef %s." ), m_Name.text ) );
108
109 if( lNode )
110 {
111 tNode = lNode;
112 lNode = FindNode( tNode, wxT( "holeDiam" ) );
113
114 if( lNode )
115 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Hole, aActualConversion );
116
117 lNode = FindNode( tNode, wxT( "viaShape" ) );
118
119 while( lNode )
120 {
121 if( lNode->GetName() == wxT( "viaShape" ) )
122 {
123 // we support only Vias on specific layers......
124 // we do not support vias on "Plane", "NonSignal" , "Signal" ... layerr
125 if( FindNode( lNode, wxT( "layerNumRef" ) ) )
126 {
127 viaShape = new PCAD_VIA_SHAPE( m_callbacks, m_board );
128 viaShape->Parse( lNode, aDefaultUnits, aActualConversion );
129 m_Shapes.Add( viaShape );
130 }
131 }
132
133 lNode = lNode->GetNext();
134 }
135 }
136}
137
138} // namespace PCAD2KICAD
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
PCAD_PAD_SHAPES_ARRAY m_Shapes
Definition: pcad_pad.h:57
int GetNetCode(const wxString &aNetName) const
virtual void Parse(XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion) override
PCAD_VIA(PCAD_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcad_via.cpp:36
virtual void Parse(XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion) override
Definition: pcad_via.cpp:47
Hold an XML or S-expression element.
Definition: xnode.h:44
XNODE * GetParent() const
Definition: xnode.h:72
XNODE * GetNext() const
Definition: xnode.h:67
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
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)