diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index adef81ba05..488ad91d59 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -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" ) ); diff --git a/common/worksheet.cpp b/common/worksheet.cpp index ff7440ca64..7102b127c7 100644 --- a/common/worksheet.cpp +++ b/common/worksheet.cpp @@ -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", diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 330a22e217..e241155692 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -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; diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 0df7bd617a..2bd8cb5426 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -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 ) ); } diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index b02d301c01..372113c0e6 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -45,8 +45,6 @@ #include #include -// 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: diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 85b679fe59..18f418c826 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -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: diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index b1e085967a..1c358d1923 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -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 ); diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h index 9b94bd9975..62c0aa4667 100644 --- a/pcbnew/kicad_plugin.h +++ b/pcbnew/kicad_plugin.h @@ -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; }