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

Go to the source code of this file.

Classes

struct  CASE_INSENSITIVE_COMPARATOR
 

Typedefs

typedef std::map< wxString, wxString, CASE_INSENSITIVE_COMPARATORaltium_override_map_t
 

Functions

LIB_ID AltiumToKiCadLibID (wxString aLibName, wxString aLibReference)
 
wxString AltiumSpecialStringsToKiCadVariables (const wxString &aString, const altium_override_map_t &aOverride)
 

Typedef Documentation

◆ altium_override_map_t

typedef std::map<wxString, wxString, CASE_INSENSITIVE_COMPARATOR> altium_override_map_t

Definition at line 44 of file altium_parser_utils.h.

Function Documentation

◆ AltiumSpecialStringsToKiCadVariables()

wxString AltiumSpecialStringsToKiCadVariables ( const wxString &  aString,
const altium_override_map_t aOverride 
)

Definition at line 45 of file altium_parser_utils.cpp.

47 {
48  if( aString.IsEmpty() || aString.at( 0 ) != '=' )
49  {
50  return aString;
51  }
52 
53  wxString result;
54 
55  size_t start = 1;
56  size_t delimiter = 0;
57  size_t escaping_start = 0;
58  do
59  {
60  delimiter = aString.find( "+", start );
61  escaping_start = aString.find( "'", start );
62 
63  if( escaping_start < delimiter )
64  {
65  size_t text_start = escaping_start + 1;
66  size_t escaping_end = aString.find( "'", text_start );
67  if( escaping_end == wxString::npos )
68  {
69  escaping_end = aString.size();
70  }
71 
72  result += aString.substr( text_start, escaping_end - text_start );
73 
74  start = escaping_end + 1;
75  }
76  else
77  {
78  wxString specialString = aString.substr( start, delimiter - start ).Trim( true );
79 
80  if( !specialString.IsEmpty() )
81  {
82  auto variableOverride = aOverride.find( specialString );
83  if( variableOverride == aOverride.end() )
84  {
85  result += wxString::Format( wxT( "${%s}" ), specialString );
86  }
87  else
88  {
89  result += variableOverride->second;
90  }
91  }
92  start = delimiter + 1;
93  }
94  } while( delimiter != wxString::npos );
95 
96  return result;
97 }
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(), and SCH_ALTIUM_PLUGIN::ParseParameter().

◆ AltiumToKiCadLibID()

LIB_ID AltiumToKiCadLibID ( wxString  aLibName,
wxString  aLibReference 
)

Definition at line 31 of file altium_parser_utils.cpp.

32 {
33  ReplaceIllegalFileNameChars( aLibName, '_' );
34  ReplaceIllegalFileNameChars( aLibReference, '_' );
35 
36  wxString key = !aLibName.empty() ? ( aLibName + ":" + aLibReference ) : aLibReference;
37 
38  LIB_ID libId;
39  libId.Parse( key, true );
40 
41  return libId;
42 }
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
Definition: string.cpp:766
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:122

References LIB_ID::Parse(), and ReplaceIllegalFileNameChars().

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