299 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
300 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
305 std::set<wxString> sch_file;
306 std::set<wxString> sch_libs;
307 std::set<wxString> pcb_libs;
312 auto matchPcbExt = [](
const wxString& aExt ) ->
int
314 if( !aExt.CmpNoCase( wxS(
"PcbDoc" ) ) )
317 if( !aExt.CmpNoCase( wxS(
"CSPcbDoc" ) ) )
320 if( !aExt.CmpNoCase( wxS(
"CMPcbDoc" ) ) )
323 if( !aExt.CmpNoCase( wxS(
"SWPcbDoc" ) ) )
329 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
330 more =
config.GetNextGroup( groupname, groupid ) )
332 if( !groupname.StartsWith( wxS(
"Document" ) ) )
335 wxString number = groupname.Mid( 8 );
338 if( !number.ToLong( &docNumber ) )
341 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
346 wxFileName fname(
path, wxPATH_WIN );
348 if( !fname.IsAbsolute() )
351 int pcbType = matchPcbExt( fname.GetExt() );
353 if( pcbType >= 0 && pcb_file.empty() )
355 pcb_file = fname.GetFullPath();
356 pcb_file_type = pcbType;
359 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
360 sch_file.insert( fname.GetFullPath() );
362 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
363 pcb_libs.insert( fname.GetFullPath() );
365 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
366 sch_libs.insert( fname.GetFullPath() );
379 for(
auto&
path : sch_file )
381 std::string key =
"sch" + std::to_string( ii++ );
385 if( !sch_file.empty() )
388 if( !pcb_file.empty() )
433 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
438 if( !file.Open( prjFile.GetFullPath() ) )
440 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
444 std::vector<wxFileName> schFiles;
446 wxString elementsDir;
448 for(
size_t i = 0; i < file.GetLineCount(); ++i )
450 wxString line = file.GetLine( i );
458 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
461 int commentPos = line.Find( wxT(
"#" ) );
463 if( commentPos != wxNOT_FOUND )
465 line = line.Left( commentPos );
473 wxStringTokenizer tok( line );
475 if( !tok.HasMoreTokens() )
478 wxString keyword = tok.GetNextToken();
480 if( keyword.CmpNoCase(
"schematics" ) == 0 )
482 while( tok.HasMoreTokens() )
484 wxString schToken = tok.GetNextToken();
485 wxFileName schFile( schToken );
487 if( !schFile.IsAbsolute() )
488 schFile.MakeAbsolute( prjFile.GetPath() );
490 schFiles.push_back( schFile );
493 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
495 wxString rest = line.Mid( keyword.length() );
500 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
502 wxString rest = line.Mid( keyword.length() );
509 if( !elementsDir.IsEmpty() )
511 wxFileName elementsPath( elementsDir );
513 if( !elementsPath.IsAbsolute() )
514 elementsPath.MakeAbsolute( prjFile.GetPath() );
516 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
519 if( schFiles.empty() )
521 wxFileName candidate = prjFile;
522 candidate.SetExt( wxS(
"sch" ) );
524 if( candidate.FileExists() )
525 schFiles.push_back( candidate );
528 auto promptForMissingFile =
529 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
531 wxString defaultDir = aFile.GetPath();
533 if( defaultDir.IsEmpty() )
534 defaultDir = prjFile.GetPath();
536 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
537 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
539 if( dlg.ShowModal() == wxID_OK )
541 aFile.Assign( dlg.GetPath() );
549 std::vector<wxFileName> resolvedSchFiles;
550 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
552 for( wxFileName schFile : schFiles )
554 if( !schFile.FileExists() )
556 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
560 resolvedSchFiles.push_back( schFile );
563 if( schFiles.empty() && resolvedSchFiles.empty() )
567 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
568 resolvedSchFiles.push_back( schFile );
571 if( resolvedSchFiles.size() > 1 )
576 wxString additionalFiles;
578 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
580 if( !additionalFiles.IsEmpty() )
581 additionalFiles += wxT(
";" );
583 additionalFiles += resolvedSchFiles[i].GetFullPath();
586 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
591 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
593 wxDir dir( aBaseDir );
595 if( !dir.IsOpened() )
599 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
603 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
604 wxDir childDir( subdirPath );
606 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
608 if( !aSymPaths.IsEmpty() )
609 aSymPaths += wxT(
"\n" );
611 aSymPaths += subdirPath;
614 cont = dir.GetNext( &subdir );
619 discoverSymDirs( prjFile.GetPath(), symPaths );
621 if( !resolvedSchFiles.empty() )
623 wxString schDir = resolvedSchFiles[0].GetPath();
625 if( schDir != prjFile.GetPath() )
626 discoverSymDirs( schDir, symPaths );
629 if( !symPaths.IsEmpty() )
630 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
632 if( !resolvedSchFiles.empty() )
635 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
636 layoutDir.RemoveLastDir();
637 layoutDir.AppendDir( wxS(
"layout" ) );
641 if( !outputName.IsEmpty() )
643 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
645 if( candidate.FileExists() )
649 if( !pcbFile.FileExists() )
651 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
653 if( candidate.FileExists() )
657 if( !pcbFile.FileExists() )
659 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
661 if( candidate.FileExists() )
665 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
667 if( !pcbFile.FileExists() )
668 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
670 if( pcbFile.FileExists() )
744 int importedSchFileType = aImportedSchFileType;
745 int importedPcbFileType = aImportedPcbFileType;
747 if( importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO || importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO_V3
752 importedSchFileType = isV3 ? SCH_IO_MGR::SCH_EASYEDAPRO_V3 : SCH_IO_MGR::SCH_EASYEDAPRO;
762 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ORCAD )
767 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
773 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
784 wxString symPaths = sourceDir;
786 auto discoverSymDirs = [&](
const wxString& aBaseDir )
788 wxDir dir( aBaseDir );
790 if( !dir.IsOpened() )
794 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
798 wxString subdirPath =
799 aBaseDir + wxFileName::GetPathSeparator() + subdir;
800 wxDir childDir( subdirPath );
802 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
803 symPaths += wxT(
"\n" ) + subdirPath;
805 cont = dir.GetNext( &subdir );
809 discoverSymDirs( sourceDir );
810 m_properties[
"sym_search_paths"] = symPaths.ToStdString();