From b68fa7cdfda646d6f6e65d309ecc2e9a250673e7 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 29 May 2012 16:01:17 -0500 Subject: [PATCH] generalize the BOARD loading process PCB_EDIT_FRAME::LoadOnePcbFile() to use any supported PLUGIN --- common/wildcards_and_files_ext.cpp | 1 + include/wildcards_and_files_ext.h | 1 + pcbnew/files.cpp | 98 ++++++++++++++++++------------ 3 files changed, 62 insertions(+), 38 deletions(-) diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 0edffe7d64..3911ce022d 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -55,6 +55,7 @@ const wxString SchematicFileWildcard( _( "KiCad schematic files (*.sch)|*.sch" ) const wxString NetlistFileWildcard( _( "KiCad netlist files (*.net)|*.net" ) ); const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) ); const wxString LegacyPcbFileWildcard( _( "KiCad printed circuit board files (*.brd)|*.brd" ) ); +const wxString EaglePcbFileWildcard( _( "Eagle printed circuit board files (*.brd)|*.brd" ) ); const wxString PcbFileWildcard( _( "KiCad s-expr printed circuit board files (*.kicad_pcb)|*.kicad_pcb" ) ); const wxString FootprintLibFileWildcard( _( "KiCad footprint library file (*.mod)|*.mod" ) ); const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) ); diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 60a80c2dc6..5d3843d3c8 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -63,6 +63,7 @@ extern const wxString NetlistFileWildcard; extern const wxString GerberFileWildcard; extern const wxString LegacyPcbFileWildcard; extern const wxString PcbFileWildcard; +extern const wxString EaglePcbFileWildcard; extern const wxString PdfFileWildcard; extern const wxString MacrosFileWildcard; extern const wxString AllFilesWildcard; diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 803e07f8dd..0945e1f441 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -90,39 +90,39 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event ) case ID_MENU_READ_LAST_SAVED_VERSION_BOARD: case ID_MENU_RECOVER_BOARD: - { - wxFileName fn; + { + wxFileName fn; - if( id == ID_MENU_RECOVER_BOARD ) - { - fn = wxFileName( wxEmptyString, saveFileName, PcbFileExtension ); - } - else - { - fn = GetScreen()->GetFileName(); - fn.SetExt( pcbBackupFileExtension ); - } + if( id == ID_MENU_RECOVER_BOARD ) + { + fn = wxFileName( wxEmptyString, saveFileName, PcbFileExtension ); + } + else + { + fn = GetScreen()->GetFileName(); + fn.SetExt( pcbBackupFileExtension ); + } - if( !fn.FileExists() ) - { - msg = _( "Recovery file " ) + fn.GetFullPath() + _( " not found." ); - DisplayInfoMessage( this, msg ); - break; - } - else - { - msg = _( "OK to load recovery file " ) + fn.GetFullPath(); - - if( !IsOK( this, msg ) ) + if( !fn.FileExists() ) + { + msg = _( "Recovery file " ) + fn.GetFullPath() + _( " not found." ); + DisplayInfoMessage( this, msg ); break; - } + } + else + { + msg = _( "OK to load recovery file " ) + fn.GetFullPath(); - LoadOnePcbFile( fn.GetFullPath(), false ); - fn.SetExt( PcbFileExtension ); - GetScreen()->SetFileName( fn.GetFullPath() ); - UpdateTitle(); + if( !IsOK( this, msg ) ) + break; + } + + LoadOnePcbFile( fn.GetFullPath(), false ); + fn.SetExt( PcbFileExtension ); + GetScreen()->SetFileName( fn.GetFullPath() ); + UpdateTitle(); + } break; - } case ID_APPEND_FILE: LoadOnePcbFile( wxEmptyString, true ); @@ -154,8 +154,6 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event ) bool PCB_EDIT_FRAME::LoadOnePcbFile( const wxString& aFileName, bool aAppend, bool aForceFileDialog ) { - wxString msg; - if( GetScreen()->IsModify() && !aAppend ) { if( !IsOK( this, _( "The current board has been modified. Do you wish to discard \ @@ -170,12 +168,32 @@ the changes?" ) ) ) GetBoard()->m_Status_Pcb = 0; } - wxFileName fileName = aFileName; + wxFileName fileName = aFileName; + + IO_MGR::PCB_FILE_T pluginType = IO_MGR::LEGACY; + + static const struct { + const wxString& filter; + IO_MGR::PCB_FILE_T pluginType; + } loaders[] = { + { LegacyPcbFileWildcard, IO_MGR::LEGACY }, + { PcbFileWildcard, IO_MGR::KICAD }, + { EaglePcbFileWildcard, IO_MGR::EAGLE }, + }; if( !fileName.IsOk() || !fileName.FileExists() || aForceFileDialog ) { wxString name; wxString path = wxGetCwd(); + wxString fileFilters; + + for( unsigned i = 0; i 0 ) + fileFilters += wxChar( '|' ); + + fileFilters += loaders[i].filter; + } if( aForceFileDialog && fileName.FileExists() ) { @@ -183,7 +201,7 @@ the changes?" ) ) ) name = fileName.GetFullName(); } - wxFileDialog dlg( this, _( "Open Board File" ), path, name, LegacyPcbFileWildcard, + wxFileDialog dlg( this, _( "Open Board File" ), path, name, fileFilters, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) @@ -191,10 +209,15 @@ the changes?" ) ) ) fileName = dlg.GetPath(); - if( !fileName.HasExt() ) - fileName.SetExt( PcbFileExtension ); + int chosenFilter = dlg.GetFilterIndex(); + pluginType = loaders[chosenFilter].pluginType; } + PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) ); + + if( !fileName.HasExt() ) + fileName.SetExt( pi->GetFileExtension() ); + if( !aAppend ) Clear_Pcb( false ); // pass false since we prompted above for a modified board @@ -224,13 +247,12 @@ the changes?" ) ) ) try { // load or append either: - loadedBoard = IO_MGR::Load( IO_MGR::LEGACY, GetScreen()->GetFileName(), - aAppend ? GetBoard() : NULL, - NULL ); + loadedBoard = pi->Load( GetScreen()->GetFileName(), aAppend ? GetBoard() : NULL, NULL ); if( !aAppend ) { - if( loadedBoard->GetFileFormatVersionAtLoad() < LEGACY_BOARD_FILE_VERSION ) + if( pluginType == IO_MGR::LEGACY && + loadedBoard->GetFileFormatVersionAtLoad() < LEGACY_BOARD_FILE_VERSION ) { DisplayInfoMessage( this, _( "This file was created by an older \ version of Pcbnew. It will be stored in the new file format when you save \