341 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
342 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
347 std::set<wxString> sch_file;
348 std::set<wxString> sch_libs;
349 std::set<wxString> pcb_libs;
354 auto matchPcbExt = [](
const wxString& aExt ) ->
int
356 if( !aExt.CmpNoCase( wxS(
"PcbDoc" ) ) )
359 if( !aExt.CmpNoCase( wxS(
"CSPcbDoc" ) ) )
362 if( !aExt.CmpNoCase( wxS(
"CMPcbDoc" ) ) )
365 if( !aExt.CmpNoCase( wxS(
"SWPcbDoc" ) ) )
371 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
372 more =
config.GetNextGroup( groupname, groupid ) )
374 if( !groupname.StartsWith( wxS(
"Document" ) ) )
377 wxString number = groupname.Mid( 8 );
380 if( !number.ToLong( &docNumber ) )
383 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
388 wxFileName fname(
path, wxPATH_WIN );
390 if( !fname.IsAbsolute() )
393 int pcbType = matchPcbExt( fname.GetExt() );
395 if( pcbType >= 0 && pcb_file.empty() )
397 pcb_file = fname.GetFullPath();
398 pcb_file_type = pcbType;
401 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
402 sch_file.insert( fname.GetFullPath() );
404 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
405 pcb_libs.insert( fname.GetFullPath() );
407 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
408 sch_libs.insert( fname.GetFullPath() );
421 for(
auto&
path : sch_file )
423 std::string key =
"sch" + std::to_string( ii++ );
427 if( !sch_file.empty() )
430 if( !pcb_file.empty() )
475 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
480 if( !file.Open( prjFile.GetFullPath() ) )
482 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
486 std::vector<wxFileName> schFiles;
488 wxString elementsDir;
490 for(
size_t i = 0; i < file.GetLineCount(); ++i )
492 wxString line = file.GetLine( i );
500 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
503 int commentPos = line.Find( wxT(
"#" ) );
505 if( commentPos != wxNOT_FOUND )
507 line = line.Left( commentPos );
515 wxStringTokenizer tok( line );
517 if( !tok.HasMoreTokens() )
520 wxString keyword = tok.GetNextToken();
522 if( keyword.CmpNoCase(
"schematics" ) == 0 )
524 while( tok.HasMoreTokens() )
526 wxString schToken = tok.GetNextToken();
527 wxFileName schFile( schToken );
529 if( !schFile.IsAbsolute() )
530 schFile.MakeAbsolute( prjFile.GetPath() );
532 schFiles.push_back( schFile );
535 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
537 wxString rest = line.Mid( keyword.length() );
542 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
544 wxString rest = line.Mid( keyword.length() );
551 if( !elementsDir.IsEmpty() )
553 wxFileName elementsPath( elementsDir );
555 if( !elementsPath.IsAbsolute() )
556 elementsPath.MakeAbsolute( prjFile.GetPath() );
558 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
561 if( schFiles.empty() )
563 wxFileName candidate = prjFile;
564 candidate.SetExt( wxS(
"sch" ) );
566 if( candidate.FileExists() )
567 schFiles.push_back( candidate );
570 auto promptForMissingFile =
571 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
573 wxString defaultDir = aFile.GetPath();
575 if( defaultDir.IsEmpty() )
576 defaultDir = prjFile.GetPath();
578 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
579 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
581 if( dlg.ShowModal() == wxID_OK )
583 aFile.Assign( dlg.GetPath() );
591 std::vector<wxFileName> resolvedSchFiles;
592 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
594 for( wxFileName schFile : schFiles )
596 if( !schFile.FileExists() )
598 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
602 resolvedSchFiles.push_back( schFile );
605 if( schFiles.empty() && resolvedSchFiles.empty() )
609 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
610 resolvedSchFiles.push_back( schFile );
613 if( resolvedSchFiles.size() > 1 )
618 wxString additionalFiles;
620 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
622 if( !additionalFiles.IsEmpty() )
623 additionalFiles += wxT(
";" );
625 additionalFiles += resolvedSchFiles[i].GetFullPath();
628 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
633 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
635 wxDir dir( aBaseDir );
637 if( !dir.IsOpened() )
641 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
645 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
646 wxDir childDir( subdirPath );
648 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
650 if( !aSymPaths.IsEmpty() )
651 aSymPaths += wxT(
"\n" );
653 aSymPaths += subdirPath;
656 cont = dir.GetNext( &subdir );
661 discoverSymDirs( prjFile.GetPath(), symPaths );
663 if( !resolvedSchFiles.empty() )
665 wxString schDir = resolvedSchFiles[0].GetPath();
667 if( schDir != prjFile.GetPath() )
668 discoverSymDirs( schDir, symPaths );
671 if( !symPaths.IsEmpty() )
672 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
674 if( !resolvedSchFiles.empty() )
677 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
678 layoutDir.RemoveLastDir();
679 layoutDir.AppendDir( wxS(
"layout" ) );
683 if( !outputName.IsEmpty() )
685 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
687 if( candidate.FileExists() )
691 if( !pcbFile.FileExists() )
693 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
695 if( candidate.FileExists() )
699 if( !pcbFile.FileExists() )
701 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
703 if( candidate.FileExists() )
707 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
709 if( !pcbFile.FileExists() )
710 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
712 if( pcbFile.FileExists() )
847 int importedSchFileType = aImportedSchFileType;
848 int importedPcbFileType = aImportedPcbFileType;
850 if( importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO || importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO_V3
855 importedSchFileType = isV3 ? SCH_IO_MGR::SCH_EASYEDAPRO_V3 : SCH_IO_MGR::SCH_EASYEDAPRO;
865 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ORCAD )
870 else if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYPC )
875 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
881 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
892 wxString symPaths = sourceDir;
894 auto discoverSymDirs = [&](
const wxString& aBaseDir )
896 wxDir dir( aBaseDir );
898 if( !dir.IsOpened() )
902 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
906 wxString subdirPath =
907 aBaseDir + wxFileName::GetPathSeparator() + subdir;
908 wxDir childDir( subdirPath );
910 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
911 symPaths += wxT(
"\n" ) + subdirPath;
913 cont = dir.GetNext( &subdir );
917 discoverSymDirs( sourceDir );
918 m_properties[
"sym_search_paths"] = symPaths.ToStdString();