119 for(
const wxString libDir : { wxS(
"sub" ), wxS(
"sym" ) } )
123 if( wxDirExists(
path ) )
127 wxString rootElementName = aLibraryFileName.GetName().Lower();
128 std::vector<wxString> uniqueAscNameKeys;
130 std::function<void(
const wxString& )> collectHierarchy;
131 collectHierarchy = [&](
const wxString& aAscNameKey )
133 uniqueAscNameKeys.push_back( aAscNameKey );
137 aReporter->
Report( wxString::Format(
_(
"Missing '%s' schematic file" ), aAscNameKey + wxS(
".asc" ) ),
147 for(
LTSPICE_FILE& newSubSchematicElement : newSubSchematicElements )
154 if( asyKey.IsEmpty() )
161 collectHierarchy( asyKey );
165 collectHierarchy( rootElementName );
168 std::map<wxString, SCH_SCREEN*> mapOfScreens;
171 for(
const wxString& elementName : uniqueAscNameKeys )
175 if( elementName == rootElementName )
182 mapOfScreens[elementName] = screen;
186 for(
const wxString& elementName : uniqueAscNameKeys )
197 SCH_SCREEN* screen = mapOfScreens[elementName];
200 const int margin =
grid * 10;
224 parser.
CreateItems( ascFile, screen, uniqueAscNameKeys, mapOfScreens, originOffset );
233 std::set<SCH_SCREEN*> visitedScreens;
235 std::function<void(
SCH_SCREEN*, std::map<wxString, wxString> )> fixLabelCase;
236 fixLabelCase = [&](
SCH_SCREEN* aScreen, std::map<wxString, wxString> aLabelMap )
243 wxString lower = lbl->GetText().Lower();
245 if( !aLabelMap.contains( lower ) && lbl->GetText() != lower )
246 aLabelMap[lower] = lbl->GetText();
255 wxString lower = lbl->GetText().Lower();
257 if( aLabelMap.contains( lower ) )
258 lbl->SetText( aLabelMap.at( lower ) );
264 if( visitedScreens.contains( sheetScreen ) )
267 visitedScreens.insert( sheetScreen );
269 std::map<wxString, wxString> childLabelMap;
272 childLabelMap[
pin->GetText().Lower()] =
pin->GetText();
274 fixLabelCase( sheetScreen, childLabelMap );
279 fixLabelCase( aRootSheet->
GetScreen(), {} );
284 std::sort( sheets.begin(), sheets.end(),
287 size_t len = std::min( a.size(), b.size() );
289 for( size_t i = 0; i < len; ++i )
291 SCH_SHEET* sheetA = a.at( i );
292 SCH_SHEET* sheetB = b.at( i );
294 if( sheetA->m_Uuid == sheetB->m_Uuid )
297 const SCH_FIELD* fieldA = sheetA->GetField( SCH_IO_LTSPICE_PARSER::LT_INSTNAME_FIELD );
298 const SCH_FIELD* fieldB = sheetB->GetField( SCH_IO_LTSPICE_PARSER::LT_INSTNAME_FIELD );
299 int cmp = StrNumCmp( fieldA ? fieldA->GetText() : wxString(),
300 fieldB ? fieldB->GetText() : wxString(), CMP_T::IGNORE_CASE );
305 return sheetA->m_Uuid < sheetB->m_Uuid;
313 sheets.SortByHierarchicalPageNumbers(
true );
314 sheets.CheckForMissingSymbolInstances( aSchematic->Project().GetProjectName() );
319 if(
path.size() <= 1 )
324 for(
size_t i = 1; i <
path.size(); ++i )
326 suffix += wxS(
"_" );
329 suffix += instNameField->GetText();
347 path.UpdateAllScreenReferences();
350 aSchematic->FixupJunctionsAfterImport();
355 std::map<wxString, wxString>& aMapOfAscFiles,
356 std::map<wxString, wxString>& aMapOfAsyFiles,
357 const std::vector<wxString>& aBaseDirs )
361 if( !aDir.IsOpened() )
364 bool cont = aDir.GetFirst( &filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN );
368 wxFileName
path( aDir.GetName(), filename );
371 [&]( std::map<wxString, wxString>& aMapToLogTo,
const wxString& aKey )
373 if( aMapToLogTo.count( aKey ) )
377 m_reporter->Report( wxString::Format(
_(
"File at '%s' was ignored. Using previously "
378 "found file at '%s' instead." ),
385 aMapToLogTo.emplace( aKey,
path.GetFullPath() );
390 wxString extension =
path.GetExt().Lower();
392 for(
size_t i = 0; i < aBaseDirs.size() + 1; i++ )
396 for(
size_t j = i; j < aBaseDirs.size(); j++ )
397 alias << aBaseDirs[j].Lower() <<
'/';
399 alias <<
path.GetName().Lower();
401 if( extension == wxS(
"asc" ) )
402 logToMap( aMapOfAscFiles, alias );
403 else if( extension == wxS(
"asy" ) )
404 logToMap( aMapOfAsyFiles, alias );
407 cont = aDir.GetNext( &filename );
412 cont = aDir.GetFirst( &filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN );
416 wxFileName
path( aDir.GetName(), filename );
417 wxDir subDir(
path.GetFullPath() );
419 std::vector<wxString> newBase = aBaseDirs;
420 newBase.push_back( filename );
424 cont = aDir.GetNext( &filename );
666 const wxString& aAsyFileContent,
LT_ASC& aAscFile )
671 lt_symbol.
Name = aSymbolName;
675 for( wxString line : wxSplit( aAsyFileContent,
'\n' ) )
679 wxArrayString tokens = wxSplit( line,
' ' );
681 if( tokens.IsEmpty() )
684 wxString element = tokens[0].Upper();
686 if( element ==
"LINE" )
690 wxString lineWidth = tokens[1];
691 wxString startPointX = tokens[2];
692 wxString startPointY = tokens[3];
693 wxString endPointX = tokens[4];
694 wxString endPointY = tokens[5];
698 lt_line.
Start =
pointCheck( startPointX, startPointY, lineNumber, aSymbolName );
699 lt_line.
End =
pointCheck( endPointX, endPointY, lineNumber, aSymbolName );
701 int lineStyleNumber = 0;
703 if( tokens.size() == 7 )
705 wxString lineStyle = tokens[6];
706 lineStyleNumber =
integerCheck( lineStyle, lineNumber, aSymbolName );
711 lt_symbol.
Lines.push_back( lt_line );
713 else if( element ==
"RECTANGLE" )
717 wxString lineWidth = tokens[1];
718 wxString botRightX = tokens[2];
719 wxString botRightY = tokens[3];
720 wxString topLeftX = tokens[4];
721 wxString topRightY = tokens[5];
725 rect.BotRight =
pointCheck( botRightX, botRightY, lineNumber, aSymbolName );
726 rect.TopLeft =
pointCheck( topLeftX, topRightY, lineNumber, aSymbolName );
728 int lineStyleNumber = 0;
730 if( tokens.size() == 7 )
732 wxString lineStyle = tokens[6];
733 lineStyleNumber =
integerCheck( lineStyle, lineNumber, aSymbolName );
740 else if( element ==
"CIRCLE" )
748 wxString lineWidth = tokens[1];
749 wxString botRightX = tokens[2];
750 wxString botRightY = tokens[3];
751 wxString topLeftX = tokens[4];
752 wxString topRightY = tokens[5];
756 circle.BotRight =
pointCheck( botRightX, botRightY, lineNumber, aSymbolName );
757 circle.TopLeft =
pointCheck( topLeftX, topRightY, lineNumber, aSymbolName );
759 int lineStyleNumber = 0;
761 if( tokens.size() == 7 )
763 wxString lineStyle = tokens[6];
764 lineStyleNumber =
integerCheck( lineStyle, lineNumber, aSymbolName );
771 else if( element ==
"ARC" )
780 wxString lineWidth = tokens[1];
781 wxString botRightX = tokens[2];
782 wxString botRightY = tokens[3];
783 wxString topLeftX = tokens[4];
784 wxString topRightY = tokens[5];
785 wxString arcStartPointX = tokens[6];
786 wxString arcStartPointY = tokens[7];
787 wxString arcEndPointX = tokens[8];
788 wxString arcEndPointY = tokens[9];
795 arc.
ArcEnd =
pointCheck( arcEndPointX, arcEndPointY, lineNumber, aSymbolName );
797 int lineStyleNumber = 0;
799 if( tokens.size() == 11 )
801 wxString lineStyle = tokens[10];
802 lineStyleNumber =
integerCheck( lineStyle, lineNumber, aSymbolName );
807 lt_symbol.
Arcs.push_back( arc );
809 else if( element ==
"WINDOW" )
813 wxString number = tokens[1];
814 wxString windowPosX = tokens[2];
815 wxString windowPosY = tokens[3];
816 wxString justification = tokens[4];
817 wxString fontSize = tokens[5];
829 lt_symbol.
Windows.push_back( window );
831 else if( element ==
"TEXT" )
837 wxString positionX = tokens[1];
838 wxString positionY = tokens[2];
839 wxString justification = tokens[3];
840 wxString fontSize = tokens[4];
841 wxString value = tokens[5];
844 text.Offset =
pointCheck( positionX, positionY, lineNumber, aSymbolName );
849 text.Value.Replace( wxS(
"\\n" ), wxS(
"\n" ) );
853 else if( element ==
"SYMATTR" )
859 wxString key = tokens[1];
860 wxString value = tokens[2];
862 if( value == wxS(
"\"\"" ) )
863 value = wxEmptyString;
867 else if( element ==
"PIN" )
871 wxString pinLocationX = tokens[1];
872 wxString pinLocationY = tokens[2];
873 wxString Justification = tokens[3];
874 wxString nameOffSet = tokens[4];
877 pin.PinLocation =
pointCheck( pinLocationX, pinLocationY, lineNumber,aSymbolName );
881 lt_symbol.
Pins.push_back(
pin );
883 else if( element ==
"PINATTR" )
889 wxString
name = tokens[1];
890 wxString Value = tokens[2];
892 lt_symbol.
Pins.back().PinAttribute.insert( {
name, Value } );
894 else if( element ==
"SYMBOLTYPE" )
898 wxString symbolType = tokens[1];
935 std::map<wxString, LT_ASC> ascFiles;
937 for(
const auto& [ fileName, contents ] : aAscFilesContent )
940 std::vector<LT_SYMBOL> symbolArray;
950 for( wxString line : wxSplit( contents,
'\n' ) )
954 wxArrayString tokens = wxSplit( line,
' ' );
956 if( tokens.IsEmpty() )
959 wxString element = tokens[0].Upper();
961 if( element ==
"SHEET" )
965 wxString sheetNumber = tokens[1];
966 wxString sheetWidth = tokens[2];
967 wxString sheetHeight = tokens[3];
972 else if( element ==
"SYMBOL" )
976 wxString symbolName = tokens[1];
977 wxString posX = tokens[2];
978 wxString posY = tokens[3];
979 wxString rotate_mirror_option = tokens[4];
981 symbolName.Replace(
'\\',
'/' );
989 wxString fullName = wxFileName( fileName ).GetFullName();
992 wxString::Format(
_(
"Missing symbol file '%s.asy', referenced from '%s' at line %d" ),
993 symbolName, fullName, lineNumber ) );
1006 ascFile.
Symbols.push_back( lt_symbol );
1020 ascFile.
Symbols.push_back( lt_symbol );
1024 else if( element ==
"WIRE" )
1028 wxString startPointX = tokens[1];
1029 wxString startPointY = tokens[2];
1030 wxString endPointX = tokens[3];
1031 wxString endPointY = tokens[4];
1034 wire.
Start =
pointCheck( startPointX, startPointY, lineNumber, fileName );
1035 wire.
End =
pointCheck( endPointX, endPointY, lineNumber, fileName );
1037 ascFile.
Wires.push_back( wire );
1041 else if( element ==
"FLAG" )
1045 wxString posX = tokens[1];
1046 wxString posY = tokens[2];
1047 wxString
name = tokens[3];
1057 else if( element ==
"DATAFLAG" )
1061 wxString posX = tokens[1];
1062 wxString posY = tokens[2];
1063 wxString expression = tokens[3];
1067 flag.Expression = expression;
1073 else if( element ==
"WINDOW" )
1077 wxString number = tokens[1];
1078 wxString windowPosX = tokens[2];
1079 wxString windowPosY = tokens[3];
1080 wxString justification = tokens[4];
1081 wxString fontSize = tokens[5];
1085 int windowNumber =
integerCheck( number, lineNumber, fileName );
1092 window = &candidate;
1100 window = &symbol->
Windows.back();
1110 else if( element ==
"SYMATTR" )
1116 wxString
name = tokens[1];
1117 wxString value = tokens[2];
1119 if( value == wxS(
"\"\"" ) )
1120 value = wxEmptyString;
1122 ascFile.
Symbols.back().SymAttributes[
name.Upper() ] = value;
1124 else if( element ==
"LINE" )
1128 wxString lineWidth = tokens[1];
1129 wxString startPointX = tokens[2];
1130 wxString startPointY = tokens[3];
1131 wxString endPointX = tokens[4];
1132 wxString endPointY = tokens[5];
1136 lt_line.
Start =
pointCheck( startPointX, startPointY, lineNumber, fileName );
1137 lt_line.
End =
pointCheck( endPointX, endPointY, lineNumber, fileName );
1139 int lineStyleNumber = 0;
1141 if( tokens.size() == 7 )
1143 wxString lineStyle = tokens[6];
1144 lineStyleNumber =
integerCheck( lineStyle, lineNumber, fileName );
1149 ascFile.
Lines.push_back( lt_line );
1153 else if( element ==
"RECTANGLE" )
1158 wxString botRightX = tokens[2];
1159 wxString botRightY = tokens[3];
1160 wxString topLeftX = tokens[4];
1161 wxString topRightY = tokens[5];
1165 rect.BotRight =
pointCheck( botRightX, botRightY, lineNumber, fileName );
1166 rect.TopLeft =
pointCheck( topLeftX, topRightY, lineNumber, fileName );
1168 int lineStyleNumber = 0;
1170 if( tokens.size() == 7 )
1172 wxString lineStyle = tokens[6];
1173 lineStyleNumber =
integerCheck( lineStyle, lineNumber, fileName );
1182 else if( element ==
"CIRCLE" )
1186 wxString lineWidth = tokens[1];
1187 wxString botRightX = tokens[2];
1188 wxString botRightY = tokens[3];
1189 wxString topLeftX = tokens[4];
1190 wxString topRightY = tokens[5];
1194 circle.BotRight =
pointCheck( botRightX, botRightY, lineNumber, fileName );
1197 int lineStyleNumber = 0;
1199 if( tokens.size() == 7 )
1201 wxString lineStyle = tokens[6];
1202 lineStyleNumber =
integerCheck( lineStyle, lineNumber, fileName );
1211 else if( element ==
"ARC" )
1220 wxString lineWidth = tokens[1];
1221 wxString botRightX = tokens[2];
1222 wxString botRightY = tokens[3];
1223 wxString topLeftX = tokens[4];
1224 wxString topRightY = tokens[5];
1225 wxString arcStartPointX = tokens[6];
1226 wxString arcStartPointY = tokens[7];
1227 wxString arcEndPointX = tokens[8];
1228 wxString arcEndPointY = tokens[9];
1234 arc.
ArcEnd =
pointCheck( arcStartPointX, arcStartPointY, lineNumber, fileName );
1237 int lineStyleNumber = 0;
1239 if( tokens.size() == 11 )
1241 wxString lineStyle = tokens[10];
1242 lineStyleNumber =
integerCheck( lineStyle, lineNumber, fileName );
1247 ascFile.
Arcs.push_back( arc );
1251 else if( element ==
"IOPIN" )
1255 wxString pinLocationX = tokens[1];
1256 wxString pinLocationY = tokens[2];
1257 wxString pinPolarity = tokens[3];
1263 ascFile.
Iopins.push_back( iopin );
1266 else if( element ==
"TEXT" )
1272 wxString positionX = tokens[1];
1273 wxString positionY = tokens[2];
1274 wxString justification = tokens[3];
1275 wxString fontSize = tokens[4];
1276 wxString value = tokens[5];
1279 text.Offset =
pointCheck( positionX, positionY, lineNumber, fileName );
1283 if( value.StartsWith( wxS(
"!" ), &
text.Value ) )
1284 text.Value.Replace( wxS(
"! " ), wxS(
"\n" ) );
1285 else if( value.StartsWith( wxS(
";" ), &
text.Value ) )
1286 text.Value.Replace( wxS(
"; " ), wxS(
"\n" ) );
1290 text.Value.Replace( wxS(
"\\n" ), wxS(
"\n" ) );
1295 else if( element ==
"BUSTAP" )
1299 wxString startPointX = tokens[1];
1300 wxString startPointY = tokens[2];
1301 wxString endPointX = tokens[3];
1302 wxString endPointY = tokens[4];
1305 bustap.
Start =
pointCheck( startPointX, startPointY, lineNumber, fileName );
1306 bustap.
End =
pointCheck( endPointX, endPointY, lineNumber, fileName );
1308 ascFile.
Bustap.push_back( bustap );
1312 else if( element ==
"VERSION" )
1314 wxString versionNumber = tokens[1];
1315 if( versionNumber.Contains(
'.' ) )
1317 wxString majorStr = versionNumber.BeforeFirst(
'.' );
1318 wxString minorStr = versionNumber.AfterFirst(
'.' );
1331 ascFiles[fileName] = std::move( ascFile );