306 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
307 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
312 std::set<wxString> sch_file;
313 std::set<wxString> sch_libs;
314 std::set<wxString> pcb_libs;
319 auto matchPcbExt = [](
const wxString& aExt ) ->
int
321 if( !aExt.CmpNoCase( wxS(
"PcbDoc" ) ) )
324 if( !aExt.CmpNoCase( wxS(
"CSPcbDoc" ) ) )
327 if( !aExt.CmpNoCase( wxS(
"CMPcbDoc" ) ) )
330 if( !aExt.CmpNoCase( wxS(
"SWPcbDoc" ) ) )
336 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
337 more =
config.GetNextGroup( groupname, groupid ) )
339 if( !groupname.StartsWith( wxS(
"Document" ) ) )
342 wxString number = groupname.Mid( 8 );
345 if( !number.ToLong( &docNumber ) )
348 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
353 wxFileName fname(
path, wxPATH_WIN );
355 if( !fname.IsAbsolute() )
358 int pcbType = matchPcbExt( fname.GetExt() );
360 if( pcbType >= 0 && pcb_file.empty() )
362 pcb_file = fname.GetFullPath();
363 pcb_file_type = pcbType;
366 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
367 sch_file.insert( fname.GetFullPath() );
369 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
370 pcb_libs.insert( fname.GetFullPath() );
372 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
373 sch_libs.insert( fname.GetFullPath() );
386 for(
auto&
path : sch_file )
388 std::string key =
"sch" + std::to_string( ii++ );
392 if( !sch_file.empty() )
395 if( !pcb_file.empty() )
440 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
445 if( !file.Open( prjFile.GetFullPath() ) )
447 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
451 std::vector<wxFileName> schFiles;
453 wxString elementsDir;
455 for(
size_t i = 0; i < file.GetLineCount(); ++i )
457 wxString line = file.GetLine( i );
465 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
468 int commentPos = line.Find( wxT(
"#" ) );
470 if( commentPos != wxNOT_FOUND )
472 line = line.Left( commentPos );
480 wxStringTokenizer tok( line );
482 if( !tok.HasMoreTokens() )
485 wxString keyword = tok.GetNextToken();
487 if( keyword.CmpNoCase(
"schematics" ) == 0 )
489 while( tok.HasMoreTokens() )
491 wxString schToken = tok.GetNextToken();
492 wxFileName schFile( schToken );
494 if( !schFile.IsAbsolute() )
495 schFile.MakeAbsolute( prjFile.GetPath() );
497 schFiles.push_back( schFile );
500 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
502 wxString rest = line.Mid( keyword.length() );
507 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
509 wxString rest = line.Mid( keyword.length() );
516 if( !elementsDir.IsEmpty() )
518 wxFileName elementsPath( elementsDir );
520 if( !elementsPath.IsAbsolute() )
521 elementsPath.MakeAbsolute( prjFile.GetPath() );
523 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
526 if( schFiles.empty() )
528 wxFileName candidate = prjFile;
529 candidate.SetExt( wxS(
"sch" ) );
531 if( candidate.FileExists() )
532 schFiles.push_back( candidate );
535 auto promptForMissingFile =
536 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
538 wxString defaultDir = aFile.GetPath();
540 if( defaultDir.IsEmpty() )
541 defaultDir = prjFile.GetPath();
543 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
544 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
546 if( dlg.ShowModal() == wxID_OK )
548 aFile.Assign( dlg.GetPath() );
556 std::vector<wxFileName> resolvedSchFiles;
557 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
559 for( wxFileName schFile : schFiles )
561 if( !schFile.FileExists() )
563 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
567 resolvedSchFiles.push_back( schFile );
570 if( schFiles.empty() && resolvedSchFiles.empty() )
574 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
575 resolvedSchFiles.push_back( schFile );
578 if( resolvedSchFiles.size() > 1 )
583 wxString additionalFiles;
585 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
587 if( !additionalFiles.IsEmpty() )
588 additionalFiles += wxT(
";" );
590 additionalFiles += resolvedSchFiles[i].GetFullPath();
593 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
598 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
600 wxDir dir( aBaseDir );
602 if( !dir.IsOpened() )
606 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
610 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
611 wxDir childDir( subdirPath );
613 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
615 if( !aSymPaths.IsEmpty() )
616 aSymPaths += wxT(
"\n" );
618 aSymPaths += subdirPath;
621 cont = dir.GetNext( &subdir );
626 discoverSymDirs( prjFile.GetPath(), symPaths );
628 if( !resolvedSchFiles.empty() )
630 wxString schDir = resolvedSchFiles[0].GetPath();
632 if( schDir != prjFile.GetPath() )
633 discoverSymDirs( schDir, symPaths );
636 if( !symPaths.IsEmpty() )
637 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
639 if( !resolvedSchFiles.empty() )
642 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
643 layoutDir.RemoveLastDir();
644 layoutDir.AppendDir( wxS(
"layout" ) );
648 if( !outputName.IsEmpty() )
650 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
652 if( candidate.FileExists() )
656 if( !pcbFile.FileExists() )
658 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
660 if( candidate.FileExists() )
664 if( !pcbFile.FileExists() )
666 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
668 if( candidate.FileExists() )
672 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
674 if( !pcbFile.FileExists() )
675 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
677 if( pcbFile.FileExists() )
812 int importedSchFileType = aImportedSchFileType;
813 int importedPcbFileType = aImportedPcbFileType;
815 if( importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO || importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO_V3
820 importedSchFileType = isV3 ? SCH_IO_MGR::SCH_EASYEDAPRO_V3 : SCH_IO_MGR::SCH_EASYEDAPRO;
830 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ORCAD )
835 else if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYPC )
840 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
846 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
857 wxString symPaths = sourceDir;
859 auto discoverSymDirs = [&](
const wxString& aBaseDir )
861 wxDir dir( aBaseDir );
863 if( !dir.IsOpened() )
867 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
871 wxString subdirPath =
872 aBaseDir + wxFileName::GetPathSeparator() + subdir;
873 wxDir childDir( subdirPath );
875 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
876 symPaths += wxT(
"\n" ) + subdirPath;
878 cont = dir.GetNext( &subdir );
882 discoverSymDirs( sourceDir );
883 m_properties[
"sym_search_paths"] = symPaths.ToStdString();