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, wxString aDefaultMeasurementUnit,
50  wxString aActualConversion )
51 {
52  XNODE* lNode, * tNode;
53  wxString propValue;
54  PCB_VIA_SHAPE* viaShape;
55 
56  m_rotation = 0;
57  lNode = FindNode( aNode, wxT( "viaStyleRef" ) );
58 
59  if( lNode )
60  {
61  lNode->GetAttribute( wxT( "Name" ), &propValue );
62  propValue.Trim( false );
63  propValue.Trim( true );
64  m_name.text = propValue;
65  }
66 
67  lNode = FindNode( aNode, wxT( "pt" ) );
68 
69  if( lNode )
70  SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
71  &m_positionX, &m_positionY, aActualConversion );
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( wxT( "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( wxT( "Unable to find viaStyleDef " ) + 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(), aDefaultMeasurementUnit, &m_hole,
116  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, aDefaultMeasurementUnit, aActualConversion );
130  m_shapes.Add( viaShape );
131  }
132  }
133 
134  lNode = lNode->GetNext();
135  }
136  }
137 }
138 
139 } // namespace PCAD2KICAD
void SetWidth(wxString aStr, wxString aDefaultMeasurementUnit, int *aWidth, wxString aActualConversion)
PCB_VIA(PCB_CALLBACKS *aCallbacks, BOARD *aBoard)
Definition: pcb_via.cpp:38
XNODE * GetParent() const
Definition: xnode.h:73
void SetPosition(wxString aStr, wxString aDefaultMeasurementUnit, int *aX, int *aY, wxString aActualConversion)
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
virtual void Parse(XNODE *aNode, wxString aDefaultMeasurementUnit, wxString aActualConversion) override
Definition: pcb_via.cpp:49
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:169
XNODE * FindNode(XNODE *aChild, 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, wxString aDefaultMeasurementUnit, wxString aActualConversion) override