KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcad_nets.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 The 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 "string_utils.h"
27
28#include <pcad/pcad_nets.h>
29
30#include <xnode.h>
31
32#include <wx/string.h>
33
34namespace PCAD2KICAD {
35
36wxString ConvertNetName( const wxString& aName )
37{
38 wxString retval;
39 bool negate = false;
40
41 for( auto c = aName.begin(); c < aName.end(); c++ )
42 {
43 if( *c != '~' )
44 {
45 retval += *c;
46 }
47 else if( !negate )
48 {
49 retval += '~';
50 retval += '{';
51 negate = true;
52 }
53 else
54 {
55 retval += '}';
56 negate = false;
57 }
58 }
59
60 retval = EscapeString( retval, CTX_NETNAME );
61 return retval;
62}
63
65{
66 m_CompRef = wxEmptyString;
67 m_PinRef = wxEmptyString;
68}
69
70
74
75
76PCAD_NET::PCAD_NET( int aNetCode ) : m_NetCode( aNetCode )
77{
78 m_Name = wxEmptyString;
79}
80
81
83{
84 int i;
85
86 for( i = 0; i < (int) m_NetNodes.GetCount(); i++ )
87 {
88 delete m_NetNodes[i];
89 }
90}
91
92
93void PCAD_NET::Parse( XNODE* aNode )
94{
95 wxString propValue, s1, s2;
96 PCAD_NET_NODE* netNode;
97 XNODE* lNode;
98
99 aNode->GetAttribute( wxT( "Name" ), &propValue );
100 propValue.Trim( false );
101 propValue.Trim( true );
102 m_Name = ConvertNetName( propValue );
103
104 lNode = FindNode( aNode, wxT( "node" ) );
105
106 while( lNode )
107 {
108 lNode->GetAttribute( wxT( "Name" ), &s2 );
109 s2.Trim( false );
110 s1 = wxEmptyString;
111
112 while( s2.Len() > 0 && s2[0] != wxT( ' ' ) )
113 {
114 s1 = s1 + s2[0];
115 s2 = s2.Mid( 1 );
116 }
117
118 netNode = new PCAD_NET_NODE;
119 s1.Trim( false );
120 s1.Trim( true );
121 netNode->m_CompRef = s1;
122
123 s2.Trim( false );
124 s2.Trim( true );
125 netNode->m_PinRef = s2;
126 m_NetNodes.Add( netNode );
127 lNode = lNode->GetNext();
128 }
129}
130
131} // namespace PCAD2KICAD
PCAD_NET_NODES_ARRAY m_NetNodes
Definition pcad_nets.h:62
void Parse(XNODE *aNode)
Definition pcad_nets.cpp:93
PCAD_NET(int aNetCode)
Definition pcad_nets.cpp:76
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:71
XNODE * GetNext() const
Definition xnode.h:106
XNODE * FindNode(XNODE *aChild, const wxString &aTag)
wxString ConvertNetName(const wxString &aName)
Definition pcad_nets.cpp:36
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME