2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2010 Jean-Pierre Charras, jean-pierre.charras@gpisa-lab.inpg.fr
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/files.cpp
|
|
|
|
* @brief Read and write board files.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "pcbcommon.h"
|
2010-05-01 13:32:25 +00:00
|
|
|
#include "3d_viewer.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
|
|
|
#include "filter_reader.h"
|
2011-10-13 19:56:32 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "protos.h"
|
|
|
|
#include "pcbnew_id.h"
|
2011-11-29 03:08:14 +00:00
|
|
|
#include "io_mgr.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
#include "class_board.h"
|
|
|
|
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
static const wxString pcbBackupFileExtension( wxT( "000" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-04-28 14:06:14 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event )
|
2009-01-17 20:31:19 +00:00
|
|
|
{
|
|
|
|
wxString fn;
|
|
|
|
|
|
|
|
fn = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) );
|
|
|
|
|
|
|
|
if( fn != wxEmptyString )
|
|
|
|
{
|
2011-02-24 20:22:12 +00:00
|
|
|
DrawPanel->EndMouseCapture( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor() );
|
2009-01-17 20:31:19 +00:00
|
|
|
::wxSetWorkingDirectory( ::wxPathOnly( fn ) );
|
2010-05-30 09:46:37 +00:00
|
|
|
LoadOnePcbFile( fn );
|
2009-01-17 20:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
int id = event.GetId();
|
|
|
|
wxString msg;
|
|
|
|
|
2011-02-09 18:41:46 +00:00
|
|
|
// If an edition is in progress, stop it.
|
|
|
|
// For something else than save, get rid of current tool.
|
|
|
|
if( id == ID_SAVE_BOARD )
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->EndMouseCapture( -1, DrawPanel->GetDefaultCursor() );
|
2011-02-09 18:41:46 +00:00
|
|
|
else
|
2011-02-24 20:22:12 +00:00
|
|
|
DrawPanel->EndMouseCapture( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case ID_LOAD_FILE:
|
2011-01-20 16:34:57 +00:00
|
|
|
LoadOnePcbFile( GetScreen()->GetFileName(), false, true );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MENU_READ_LAST_SAVED_VERSION_BOARD:
|
|
|
|
case ID_MENU_RECOVER_BOARD:
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
|
|
|
if( id == ID_MENU_RECOVER_BOARD )
|
|
|
|
{
|
2010-05-17 20:35:46 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_SaveFileName, PcbFileExtension );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
fn = GetScreen()->GetFileName();
|
2011-10-15 13:25:57 +00:00
|
|
|
fn.SetExt( pcbBackupFileExtension );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !fn.FileExists() )
|
|
|
|
{
|
2010-04-23 14:46:00 +00:00
|
|
|
msg = _( "Recovery file " ) + fn.GetFullPath() + _( " not found." );
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, msg );
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2010-04-23 14:46:00 +00:00
|
|
|
msg = _( "OK to load recovery file " ) + fn.GetFullPath();
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
LoadOnePcbFile( fn.GetFullPath(), false );
|
2010-05-17 20:35:46 +00:00
|
|
|
fn.SetExt( PcbFileExtension );
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->SetFileName( fn.GetFullPath() );
|
2011-08-26 17:01:17 +00:00
|
|
|
UpdateTitle();
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
case ID_APPEND_FILE:
|
2009-09-27 11:00:21 +00:00
|
|
|
LoadOnePcbFile( wxEmptyString, true );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_NEW_BOARD:
|
2009-09-27 11:00:21 +00:00
|
|
|
Clear_Pcb( true );
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->GetFileName().Printf( wxT( "%s%cnoname%s" ),
|
2011-02-21 13:54:29 +00:00
|
|
|
GetChars( wxGetCwd() ), DIR_SEP,
|
|
|
|
GetChars( PcbFileExtension ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
UpdateTitle();
|
2008-04-29 15:43:28 +00:00
|
|
|
ReCreateLayerBox( NULL );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SAVE_BOARD:
|
2011-01-20 16:34:57 +00:00
|
|
|
SavePcbFile( GetScreen()->GetFileName() );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
case ID_SAVE_BOARD_AS:
|
2007-08-06 02:02:39 +00:00
|
|
|
SavePcbFile( wxEmptyString );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DisplayError( this, wxT( "File_io Internal Error" ) ); break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_EDIT_FRAME::LoadOnePcbFile( const wxString& aFileName, bool aAppend,
|
|
|
|
bool aForceFileDialog )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( GetScreen()->IsModify() && !aAppend )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2010-04-28 14:06:14 +00:00
|
|
|
if( !IsOK( this, _( "The current board has been modified. Do you wish to discard \
|
|
|
|
the changes?" ) ) )
|
2009-09-22 12:27:57 +00:00
|
|
|
return false;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aAppend )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->SetFileName( wxEmptyString );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2010-05-17 20:35:46 +00:00
|
|
|
wxFileName fileName = aFileName;
|
2008-04-29 03:18:02 +00:00
|
|
|
|
2010-05-17 20:35:46 +00:00
|
|
|
if( !fileName.IsOk() || !fileName.FileExists() || aForceFileDialog )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2010-05-17 20:35:46 +00:00
|
|
|
wxString name;
|
|
|
|
wxString path = wxGetCwd();
|
|
|
|
|
|
|
|
if( aForceFileDialog && fileName.FileExists() )
|
|
|
|
{
|
|
|
|
path = fileName.GetPath();
|
|
|
|
name = fileName.GetFullName();
|
|
|
|
}
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2010-05-17 20:35:46 +00:00
|
|
|
wxFileDialog dlg( this, _( "Open Board File" ), path, name, PcbFileWildcard,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2009-09-22 12:27:57 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fileName = dlg.GetPath();
|
2010-05-17 20:35:46 +00:00
|
|
|
|
|
|
|
if( !fileName.HasExt() )
|
|
|
|
fileName.SetExt( PcbFileExtension );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2008-04-29 03:18:02 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( !aAppend )
|
2008-04-29 03:18:02 +00:00
|
|
|
Clear_Pcb( false ); // pass false since we prompted above for a modified board
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
CheckForAutoSaveFile( fileName, pcbBackupFileExtension );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-10-13 19:56:32 +00:00
|
|
|
GetScreen()->SetFileName( fileName.GetFullPath() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
#if 1
|
2011-10-13 19:56:32 +00:00
|
|
|
// Start read PCB file
|
2011-11-29 03:08:14 +00:00
|
|
|
FILE* source = wxFopen( GetScreen()->GetFileName(), wxT( "rt" ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( source == NULL )
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
msg.Printf( _( "File <%s> not found" ), GetChars( GetScreen()->GetFileName() ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
DisplayError( this, msg );
|
2009-09-22 12:27:57 +00:00
|
|
|
return false;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
FILE_LINE_READER fileReader( source, GetScreen()->GetFileName() );
|
2011-01-14 17:43:30 +00:00
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/* Read header and TEST if it is a PCB file format */
|
2011-01-14 17:43:30 +00:00
|
|
|
reader.ReadLine();
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
if( strncmp( reader.Line(), "PCBNEW-BOARD", 12 ) != 0 )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "Unknown file type" ) );
|
2009-09-22 12:27:57 +00:00
|
|
|
return false;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 16:05:23 +00:00
|
|
|
int ver;
|
2011-01-14 17:43:30 +00:00
|
|
|
sscanf( reader.Line() , "PCBNEW-BOARD Version %d date", &ver );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2008-04-06 16:05:23 +00:00
|
|
|
if ( ver > g_CurrentVersionPCB )
|
|
|
|
{
|
2009-09-22 12:27:57 +00:00
|
|
|
DisplayInfoMessage( this, _( "This file was created by a more recent \
|
2011-09-30 18:15:37 +00:00
|
|
|
version of Pcbnew and may not load correctly. Please consider updating!" ) );
|
2008-04-06 16:05:23 +00:00
|
|
|
}
|
|
|
|
else if ( ver < g_CurrentVersionPCB )
|
|
|
|
{
|
2009-09-22 12:27:57 +00:00
|
|
|
DisplayInfoMessage( this, _( "This file was created by an older \
|
2011-09-30 18:15:37 +00:00
|
|
|
version of Pcbnew. It will be stored in the new file format when you save \
|
2010-04-28 14:06:14 +00:00
|
|
|
this file again." ) );
|
2008-04-06 16:05:23 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
// Reload the corresponding configuration file:
|
2011-01-20 16:34:57 +00:00
|
|
|
wxSetWorkingDirectory( wxPathOnly( GetScreen()->GetFileName() ) );
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aAppend )
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
ReadPcbFile( &reader, true );
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
else
|
|
|
|
{
|
2007-08-30 08:15:05 +00:00
|
|
|
// Update the option toolbar
|
2007-08-06 02:02:39 +00:00
|
|
|
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
|
|
|
|
m_DisplayModText = DisplayOpt.DisplayModText;
|
|
|
|
m_DisplayModEdge = DisplayOpt.DisplayModEdge;
|
|
|
|
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
|
2009-09-29 04:44:35 +00:00
|
|
|
m_DisplayViaFill = DisplayOpt.DisplayViaFill;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
ReadPcbFile( &reader, false );
|
2011-01-20 16:34:57 +00:00
|
|
|
LoadProjectSettings( GetScreen()->GetFileName() );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
if( !aAppend )
|
|
|
|
{
|
|
|
|
// Update the option toolbar
|
|
|
|
m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
|
|
|
|
m_DisplayModText = DisplayOpt.DisplayModText;
|
|
|
|
m_DisplayModEdge = DisplayOpt.DisplayModEdge;
|
|
|
|
m_DisplayPadFill = DisplayOpt.DisplayPadFill;
|
|
|
|
m_DisplayViaFill = DisplayOpt.DisplayViaFill;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// load or append either:
|
|
|
|
BOARD* board = IO_MGR::Load( IO_MGR::KICAD, GetScreen()->GetFileName(),
|
|
|
|
aAppend ? GetBoard() : NULL,
|
|
|
|
NULL );
|
|
|
|
|
|
|
|
if( !aAppend )
|
|
|
|
SetBoard( board );
|
|
|
|
}
|
|
|
|
catch ( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
// @todo
|
|
|
|
printf( "Error loading board: %s\n", TO_UTF8( ioe.errorText ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aAppend )
|
|
|
|
{
|
|
|
|
LoadProjectSettings( GetScreen()->GetFileName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
GetScreen()->ClrModify();
|
|
|
|
|
2008-07-22 05:29:16 +00:00
|
|
|
/* If append option: change the initial board name to <oldname>-append.brd */
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aAppend )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
wxString new_filename = GetScreen()->GetFileName().BeforeLast( '.' );
|
|
|
|
|
2010-04-23 14:46:00 +00:00
|
|
|
if ( ! new_filename.EndsWith( wxT( "-append" ) ) )
|
|
|
|
new_filename += wxT( "-append" );
|
2008-07-22 05:29:16 +00:00
|
|
|
|
2010-05-17 20:35:46 +00:00
|
|
|
new_filename += wxT( "." ) + PcbFileExtension;
|
2008-07-22 05:29:16 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->SetFileName( new_filename );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->GetFileName().Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
2008-07-22 05:29:16 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
UpdateTitle();
|
2011-03-17 19:14:45 +00:00
|
|
|
UpdateFileHistory( GetScreen()->GetFileName() );
|
2008-07-22 05:29:16 +00:00
|
|
|
|
2007-08-30 08:15:05 +00:00
|
|
|
/* Rebuild the new pad list (for drc and ratsnet control ...) */
|
2009-05-24 18:28:36 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2009-06-19 20:13:22 +00:00
|
|
|
|
2010-01-30 20:17:56 +00:00
|
|
|
/* Reset the items visibility flag when loading a new config
|
2009-11-12 12:54:56 +00:00
|
|
|
* Because it could creates SERIOUS mistakes for the user,
|
2010-01-30 20:17:56 +00:00
|
|
|
* if board items are not visible after loading a board...
|
|
|
|
* Grid and ratsnest can be left to their previous state
|
2009-11-12 12:54:56 +00:00
|
|
|
*/
|
2010-04-23 14:46:00 +00:00
|
|
|
bool showGrid = IsElementVisible( GRID_VISIBLE );
|
|
|
|
bool showRats = IsElementVisible( RATSNEST_VISIBLE );
|
|
|
|
SetVisibleAlls();
|
|
|
|
SetElementVisibility( GRID_VISIBLE, showGrid );
|
|
|
|
SetElementVisibility( RATSNEST_VISIBLE, showRats );
|
2009-11-12 12:54:56 +00:00
|
|
|
|
2009-12-03 09:33:48 +00:00
|
|
|
// Update info shown by the horizontal toolbars
|
|
|
|
GetBoard()->SetCurrentNetClass( NETCLASS::Default );
|
2010-01-21 07:41:30 +00:00
|
|
|
ReFillLayerWidget();
|
|
|
|
|
2009-12-03 09:33:48 +00:00
|
|
|
ReCreateLayerBox( NULL );
|
2010-04-23 14:46:00 +00:00
|
|
|
syncLayerWidget();
|
2009-12-03 09:33:48 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
updateTraceWidthSelectBox();
|
|
|
|
updateViaSizeSelectBox();
|
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
// Display the loaded board:
|
2009-12-19 19:24:49 +00:00
|
|
|
Zoom_Automatique( false );
|
2009-07-30 11:04:07 +00:00
|
|
|
|
2010-04-28 14:06:14 +00:00
|
|
|
// Compile ratsnest and displays net info
|
2011-04-09 10:52:14 +00:00
|
|
|
wxBusyCursor dummy; // Displays an Hourglass while building connectivity
|
2009-05-28 08:42:24 +00:00
|
|
|
Compile_Ratsnest( NULL, true );
|
2009-04-17 08:51:02 +00:00
|
|
|
GetBoard()->DisplayInfo( this );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-05-01 13:32:25 +00:00
|
|
|
// Refresh the 3D view, if any
|
|
|
|
if( m_Draw3DFrame )
|
|
|
|
m_Draw3DFrame->NewDisplay();
|
2008-04-18 13:28:56 +00:00
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
2011-09-30 18:15:37 +00:00
|
|
|
// note this freezes up Pcbnew when run under the KiCad project
|
|
|
|
// manager. runs fine from command prompt. This is because the KiCad
|
|
|
|
// project manager redirects stdout of the child Pcbnew process to itself,
|
2008-04-18 13:28:56 +00:00
|
|
|
// but never reads from that pipe, and that in turn eventually blocks
|
2011-09-30 18:15:37 +00:00
|
|
|
// the Pcbnew program when the pipe it is writing to gets full.
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2007-10-31 06:40:15 +00:00
|
|
|
// Output the board object tree to stdout, but please run from command prompt:
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Show( 0, std::cout );
|
2007-08-06 02:02:39 +00:00
|
|
|
#endif
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-13 19:56:32 +00:00
|
|
|
bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupFile )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName backupFileName;
|
|
|
|
wxFileName pcbFileName;
|
2007-10-22 20:40:18 +00:00
|
|
|
wxString upperTxt;
|
|
|
|
wxString lowerTxt;
|
|
|
|
wxString msg;
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2009-09-27 11:00:21 +00:00
|
|
|
bool saveok = true;
|
2007-10-22 20:40:18 +00:00
|
|
|
FILE* dest;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( aFileName == wxEmptyString )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileDialog dlg( this, _( "Save Board File" ), wxEmptyString,
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->GetFileName(), PcbFileWildcard,
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2011-05-16 19:32:57 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->SetFileName( dlg.GetPath() );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
else
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
|
|
|
GetScreen()->SetFileName( aFileName );
|
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2007-10-29 10:05:07 +00:00
|
|
|
/* If changes are made, update the board date */
|
2007-08-06 02:02:39 +00:00
|
|
|
if( GetScreen()->IsModify() )
|
|
|
|
{
|
|
|
|
GetScreen()->m_Date = GenDate();
|
|
|
|
}
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
pcbFileName = GetScreen()->GetFileName();
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( !IsWritable( pcbFileName ) )
|
|
|
|
return false;
|
|
|
|
|
2011-10-13 19:56:32 +00:00
|
|
|
if( aCreateBackupFile )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-10-13 19:56:32 +00:00
|
|
|
/* Get the backup file name */
|
|
|
|
backupFileName = pcbFileName;
|
2011-10-15 13:25:57 +00:00
|
|
|
backupFileName.SetExt( pcbBackupFileExtension );
|
2011-10-13 19:56:32 +00:00
|
|
|
|
|
|
|
/* If an old backup file exists, delete it. If an old board file exists, rename
|
|
|
|
* it to the backup file name
|
|
|
|
*/
|
|
|
|
if( pcbFileName.FileExists() )
|
|
|
|
{
|
|
|
|
// Remove the old file xxx.000 if it exists.
|
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
|
|
|
|
|
|
|
// Rename the "old" file" from xxx.brd to xxx.000
|
|
|
|
if( !wxRenameFile( pcbFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
msg = _( "Warning: unable to create backup file " ) + backupFileName.GetFullPath();
|
|
|
|
DisplayError( this, msg );
|
|
|
|
saveok = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-10-13 19:56:32 +00:00
|
|
|
backupFileName.Clear();
|
2009-09-22 12:27:57 +00:00
|
|
|
saveok = false;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-29 10:05:07 +00:00
|
|
|
/* Create the file */
|
2009-04-05 20:49:15 +00:00
|
|
|
dest = wxFopen( pcbFileName.GetFullPath(), wxT( "wt" ) );
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( dest == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Unable to create " ) + pcbFileName.GetFullPath();
|
2007-08-06 02:02:39 +00:00
|
|
|
DisplayError( this, msg );
|
2009-09-22 12:27:57 +00:00
|
|
|
saveok = false;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( dest )
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->SetFileName( pcbFileName.GetFullPath() );
|
2011-08-26 17:01:17 +00:00
|
|
|
UpdateTitle();
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
SavePcbFormatAscii( dest );
|
|
|
|
fclose( dest );
|
|
|
|
}
|
|
|
|
|
2007-10-29 10:05:07 +00:00
|
|
|
/* Display the file names: */
|
2007-08-06 02:02:39 +00:00
|
|
|
MsgPanel->EraseMsgBox();
|
|
|
|
|
|
|
|
if( saveok )
|
|
|
|
{
|
2011-10-13 19:56:32 +00:00
|
|
|
// Delete auto save file on successful save.
|
|
|
|
wxFileName autoSaveFileName = pcbFileName;
|
|
|
|
autoSaveFileName.SetName( wxT( "$" ) + pcbFileName.GetName() );
|
|
|
|
|
|
|
|
if( autoSaveFileName.FileExists() )
|
|
|
|
wxRemoveFile( autoSaveFileName.GetFullPath() );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
upperTxt = _( "Backup file: " ) + backupFileName.GetFullPath();
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( dest )
|
2007-10-22 20:40:18 +00:00
|
|
|
lowerTxt = _( "Wrote board file: " );
|
2007-08-06 02:02:39 +00:00
|
|
|
else
|
2007-10-22 20:40:18 +00:00
|
|
|
lowerTxt = _( "Failed to create " );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
lowerTxt += pcbFileName.GetFullPath();
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-04-28 14:06:14 +00:00
|
|
|
ClearMsgPanel();
|
|
|
|
AppendMsgPanel( upperTxt, lowerTxt, CYAN );
|
2008-04-18 13:28:56 +00:00
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
GetScreen()->ClrSave();
|
2007-08-06 02:02:39 +00:00
|
|
|
GetScreen()->ClrModify();
|
2009-09-22 12:27:57 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2011-10-13 19:56:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool PCB_EDIT_FRAME::doAutoSave()
|
|
|
|
{
|
|
|
|
wxFileName tmpFileName = GetScreen()->GetFileName();
|
|
|
|
wxFileName fn = tmpFileName;
|
|
|
|
|
|
|
|
// Auto save file name is the normal file name prepended with $.
|
|
|
|
fn.SetName( wxT( "$" ) + fn.GetName() );
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Creating auto save file <" + fn.GetFullPath() ) + wxT( ">" ) );
|
|
|
|
|
2011-10-13 19:56:32 +00:00
|
|
|
if( SavePcbFile( fn.GetFullPath(), NO_BACKUP_FILE ) )
|
|
|
|
{
|
2011-10-15 13:25:57 +00:00
|
|
|
GetScreen()->SetModify();
|
2011-10-13 19:56:32 +00:00
|
|
|
GetScreen()->SetFileName( tmpFileName.GetFullPath() );
|
|
|
|
UpdateTitle();
|
2011-10-15 13:25:57 +00:00
|
|
|
m_autoSaveState = false;
|
2011-10-13 19:56:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetScreen()->SetFileName( tmpFileName.GetFullPath() );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|