234 wxFileConfig
config( wxEmptyString, wxEmptyString, wxEmptyString,
m_InputFile.GetFullPath(),
235 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
240 std::set<wxString> sch_file;
241 std::set<wxString> sch_libs;
242 std::set<wxString> pcb_libs;
247 auto matchPcbExt = [](
const wxString& aExt ) ->
int
249 if( !aExt.CmpNoCase( wxS(
"PcbDoc" ) ) )
252 if( !aExt.CmpNoCase( wxS(
"CSPcbDoc" ) ) )
255 if( !aExt.CmpNoCase( wxS(
"CMPcbDoc" ) ) )
258 if( !aExt.CmpNoCase( wxS(
"SWPcbDoc" ) ) )
264 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
265 more =
config.GetNextGroup( groupname, groupid ) )
267 if( !groupname.StartsWith( wxS(
"Document" ) ) )
270 wxString number = groupname.Mid( 8 );
273 if( !number.ToLong( &docNumber ) )
276 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
281 wxFileName fname(
path, wxPATH_WIN );
283 if( !fname.IsAbsolute() )
286 int pcbType = matchPcbExt( fname.GetExt() );
288 if( pcbType >= 0 && pcb_file.empty() )
290 pcb_file = fname.GetFullPath();
291 pcb_file_type = pcbType;
294 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
295 sch_file.insert( fname.GetFullPath() );
297 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
298 pcb_libs.insert( fname.GetFullPath() );
300 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
301 sch_libs.insert( fname.GetFullPath() );
311 for(
auto&
path : sch_file )
313 std::string key =
"sch" + std::to_string( ii++ );
317 if( !sch_file.empty() )
320 if( !pcb_file.empty() )
365 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
370 if( !file.Open( prjFile.GetFullPath() ) )
372 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
376 std::vector<wxFileName> schFiles;
378 wxString elementsDir;
380 for(
size_t i = 0; i < file.GetLineCount(); ++i )
382 wxString line = file.GetLine( i );
390 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
393 int commentPos = line.Find( wxT(
"#" ) );
395 if( commentPos != wxNOT_FOUND )
397 line = line.Left( commentPos );
405 wxStringTokenizer tok( line );
407 if( !tok.HasMoreTokens() )
410 wxString keyword = tok.GetNextToken();
412 if( keyword.CmpNoCase(
"schematics" ) == 0 )
414 while( tok.HasMoreTokens() )
416 wxString schToken = tok.GetNextToken();
417 wxFileName schFile( schToken );
419 if( !schFile.IsAbsolute() )
420 schFile.MakeAbsolute( prjFile.GetPath() );
422 schFiles.push_back( schFile );
425 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
427 wxString rest = line.Mid( keyword.length() );
432 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
434 wxString rest = line.Mid( keyword.length() );
441 if( !elementsDir.IsEmpty() )
443 wxFileName elementsPath( elementsDir );
445 if( !elementsPath.IsAbsolute() )
446 elementsPath.MakeAbsolute( prjFile.GetPath() );
448 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
451 if( schFiles.empty() )
453 wxFileName candidate = prjFile;
454 candidate.SetExt( wxS(
"sch" ) );
456 if( candidate.FileExists() )
457 schFiles.push_back( candidate );
460 auto promptForMissingFile =
461 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
463 wxString defaultDir = aFile.GetPath();
465 if( defaultDir.IsEmpty() )
466 defaultDir = prjFile.GetPath();
468 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
469 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
471 if( dlg.ShowModal() == wxID_OK )
473 aFile.Assign( dlg.GetPath() );
481 std::vector<wxFileName> resolvedSchFiles;
482 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
484 for( wxFileName schFile : schFiles )
486 if( !schFile.FileExists() )
488 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
492 resolvedSchFiles.push_back( schFile );
495 if( schFiles.empty() && resolvedSchFiles.empty() )
499 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
500 resolvedSchFiles.push_back( schFile );
503 if( resolvedSchFiles.size() > 1 )
508 wxString additionalFiles;
510 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
512 if( !additionalFiles.IsEmpty() )
513 additionalFiles += wxT(
";" );
515 additionalFiles += resolvedSchFiles[i].GetFullPath();
518 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
523 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
525 wxDir dir( aBaseDir );
527 if( !dir.IsOpened() )
531 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
535 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
536 wxDir childDir( subdirPath );
538 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
540 if( !aSymPaths.IsEmpty() )
541 aSymPaths += wxT(
"\n" );
543 aSymPaths += subdirPath;
546 cont = dir.GetNext( &subdir );
551 discoverSymDirs( prjFile.GetPath(), symPaths );
553 if( !resolvedSchFiles.empty() )
555 wxString schDir = resolvedSchFiles[0].GetPath();
557 if( schDir != prjFile.GetPath() )
558 discoverSymDirs( schDir, symPaths );
561 if( !symPaths.IsEmpty() )
562 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
564 if( !resolvedSchFiles.empty() )
567 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
568 layoutDir.RemoveLastDir();
569 layoutDir.AppendDir( wxS(
"layout" ) );
573 if( !outputName.IsEmpty() )
575 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
577 if( candidate.FileExists() )
581 if( !pcbFile.FileExists() )
583 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
585 if( candidate.FileExists() )
589 if( !pcbFile.FileExists() )
591 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
593 if( candidate.FileExists() )
597 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
599 if( !pcbFile.FileExists() )
600 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
602 if( pcbFile.FileExists() )
611 if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO
616 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ALTIUM
622 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
628 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
639 wxString symPaths = sourceDir;
641 auto discoverSymDirs = [&](
const wxString& aBaseDir )
643 wxDir dir( aBaseDir );
645 if( !dir.IsOpened() )
649 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
653 wxString subdirPath =
654 aBaseDir + wxFileName::GetPathSeparator() + subdir;
655 wxDir childDir( subdirPath );
657 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
658 symPaths += wxT(
"\n" ) + subdirPath;
660 cont = dir.GetNext( &subdir );
664 discoverSymDirs( sourceDir );
665 m_properties[
"sym_search_paths"] = symPaths.ToStdString();