2011-10-15 13:25:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-05-07 18:32:06 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
|
2013-01-24 17:46:37 +00:00
|
|
|
* Copyright (C) 2013 CERN (www.cern.ch)
|
2013-05-07 18:32:06 +00:00
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-15 13:25:57 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2013-01-04 12:06:50 +00:00
|
|
|
#include <appl_wxstruct.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <libeditframe.h>
|
|
|
|
#include <sch_sheet.h>
|
2013-01-24 17:46:37 +00:00
|
|
|
#include <sch_component.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;
|
2013-02-13 17:18:23 +00:00
|
|
|
wxFileName schematicFileName;
|
2011-08-18 19:25:12 +00:00
|
|
|
FILE* f;
|
2013-02-13 17:18:23 +00:00
|
|
|
bool success;
|
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
|
|
|
|
2013-05-07 18:32:06 +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
|
|
|
|
2013-05-07 18:32:06 +00:00
|
|
|
// Construct the name of the file to be saved
|
2013-02-13 17:18:23 +00:00
|
|
|
schematicFileName = aScreen->GetFileName();
|
|
|
|
|
|
|
|
if( aSaveUnderNewName )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
2013-02-13 17:18:23 +00:00
|
|
|
wxFileDialog dlg( this, _( "Schematic Files" ), wxGetCwd(),
|
|
|
|
schematicFileName.GetFullName(), SchematicFileWildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
schematicFileName = dlg.GetPath();
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( schematicFileName.GetExt() != SchematicFileExtension )
|
|
|
|
schematicFileName.SetExt( SchematicFileExtension );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-28 20:30:50 +00:00
|
|
|
// Sheet file names are relative to the root sheet path which is the current
|
2013-05-07 18:32:06 +00:00
|
|
|
// working directory. The IsWritable function expects the path to be set.
|
2011-10-28 20:30:50 +00:00
|
|
|
if( schematicFileName.GetPath().IsEmpty() )
|
2013-05-07 18:32:06 +00:00
|
|
|
schematicFileName.Assign( wxFileName::GetCwd(),
|
|
|
|
schematicFileName.GetFullName() );
|
2012-09-28 17:47:41 +00:00
|
|
|
}
|
2011-08-18 19:25:12 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( !IsWritable( schematicFileName ) )
|
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
/* Create backup if requested */
|
|
|
|
if( aCreateBackupFile && schematicFileName.FileExists() )
|
|
|
|
{
|
|
|
|
wxFileName backupFileName = schematicFileName;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
/* Rename the old file to a '.bak' one: */
|
|
|
|
backupFileName.SetExt( SchematicBackupFileExtension );
|
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Could not save backup of file <%s>" ),
|
|
|
|
GetChars( schematicFileName.GetFullPath() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
/* Save */
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
success = aScreen->Save( f );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
if( success )
|
2011-08-18 19:25:12 +00:00
|
|
|
{
|
2013-02-13 17:18:23 +00:00
|
|
|
// Delete auto save file.
|
2011-10-15 13:25:57 +00:00
|
|
|
wxFileName autoSaveFileName = schematicFileName;
|
|
|
|
autoSaveFileName.SetName( wxT( "$" ) + schematicFileName.GetName() );
|
|
|
|
|
|
|
|
if( autoSaveFileName.FileExists() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceAutoSave,
|
|
|
|
wxT( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
|
|
|
|
wxT( ">" ) );
|
|
|
|
|
|
|
|
wxRemoveFile( autoSaveFileName.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
2013-02-13 17:18:23 +00:00
|
|
|
// Update the screen and frame info.
|
|
|
|
if( aSaveUnderNewName )
|
|
|
|
aScreen->SetFileName( schematicFileName.GetFullPath() );
|
2011-10-15 13:25:57 +00:00
|
|
|
aScreen->ClrSave();
|
2011-08-18 19:25:12 +00:00
|
|
|
aScreen->ClrModify();
|
2013-02-13 17:18:23 +00:00
|
|
|
|
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
|
|
|
}
|
2013-02-13 17:18:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "File write operation failed." ) );
|
|
|
|
}
|
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:
|
2013-01-21 19:58:02 +00:00
|
|
|
if( SaveEEFile( NULL, true ) )
|
|
|
|
{
|
2013-05-07 18:32:06 +00:00
|
|
|
CreateArchiveLibraryCacheFile( true );
|
2013-01-21 19:58:02 +00:00
|
|
|
}
|
2007-09-30 02:37:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-01 07:58:49 +00:00
|
|
|
|
|
|
|
UpdateTitle();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-24 17:46:37 +00:00
|
|
|
bool SCH_EDIT_FRAME::LoadCacheLibrary( const wxString& aFilename )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
bool LibCacheExist = false;
|
|
|
|
wxFileName fn = aFilename;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
* so if the <name>-cache.lib is not found, the old way will be tried
|
|
|
|
*/
|
|
|
|
bool use_oldcachename = false;
|
|
|
|
wxString cachename = fn.GetName() + wxT( "-cache" );
|
|
|
|
|
|
|
|
fn.SetName( cachename );
|
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
|
|
|
|
|
|
|
if( ! fn.FileExists() )
|
|
|
|
{
|
|
|
|
fn = aFilename;
|
|
|
|
fn.SetExt( wxT( "cache.lib" ) );
|
|
|
|
use_oldcachename = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fn.FileExists() )
|
|
|
|
{
|
|
|
|
wxString errMsg;
|
|
|
|
|
|
|
|
wxLogDebug( wxT( "Load schematic cache library file <%s>" ),
|
|
|
|
GetChars( fn.GetFullPath() ) );
|
|
|
|
msg = wxT( "Load " ) + fn.GetFullPath();
|
|
|
|
|
|
|
|
CMP_LIBRARY* LibCache = CMP_LIBRARY::LoadLibrary( fn, errMsg );
|
|
|
|
|
|
|
|
if( LibCache )
|
|
|
|
{
|
|
|
|
LibCache->SetCache();
|
|
|
|
msg += wxT( " OK" );
|
|
|
|
|
|
|
|
if ( use_oldcachename ) // set the new name
|
|
|
|
{
|
|
|
|
fn.SetName( cachename );
|
|
|
|
fn.SetExt( SchematicLibraryFileExtension );
|
|
|
|
LibCache->SetFileName( fn );
|
|
|
|
}
|
|
|
|
|
|
|
|
LibCacheExist = true;
|
|
|
|
CMP_LIBRARY::GetLibraryList().push_back( LibCache );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString prompt;
|
|
|
|
|
|
|
|
prompt.Printf( _( "Component library <%s> failed to load.\nError: %s" ),
|
|
|
|
GetChars( fn.GetFullPath() ),
|
|
|
|
GetChars( errMsg ) );
|
|
|
|
DisplayError( this, prompt );
|
|
|
|
msg += _( " ->Error" );
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintMsg( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return LibCacheExist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2013-01-04 12:06:50 +00:00
|
|
|
if( !wxGetApp().LockFile( FullFileName ) )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "This file is already open." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the screen before open a new file
|
|
|
|
if( g_RootSheet )
|
|
|
|
{
|
2013-04-28 14:28:13 +00:00
|
|
|
delete g_RootSheet;
|
|
|
|
g_RootSheet = NULL;
|
2013-01-04 12:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateScreens();
|
|
|
|
screen = GetScreen();
|
|
|
|
|
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.
|
2013-04-09 17:49:01 +00:00
|
|
|
msg.Printf( _( "Ready\nWorking dir: <%s>\n" ), GetChars( wxGetCwd() ) );
|
2008-03-20 01:50:21 +00:00
|
|
|
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
|
|
|
|
2013-01-24 17:46:37 +00:00
|
|
|
LibCacheExist = LoadCacheLibrary( g_RootSheet->GetScreen()->GetFileName() );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2013-01-24 17:46:37 +00:00
|
|
|
bool SCH_EDIT_FRAME::AppendOneEEProject()
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
wxString FullFileName;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
screen = GetScreen();
|
|
|
|
|
|
|
|
if( !screen )
|
|
|
|
{
|
|
|
|
wxLogError( wxT("Document not ready, cannot import") );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// open file chooser dialog
|
|
|
|
wxFileDialog dlg( this, _( "Import Schematic" ), wxGetCwd(),
|
|
|
|
wxEmptyString, SchematicFileWildcard,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FullFileName = dlg.GetPath();
|
|
|
|
|
|
|
|
wxFileName fn = FullFileName;
|
|
|
|
|
|
|
|
if( fn.IsRelative() )
|
|
|
|
{
|
|
|
|
fn.MakeAbsolute();
|
|
|
|
FullFileName = fn.GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadCacheLibrary( FullFileName );
|
|
|
|
|
|
|
|
wxLogDebug( wxT( "Importing schematic " ) + FullFileName );
|
|
|
|
|
|
|
|
// load the project
|
|
|
|
bool success = LoadOneEEFile( screen, FullFileName, true );
|
|
|
|
if( success )
|
|
|
|
{
|
|
|
|
// load sub-sheets
|
|
|
|
EDA_ITEM* bs = screen->GetDrawItems();
|
|
|
|
while( bs )
|
|
|
|
{
|
|
|
|
// do not append hierarchical sheets
|
|
|
|
if( bs->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
screen->Remove( (SCH_SHEET*) bs );
|
|
|
|
}
|
|
|
|
// clear annotation and init new time stamp for the new components
|
|
|
|
else if( bs->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
( (SCH_COMPONENT*) bs )->SetTimeStamp( GetNewTimeStamp() );
|
|
|
|
( (SCH_COMPONENT*) bs )->ClearAnnotation( NULL );
|
|
|
|
// Clear flags, which are set by these previous modifications:
|
|
|
|
bs->ClearFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
bs = bs->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// redraw base screen (ROOT) if necessary
|
|
|
|
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
SetSheetNumberAndCount();
|
|
|
|
m_canvas->Refresh( true );
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::OnAppendProject( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString msg = _( "This operation cannot be undone. "
|
|
|
|
"Besides, take into account that hierarchical sheets will not be appended.\n\n"
|
|
|
|
"Do you want to save the current document before proceeding?" );
|
|
|
|
|
|
|
|
if( IsOK( this, msg ) )
|
|
|
|
OnSaveProject( event );
|
|
|
|
|
|
|
|
AppendOneEEProject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2013-05-07 18:32:06 +00:00
|
|
|
|
|
|
|
// Ensure a path exists. if no path, assume the cwd is used
|
|
|
|
// The IsWritable function expects the path to be set
|
|
|
|
if( !fn.GetPath().IsEmpty() )
|
|
|
|
tmp.AssignDir( fn.GetPath() );
|
|
|
|
else
|
|
|
|
tmp.AssignDir( wxGetCwd() );
|
2011-08-18 19:25:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-01-21 19:58:02 +00:00
|
|
|
CreateArchiveLibraryCacheFile();
|
2013-02-01 07:58:49 +00:00
|
|
|
|
|
|
|
UpdateTitle();
|
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;
|
|
|
|
}
|