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  return converted;
77 }

Referenced by ALTIUM_PARSER::ReadProperties().

◆ AltiumSpecialStringsToKiCadVariables()

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

Definition at line 81 of file altium_parser_utils.cpp.

83 {
84  if( aString.IsEmpty() || aString.at( 0 ) != '=' )
85  {
86  return aString;
87  }
88 
89  wxString result;
90 
91  size_t start = 1;
92  size_t delimiter = 0;
93  size_t escaping_start = 0;
94  do
95  {
96  delimiter = aString.find( "+", start );
97  escaping_start = aString.find( "'", start );
98 
99  if( escaping_start < delimiter )
100  {
101  size_t text_start = escaping_start + 1;
102  size_t escaping_end = aString.find( "'", text_start );
103 
104  if( escaping_end == wxString::npos )
105  {
106  escaping_end = aString.size();
107  }
108 
109  result += aString.substr( text_start, escaping_end - text_start );
110 
111  start = escaping_end + 1;
112  }
113  else
114  {
115  wxString specialString = aString.substr( start, delimiter - start ).Trim().Trim( false );
116 
117  if( specialString.StartsWith( "\"" ) && specialString.EndsWith( "\"" ) )
118  specialString = specialString.Mid( 1, specialString.Length() - 2 );
119 
120  if( !specialString.IsEmpty() )
121  {
122  // Note: Altium variable references are case-insensitive. KiCad matches
123  // case-senstive OR to all-upper-case, so make the references all-upper-case.
124  specialString.UpperCase();
125 
126  auto overrideIt = aOverrides.find( specialString );
127 
128  if( overrideIt != aOverrides.end() )
129  specialString = overrideIt->second;
130 
131  result += wxString::Format( wxT( "${%s}" ), specialString );
132  }
133 
134  start = delimiter + 1;
135  }
136  } while( delimiter != wxString::npos );
137 
138  return result;
139 }
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:51
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:49
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...

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

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