337 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
338 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
343 std::set<wxString> sch_file;
344 std::set<wxString> sch_libs;
345 std::set<wxString> pcb_libs;
350 auto matchPcbExt = [](
const wxString& aExt ) ->
int
352 if( !aExt.CmpNoCase( wxS(
"PcbDoc" ) ) )
355 if( !aExt.CmpNoCase( wxS(
"CSPcbDoc" ) ) )
358 if( !aExt.CmpNoCase( wxS(
"CMPcbDoc" ) ) )
361 if( !aExt.CmpNoCase( wxS(
"SWPcbDoc" ) ) )
367 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
368 more =
config.GetNextGroup( groupname, groupid ) )
370 if( !groupname.StartsWith( wxS(
"Document" ) ) )
373 wxString number = groupname.Mid( 8 );
376 if( !number.ToLong( &docNumber ) )
379 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
384 wxFileName fname(
path, wxPATH_WIN );
386 if( !fname.IsAbsolute() )
389 int pcbType = matchPcbExt( fname.GetExt() );
391 if( pcbType >= 0 && pcb_file.empty() )
393 pcb_file = fname.GetFullPath();
394 pcb_file_type = pcbType;
397 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
398 sch_file.insert( fname.GetFullPath() );
400 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
401 pcb_libs.insert( fname.GetFullPath() );
403 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
404 sch_libs.insert( fname.GetFullPath() );
417 for(
auto&
path : sch_file )
419 std::string key =
"sch" + std::to_string( ii++ );
423 if( !sch_file.empty() )
426 if( !pcb_file.empty() )
471 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
476 if( !file.Open( prjFile.GetFullPath() ) )
478 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
482 std::vector<wxFileName> schFiles;
484 wxString elementsDir;
486 for(
size_t i = 0; i < file.GetLineCount(); ++i )
488 wxString line = file.GetLine( i );
496 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
499 int commentPos = line.Find( wxT(
"#" ) );
501 if( commentPos != wxNOT_FOUND )
503 line = line.Left( commentPos );
511 wxStringTokenizer tok( line );
513 if( !tok.HasMoreTokens() )
516 wxString keyword = tok.GetNextToken();
518 if( keyword.CmpNoCase(
"schematics" ) == 0 )
520 while( tok.HasMoreTokens() )
522 wxString schToken = tok.GetNextToken();
523 wxFileName schFile( schToken );
525 if( !schFile.IsAbsolute() )
526 schFile.MakeAbsolute( prjFile.GetPath() );
528 schFiles.push_back( schFile );
531 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
533 wxString rest = line.Mid( keyword.length() );
538 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
540 wxString rest = line.Mid( keyword.length() );
547 if( !elementsDir.IsEmpty() )
549 wxFileName elementsPath( elementsDir );
551 if( !elementsPath.IsAbsolute() )
552 elementsPath.MakeAbsolute( prjFile.GetPath() );
554 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
557 if( schFiles.empty() )
559 wxFileName candidate = prjFile;
560 candidate.SetExt( wxS(
"sch" ) );
562 if( candidate.FileExists() )
563 schFiles.push_back( candidate );
566 auto promptForMissingFile =
567 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
569 wxString defaultDir = aFile.GetPath();
571 if( defaultDir.IsEmpty() )
572 defaultDir = prjFile.GetPath();
574 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
575 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
577 if( dlg.ShowModal() == wxID_OK )
579 aFile.Assign( dlg.GetPath() );
587 std::vector<wxFileName> resolvedSchFiles;
588 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
590 for( wxFileName schFile : schFiles )
592 if( !schFile.FileExists() )
594 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
598 resolvedSchFiles.push_back( schFile );
601 if( schFiles.empty() && resolvedSchFiles.empty() )
605 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
606 resolvedSchFiles.push_back( schFile );
609 if( resolvedSchFiles.size() > 1 )
614 wxString additionalFiles;
616 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
618 if( !additionalFiles.IsEmpty() )
619 additionalFiles += wxT(
";" );
621 additionalFiles += resolvedSchFiles[i].GetFullPath();
624 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
629 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
631 wxDir dir( aBaseDir );
633 if( !dir.IsOpened() )
637 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
641 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
642 wxDir childDir( subdirPath );
644 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
646 if( !aSymPaths.IsEmpty() )
647 aSymPaths += wxT(
"\n" );
649 aSymPaths += subdirPath;
652 cont = dir.GetNext( &subdir );
657 discoverSymDirs( prjFile.GetPath(), symPaths );
659 if( !resolvedSchFiles.empty() )
661 wxString schDir = resolvedSchFiles[0].GetPath();
663 if( schDir != prjFile.GetPath() )
664 discoverSymDirs( schDir, symPaths );
667 if( !symPaths.IsEmpty() )
668 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
670 if( !resolvedSchFiles.empty() )
673 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
674 layoutDir.RemoveLastDir();
675 layoutDir.AppendDir( wxS(
"layout" ) );
679 if( !outputName.IsEmpty() )
681 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
683 if( candidate.FileExists() )
687 if( !pcbFile.FileExists() )
689 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
691 if( candidate.FileExists() )
695 if( !pcbFile.FileExists() )
697 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
699 if( candidate.FileExists() )
703 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
705 if( !pcbFile.FileExists() )
706 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
708 if( pcbFile.FileExists() )
843 int importedSchFileType = aImportedSchFileType;
844 int importedPcbFileType = aImportedPcbFileType;
846 if( importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO || importedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO_V3
851 importedSchFileType = isV3 ? SCH_IO_MGR::SCH_EASYEDAPRO_V3 : SCH_IO_MGR::SCH_EASYEDAPRO;
861 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ORCAD )
866 else if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYPC )
871 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
877 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
888 wxString symPaths = sourceDir;
890 auto discoverSymDirs = [&](
const wxString& aBaseDir )
892 wxDir dir( aBaseDir );
894 if( !dir.IsOpened() )
898 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
902 wxString subdirPath =
903 aBaseDir + wxFileName::GetPathSeparator() + subdir;
904 wxDir childDir( subdirPath );
906 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
907 symPaths += wxT(
"\n" ) + subdirPath;
909 cont = dir.GetNext( &subdir );
913 discoverSymDirs( sourceDir );
914 m_properties[
"sym_search_paths"] = symPaths.ToStdString();