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