Commit b68fa7cd authored by Dick Hollenbeck's avatar Dick Hollenbeck

generalize the BOARD loading process PCB_EDIT_FRAME::LoadOnePcbFile() to use any supported PLUGIN

parent ad86e50a
......@@ -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" ) );
......
......@@ -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;
......
......@@ -121,8 +121,8 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
fn.SetExt( PcbFileExtension );
GetScreen()->SetFileName( fn.GetFullPath() );
UpdateTitle();
break;
}
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 \
......@@ -172,10 +170,30 @@ the changes?" ) ) )
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<DIM( loaders ); ++i )
{
if( 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 \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment