303 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
304 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
309 std::set<wxString> sch_file;
310 std::set<wxString> sch_libs;
311 std::set<wxString> pcb_libs;
316 auto matchPcbExt = [](
const wxString& aExt ) ->
int
318 if( !aExt.CmpNoCase( wxS(
"PcbDoc" ) ) )
321 if( !aExt.CmpNoCase( wxS(
"CSPcbDoc" ) ) )
324 if( !aExt.CmpNoCase( wxS(
"CMPcbDoc" ) ) )
327 if( !aExt.CmpNoCase( wxS(
"SWPcbDoc" ) ) )
333 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
334 more =
config.GetNextGroup( groupname, groupid ) )
336 if( !groupname.StartsWith( wxS(
"Document" ) ) )
339 wxString number = groupname.Mid( 8 );
342 if( !number.ToLong( &docNumber ) )
345 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
350 wxFileName fname(
path, wxPATH_WIN );
352 if( !fname.IsAbsolute() )
355 int pcbType = matchPcbExt( fname.GetExt() );
357 if( pcbType >= 0 && pcb_file.empty() )
359 pcb_file = fname.GetFullPath();
360 pcb_file_type = pcbType;
363 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
364 sch_file.insert( fname.GetFullPath() );
366 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
367 pcb_libs.insert( fname.GetFullPath() );
369 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
370 sch_libs.insert( fname.GetFullPath() );
383 for(
auto&
path : sch_file )
385 std::string key =
"sch" + std::to_string( ii++ );
389 if( !sch_file.empty() )
392 if( !pcb_file.empty() )
437 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
442 if( !file.Open( prjFile.GetFullPath() ) )
444 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
448 std::vector<wxFileName> schFiles;
450 wxString elementsDir;
452 for(
size_t i = 0; i < file.GetLineCount(); ++i )
454 wxString line = file.GetLine( i );
462 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
465 int commentPos = line.Find( wxT(
"#" ) );
467 if( commentPos != wxNOT_FOUND )
469 line = line.Left( commentPos );
477 wxStringTokenizer tok( line );
479 if( !tok.HasMoreTokens() )
482 wxString keyword = tok.GetNextToken();
484 if( keyword.CmpNoCase(
"schematics" ) == 0 )
486 while( tok.HasMoreTokens() )
488 wxString schToken = tok.GetNextToken();
489 wxFileName schFile( schToken );
491 if( !schFile.IsAbsolute() )
492 schFile.MakeAbsolute( prjFile.GetPath() );
494 schFiles.push_back( schFile );
497 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
499 wxString rest = line.Mid( keyword.length() );
504 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
506 wxString rest = line.Mid( keyword.length() );
513 if( !elementsDir.IsEmpty() )
515 wxFileName elementsPath( elementsDir );
517 if( !elementsPath.IsAbsolute() )
518 elementsPath.MakeAbsolute( prjFile.GetPath() );
520 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
523 if( schFiles.empty() )
525 wxFileName candidate = prjFile;
526 candidate.SetExt( wxS(
"sch" ) );
528 if( candidate.FileExists() )
529 schFiles.push_back( candidate );
532 auto promptForMissingFile =
533 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
535 wxString defaultDir = aFile.GetPath();
537 if( defaultDir.IsEmpty() )
538 defaultDir = prjFile.GetPath();
540 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
541 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
543 if( dlg.ShowModal() == wxID_OK )
545 aFile.Assign( dlg.GetPath() );
553 std::vector<wxFileName> resolvedSchFiles;
554 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
556 for( wxFileName schFile : schFiles )
558 if( !schFile.FileExists() )
560 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
564 resolvedSchFiles.push_back( schFile );
567 if( schFiles.empty() && resolvedSchFiles.empty() )
571 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
572 resolvedSchFiles.push_back( schFile );
575 if( resolvedSchFiles.size() > 1 )
580 wxString additionalFiles;
582 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
584 if( !additionalFiles.IsEmpty() )
585 additionalFiles += wxT(
";" );
587 additionalFiles += resolvedSchFiles[i].GetFullPath();
590 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
595 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
597 wxDir dir( aBaseDir );
599 if( !dir.IsOpened() )
603 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
607 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
608 wxDir childDir( subdirPath );
610 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
612 if( !aSymPaths.IsEmpty() )
613 aSymPaths += wxT(
"\n" );
615 aSymPaths += subdirPath;
618 cont = dir.GetNext( &subdir );
623 discoverSymDirs( prjFile.GetPath(), symPaths );
625 if( !resolvedSchFiles.empty() )
627 wxString schDir = resolvedSchFiles[0].GetPath();
629 if( schDir != prjFile.GetPath() )
630 discoverSymDirs( schDir, symPaths );
633 if( !symPaths.IsEmpty() )
634 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
636 if( !resolvedSchFiles.empty() )
639 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
640 layoutDir.RemoveLastDir();
641 layoutDir.AppendDir( wxS(
"layout" ) );
645 if( !outputName.IsEmpty() )
647 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
649 if( candidate.FileExists() )
653 if( !pcbFile.FileExists() )
655 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
657 if( candidate.FileExists() )
661 if( !pcbFile.FileExists() )
663 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
665 if( candidate.FileExists() )
669 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
671 if( !pcbFile.FileExists() )
672 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
674 if( pcbFile.FileExists() )
754 int importedSchFileType = aImportedSchFileType;
755 int importedPcbFileType = aImportedPcbFileType;
757 if( importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO || importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO_V3
762 importedSchFileType = isV3 ? SCH_IO_MGR::SCH_EASYEDAPRO_V3 : SCH_IO_MGR::SCH_EASYEDAPRO;
772 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ORCAD )
777 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
783 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
794 wxString symPaths = sourceDir;
796 auto discoverSymDirs = [&](
const wxString& aBaseDir )
798 wxDir dir( aBaseDir );
800 if( !dir.IsOpened() )
804 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
808 wxString subdirPath =
809 aBaseDir + wxFileName::GetPathSeparator() + subdir;
810 wxDir childDir( subdirPath );
812 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
813 symPaths += wxT(
"\n" ) + subdirPath;
815 cont = dir.GetNext( &subdir );
819 discoverSymDirs( sourceDir );
820 m_properties[
"sym_search_paths"] = symPaths.ToStdString();