generalize the BOARD loading process PCB_EDIT_FRAME::LoadOnePcbFile() to use any supported PLUGIN
This commit is contained in:
parent
ad86e50a69
commit
b68fa7cdfd
|
@ -55,6 +55,7 @@ const wxString SchematicFileWildcard( _( "KiCad schematic files (*.sch)|*.sch" )
|
||||||
const wxString NetlistFileWildcard( _( "KiCad netlist files (*.net)|*.net" ) );
|
const wxString NetlistFileWildcard( _( "KiCad netlist files (*.net)|*.net" ) );
|
||||||
const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) );
|
const wxString GerberFileWildcard( _( "Gerber files (*.pho)|*.pho" ) );
|
||||||
const wxString LegacyPcbFileWildcard( _( "KiCad printed circuit board files (*.brd)|*.brd" ) );
|
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 PcbFileWildcard( _( "KiCad s-expr printed circuit board files (*.kicad_pcb)|*.kicad_pcb" ) );
|
||||||
const wxString FootprintLibFileWildcard( _( "KiCad footprint library file (*.mod)|*.mod" ) );
|
const wxString FootprintLibFileWildcard( _( "KiCad footprint library file (*.mod)|*.mod" ) );
|
||||||
const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) );
|
const wxString PdfFileWildcard( _( "Portable document format files (*.pdf)|*.pdf" ) );
|
||||||
|
|
|
@ -63,6 +63,7 @@ extern const wxString NetlistFileWildcard;
|
||||||
extern const wxString GerberFileWildcard;
|
extern const wxString GerberFileWildcard;
|
||||||
extern const wxString LegacyPcbFileWildcard;
|
extern const wxString LegacyPcbFileWildcard;
|
||||||
extern const wxString PcbFileWildcard;
|
extern const wxString PcbFileWildcard;
|
||||||
|
extern const wxString EaglePcbFileWildcard;
|
||||||
extern const wxString PdfFileWildcard;
|
extern const wxString PdfFileWildcard;
|
||||||
extern const wxString MacrosFileWildcard;
|
extern const wxString MacrosFileWildcard;
|
||||||
extern const wxString AllFilesWildcard;
|
extern const wxString AllFilesWildcard;
|
||||||
|
|
|
@ -90,39 +90,39 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
|
||||||
|
|
||||||
case ID_MENU_READ_LAST_SAVED_VERSION_BOARD:
|
case ID_MENU_READ_LAST_SAVED_VERSION_BOARD:
|
||||||
case ID_MENU_RECOVER_BOARD:
|
case ID_MENU_RECOVER_BOARD:
|
||||||
{
|
{
|
||||||
wxFileName fn;
|
wxFileName fn;
|
||||||
|
|
||||||
if( id == ID_MENU_RECOVER_BOARD )
|
if( id == ID_MENU_RECOVER_BOARD )
|
||||||
{
|
{
|
||||||
fn = wxFileName( wxEmptyString, saveFileName, PcbFileExtension );
|
fn = wxFileName( wxEmptyString, saveFileName, PcbFileExtension );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fn = GetScreen()->GetFileName();
|
fn = GetScreen()->GetFileName();
|
||||||
fn.SetExt( pcbBackupFileExtension );
|
fn.SetExt( pcbBackupFileExtension );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !fn.FileExists() )
|
if( !fn.FileExists() )
|
||||||
{
|
{
|
||||||
msg = _( "Recovery file " ) + fn.GetFullPath() + _( " not found." );
|
msg = _( "Recovery file " ) + fn.GetFullPath() + _( " not found." );
|
||||||
DisplayInfoMessage( this, msg );
|
DisplayInfoMessage( this, msg );
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg = _( "OK to load recovery file " ) + fn.GetFullPath();
|
|
||||||
|
|
||||||
if( !IsOK( this, msg ) )
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = _( "OK to load recovery file " ) + fn.GetFullPath();
|
||||||
|
|
||||||
LoadOnePcbFile( fn.GetFullPath(), false );
|
if( !IsOK( this, msg ) )
|
||||||
fn.SetExt( PcbFileExtension );
|
break;
|
||||||
GetScreen()->SetFileName( fn.GetFullPath() );
|
}
|
||||||
UpdateTitle();
|
|
||||||
|
LoadOnePcbFile( fn.GetFullPath(), false );
|
||||||
|
fn.SetExt( PcbFileExtension );
|
||||||
|
GetScreen()->SetFileName( fn.GetFullPath() );
|
||||||
|
UpdateTitle();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case ID_APPEND_FILE:
|
case ID_APPEND_FILE:
|
||||||
LoadOnePcbFile( wxEmptyString, true );
|
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 PCB_EDIT_FRAME::LoadOnePcbFile( const wxString& aFileName, bool aAppend,
|
||||||
bool aForceFileDialog )
|
bool aForceFileDialog )
|
||||||
{
|
{
|
||||||
wxString msg;
|
|
||||||
|
|
||||||
if( GetScreen()->IsModify() && !aAppend )
|
if( GetScreen()->IsModify() && !aAppend )
|
||||||
{
|
{
|
||||||
if( !IsOK( this, _( "The current board has been modified. Do you wish to discard \
|
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;
|
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 )
|
if( !fileName.IsOk() || !fileName.FileExists() || aForceFileDialog )
|
||||||
{
|
{
|
||||||
wxString name;
|
wxString name;
|
||||||
wxString path = wxGetCwd();
|
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() )
|
if( aForceFileDialog && fileName.FileExists() )
|
||||||
{
|
{
|
||||||
|
@ -183,7 +201,7 @@ the changes?" ) ) )
|
||||||
name = fileName.GetFullName();
|
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 );
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
if( dlg.ShowModal() == wxID_CANCEL )
|
||||||
|
@ -191,10 +209,15 @@ the changes?" ) ) )
|
||||||
|
|
||||||
fileName = dlg.GetPath();
|
fileName = dlg.GetPath();
|
||||||
|
|
||||||
if( !fileName.HasExt() )
|
int chosenFilter = dlg.GetFilterIndex();
|
||||||
fileName.SetExt( PcbFileExtension );
|
pluginType = loaders[chosenFilter].pluginType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
|
||||||
|
|
||||||
|
if( !fileName.HasExt() )
|
||||||
|
fileName.SetExt( pi->GetFileExtension() );
|
||||||
|
|
||||||
if( !aAppend )
|
if( !aAppend )
|
||||||
Clear_Pcb( false ); // pass false since we prompted above for a modified board
|
Clear_Pcb( false ); // pass false since we prompted above for a modified board
|
||||||
|
|
||||||
|
@ -224,13 +247,12 @@ the changes?" ) ) )
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// load or append either:
|
// load or append either:
|
||||||
loadedBoard = IO_MGR::Load( IO_MGR::LEGACY, GetScreen()->GetFileName(),
|
loadedBoard = pi->Load( GetScreen()->GetFileName(), aAppend ? GetBoard() : NULL, NULL );
|
||||||
aAppend ? GetBoard() : NULL,
|
|
||||||
NULL );
|
|
||||||
|
|
||||||
if( !aAppend )
|
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 \
|
DisplayInfoMessage( this, _( "This file was created by an older \
|
||||||
version of Pcbnew. It will be stored in the new file format when you save \
|
version of Pcbnew. It will be stored in the new file format when you save \
|
||||||
|
|
Loading…
Reference in New Issue