34 wxString key = !libName.empty() ? ( libName +
":" + libReference ) : libReference;
37 libId.
Parse( key,
true );
50 for( wxString::const_iterator it = aString.begin(); it != aString.end(); ++it )
54 if( (*it).GetAsChar( &ch ) )
70 if( !tempString.empty() )
72 output +=
"~{" + tempString +
"}";
84 if( !tempString.IsEmpty() )
85 output +=
"~{" + tempString +
"}";
99 for(
size_t i = 0; i < aText.length(); i++ )
101 wxUniChar ch = aText[i];
104 if( depth == 0 && ( ch ==
'$' || ch ==
'@' ) && i + 1 < aText.length() && aText[i + 1] ==
'{' )
114 if( depth > 0 && ch ==
'{' )
116 else if( depth > 0 && ch ==
'}' )
128 const std::map<wxString, wxString>& aOverrides,
129 std::set<wxString>* aUnmapped )
131 if( aString.IsEmpty() || aString.at( 0 ) !=
'=' )
140 size_t delimiter = 0;
141 size_t escaping_start = 0;
144 delimiter = aString.find(
"+", start );
145 escaping_start = aString.find(
"'", start );
147 if( escaping_start < delimiter )
149 size_t text_start = escaping_start + 1;
150 size_t escaping_end = aString.find(
"'", text_start );
152 if( escaping_end == wxString::npos )
154 escaping_end = aString.size();
157 literal += aString.substr( text_start, escaping_end - text_start );
159 start = escaping_end + 1;
163 wxString specialString =
164 aString.substr( start, delimiter - start ).Trim().Trim(
false );
166 if( specialString.StartsWith(
"\"" ) && specialString.EndsWith(
"\"" ) )
167 specialString = specialString.Mid( 1, specialString.Length() - 2 );
169 if( !specialString.IsEmpty() )
173 specialString.UpperCase();
175 auto overrideIt = aOverrides.find( specialString );
177 if( overrideIt != aOverrides.end() )
178 specialString = overrideIt->second;
180 aUnmapped->insert( specialString );
186 start = delimiter + 1;
188 }
while( delimiter != wxString::npos );
198 const std::map<wxString, wxString>& aOverrides,
199 std::set<wxString>* aUnmapped )
201 if( aString.IsEmpty() )
205 const auto getVariable = [&](
const wxString& aSpecialString )
207 wxString str = aSpecialString;
210 auto it = aOverrides.find( str );
212 if( it != aOverrides.end() )
215 aUnmapped->insert( str );
217 return wxString::Format( wxT(
"${%s}" ), str );
221 if( aString.at( 0 ) ==
'.' )
223 wxString specialString = aString.substr( 1 );
225 if( specialString.Contains(
'=' ) )
228 return getVariable( specialString );
236 if( !aString.Contains(
"'." ) )
241 wxString stringCopy = aString;
245 const auto tryReplacement = [&]( wxString& aStr,
unsigned aDotPos )
248 if( aDotPos == 0 || aStr.at( aDotPos - 1 ) !=
'\'' )
252 size_t apostrophePos = aStr.find(
'\'', aDotPos + 1 );
255 if( apostrophePos == wxString::npos )
259 wxString specialString = aStr.substr( aDotPos + 1, apostrophePos - aDotPos - 1 );
260 wxString replacement = getVariable( specialString );
262 aStr.replace( aDotPos - 1, apostrophePos - aDotPos + 2, replacement );
267 for(
size_t pos = stringCopy.size() - 1; pos > 0; --pos )
269 if( stringCopy[pos] ==
'.' )
271 tryReplacement( stringCopy, pos );
281 if( aString.IsEmpty() )
282 return wxEmptyString;
286 if( aString.StartsWith(
'\\', &rest ) && !rest.Contains(
'\\' ) )
287 return "~{" + rest +
"}";
295 wxString designator = aDesignator;
296 designator.Trim(
true ).Trim(
false );
298 if( !designator.Contains( wxT(
"," ) ) )
303 wxArrayString cleaned;
305 for( wxString token : wxSplit( designator,
',',
'\0' ) )
307 token.Trim(
true ).Trim(
false );
309 if( !token.IsEmpty() )
313 if( cleaned.IsEmpty() )
316 if( cleaned.GetCount() == 1 )
319 return wxT(
"[" ) + wxJoin( cleaned,
',',
'\0' ) + wxT(
"]" );
325 if( aMajor == 0 || aMinor == 0 )
328 double numerator = aMajor * aMinor;
329 double majorTerm = aMajor * sin( aAngleRadians );
330 double minorTerm = aMinor * cos( aAngleRadians );
331 double denominator = sqrt( majorTerm * majorTerm + minorTerm * minorTerm );
333 double radius = numerator / denominator;
wxString AltiumPinDesignatorToKiCad(const wxString &aDesignator)
Convert an Altium pin designator string to the equivalent KiCad pin number.
wxString AltiumPcbSpecialStringsToKiCadStrings(const wxString &aString, const std::map< wxString, wxString > &aOverrides, std::set< wxString > *aUnmapped)
Convert the special strings in Altium PCB text to KiCad variables.
wxString AltiumSchSpecialStringsToKiCadVariables(const wxString &aString, const std::map< wxString, wxString > &aOverrides, std::set< wxString > *aUnmapped)
Convert the special strings in Altium schematic text to KiCad variables.
wxString AltiumPropertyToKiCadString(const wxString &aString)
wxString AltiumEscapeTextVars(const wxString &aText)
Escape the KiCad variables and expressions in literal Altium text, which Altium shows as typed.
wxString AltiumPinNamesToKiCad(wxString &aString)
VECTOR2I AltiumGetEllipticalPos(double aMajor, double aMinor, double aAngleRadians)
LIB_ID AltiumToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
wxString EscapeStackedPinItem(const wxString &aPinNumber)
Escape the characters that carry structural meaning inside stacked pin notation ('[',...
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I