KiCad PCB EDA Suite
altium_parser_utils.h File Reference
#include <map>
#include <string_utils.h>
#include <lib_id.h>
#include <iostream>

Go to the source code of this file.

Functions

LIB_ID AltiumToKiCadLibID (const wxString &aLibName, const wxString &aLibReference)
 
wxString AltiumPropertyToKiCadString (const wxString &aString)
 
wxString AltiumSpecialStringsToKiCadVariables (const wxString &aString, const std::map< wxString, wxString > &aOverrides)
 

Function Documentation

◆ AltiumPropertyToKiCadString()

wxString AltiumPropertyToKiCadString ( const wxString &  aString)

Definition at line 44 of file altium_parser_utils.cpp.

45{
46 wxString converted;
47 bool inOverbar = false;
48
49 for( wxString::const_iterator chIt = aString.begin(); chIt != aString.end(); ++chIt )
50 {
51 wxString::const_iterator lookahead = chIt + 1;
52
53 if( lookahead != aString.end() && *lookahead == '\\' )
54 {
55 if( !inOverbar )
56 {
57 converted += "~{";
58 inOverbar = true;
59 }
60
61 converted += *chIt;
62 chIt = lookahead;
63 }
64 else
65 {
66 if( inOverbar )
67 {
68 converted += "}";
69 inOverbar = false;
70 }
71
72 converted += *chIt;
73 }
74 }
75
76 if( inOverbar )
77 converted += "}";
78
79 return converted;
80}

Referenced by ALTIUM_PARSER::ReadProperties().

◆ AltiumSpecialStringsToKiCadVariables()

wxString AltiumSpecialStringsToKiCadVariables ( const wxString &  aString,
const std::map< wxString, wxString > &  aOverrides 
)

Definition at line 84 of file altium_parser_utils.cpp.

86{
87 if( aString.IsEmpty() || aString.at( 0 ) != '=' )
88 {
89 return aString;
90 }
91
92 wxString result;
93
94 size_t start = 1;
95 size_t delimiter = 0;
96 size_t escaping_start = 0;
97 do
98 {
99 delimiter = aString.find( "+", start );
100 escaping_start = aString.find( "'", start );
101
102 if( escaping_start < delimiter )
103 {
104 size_t text_start = escaping_start + 1;
105 size_t escaping_end = aString.find( "'", text_start );
106
107 if( escaping_end == wxString::npos )
108 {
109 escaping_end = aString.size();
110 }
111
112 result += aString.substr( text_start, escaping_end - text_start );
113
114 start = escaping_end + 1;
115 }
116 else
117 {
118 wxString specialString = aString.substr( start, delimiter - start ).Trim().Trim( false );
119
120 if( specialString.StartsWith( "\"" ) && specialString.EndsWith( "\"" ) )
121 specialString = specialString.Mid( 1, specialString.Length() - 2 );
122
123 if( !specialString.IsEmpty() )
124 {
125 // Note: Altium variable references are case-insensitive. KiCad matches
126 // case-sensitive OR to all-upper-case, so make the references all-upper-case.
127 specialString.UpperCase();
128
129 auto overrideIt = aOverrides.find( specialString );
130
131 if( overrideIt != aOverrides.end() )
132 specialString = overrideIt->second;
133
134 result += wxString::Format( wxT( "${%s}" ), specialString );
135 }
136
137 start = delimiter + 1;
138 }
139 } while( delimiter != wxString::npos );
140
141 return result;
142}
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format().

Referenced by BOOST_AUTO_TEST_CASE(), SCH_ALTIUM_PLUGIN::ParseLabel(), and SCH_ALTIUM_PLUGIN::ParseParameter().

◆ AltiumToKiCadLibID()

LIB_ID AltiumToKiCadLibID ( const wxString &  aLibName,
const wxString &  aLibReference 
)

Definition at line 31 of file altium_parser_utils.cpp.

32{
33 wxString libReference = EscapeString( aLibReference, CTX_LIBID );
34
35 wxString key = !aLibName.empty() ? ( aLibName + ":" + libReference ) : libReference;
36
37 LIB_ID libId;
38 libId.Parse( key, true );
39
40 return libId;
41}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:50
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
Definition: string_utils.h:55

References CTX_LIBID, EscapeString(), and LIB_ID::Parse().

Referenced by SCH_ALTIUM_PLUGIN::ParseComponent(), ALTIUM_PCB::ParseComponents6Data(), ALTIUM_PCB::ParseFootprint(), SCH_ALTIUM_PLUGIN::ParseImplementation(), and SCH_ALTIUM_PLUGIN::ParsePowerPort().