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 = aString.substr( start, delimiter - start ).Trim().Trim(
false );
165 if( specialString.StartsWith(
"\"" ) && specialString.EndsWith(
"\"" ) )
166 specialString = specialString.Mid( 1, specialString.Length() - 2 );
168 if( !specialString.IsEmpty() )
172 specialString.UpperCase();
174 auto overrideIt = aOverrides.find( specialString );
176 if( overrideIt != aOverrides.end() )
177 specialString = overrideIt->second;
179 aUnmapped->insert( specialString );
185 start = delimiter + 1;
187 }
while( delimiter != wxString::npos );
197 const std::map<wxString, wxString>& aOverrides,
198 std::set<wxString>* aUnmapped )
200 if( aString.IsEmpty() )
204 const auto getVariable = [&](
const wxString& aSpecialString )
206 wxString str = aSpecialString;
209 auto it = aOverrides.find( str );
211 if( it != aOverrides.end() )
214 aUnmapped->insert( str );
216 return wxString::Format( wxT(
"${%s}" ), str );
220 if( aString.at( 0 ) ==
'.' )
222 wxString specialString = aString.substr( 1 );
224 if( specialString.Contains(
'=' ) )
227 return getVariable( specialString );
235 if( !aString.Contains(
"'." ) )
240 wxString stringCopy = aString;
244 const auto tryReplacement = [&]( wxString& aStr,
unsigned aDotPos )
247 if( aDotPos == 0 || aStr.at( aDotPos - 1 ) !=
'\'' )
251 size_t apostrophePos = aStr.find(
'\'', aDotPos + 1 );
254 if( apostrophePos == wxString::npos )
258 wxString specialString = aStr.substr( aDotPos + 1, apostrophePos - aDotPos - 1 );
259 wxString replacement = getVariable( specialString );
261 aStr.replace( aDotPos - 1, apostrophePos - aDotPos + 2, replacement );
266 for(
size_t pos = stringCopy.size() - 1; pos > 0; --pos )
268 if( stringCopy[pos] ==
'.' )
270 tryReplacement( stringCopy, pos );
280 if( aString.IsEmpty() )
281 return wxEmptyString;
285 if( aString.StartsWith(
'\\', &rest ) && !rest.Contains(
'\\' ) )
286 return "~{" + rest +
"}";
294 wxString designator = aDesignator;
295 designator.Trim(
true ).Trim(
false );
297 if( !designator.Contains( wxT(
"," ) ) )
302 wxArrayString cleaned;
304 for( wxString token : wxSplit( designator,
',',
'\0' ) )
306 token.Trim(
true ).Trim(
false );
308 if( !token.IsEmpty() )
312 if( cleaned.IsEmpty() )
315 if( cleaned.GetCount() == 1 )
318 return wxT(
"[" ) + wxJoin( cleaned,
',',
'\0' ) + wxT(
"]" );
324 if( aMajor == 0 || aMinor == 0 )
327 double numerator = aMajor * aMinor;
328 double majorTerm = aMajor * sin( aAngleRadians );
329 double minorTerm = aMinor * cos( aAngleRadians );
330 double denominator = sqrt( majorTerm * majorTerm + minorTerm * minorTerm );
332 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