Switch over to *.kicad_pcb format as the default BOARD format.

Add KiCadPcbFileExt global.
This commit is contained in:
Dick Hollenbeck 2012-12-14 10:54:54 -06:00
parent 312254bc8a
commit 79b4846200
8 changed files with 59 additions and 35 deletions

View File

@ -44,7 +44,10 @@ const wxString NetlistFileExtension( wxT( "net" ) );
const wxString LegacyFootprintLibPathExtension( wxT( "mod" ) );
const wxString ComponentFileExtension( wxT( "cmp" ) );
const wxString GerberFileExtension( wxT( "pho" ) );
const wxString PcbFileExtension( wxT( "brd" ) );
const wxString LegacyPcbFileExtension( wxT( "brd" ) );
const wxString KiCadPcbFileExtension( wxT( "kicad_pcb" ) );
const wxString PdfFileExtension( wxT( "pdf" ) );
const wxString MacrosFileExtension( wxT( "mcr" ) );
const wxString DrillFileExtension( wxT( "drl" ) );

View File

@ -1666,19 +1666,21 @@ void TITLE_BLOCK::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aCont
throw( IO_ERROR )
{
// Don't write the title block information if there is nothing to write.
if( !m_title.IsEmpty() || !m_date.IsEmpty() || !m_revision.IsEmpty()
if( !m_title.IsEmpty() || /* !m_date.IsEmpty() || */ !m_revision.IsEmpty()
|| !m_company.IsEmpty() || !m_comment1.IsEmpty() || !m_comment2.IsEmpty()
|| !m_comment3.IsEmpty() || !m_comment4.IsEmpty() )
{
aFormatter->Print( aNestLevel, "(title_block\n" );
aFormatter->Print( aNestLevel, "(title_block " );
if( !m_title.IsEmpty() )
aFormatter->Print( aNestLevel+1, "(title %s)\n",
aFormatter->Quotew( m_title ).c_str() );
/* version control users were complaining, see mailing list.
if( !m_date.IsEmpty() )
aFormatter->Print( aNestLevel+1, "(date %s)\n",
aFormatter->Quotew( m_date ).c_str() );
*/
if( !m_revision.IsEmpty() )
aFormatter->Print( aNestLevel+1, "(rev %s)\n",

View File

@ -51,7 +51,11 @@ extern const wxString ProjectFileExtension;
extern const wxString SchematicFileExtension;
extern const wxString NetlistFileExtension;
extern const wxString GerberFileExtension;
extern const wxString PcbFileExtension;
extern const wxString LegacyPcbFileExtension;
extern const wxString KiCadPcbFileExtension;
#define PcbFileExtension KiCadPcbFileExtension // symlink choice
extern const wxString LegacyFootprintLibPathExtension;
extern const wxString PdfFileExtension;
extern const wxString MacrosFileExtension;

View File

@ -199,10 +199,16 @@ void KICAD_MANAGER_FRAME::OnRunPcbCalculator( wxCommandEvent& event )
void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
wxFileName legacy_board( m_ProjectFileName );
wxFileName kicad_board( m_ProjectFileName );
fn.SetExt( PcbFileExtension );
ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( fn ) );
legacy_board.SetExt( LegacyPcbFileExtension );
kicad_board.SetExt( KiCadPcbFileExtension );
if( !legacy_board.FileExists() || kicad_board.FileExists() )
ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( kicad_board ) );
else
ExecuteFile( this, PCBNEW_EXE, QuoteFullPath( legacy_board ) );
}

View File

@ -45,8 +45,6 @@
#include <wx/imaglist.h>
#include <menus_helpers.h>
// TODO: use the wxString defined in wildcards_and_files_ext.h, when exists
const wxString PcbSexpFileExtension( wxT("kicad_brd") );
/* Note about the tree project build process:
* Building the tree project can be *very* long if there are a lot of subdirectories
@ -419,11 +417,11 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
break;
case TREE_LEGACY_PCB:
ext = PcbFileExtension;
ext = LegacyPcbFileExtension;
break;
case TREE_SEXP_PCB:
ext = PcbSexpFileExtension;
ext = KiCadPcbFileExtension;
break;
case TREE_GERBER:

View File

@ -188,8 +188,8 @@ the changes?" ) ) )
IO_MGR::PCB_FILE_T pluginType;
} loaders[] =
{
{ LegacyPcbFileWildcard, IO_MGR::LEGACY },
{ PcbFileWildcard, IO_MGR::KICAD },
{ LegacyPcbFileWildcard, IO_MGR::LEGACY },
{ EaglePcbFileWildcard, IO_MGR::EAGLE },
};
@ -405,31 +405,41 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
wxString upperTxt;
wxString lowerTxt;
wxString msg;
wxString wildcard;
int wildcardIndex = 0;
bool saveok = true;
wildcard << wxGetTranslation( LegacyPcbFileWildcard ) << wxChar( '|' ) <<
wxGetTranslation( PcbFileWildcard );
IO_MGR::PCB_FILE_T pluginType;
if( aFileName == wxEmptyString )
{
wxString wildcard;
wildcard << wxGetTranslation( PcbFileWildcard ) << wxChar( '|' ) <<
wxGetTranslation( LegacyPcbFileWildcard );
wxFileDialog dlg( this, _( "Save Board File" ), wxEmptyString, GetBoard()->GetFileName(),
wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() != wxID_OK )
return false;
GetBoard()->SetFileName( dlg.GetPath() );
wildcardIndex = dlg.GetFilterIndex(); // Legacy or s-expression file format.
pluginType = ( dlg.GetFilterIndex() == 1 ) ? IO_MGR::LEGACY : IO_MGR::KICAD;
pcbFileName = dlg.GetPath();
// enforce file extension, must match plugin's policy.
pcbFileName.SetExt( IO_MGR::GetFileExtension( pluginType ) );
}
else
{
GetBoard()->SetFileName( aFileName );
}
pcbFileName = aFileName;
IO_MGR::PCB_FILE_T pluginType = ( wildcardIndex == 0 ) ? IO_MGR::LEGACY : IO_MGR::KICAD;
if( pcbFileName.GetExt() == LegacyPcbFileExtension )
pluginType = IO_MGR::LEGACY;
else
{
pluginType = IO_MGR::KICAD;
pcbFileName.SetExt( KiCadPcbFileExtension );
}
}
// If changes are made, update the board date
if( GetScreen()->IsModify() )
@ -440,11 +450,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
SetTitleBlock( tb );
}
pcbFileName = GetBoard()->GetFileName();
if( pcbFileName.GetExt().IsEmpty() )
pcbFileName.SetExt( IO_MGR::GetFileExtension( pluginType ) );
if( !IsWritable( pcbFileName ) )
return false;
@ -462,7 +467,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
if( backupFileName.FileExists() )
wxRemoveFile( backupFileName.GetFullPath() );
// Rename the "old" file" from xxx.brd to xxx.000
// Rename the "old" file" from xxx.kicad_pcb to xxx.000
if( !wxRenameFile( pcbFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
msg = _( "Warning: unable to create backup file " ) + backupFileName.GetFullPath();
@ -495,8 +500,8 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
GetChars( pcbFileName.GetExt() ) ) );
wxString header = wxString::Format(
wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s\n\n" ),
LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(),
wxT( "PCBNEW-BOARD Version %d\n# Created by Pcbnew%s\n\n" ),
LEGACY_BOARD_FILE_VERSION,
GetBuildVersion().GetData() );
props["header"] = header;
@ -515,6 +520,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
{
GetBoard()->SetFileName( pcbFileName.GetFullPath() );
UpdateTitle();
UpdateFileHistory( GetBoard()->GetFileName() );
}
// Display the file names:

View File

@ -77,7 +77,7 @@ class FP_CACHE_ITEM
wxFileName m_file_name; ///< The the full file name and path of the footprint to cache.
bool m_writable; ///< Writability status of the footprint file.
wxDateTime m_mod_time; ///< The last file modified time stamp.
auto_ptr< MODULE > m_module;
auto_ptr< MODULE > m_module;
public:
FP_CACHE_ITEM( MODULE* aModule, const wxFileName& aFileName );
@ -606,8 +606,8 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
for( BOARD_ITEM* item = aBoard->m_Drawings; item; item = item->Next() )
Format( item, aNestLevel );
m_out->Print( 0, "\n" );
m_out->Print( 0, "\n" );
if( aBoard->m_Drawings.GetCount() )
m_out->Print( 0, "\n" );
// Do not save MARKER_PCBs, they can be regenerated easily.
@ -615,11 +615,12 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
Format( track, aNestLevel );
if( aBoard->m_Track.GetCount() )
m_out->Print( 0, "\n" );
/// @todo Add warning here that the old segment filed zones are no longer supported and
/// will not be saved.
m_out->Print( 0, "\n" );
// Save the polygon (which are the newer technology) zones.
for( int i=0; i < aBoard->GetAreaCount(); ++i )
Format( aBoard->GetArea( i ), aNestLevel );

View File

@ -73,6 +73,10 @@ public:
const wxString& GetFileExtension() const
{
// Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
// but to be pure, a plugin should not assume that it will always be linked
// with the core of the pcbnew code. (Might someday be a DLL/DSO.) Besides,
// file extension policy should be controlled by the plugin.
static const wxString extension = wxT( "kicad_pcb" );
return extension;
}