2011-10-15 13:25:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.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-10-17 20:01:27 +00:00
|
|
|
* @file eeschema/files-io.cpp
|
2011-10-15 13:25:57 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <libeditframe.h>
|
|
|
|
#include <sch_sheet.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName, bool aCreateBackupFile )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
wxFileName schematicFileName, backupFileName;
|
2011-08-18 19:25:12 +00:00
|
|
|
FILE* f;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
if( aScreen == NULL )
|
|
|
|
aScreen = GetScreen();
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
/* If no name exists in the window yet - save as new. */
|
2011-08-18 19:25:12 +00:00
|
|
|
if( aScreen->GetFileName().IsEmpty() )
|
2012-09-28 17:47:41 +00:00
|
|
|
aSaveUnderNewName = true;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
if( aSaveUnderNewName == false )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2011-08-18 19:25:12 +00:00
|
|
|
schematicFileName = aScreen->GetFileName();
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2011-10-28 20:30:50 +00:00
|
|
|
// Sheet file names are relative to the root sheet path which is the current
|
|
|
|
// working directory. The IsWritable funtion expects the path to be set.
|
|
|
|
if( schematicFileName.GetPath().IsEmpty() )
|
|
|
|
schematicFileName.Assign( wxFileName::GetCwd(), schematicFileName.GetFullName() );
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
if( aCreateBackupFile )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2011-10-15 13:25:57 +00:00
|
|
|
backupFileName = schematicFileName;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
if( !IsWritable( schematicFileName ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Rename the old file to a '.bak' one: */
|
|
|
|
if( schematicFileName.FileExists() )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2012-09-28 17:47:41 +00:00
|
|
|
backupFileName.SetExt( SchematicBackupFileExtension );
|
2011-12-22 08:07:50 +00:00
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
2011-10-15 13:25:57 +00:00
|
|
|
|
|
|
|
if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
|
|
|
{
|
2011-10-28 20:30:50 +00:00
|
|
|
msg.Printf( _( "Could not save backup of file <%s>" ),
|
2011-10-16 08:02:36 +00:00
|
|
|
GetChars( schematicFileName.GetFullPath() ) );
|
|
|
|
DisplayError( this, msg );
|
2011-10-15 13:25:57 +00:00
|
|
|
}
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 17:47:41 +00:00
|
|
|
}
|
|
|
|
else
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2011-08-18 19:25:12 +00:00
|
|
|
schematicFileName = aScreen->GetFileName();
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
wxFileDialog dlg( this, _( "Schematic Files" ), wxGetCwd(),
|
2011-08-18 19:25:12 +00:00
|
|
|
schematicFileName.GetFullName(), SchematicFileWildcard,
|
2010-10-26 20:25:48 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
aScreen->SetFileName( dlg.GetPath() );
|
2010-10-26 20:25:48 +00:00
|
|
|
schematicFileName = dlg.GetPath();
|
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
if( !IsWritable( schematicFileName ) )
|
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 13:25:57 +00:00
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) );
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
if( ( f = wxFopen( schematicFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL )
|
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Failed to create file <%s>" ),
|
|
|
|
GetChars( schematicFileName.GetFullPath() ) );
|
2010-10-26 20:25:48 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
if( aSaveUnderNewName )
|
2011-08-18 19:25:12 +00:00
|
|
|
aScreen->SetFileName( schematicFileName.GetFullPath() );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
bool success = aScreen->Save( f );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
if( !success )
|
2011-08-18 19:25:12 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
DisplayError( this, _( "File write operation failed." ) );
|
2011-08-18 19:25:12 +00:00
|
|
|
}
|
2010-10-26 20:25:48 +00:00
|
|
|
else
|
2011-02-17 18:34:27 +00:00
|
|
|
{
|
2011-10-15 13:25:57 +00:00
|
|
|
// Delete auto save file on successful save.
|
|
|
|
wxFileName autoSaveFileName = schematicFileName;
|
|
|
|
autoSaveFileName.SetName( wxT( "$" ) + schematicFileName.GetName() );
|
|
|
|
|
|
|
|
if( autoSaveFileName.FileExists() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
|
|
|
|
wxT( ">" ) );
|
|
|
|
|
|
|
|
wxRemoveFile( autoSaveFileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
aScreen->ClrSave();
|
2011-08-18 19:25:12 +00:00
|
|
|
aScreen->ClrModify();
|
2011-02-17 18:34:27 +00:00
|
|
|
wxString msg;
|
2011-08-18 19:25:12 +00:00
|
|
|
msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) );
|
|
|
|
SetStatusText( msg, 0 );
|
2011-02-17 18:34:27 +00:00
|
|
|
}
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
fclose( f );
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::Save_File( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-30 02:37:06 +00:00
|
|
|
int id = event.GetId();
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2012-09-28 17:47:41 +00:00
|
|
|
case ID_UPDATE_ONE_SHEET:
|
|
|
|
SaveEEFile( NULL );
|
2007-09-30 02:37:06 +00:00
|
|
|
break;
|
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
case ID_SAVE_ONE_SHEET_UNDER_NEW_NAME:
|
|
|
|
SaveEEFile( NULL, true );
|
2007-09-30 02:37:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* screen;
|
|
|
|
wxString FullFileName, msg;
|
|
|
|
bool LibCacheExist = false;
|
|
|
|
SCH_SCREENS ScreenList;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-04-06 14:09:52 +00:00
|
|
|
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
|
|
|
if( screen->IsModify() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( screen )
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
if( !IsOK( this, _( "Discard changes to the current schematic?" ) ) )
|
2010-05-17 20:35:46 +00:00
|
|
|
return false;
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
FullFileName = aFileName;
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
if( ( FullFileName.IsEmpty() ) && !aIsNew )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2009-04-08 18:20:27 +00:00
|
|
|
wxFileDialog dlg( this, _( "Open Schematic" ), wxGetCwd(),
|
2009-04-06 18:54:57 +00:00
|
|
|
wxEmptyString, SchematicFileWildcard,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2010-05-17 20:35:46 +00:00
|
|
|
return false;
|
2009-04-06 18:54:57 +00:00
|
|
|
|
|
|
|
FullFileName = dlg.GetPath();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2009-04-06 18:54:57 +00:00
|
|
|
|
2008-07-18 07:04:43 +00:00
|
|
|
if( g_RootSheet )
|
|
|
|
{
|
|
|
|
SAFE_DELETE( g_RootSheet );
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
CreateScreens();
|
2010-12-10 19:47:44 +00:00
|
|
|
screen = GetScreen();
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
wxFileName fn = FullFileName;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( fn.IsRelative() )
|
|
|
|
{
|
|
|
|
fn.MakeAbsolute();
|
|
|
|
FullFileName = fn.GetFullPath();
|
|
|
|
}
|
2011-08-18 19:25:12 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
wxLogDebug( wxT( "Loading schematic " ) + FullFileName );
|
|
|
|
wxSetWorkingDirectory( fn.GetPath() );
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
screen->SetFileName( FullFileName );
|
2008-07-18 07:04:43 +00:00
|
|
|
g_RootSheet->SetFileName( FullFileName );
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( wxEmptyString );
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-02-23 20:18:27 +00:00
|
|
|
screen->ClrModify();
|
2008-07-18 07:04:43 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
if( aIsNew )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2012-01-05 08:07:11 +00:00
|
|
|
/* SCH_SCREEN constructor does this now
|
|
|
|
screen->SetPageSettings( PAGE_INFO( wxT( "A4" ) ) );
|
|
|
|
*/
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
screen->SetZoom( 32 );
|
2009-10-14 19:43:31 +00:00
|
|
|
screen->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
2012-01-09 08:35:06 +00:00
|
|
|
|
|
|
|
TITLE_BLOCK tb;
|
|
|
|
wxString title;
|
|
|
|
|
|
|
|
title += NAMELESS_PROJECT;
|
|
|
|
title += wxT( ".sch" );
|
|
|
|
tb.SetTitle( title );
|
|
|
|
screen->SetTitleBlock( tb );
|
|
|
|
|
|
|
|
GetScreen()->SetFileName( title );
|
|
|
|
|
2011-03-01 18:45:21 +00:00
|
|
|
LoadProjectFile( wxEmptyString, true );
|
|
|
|
Zoom_Automatique( false );
|
2008-04-30 17:04:22 +00:00
|
|
|
SetSheetNumberAndCount();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2010-05-17 20:35:46 +00:00
|
|
|
return true;
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Reloading configuration.
|
2008-03-20 01:50:21 +00:00
|
|
|
msg = _( "Ready\nWorking dir: \n" ) + wxGetCwd();
|
|
|
|
PrintMsg( msg );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2011-03-01 18:45:21 +00:00
|
|
|
LoadProjectFile( wxEmptyString, false );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2009-12-22 20:08:56 +00:00
|
|
|
// Clear (if needed) the current active library in libedit because it could be
|
|
|
|
// removed from memory
|
2010-11-19 16:28:46 +00:00
|
|
|
LIB_EDIT_FRAME::EnsureActiveLibExists();
|
2009-12-22 20:08:56 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
// Delete old caches.
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY::RemoveCacheLibrary();
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-04-11 15:50:31 +00:00
|
|
|
/* Loading the project library cache
|
|
|
|
* until apr 2009 the lib is named <root_name>.cache.lib
|
|
|
|
* and after (due to code change): <root_name>-cache.lib
|
2009-11-04 20:46:53 +00:00
|
|
|
* so if the <name>-cache.lib is not found, the old way will be tried
|
2011-08-18 19:25:12 +00:00
|
|
|
*/
|
2011-01-20 16:34:57 +00:00
|
|
|
fn = g_RootSheet->GetScreen()->GetFileName();
|
2010-04-06 14:09:52 +00:00
|
|
|
|
|
|
|
bool use_oldcachename = false;
|
2010-05-17 20:35:46 +00:00
|
|
|
wxString cachename = fn.GetName() + wxT( "-cache" );
|
2010-04-06 14:09:52 +00:00
|
|
|
|
2009-04-11 15:50:31 +00:00
|
|
|
fn.SetName( cachename );
|
2012-09-28 17:47:41 +00:00
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2009-04-11 15:50:31 +00:00
|
|
|
if( ! fn.FileExists() )
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
fn = g_RootSheet->GetScreen()->GetFileName();
|
2009-04-11 15:50:31 +00:00
|
|
|
fn.SetExt( wxT( "cache.lib" ) );
|
|
|
|
use_oldcachename = true;
|
|
|
|
}
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fn.FileExists() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString errMsg;
|
|
|
|
|
2010-02-15 14:24:52 +00:00
|
|
|
wxLogDebug( wxT( "LoadOneEEProject() load schematic cache library file <%s>" ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = wxT( "Load " ) + fn.GetFullPath();
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
CMP_LIBRARY* LibCache = CMP_LIBRARY::LoadLibrary( fn, errMsg );
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
if( LibCache )
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
LibCache->SetCache();
|
2008-03-20 01:50:21 +00:00
|
|
|
msg += wxT( " OK" );
|
2011-08-18 19:25:12 +00:00
|
|
|
|
2009-04-11 15:50:31 +00:00
|
|
|
if ( use_oldcachename ) // set the new name
|
|
|
|
{
|
2010-05-17 20:35:46 +00:00
|
|
|
fn.SetName( cachename );
|
2012-09-28 17:47:41 +00:00
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
2009-09-18 14:56:05 +00:00
|
|
|
LibCache->SetFileName( fn );
|
2009-04-11 15:50:31 +00:00
|
|
|
}
|
2009-09-18 14:56:05 +00:00
|
|
|
|
|
|
|
LibCacheExist = true;
|
|
|
|
CMP_LIBRARY::GetLibraryList().push_back( LibCache );
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
|
|
|
wxString prompt;
|
|
|
|
|
2010-11-01 18:33:44 +00:00
|
|
|
prompt.Printf( _( "Component library <%s> failed to load.\nError: %s" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( fn.GetFullPath() ),
|
|
|
|
GetChars( errMsg ) );
|
2009-09-18 14:56:05 +00:00
|
|
|
DisplayError( this, prompt );
|
2010-06-19 10:58:50 +00:00
|
|
|
msg += _( " ->Error" );
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
PrintMsg( msg );
|
|
|
|
}
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( !wxFileExists( g_RootSheet->GetScreen()->GetFileName() ) && !LibCacheExist )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2008-10-01 17:34:55 +00:00
|
|
|
msg.Printf( _( "File <%s> not found." ),
|
2011-01-20 16:34:57 +00:00
|
|
|
GetChars( g_RootSheet->GetScreen()->GetFileName() ) );
|
2011-10-15 13:25:57 +00:00
|
|
|
DisplayInfoMessage( this, msg );
|
2010-05-17 20:35:46 +00:00
|
|
|
return false;
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// load the project.
|
2011-01-20 16:34:57 +00:00
|
|
|
g_RootSheet->SetScreen( NULL );
|
2008-07-18 07:04:43 +00:00
|
|
|
bool diag = g_RootSheet->Load( this );
|
2011-02-05 16:11:24 +00:00
|
|
|
SetScreen( m_CurrentSheet->LastScreen() );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2011-04-17 17:11:53 +00:00
|
|
|
UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() );
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Redraw base screen (ROOT) if necessary. */
|
2010-05-17 20:35:46 +00:00
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2008-04-30 17:04:22 +00:00
|
|
|
SetSheetNumberAndCount();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh( true );
|
2008-03-20 01:50:21 +00:00
|
|
|
return diag;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-07-18 07:04:43 +00:00
|
|
|
|
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* screen;
|
|
|
|
wxFileName fn;
|
2011-08-18 19:25:12 +00:00
|
|
|
wxFileName tmp;
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREENS ScreenList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
fn = g_RootSheet->GetFileName();
|
|
|
|
tmp.AssignDir( fn.GetPath() );
|
|
|
|
|
|
|
|
if( !IsWritable( tmp ) )
|
|
|
|
return;
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
|
2012-09-28 17:47:41 +00:00
|
|
|
SaveEEFile( screen );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-08-18 19:25:12 +00:00
|
|
|
wxString cachename = fn.GetName() + wxT( "-cache" );
|
2009-04-11 15:50:31 +00:00
|
|
|
fn.SetName( cachename );
|
2012-09-28 17:47:41 +00:00
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
2011-11-11 20:10:24 +00:00
|
|
|
CreateArchiveLibrary( fn.GetFullPath() );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2011-10-15 13:25:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::doAutoSave()
|
|
|
|
{
|
|
|
|
wxFileName tmpFileName = g_RootSheet->GetFileName();
|
|
|
|
wxFileName fn = tmpFileName;
|
|
|
|
wxFileName tmp;
|
|
|
|
SCH_SCREENS screens;
|
|
|
|
bool autoSaveOk = true;
|
|
|
|
|
|
|
|
tmp.AssignDir( fn.GetPath() );
|
|
|
|
|
|
|
|
if( !IsWritable( tmp ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
|
|
|
|
{
|
|
|
|
// Only create auto save files for the schematics that have been modified.
|
|
|
|
if( !screen->IsSave() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmpFileName = fn = screen->GetFileName();
|
|
|
|
|
|
|
|
// Auto save file name is the normal file name prefixed with $.
|
|
|
|
fn.SetName( wxT( "$" ) + fn.GetName() );
|
|
|
|
|
|
|
|
screen->SetFileName( fn.GetFullPath() );
|
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
if( SaveEEFile( screen, false, NO_BACKUP_FILE ) )
|
2011-10-15 13:25:57 +00:00
|
|
|
screen->SetModify();
|
|
|
|
else
|
|
|
|
autoSaveOk = false;
|
|
|
|
|
|
|
|
screen->SetFileName( tmpFileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( autoSaveOk )
|
|
|
|
m_autoSaveState = false;
|
|
|
|
|
|
|
|
return autoSaveOk;
|
|
|
|
}
|