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> pcb_file;
242 std::set<wxString> sch_libs;
243 std::set<wxString> pcb_libs;
245 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
246 more =
config.GetNextGroup( groupname, groupid ) )
248 if( !groupname.StartsWith( wxS(
"Document" ) ) )
251 wxString number = groupname.Mid( 8 );
254 if( !number.ToLong( &docNumber ) )
257 wxString
path =
config.Read( groupname + wxS(
"/DocumentPath" ), wxEmptyString );
262 wxFileName fname(
path, wxPATH_WIN );
264 if( !fname.IsAbsolute() )
267 if( !fname.GetExt().CmpNoCase(
"PCBDOC" ) )
268 pcb_file.insert( fname.GetFullPath() );
270 if( !fname.GetExt().CmpNoCase(
"SCHDOC" ) )
271 sch_file.insert( fname.GetFullPath() );
273 if( !fname.GetExt().CmpNoCase(
"PCBLIB" ) )
274 pcb_libs.insert( fname.GetFullPath() );
276 if( !fname.GetExt().CmpNoCase(
"SCHLIB" ) )
277 sch_libs.insert( fname.GetFullPath() );
287 for(
auto&
path : sch_file )
289 std::string key =
"sch" + std::to_string( ii++ );
293 if( !sch_file.empty() )
296 if( !pcb_file.empty() )
341 if( prjFile.GetExt().CmpNoCase(
"prj" ) != 0 )
346 if( !file.Open( prjFile.GetFullPath() ) )
348 wxLogWarning(
_(
"Could not open gEDA / Lepton EDA project file '%s'." ), prjFile.GetFullPath() );
352 std::vector<wxFileName> schFiles;
354 wxString elementsDir;
356 for(
size_t i = 0; i < file.GetLineCount(); ++i )
358 wxString line = file.GetLine( i );
366 if( line.StartsWith( wxT(
"#" ) ) || line.StartsWith( wxT(
";" ) ) )
369 int commentPos = line.Find( wxT(
"#" ) );
371 if( commentPos != wxNOT_FOUND )
373 line = line.Left( commentPos );
381 wxStringTokenizer tok( line );
383 if( !tok.HasMoreTokens() )
386 wxString keyword = tok.GetNextToken();
388 if( keyword.CmpNoCase(
"schematics" ) == 0 )
390 while( tok.HasMoreTokens() )
392 wxString schToken = tok.GetNextToken();
393 wxFileName schFile( schToken );
395 if( !schFile.IsAbsolute() )
396 schFile.MakeAbsolute( prjFile.GetPath() );
398 schFiles.push_back( schFile );
401 else if( keyword.CmpNoCase(
"output-name" ) == 0 )
403 wxString rest = line.Mid( keyword.length() );
408 else if( keyword.CmpNoCase(
"elements-dir" ) == 0 )
410 wxString rest = line.Mid( keyword.length() );
417 if( !elementsDir.IsEmpty() )
419 wxFileName elementsPath( elementsDir );
421 if( !elementsPath.IsAbsolute() )
422 elementsPath.MakeAbsolute( prjFile.GetPath() );
424 m_properties[
"elements_dir"] = elementsPath.GetFullPath().ToStdString();
427 if( schFiles.empty() )
429 wxFileName candidate = prjFile;
430 candidate.SetExt( wxS(
"sch" ) );
432 if( candidate.FileExists() )
433 schFiles.push_back( candidate );
436 auto promptForMissingFile =
437 [&](
const wxString& aTitle,
const wxString& aWildcard, wxFileName& aFile ) ->
bool
439 wxString defaultDir = aFile.GetPath();
441 if( defaultDir.IsEmpty() )
442 defaultDir = prjFile.GetPath();
444 wxFileDialog dlg(
m_frame, aTitle, defaultDir, wxEmptyString, aWildcard,
445 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
447 if( dlg.ShowModal() == wxID_OK )
449 aFile.Assign( dlg.GetPath() );
457 std::vector<wxFileName> resolvedSchFiles;
458 const wxString schWildcard =
_(
"gEDA / Lepton EDA schematic files" ) + wxS(
" (*.sch)|*.sch" );
460 for( wxFileName schFile : schFiles )
462 if( !schFile.FileExists() )
464 if( !promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
468 resolvedSchFiles.push_back( schFile );
471 if( schFiles.empty() && resolvedSchFiles.empty() )
475 if( promptForMissingFile(
_(
"Locate gEDA / Lepton EDA Schematic" ), schWildcard, schFile ) )
476 resolvedSchFiles.push_back( schFile );
479 if( resolvedSchFiles.size() > 1 )
484 wxString additionalFiles;
486 for(
size_t i = 1; i < resolvedSchFiles.size(); i++ )
488 if( !additionalFiles.IsEmpty() )
489 additionalFiles += wxT(
";" );
491 additionalFiles += resolvedSchFiles[i].GetFullPath();
494 m_properties[
"additional_schematics"] = additionalFiles.ToStdString();
499 auto discoverSymDirs = [&](
const wxString& aBaseDir, wxString& aSymPaths )
501 wxDir dir( aBaseDir );
503 if( !dir.IsOpened() )
507 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
511 wxString subdirPath = aBaseDir + wxFileName::GetPathSeparator() + subdir;
512 wxDir childDir( subdirPath );
514 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
516 if( !aSymPaths.IsEmpty() )
517 aSymPaths += wxT(
"\n" );
519 aSymPaths += subdirPath;
522 cont = dir.GetNext( &subdir );
527 discoverSymDirs( prjFile.GetPath(), symPaths );
529 if( !resolvedSchFiles.empty() )
531 wxString schDir = resolvedSchFiles[0].GetPath();
533 if( schDir != prjFile.GetPath() )
534 discoverSymDirs( schDir, symPaths );
537 if( !symPaths.IsEmpty() )
538 m_properties[
"sym_search_paths"] = symPaths.ToStdString();
540 if( !resolvedSchFiles.empty() )
543 wxFileName layoutDir( prjFile.GetPath(), wxEmptyString );
544 layoutDir.RemoveLastDir();
545 layoutDir.AppendDir( wxS(
"layout" ) );
549 if( !outputName.IsEmpty() )
551 wxFileName candidate( layoutDir.GetPath(), outputName, wxS(
"pcb" ) );
553 if( candidate.FileExists() )
557 if( !pcbFile.FileExists() )
559 wxFileName candidate( prjFile.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
561 if( candidate.FileExists() )
565 if( !pcbFile.FileExists() )
567 wxFileName candidate( layoutDir.GetPath(), prjFile.GetName(), wxS(
"pcb" ) );
569 if( candidate.FileExists() )
573 const wxString pcbWildcard =
_(
"gEDA / Lepton EDA PCB files" ) + wxS(
" (*.pcb)|*.pcb" );
575 if( !pcbFile.FileExists() )
576 promptForMissingFile(
_(
"Locate gEDA / Lepton EDA PCB" ), pcbWildcard, pcbFile );
578 if( pcbFile.FileExists() )
587 if( aImportedSchFileType == SCH_IO_MGR::SCH_EASYEDAPRO
592 else if( aImportedSchFileType == SCH_IO_MGR::SCH_ALTIUM
598 else if( aImportedSchFileType == SCH_IO_MGR::SCH_GEDA )
604 else if(
m_InputFile.GetExt().CmpNoCase(
"pcb" ) == 0 )
615 wxString symPaths = sourceDir;
617 auto discoverSymDirs = [&](
const wxString& aBaseDir )
619 wxDir dir( aBaseDir );
621 if( !dir.IsOpened() )
625 bool cont = dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS );
629 wxString subdirPath =
630 aBaseDir + wxFileName::GetPathSeparator() + subdir;
631 wxDir childDir( subdirPath );
633 if( childDir.IsOpened() && childDir.HasFiles( wxT(
"*.sym" ) ) )
634 symPaths += wxT(
"\n" ) + subdirPath;
636 cont = dir.GetNext( &subdir );
640 discoverSymDirs( sourceDir );
641 m_properties[
"sym_search_paths"] = symPaths.ToStdString();