From 0f8af51da6548a9ad85f458a775cc3be064cd208 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 15 Dec 2012 14:39:36 +0100 Subject: [PATCH] Pcbnew: add a dialog to load a legacy file in "old" projects, when the .kicad_pcb file is not existing, and the correspoinding .brd file exists. Fix also an issue in pcb_parser when a netclass name is just a number (like a track width as name) --- pcbnew/pcb_parser.cpp | 3 ++- pcbnew/pcbframe.cpp | 10 +++++----- pcbnew/pcbnew.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 533b18a797..f41cfe99a4 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -1064,7 +1064,8 @@ void PCB_PARSER::parseNETCLASS() throw( IO_ERROR, PARSE_ERROR ) auto_ptr nc( new NETCLASS( m_board, wxEmptyString ) ); - NeedSYMBOL(); + // Read netclass name (can be a name or just a number like track width) + NeedSYMBOLorNUMBER(); nc->SetName( FromUTF8() ); NeedSYMBOL(); nc->SetDescription( FromUTF8() ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index c4658a3b3f..a68c9c4562 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -778,18 +778,18 @@ void PCB_EDIT_FRAME::UpdateTitle() wxString title; wxFileName fileName = GetBoard()->GetFileName(); + title.Printf( wxT( "Pcbnew %s " ), GetChars( GetBuildVersion() ) ); + if( fileName.IsOk() && fileName.FileExists() ) { - title.Printf( wxT( "Pcbnew %s %s" ), GetChars( GetBuildVersion() ), - GetChars( fileName.GetFullPath() ) ); + title << fileName.GetFullPath(); if( !fileName.IsFileWritable() ) - title += _( " [Read Only]" ); + title << _( " [Read Only]" ); } else { - title.Printf( wxT( "Pcbnew %s " ), GetChars( GetBuildVersion() ) ); - title << _( " [no file]" ); + title << _( " [new file]" ) << wxT(" ") << fileName.GetFullPath(); } SetTitle( title ); diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 76315b6267..86e6083424 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -132,7 +132,8 @@ bool EDA_APP::OnInit() if( fn.GetExt() != PcbFileExtension ) { wxLogDebug( wxT( "Pcbnew file <%s> has the wrong extension. \ -Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); +Changing extension to .%s." ), GetChars( fn.GetFullPath() ), + GetChars( PcbFileExtension ) ); fn.SetExt( PcbFileExtension ); } @@ -173,12 +174,48 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); { /* Note the first time Pcbnew is called after creating a new project * the board file may not exist so we load settings only. + * However, because legacy board files are named *.brd, + * and new files are named *.kicad_pcb, + * for all previous projects ( before 2012, december 14 ), + * becuse KiCad manager ask to load a .kicad_pcb file + * if this file does not exist, it is certainly useful + * to test if a legacy file is existing, + * under the same name, and therefore if the user want to load it */ + bool file_exists = false; + if( fn.FileExists() ) { + file_exists = true; frame->LoadOnePcbFile( fn.GetFullPath() ); } - else + else if( fn.GetExt() == KiCadPcbFileExtension ) + { + // Try to find a legacy file with the same name: + wxFileName fn_legacy = fn; + fn_legacy.SetExt( LegacyPcbFileExtension ); + if( fn_legacy.FileExists() ) + { + wxString msg; + msg.Printf( _( "File <%s> does not exist.\n" +"However a legacy file <%s> exists.\nDo you want to load it?\n" +"It will be saved under the new file format" ), + GetChars( fn.GetFullPath() ), + GetChars( fn_legacy.GetFullPath() ) ); + if( IsOK( frame, msg ) ) + { + file_exists = true; + frame->LoadOnePcbFile( fn_legacy.GetFullPath() ); + wxString filename = fn.GetFullPath(); + filename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); + frame->GetBoard()->SetFileName( filename ); + frame->UpdateTitle(); + frame->OnModify(); // Ready to save theboard inder the new fmt + } + } + } + + if( ! file_exists ) { // File does not exists: prepare an empty board wxSetWorkingDirectory( fn.GetPath() ); frame->GetBoard()->SetFileName( fn.GetFullPath( wxPATH_UNIX ) );