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 <developer@lura.sk>
5  * Copyright (C) 2007, 2008, 2012 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 <pcb_via.h>
34 #include <pcb_via_shape.h>
35 
36 namespace PCAD2KICAD {
37 
38 PCB_VIA::PCB_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_PAD( aCallbacks, aBoard )
39 {
40  m_objType = wxT( 'V' );
41 }
42 
43 
45 {
46 }
47 
48 
49 void PCB_VIA::Parse( XNODE* aNode,
50  const wxString& aDefaultMeasurementUnit,
51  const wxString& aActualConversion )
52 {
53  XNODE* lNode, * tNode;
54  wxString propValue;
55  PCB_VIA_SHAPE* viaShape;
56 
57  m_rotation = 0;
58  lNode = FindNode( aNode, wxT( "viaStyleRef" ) );
59 
60  if( lNode )
61  {
62  lNode->GetAttribute( wxT( "Name" ), &propValue );
63  propValue.Trim( false );
64  propValue.Trim( true );
65  m_name.text = propValue;
66  }
67 
68  lNode = FindNode( aNode, wxT( "pt" ) );
69 
70  if( lNode )
71  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
72  &m_positionX, &m_positionY, aActualConversion );
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( wxT( "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( wxT( "Unable to find viaStyleDef " ) + 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(), aDefaultMeasurementUnit, &m_hole,
117  aActualConversion );
118 
119  lNode = FindNode( tNode, wxT( "viaShape" ) );
120 
121  while( lNode )
122  {
123  if( lNode->GetName() == wxT( "viaShape" ) )
124  {
125  // we support only Vias on specific layers......
126  // we do not support vias on "Plane", "NonSignal" , "Signal" ... layerr
127  if( FindNode( lNode, wxT( "layerNumRef" ) ) )
128  {
129  viaShape = new PCB_VIA_SHAPE( m_callbacks, m_board );
130  viaShape->Parse( lNode, aDefaultMeasurementUnit, aActualConversion );
131  m_shapes.Add( viaShape );
132  }
133  }
134 
135  lNode = lNode->GetNext();
136  }
137  }
138 }
139 
140 } // namespace PCAD2KICAD
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void SetWidth(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
PCB_VIA(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_via.cpp:38
XNODE * GetParent() const
Definition: xnode.h:73
#define THROW_IO_ERROR(msg)
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
PCB_CALLBACKS * m_callbacks
Definition: pcb_component.h:78
PCB_PAD_SHAPES_ARRAY m_shapes
Definition: pcb_pad.h:46
int GetNetCode(wxString aNetName)
Definition: pcb_component.h:75
virtual void Parse(XNODE *aNode, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion) override
Definition: pcb_via.cpp:49
virtual void Parse(XNODE *aNode, const wxString &aDefaultMeasurementUnit, const wxString &aActualConversion) override