KiCad PCB EDA Suite
pcb_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-2020 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/pcb_via.h>
27#include <pcad/pcb_via_shape.h>
28
29#include <xnode.h>
30
31#include <wx/string.h>
32#include <wx/translation.h>
33
34namespace PCAD2KICAD {
35
36PCB_VIA::PCB_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
37 PCB_PAD( aCallbacks, aBoard )
38{
39 m_objType = wxT( 'V' );
40}
41
42
44{
45}
46
47
48void PCB_VIA::Parse( XNODE* aNode, const wxString& aDefaultUnits,
49 const wxString& aActualConversion )
50{
51 XNODE* lNode, * tNode;
52 wxString propValue;
53 PCB_VIA_SHAPE* viaShape;
54
56 lNode = FindNode( aNode, wxT( "viaStyleRef" ) );
57
58 if( lNode )
59 {
60 lNode->GetAttribute( wxT( "Name" ), &propValue );
61 propValue.Trim( false );
62 propValue.Trim( true );
63 m_name.text = propValue;
64 }
65
66 lNode = FindNode( aNode, wxT( "pt" ) );
67
68 if( lNode )
69 {
70 SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
71 aActualConversion );
72 }
73
74 lNode = FindNode( aNode, wxT( "netNameRef" ) );
75
76 if( lNode )
77 {
78 lNode->GetAttribute( wxT( "Name" ), &propValue );
79 propValue.Trim( false );
80 propValue.Trim( true );
81 m_net = propValue;
83 }
84
85 lNode = aNode;
86
87 while( lNode && lNode->GetName() != wxT( "www.lura.sk" ) )
88 lNode = lNode->GetParent();
89
90 lNode = FindNode( lNode, wxT( "library" ) );
91
92 if ( !lNode )
93 THROW_IO_ERROR( _( "Unable to find library section." ) );
94
95 lNode = FindNode( lNode, wxT( "viaStyleDef" ) );
96
97 while( lNode )
98 {
99 lNode->GetAttribute( wxT( "Name" ), &propValue );
100
101 if( propValue.IsSameAs( m_name.text, false ) )
102 break;
103
104 lNode = lNode->GetNext();
105 }
106
107 if ( !lNode )
108 THROW_IO_ERROR( wxString::Format( _( "Unable to find viaStyleDef %s." ), m_name.text ) );
109
110 if( lNode )
111 {
112 tNode = lNode;
113 lNode = FindNode( tNode, wxT( "holeDiam" ) );
114
115 if( lNode )
116 SetWidth( lNode->GetNodeContent(), aDefaultUnits, &m_Hole, aActualConversion );
117
118 lNode = FindNode( tNode, wxT( "viaShape" ) );
119
120 while( lNode )
121 {
122 if( lNode->GetName() == wxT( "viaShape" ) )
123 {
124 // we support only Vias on specific layers......
125 // we do not support vias on "Plane", "NonSignal" , "Signal" ... layerr
126 if( FindNode( lNode, wxT( "layerNumRef" ) ) )
127 {
128 viaShape = new PCB_VIA_SHAPE( m_callbacks, m_board );
129 viaShape->Parse( lNode, aDefaultUnits, aActualConversion );
130 m_Shapes.Add( viaShape );
131 }
132 }
133
134 lNode = lNode->GetNext();
135 }
136 }
137}
138
139} // namespace PCAD2KICAD
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
int GetNetCode(const wxString &aNetName) const
Definition: pcb_component.h:58
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:78
PCB_PAD_SHAPES_ARRAY m_Shapes
Definition: pcb_pad.h:61
virtual void Parse(XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion) override
virtual void Parse(XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion) override
Definition: pcb_via.cpp:48
PCB_VIA(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_via.cpp:36
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:412
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200