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 <richio.h>
30#include <xnode.h>
31
32#include <wx/string.h>
33#include <wx/translation.h>
34
35namespace PCAD2KICAD {
36
37PCAD_VIA::PCAD_VIA( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCAD_PAD( aCallbacks, aBoard )
38{
39 m_ObjType = wxT( 'V' );
40}
41
42
44{
45}
46
47
48void PCAD_VIA::Parse( XNODE* aNode, const wxString& aDefaultUnits,
49 const wxString& aActualConversion )
50{
51 XNODE* lNode, * tNode;
52 wxString propValue;
53 PCAD_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 PCAD_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:290
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:37
virtual void Parse(XNODE *aNode, const wxString &aDefaultUnits, const wxString &aActualConversion) override
Definition: pcad_via.cpp:48
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetParent() const
Definition: xnode.h:71
XNODE * GetNext() const
Definition: xnode.h:66
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
#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)