Commit 121b65bf authored by Wayne Stambaugh's avatar Wayne Stambaugh

More auto save improvements.

* Factor test for auto save file into base frame class.
* Added auto save feature to Eeschema for saving schematics, addresses
  launchpad question 173631.
* Add auto save interval control to Eeschema options dialog.
* Fix problem with subsequent auto saves in last commit.
parent 8e6ac6c5
/********************************************************/ /*
/* base_screen.cpp - BASE_SCREEN object implementation. */ * 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) 2009 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
*/
#ifdef __GNUG__ /**
#pragma implementation * @file base_screen.cpp
#endif * @brief BASE_SCREEN object implementation.
*/
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
...@@ -19,12 +41,11 @@ ...@@ -19,12 +41,11 @@
BASE_SCREEN::BASE_SCREEN( KICAD_T aType ) : EDA_ITEM( aType ) BASE_SCREEN::BASE_SCREEN( KICAD_T aType ) : EDA_ITEM( aType )
{ {
m_drawList = NULL; /* Draw items list */ m_drawList = NULL; /* Draw items list */
m_UndoRedoCountMax = 10; /* undo/Redo command Max depth, 10 is a m_UndoRedoCountMax = 10; /* undo/Redo command Max depth, 10 is a reasonable value */
* reasonable value */
m_FirstRedraw = TRUE; m_FirstRedraw = TRUE;
m_ScreenNumber = 1; m_ScreenNumber = 1;
m_NumberOfScreen = 1; /* Hierarchy: Root: ScreenNumber = 1 */ m_NumberOfScreen = 1; /* Hierarchy: Root: ScreenNumber = 1 */
m_Zoom = 32.0; m_Zoom = 32.0;
m_Grid.m_Size = wxRealPoint( 50, 50 ); /* Default grid size */ m_Grid.m_Size = wxRealPoint( 50, 50 ); /* Default grid size */
m_Grid.m_Id = ID_POPUP_GRID_LEVEL_50; m_Grid.m_Id = ID_POPUP_GRID_LEVEL_50;
m_Center = true; m_Center = true;
...@@ -61,8 +82,8 @@ void BASE_SCREEN::InitDatas() ...@@ -61,8 +82,8 @@ void BASE_SCREEN::InitDatas()
SetCurItem( NULL ); SetCurItem( NULL );
m_FlagModified = 0; // Set when any change is made on broad m_FlagModified = false; // Set when any change is made on broad.
m_FlagSave = 1; // Used in auto save: set when an auto save is made m_FlagSave = false; // Used in auto save set when an auto save is required.
} }
...@@ -450,8 +471,6 @@ void BASE_SCREEN::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGr ...@@ -450,8 +471,6 @@ void BASE_SCREEN::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGr
} }
/* free the undo and the redo lists
*/
void BASE_SCREEN::ClearUndoRedoList() void BASE_SCREEN::ClearUndoRedoList()
{ {
ClearUndoORRedoList( m_UndoList ); ClearUndoORRedoList( m_UndoList );
...@@ -459,9 +478,6 @@ void BASE_SCREEN::ClearUndoRedoList() ...@@ -459,9 +478,6 @@ void BASE_SCREEN::ClearUndoRedoList()
} }
/* Put aNewitem in top of undo list
* Deletes old items if > count max.
*/
void BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem ) void BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem )
{ {
m_UndoList.PushCommand( aNewitem ); m_UndoList.PushCommand( aNewitem );
...@@ -515,13 +531,7 @@ void BASE_SCREEN::InsertItem( EDA_ITEMS::iterator aIter, EDA_ITEM* aItem ) ...@@ -515,13 +531,7 @@ void BASE_SCREEN::InsertItem( EDA_ITEMS::iterator aIter, EDA_ITEM* aItem )
#if defined(DEBUG) #if defined(DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void BASE_SCREEN::Show( int nestLevel, std::ostream& os ) void BASE_SCREEN::Show( int nestLevel, std::ostream& os )
{ {
EDA_ITEM* item = m_drawList; EDA_ITEM* item = m_drawList;
...@@ -536,4 +546,5 @@ void BASE_SCREEN::Show( int nestLevel, std::ostream& os ) ...@@ -536,4 +546,5 @@ void BASE_SCREEN::Show( int nestLevel, std::ostream& os )
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n"; NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
} }
#endif #endif
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
#define DEFAULT_AUTO_SAVE_INTERVAL 600 #define DEFAULT_AUTO_SAVE_INTERVAL 600
const wxChar* traceAutoSave = wxT( "KicadAutoSave" );
/// Configuration file entry name for auto save interval.
static const wxChar* entryAutoSaveInterval = wxT( "AutoSaveInterval" ); static const wxChar* entryAutoSaveInterval = wxT( "AutoSaveInterval" );
...@@ -116,15 +119,17 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent ) ...@@ -116,15 +119,17 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
if( !wxFrame::ProcessEvent( aEvent ) ) if( !wxFrame::ProcessEvent( aEvent ) )
return false; return false;
if( m_hasAutoSave && (m_autoSaveState != isModified()) && (m_autoSaveInterval > 0) ) if( m_hasAutoSave && (m_autoSaveState != isAutoSaveRequired()) && (m_autoSaveInterval > 0) )
{ {
if( !m_autoSaveState ) if( !m_autoSaveState )
{ {
wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT ); m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
m_autoSaveState = true; m_autoSaveState = true;
} }
else else if( m_autoSaveTimer->IsRunning() )
{ {
wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
m_autoSaveTimer->Stop(); m_autoSaveTimer->Stop();
m_autoSaveState = false; m_autoSaveState = false;
} }
...@@ -569,3 +574,70 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName ) ...@@ -569,3 +574,70 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName )
return true; return true;
} }
void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName,
const wxString& aBackupFileExtension )
{
wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
wxCHECK_RET( !aBackupFileExtension.IsEmpty(), wxT( "Invalid backup file extension!" ) );
wxFileName autoSaveFileName = aFileName;
// Check for auto save file.
autoSaveFileName.SetName( wxT( "$" ) + aFileName.GetName() );
wxLogTrace( traceAutoSave,
wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
if( !autoSaveFileName.FileExists() )
return;
wxString msg;
msg.Printf( _( "Well this is potentially embarrassing! It appears that the last time \
you were editing the file <%s> it was not saved properly. Do you wish to restore the last \
edits you made?" ),
GetChars( aFileName.GetFullName() ) );
int response = wxMessageBox( msg, wxGetApp().GetAppName(), wxYES_NO | wxICON_QUESTION, this );
// Make a backup of the current file, delete the file, and rename the auto save file to
// the file name.
if( response == wxYES )
{
// Get the backup file name.
wxFileName backupFileName = aFileName;
backupFileName.SetExt( aBackupFileExtension );
// If an old backup file exists, delete it. If an old copy of the file exists, rename
// it to the backup file name
if( aFileName.FileExists() )
{
// Remove the old file backup file.
if( backupFileName.FileExists() )
wxRemoveFile( backupFileName.GetFullPath() );
// Rename the old file to the backup file name.
if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
msg = _( "Could not create backup file " ) + backupFileName.GetFullPath();
DisplayError( this, msg );
}
}
if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
{
wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
wxGetApp().GetAppName(), wxOK | wxICON_EXCLAMATION, this );
}
}
else
{
wxLogTrace( traceAutoSave,
wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
// Remove the auto save file when using the previous file as is.
wxRemoveFile( autoSaveFileName.GetFullPath() );
}
}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 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
*/
/**
* @file dialog_eeschema_options.cpp
*/
#include "fctsys.h" #include "fctsys.h"
#include "class_base_screen.h" #include "class_base_screen.h"
......
#ifndef __dialog_eeschema_options__ /*
#define __dialog_eeschema_options__ * This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 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
*/
/** /**
* @file * @file dialog_eeschema_options.h
*
* Subclass of DIALOG_EESCHEMA_OPTIONS_BASE, which is generated by wxFormBuilder. * Subclass of DIALOG_EESCHEMA_OPTIONS_BASE, which is generated by wxFormBuilder.
*/ */
#ifndef __dialog_eeschema_options__
#define __dialog_eeschema_options__
#include "dialog_eeschema_options_base.h" #include "dialog_eeschema_options_base.h"
class DIALOG_EESCHEMA_OPTIONS : public DIALOG_EESCHEMA_OPTIONS_BASE class DIALOG_EESCHEMA_OPTIONS : public DIALOG_EESCHEMA_OPTIONS_BASE
...@@ -56,6 +81,9 @@ public: ...@@ -56,6 +81,9 @@ public:
} }
int GetRepeatLabel( void ) { return m_spinRepeatLabel->GetValue(); } int GetRepeatLabel( void ) { return m_spinRepeatLabel->GetValue(); }
void SetAutoSaveInterval( int aInterval ) { m_spinAutoSaveInterval->SetValue( aInterval ); }
int GetAutoSaveInterval() const { return m_spinAutoSaveInterval->GetValue(); }
void SetShowGrid( bool show ) { m_checkShowGrid->SetValue( show ); } void SetShowGrid( bool show ) { m_checkShowGrid->SetValue( show ); }
bool GetShowGrid( void ) { return m_checkShowGrid->GetValue(); } bool GetShowGrid( void ) { return m_checkShowGrid->GetValue(); }
......
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Nov 17 2010) // C++ code generated with wxFormBuilder (version Sep 8 2010)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
...@@ -16,7 +16,6 @@ END_EVENT_TABLE() ...@@ -16,7 +16,6 @@ END_EVENT_TABLE()
DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{ {
this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetSizeHints( wxDefaultSize, wxDefaultSize );
this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
wxBoxSizer* mainSizer; wxBoxSizer* mainSizer;
mainSizer = new wxBoxSizer( wxVERTICAL ); mainSizer = new wxBoxSizer( wxVERTICAL );
...@@ -25,9 +24,9 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx ...@@ -25,9 +24,9 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx
bOptionsSizer = new wxBoxSizer( wxVERTICAL ); bOptionsSizer = new wxBoxSizer( wxVERTICAL );
m_notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_panel1 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_notebook1->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
m_panel1->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
m_panel1 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* p1mainSizer; wxBoxSizer* p1mainSizer;
p1mainSizer = new wxBoxSizer( wxHORIZONTAL ); p1mainSizer = new wxBoxSizer( wxHORIZONTAL );
...@@ -35,7 +34,7 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx ...@@ -35,7 +34,7 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx
bSizer3 = new wxBoxSizer( wxVERTICAL ); bSizer3 = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizer1; wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 7, 3, 0, 0 ); fgSizer1 = new wxFlexGridSizer( 8, 3, 0, 0 );
fgSizer1->AddGrowableCol( 0 ); fgSizer1->AddGrowableCol( 0 );
fgSizer1->AddGrowableCol( 1 ); fgSizer1->AddGrowableCol( 1 );
fgSizer1->AddGrowableCol( 2 ); fgSizer1->AddGrowableCol( 2 );
...@@ -121,6 +120,17 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx ...@@ -121,6 +120,17 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx
fgSizer1->Add( 0, 0, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 ); fgSizer1->Add( 0, 0, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 3 );
m_staticText221 = new wxStaticText( m_panel1, wxID_ANY, _("Auto save time interval:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText221->Wrap( -1 );
fgSizer1->Add( m_staticText221, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_spinAutoSaveInterval = new wxSpinCtrl( m_panel1, ID_M_SPINAUTOSAVEINTERVAL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 1000, 10 );
fgSizer1->Add( m_spinAutoSaveInterval, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 3 );
m_staticText23 = new wxStaticText( m_panel1, wxID_ANY, _("minutes"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText23->Wrap( -1 );
fgSizer1->Add( m_staticText23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
bSizer3->Add( fgSizer1, 0, wxALIGN_CENTER|wxEXPAND, 0 ); bSizer3->Add( fgSizer1, 0, wxALIGN_CENTER|wxEXPAND, 0 );
wxBoxSizer* bSizer2; wxBoxSizer* bSizer2;
...@@ -153,7 +163,6 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx ...@@ -153,7 +163,6 @@ DIALOG_EESCHEMA_OPTIONS_BASE::DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wx
p1mainSizer->Fit( m_panel1 ); p1mainSizer->Fit( m_panel1 );
m_notebook1->AddPage( m_panel1, _("General Options"), true ); m_notebook1->AddPage( m_panel1, _("General Options"), true );
m_panel2 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_panel2 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_panel2->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
m_panel2->SetToolTip( _("User defined field names for schematic components. ") ); m_panel2->SetToolTip( _("User defined field names for schematic components. ") );
wxBoxSizer* bSizer6; wxBoxSizer* bSizer6;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Nov 17 2010) // C++ code generated with wxFormBuilder (version Sep 8 2010)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
...@@ -44,6 +44,11 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog ...@@ -44,6 +44,11 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog
protected: protected:
enum
{
ID_M_SPINAUTOSAVEINTERVAL = 1000,
};
wxNotebook* m_notebook1; wxNotebook* m_notebook1;
wxPanel* m_panel1; wxPanel* m_panel1;
wxStaticText* m_staticText2; wxStaticText* m_staticText2;
...@@ -67,6 +72,9 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog ...@@ -67,6 +72,9 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog
wxStaticText* m_staticText16; wxStaticText* m_staticText16;
wxSpinCtrl* m_spinRepeatLabel; wxSpinCtrl* m_spinRepeatLabel;
wxStaticText* m_staticText221;
wxSpinCtrl* m_spinAutoSaveInterval;
wxStaticText* m_staticText23;
wxCheckBox* m_checkShowGrid; wxCheckBox* m_checkShowGrid;
wxCheckBox* m_checkShowHiddenPins; wxCheckBox* m_checkShowHiddenPins;
wxCheckBox* m_checkAutoPan; wxCheckBox* m_checkAutoPan;
...@@ -101,7 +109,7 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog ...@@ -101,7 +109,7 @@ class DIALOG_EESCHEMA_OPTIONS_BASE : public wxDialog
public: public:
DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Schematic Editor Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_EESCHEMA_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Schematic Editor Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EESCHEMA_OPTIONS_BASE(); ~DIALOG_EESCHEMA_OPTIONS_BASE();
}; };
......
...@@ -39,6 +39,7 @@ wxString g_NetCmpExtBuffer( wxT( "cmp" ) ); ...@@ -39,6 +39,7 @@ wxString g_NetCmpExtBuffer( wxT( "cmp" ) );
const wxString SymbolFileExtension( wxT( "sym" ) ); const wxString SymbolFileExtension( wxT( "sym" ) );
const wxString CompLibFileExtension( wxT( "lib" ) ); const wxString CompLibFileExtension( wxT( "lib" ) );
const wxString g_SchematicBackupFileExtension( wxT( "bak" ) );
const wxString SymbolFileWildcard( wxT( "KiCad drawing symbol file (*.sym)|*.sym" ) ); const wxString SymbolFileWildcard( wxT( "KiCad drawing symbol file (*.sym)|*.sym" ) );
const wxString CompLibFileWildcard( wxT( "KiCad component library file (*.lib)|*.lib" ) ); const wxString CompLibFileWildcard( wxT( "KiCad component library file (*.lib)|*.lib" ) );
......
...@@ -189,6 +189,7 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event ) ...@@ -189,6 +189,7 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event )
dlg.SetRepeatHorizontal( g_RepeatStep.x ); dlg.SetRepeatHorizontal( g_RepeatStep.x );
dlg.SetRepeatVertical( g_RepeatStep.y ); dlg.SetRepeatVertical( g_RepeatStep.y );
dlg.SetRepeatLabel( g_RepeatDeltaLabel ); dlg.SetRepeatLabel( g_RepeatDeltaLabel );
dlg.SetAutoSaveInterval( GetAutoSaveInterval() / 60 );
dlg.SetShowGrid( IsGridVisible() ); dlg.SetShowGrid( IsGridVisible() );
dlg.SetShowHiddenPins( m_ShowAllPins ); dlg.SetShowHiddenPins( m_ShowAllPins );
dlg.SetEnableAutoPan( DrawPanel->m_AutoPAN_Enable ); dlg.SetEnableAutoPan( DrawPanel->m_AutoPAN_Enable );
...@@ -219,6 +220,7 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event ) ...@@ -219,6 +220,7 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event )
g_RepeatStep.x = dlg.GetRepeatHorizontal(); g_RepeatStep.x = dlg.GetRepeatHorizontal();
g_RepeatStep.y = dlg.GetRepeatVertical(); g_RepeatStep.y = dlg.GetRepeatVertical();
g_RepeatDeltaLabel = dlg.GetRepeatLabel(); g_RepeatDeltaLabel = dlg.GetRepeatLabel();
SetAutoSaveInterval( dlg.GetAutoSaveInterval() * 60 );
SetGridVisibility( dlg.GetShowGrid() ); SetGridVisibility( dlg.GetShowGrid() );
m_ShowAllPins = dlg.GetShowHiddenPins(); m_ShowAllPins = dlg.GetShowHiddenPins();
DrawPanel->m_AutoPAN_Enable = dlg.GetEnableAutoPan(); DrawPanel->m_AutoPAN_Enable = dlg.GetEnableAutoPan();
......
/****************************/ /*
/* EESCHEMA - files-io.cpp */ * 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
*/
/**
* @file files-io.cpp
*/
#include "fctsys.h" #include "fctsys.h"
#include "class_drawpanel.h" #include "class_drawpanel.h"
...@@ -16,7 +41,7 @@ ...@@ -16,7 +41,7 @@
#include "sch_sheet.h" #include "sch_sheet.h"
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType ) bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType, bool aCreateBackupFile )
{ {
wxString msg; wxString msg;
wxFileName schematicFileName, backupFileName; wxFileName schematicFileName, backupFileName;
...@@ -33,23 +58,28 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType ) ...@@ -33,23 +58,28 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType )
{ {
case FILE_SAVE_AS: case FILE_SAVE_AS:
schematicFileName = aScreen->GetFileName(); schematicFileName = aScreen->GetFileName();
backupFileName = schematicFileName;
if( !IsWritable( schematicFileName ) ) if( aCreateBackupFile )
return false;
/* Rename the old file to a '.bak' one: */
if( schematicFileName.FileExists() )
{ {
backupFileName.SetExt( wxT( "bak" ) ); backupFileName = schematicFileName;
wxRemoveFile( backupFileName.GetFullPath() );
if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) ) if( !IsWritable( schematicFileName ) )
return false;
/* Rename the old file to a '.bak' one: */
if( schematicFileName.FileExists() )
{ {
DisplayError( this, _( "Could not save backup of file <" ) + backupFileName.SetExt( g_SchematicBackupFileExtension );
schematicFileName.GetFullPath() + wxT( ">." ) ); wxRemoveFile( backupFileName.GetFullPath() );
if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
DisplayError( this, _( "Could not save backup of file <" ) +
schematicFileName.GetFullPath() + wxT( ">." ) );
}
} }
} }
break; break;
case FILE_SAVE_NEW: case FILE_SAVE_NEW:
...@@ -76,6 +106,9 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType ) ...@@ -76,6 +106,9 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType )
break; break;
} }
wxLogTrace( traceAutoSave,
wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) );
if( ( f = wxFopen( schematicFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL ) if( ( f = wxFopen( schematicFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL )
{ {
msg = _( "Failed to create file " ) + schematicFileName.GetFullPath(); msg = _( "Failed to create file " ) + schematicFileName.GetFullPath();
...@@ -94,6 +127,20 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType ) ...@@ -94,6 +127,20 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType )
} }
else else
{ {
// 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();
aScreen->ClrModify(); aScreen->ClrModify();
wxString msg; wxString msg;
msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) ); msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) );
...@@ -284,7 +331,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew ) ...@@ -284,7 +331,7 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
Zoom_Automatique( false ); Zoom_Automatique( false );
msg.Printf( _( "File <%s> not found." ), msg.Printf( _( "File <%s> not found." ),
GetChars( g_RootSheet->GetScreen()->GetFileName() ) ); GetChars( g_RootSheet->GetScreen()->GetFileName() ) );
DisplayInfoMessage( this, msg, 0 ); DisplayInfoMessage( this, msg );
return false; return false;
} }
...@@ -319,7 +366,6 @@ void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent ) ...@@ -319,7 +366,6 @@ void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() ) for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
{ {
D( printf( "SaveEEFile, %s\n", TO_UTF8( screen->GetFileName() ) ); )
SaveEEFile( screen, FILE_SAVE_AS ); SaveEEFile( screen, FILE_SAVE_AS );
} }
...@@ -328,3 +374,48 @@ void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent ) ...@@ -328,3 +374,48 @@ void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent )
fn.SetExt( CompLibFileExtension ); fn.SetExt( CompLibFileExtension );
LibArchive( this, fn.GetFullPath() ); LibArchive( this, fn.GetFullPath() );
} }
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() );
if( SaveEEFile( screen, FILE_SAVE_AS, NO_BACKUP_FILE ) )
{
screen->SetModify();
}
else
{
autoSaveOk = false;
}
screen->SetFileName( tmpFileName.GetFullPath() );
}
if( autoSaveOk )
m_autoSaveState = false;
return autoSaveOk;
}
...@@ -138,6 +138,8 @@ extern const wxString SymbolFileWildcard; ...@@ -138,6 +138,8 @@ extern const wxString SymbolFileWildcard;
extern const wxString CompLibFileExtension; extern const wxString CompLibFileExtension;
extern const wxString CompLibFileWildcard; extern const wxString CompLibFileWildcard;
extern const wxString g_SchematicBackupFileExtension;
extern LayerStruct g_LayerDescr; extern LayerStruct g_LayerDescr;
extern bool g_EditPinByPinIsOn; /* True to prevent displacing extern bool g_EditPinByPinIsOn; /* True to prevent displacing
......
/*
* 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
*/
/** /**
* @file load_one_schematic_file.cpp * @file load_one_schematic_file.cpp
* @brief Code to load and save Eeschema files. * @brief Code to load and save Eeschema files.
...@@ -37,24 +62,29 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi ...@@ -37,24 +62,29 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
SCH_ITEM* item; SCH_ITEM* item;
wxString MsgDiag; // Error and log messages wxString MsgDiag; // Error and log messages
char* line; char* line;
wxFileName fn;
if( aScreen == NULL ) if( aScreen == NULL )
return FALSE; return false;
if( aFullFileName.IsEmpty() ) if( aFullFileName.IsEmpty() )
return FALSE; return false;
fn = aFullFileName;
CheckForAutoSaveFile( fn, g_SchematicBackupFileExtension );
wxLogTrace( traceAutoSave, wxT( "Loading schematic file " ) + aFullFileName );
aScreen->SetCurItem( NULL ); aScreen->SetCurItem( NULL );
aScreen->SetFileName( aFullFileName ); aScreen->SetFileName( aFullFileName );
// D(printf("LoadOneEEFile:%s\n", TO_UTF8( aFullFileName ) ); ) FILE* f;
FILE* f;
if( ( f = wxFopen( aFullFileName, wxT( "rt" ) ) ) == NULL ) if( ( f = wxFopen( aFullFileName, wxT( "rt" ) ) ) == NULL )
{ {
MsgDiag = _( "Failed to open " ) + aFullFileName; MsgDiag = _( "Failed to open " ) + aFullFileName;
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
return FALSE; return false;
} }
// reader now owns the open FILE. // reader now owns the open FILE.
...@@ -68,7 +98,7 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi ...@@ -68,7 +98,7 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
{ {
MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" ); MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
return FALSE; return false;
} }
line = reader.Line(); line = reader.Line();
...@@ -105,7 +135,7 @@ again." ); ...@@ -105,7 +135,7 @@ again." );
{ {
MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" ); MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
return FALSE; return false;
} }
LoadLayers( &reader ); LoadLayers( &reader );
......
///////////////////////////////////////////////////////////////////////////// /*
// Name: sch_sheet_path.cpp * This program source code file is part of KiCad, a free EDA CAD application.
// Purpose: member functions for SCH_SHEET_PATH *
// header = sch_sheet_path.h * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
// Author: jean-pierre Charras * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
// Modified by: * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
// License: License GNU *
///////////////////////////////////////////////////////////////////////////// * 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
*/
/**
* @file sch_sheet_path.cpp
* @brief SCH_SHEET_PATH class implementation.
*/
#include "fctsys.h" #include "fctsys.h"
...@@ -562,6 +583,18 @@ bool SCH_SHEET_LIST::IsModified() ...@@ -562,6 +583,18 @@ bool SCH_SHEET_LIST::IsModified()
} }
bool SCH_SHEET_LIST::IsAutoSaveRequired()
{
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet != NULL; sheet = GetNext() )
{
if( sheet->LastScreen() && sheet->LastScreen()->IsSave() )
return true;
}
return false;
}
void SCH_SHEET_LIST::ClearModifyStatus() void SCH_SHEET_LIST::ClearModifyStatus()
{ {
for( SCH_SHEET_PATH* sheet = GetFirst(); sheet != NULL; sheet = GetNext() ) for( SCH_SHEET_PATH* sheet = GetFirst(); sheet != NULL; sheet = GetNext() )
......
/*
* 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
*/
/** /**
* @file sch_sheet_path.h * @file sch_sheet_path.h
* @brief Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema. * @brief Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
...@@ -272,12 +297,10 @@ private: ...@@ -272,12 +297,10 @@ private:
* starting at the given sheet in constructor . * starting at the given sheet in constructor .
* the given sheet is counted * the given sheet is counted
*/ */
int m_index; /* internal variable to handle GetNext(): int m_index; /* internal variable to handle GetNext(): cleared by
* cleared by GetFirst() * GetFirst() and incremented by GetNext() after
* and incremented by GetNext() after * returning the next item in m_List. Also used for
* returning the next item in m_List * internal calculations in BuildSheetList()
* Also used for internal calculations in
* BuildSheetList()
*/ */
SCH_SHEET_PATH m_currList; SCH_SHEET_PATH m_currList;
...@@ -351,6 +374,13 @@ public: ...@@ -351,6 +374,13 @@ public:
*/ */
bool IsModified(); bool IsModified();
/**
* Function IsAutoSaveRequired
* checks the entire hierarchy for any modifications that require auto save.
* @returns True if the hierarchy is modified otherwise false.
*/
bool IsAutoSaveRequired();
void ClearModifyStatus(); void ClearModifyStatus();
/** /**
......
/*
* 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
*/
/** /**
* @file schframe.cpp * @file schframe.cpp
*/ */
...@@ -174,6 +199,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father, ...@@ -174,6 +199,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father,
m_dlgFindReplace = NULL; m_dlgFindReplace = NULL;
m_findReplaceData = new wxFindReplaceData( wxFR_DOWN ); m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
m_undoItem = NULL; m_undoItem = NULL;
m_hasAutoSave = true;
CreateScreens(); CreateScreens();
...@@ -261,12 +287,6 @@ SCH_SHEET_PATH* SCH_EDIT_FRAME::GetSheet() ...@@ -261,12 +287,6 @@ SCH_SHEET_PATH* SCH_EDIT_FRAME::GetSheet()
} }
/**
* Function SetSheetNumberAndCount
* Set the m_ScreenNumber and m_NumberOfScreen members for screens
* must be called after a delete or add sheet command, and when entering a
* sheet
*/
void SCH_EDIT_FRAME::SetSheetNumberAndCount() void SCH_EDIT_FRAME::SetSheetNumberAndCount()
{ {
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
...@@ -412,6 +432,20 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) ...@@ -412,6 +432,20 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
} }
} }
SCH_SCREENS screens;
wxFileName fn;
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
{
fn = screen->GetFileName();
// Auto save file name is the normal file name prepended with $.
fn.SetName( wxT( "$" ) + fn.GetName() );
if( fn.FileExists() && fn.IsFileWritable() )
wxRemoveFile( fn.GetFullPath() );
}
SheetList.ClearModifyStatus(); SheetList.ClearModifyStatus();
if( !g_RootSheet->GetScreen()->GetFileName().IsEmpty() if( !g_RootSheet->GetScreen()->GetFileName().IsEmpty()
...@@ -482,15 +516,11 @@ wxString SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet() ...@@ -482,15 +516,11 @@ wxString SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet()
return filename; return filename;
} }
/**
* Function OnModify
* Must be called after a schematic change
* in order to set the "modify" flag of the current screen
* and update the date in frame reference
*/
void SCH_EDIT_FRAME::OnModify( ) void SCH_EDIT_FRAME::OnModify( )
{ {
GetScreen()->SetModify(); GetScreen()->SetModify();
GetScreen()->SetSave();
wxString date = GenDate(); wxString date = GenDate();
SCH_SCREENS s_list; SCH_SCREENS s_list;
...@@ -788,15 +818,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event ) ...@@ -788,15 +818,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event )
frame.ShowModal(); frame.ShowModal();
} }
/*
* Function PrintPage (virtual)
* Previously used to print a page,
* but now only used to plot/print the current sheet to the clipboard
* @param aDC = wxDC given by the calling print function
* @param aPrintMask = not used here
* @param aPrintMirrorMode = not used here (Set when printing in mirror mode)
* @param aData = a pointer on an auxiliary data (not used here)
*/
void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData ) void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData )
{ {
GetScreen()->Draw( DrawPanel, aDC, GR_DEFAULT_DRAWMODE ); GetScreen()->Draw( DrawPanel, aDC, GR_DEFAULT_DRAWMODE );
...@@ -817,3 +839,11 @@ void SCH_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent ) ...@@ -817,3 +839,11 @@ void SCH_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
GetScreen()->SetCurItem( item ); GetScreen()->SetCurItem( item );
} }
} }
bool SCH_EDIT_FRAME::isAutoSaveRequired() const
{
SCH_SHEET_LIST SheetList;
return SheetList.IsAutoSaveRequired();
}
/********************** /*
* class_base_screen.h * 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
*/
/* define : /**
* class BASE_SCREEN to handle how to draw a screen (a board, a schematic ...) * @file class_base_screen.h
* @brief BASE_SCREEN class implementation.
*/ */
#ifndef __CLASS_BASE_SCREEN_H__ #ifndef __CLASS_BASE_SCREEN_H__
...@@ -48,9 +70,10 @@ public: ...@@ -48,9 +70,10 @@ public:
typedef std::vector< GRID_TYPE > GRIDS; typedef std::vector< GRID_TYPE > GRIDS;
/*******************************************************************/ /**
/* Class to handle how to draw a screen (a board, a schematic ...) */ * Class BASE_SCREEN
/*******************************************************************/ * handle how to draw a screen (a board, a schematic ...)
*/
class BASE_SCREEN : public EDA_ITEM class BASE_SCREEN : public EDA_ITEM
{ {
EDA_ITEMS m_items; ///< The drawing items associated with this screen. EDA_ITEMS m_items; ///< The drawing items associated with this screen.
...@@ -58,8 +81,8 @@ class BASE_SCREEN : public EDA_ITEM ...@@ -58,8 +81,8 @@ class BASE_SCREEN : public EDA_ITEM
EDA_ITEM* m_drawList; ///< Object list for the screen. EDA_ITEM* m_drawList; ///< Object list for the screen.
wxString m_fileName; ///< File used to load the screen. wxString m_fileName; ///< File used to load the screen.
char m_FlagRefreshReq; ///< Indicates that the screen should be redrawn. char m_FlagRefreshReq; ///< Indicates that the screen should be redrawn.
char m_FlagModified; ///< Indicates current drawing has been modified. bool m_FlagModified; ///< Indicates current drawing has been modified.
char m_FlagSave; ///< Indicates automatic file save. bool m_FlagSave; ///< Indicates automatic file save.
EDA_ITEM* m_CurrentItem; ///< Currently selected object EDA_ITEM* m_CurrentItem; ///< Currently selected object
GRID_TYPE m_Grid; ///< Current grid selection. GRID_TYPE m_Grid; ///< Current grid selection.
wxPoint m_scrollCenter; ///< Current scroll center point in logical units. wxPoint m_scrollCenter; ///< Current scroll center point in logical units.
...@@ -248,12 +271,12 @@ public: ...@@ -248,12 +271,12 @@ public:
} }
void SetModify() { m_FlagModified = 1; m_FlagSave = 0; } void SetModify() { m_FlagModified = true; }
void ClrModify() { m_FlagModified = 0; m_FlagSave = 1; } void ClrModify() { m_FlagModified = false;; }
void SetSave() { m_FlagSave = 1; } void SetSave() { m_FlagSave = true; }
void ClrSave() { m_FlagSave = 0; } void ClrSave() { m_FlagSave = false; }
int IsModify() { return m_FlagModified & 1; } int IsModify() { return m_FlagModified; }
int IsSave() { return m_FlagSave & 1; } int IsSave() { return m_FlagSave; }
//----<zoom stuff>--------------------------------------------------------- //----<zoom stuff>---------------------------------------------------------
......
/*
* 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
*/
/** /**
* @file class_sch_screen.h * @file class_sch_screen.h
* @brief Definitions for the Eeschema program SCH_SCREEN class. * @brief Definitions for the Eeschema program SCH_SCREEN class.
......
This diff is collapsed.
...@@ -43,10 +43,6 @@ ...@@ -43,10 +43,6 @@
#endif #endif
#define CREATE_BACKUP_FILE true
#define NO_BACKUP_FILE false
/* Forward declarations of classes. */ /* Forward declarations of classes. */
class PCB_SCREEN; class PCB_SCREEN;
class BOARD; class BOARD;
...@@ -152,10 +148,10 @@ protected: ...@@ -152,10 +148,10 @@ protected:
virtual bool doAutoSave(); virtual bool doAutoSave();
/** /**
* Function isModified * Function isautoSaveRequired
* returns true if the board has been modified. * returns true if the board has been modified.
*/ */
virtual bool isModified() const; virtual bool isAutoSaveRequired() const;
public: public:
LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer
......
...@@ -60,6 +60,12 @@ ...@@ -60,6 +60,12 @@
#define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS #define KICAD_DEFAULT_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS
// Readability helper definitions for creating backup files.
#define CREATE_BACKUP_FILE true
#define NO_BACKUP_FILE false
class EDA_ITEM; class EDA_ITEM;
class EDA_RECT; class EDA_RECT;
class EDA_DRAW_PANEL; class EDA_DRAW_PANEL;
...@@ -100,6 +106,10 @@ enum id_toolbar { ...@@ -100,6 +106,10 @@ enum id_toolbar {
}; };
/// Custom trace mask to enable and disable auto save tracing.
extern const wxChar* traceAutoSave;
/** /**
* Class EDA_BASE_FRAME * Class EDA_BASE_FRAME
* is the base frame for deriving all KiCad main window classes. This class is not * is the base frame for deriving all KiCad main window classes. This class is not
...@@ -140,11 +150,11 @@ protected: ...@@ -140,11 +150,11 @@ protected:
void onAutoSaveTimer( wxTimerEvent& aEvent ); void onAutoSaveTimer( wxTimerEvent& aEvent );
/** /**
* Function isModified * Function autoSaveRequired
* returns the modification status of the application. Override this function if * returns the auto save status of the application. Override this function if
* your derived frame supports automatic file saving. * your derived frame supports automatic file saving.
*/ */
virtual bool isModified() const { return false; } virtual bool isAutoSaveRequired() const { return false; }
/** /**
* Function doAutoSave * Function doAutoSave
...@@ -328,6 +338,24 @@ public: ...@@ -328,6 +338,24 @@ public:
* @return False if \a aFileName cannot be written. * @return False if \a aFileName cannot be written.
*/ */
bool IsWritable( const wxFileName& aFileName ); bool IsWritable( const wxFileName& aFileName );
/**
* Function CheckForAutoSaveFile
* checks if an auto save file exists for \a aFileName and takes the appropriate
* action depending on the user input.
* <p>
* If an auto save file exists for \a aFileName, the user is prompted if they wish
* to replace file \a aFileName with the auto saved file. If the user chooses to
* replace the file, the backup file of \a aFileName is removed, \a aFileName is
* renamed to the backup file name, and the auto save file is renamed to \a aFileName.
* If user chooses to keep the existing version of \a aFileName, the auto save file
* is removed.
* </p>
* @param aFileName A wxFileName object containing the file name to check.
* @param aBackupFileExtension A wxString object containing the backup file extension
* used to create the backup file name.
*/
void CheckForAutoSaveFile( const wxFileName& aFileName, const wxString& aBackupFileExtension );
}; };
......
/********************/ /*
/* basepcbframe.cpp */ * 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
*/
/**
* @file basepcbframe.cpp
*/
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation #pragma implementation
...@@ -36,10 +61,6 @@ static const wxString FastGrid1Entry( wxT( "FastGrid1" ) ); ...@@ -36,10 +61,6 @@ static const wxString FastGrid1Entry( wxT( "FastGrid1" ) );
static const wxString FastGrid2Entry( wxT( "FastGrid2" ) ); static const wxString FastGrid2Entry( wxT( "FastGrid2" ) );
/****************************/
/* class PCB_BASE_FRAME */
/****************************/
BEGIN_EVENT_TABLE( PCB_BASE_FRAME, EDA_DRAW_FRAME ) BEGIN_EVENT_TABLE( PCB_BASE_FRAME, EDA_DRAW_FRAME )
EVT_MENU_RANGE( ID_POPUP_PCB_ITEM_SELECTION_START, ID_POPUP_PCB_ITEM_SELECTION_END, EVT_MENU_RANGE( ID_POPUP_PCB_ITEM_SELECTION_START, ID_POPUP_PCB_ITEM_SELECTION_END,
PCB_BASE_FRAME::ProcessItemSelection ) PCB_BASE_FRAME::ProcessItemSelection )
...@@ -459,12 +480,6 @@ void PCB_BASE_FRAME::unitsChangeRefresh() ...@@ -459,12 +480,6 @@ void PCB_BASE_FRAME::unitsChangeRefresh()
} }
/**
* Load PCB base frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
void PCB_BASE_FRAME::LoadSettings() void PCB_BASE_FRAME::LoadSettings()
{ {
wxASSERT( wxGetApp().m_EDA_Config != NULL ); wxASSERT( wxGetApp().m_EDA_Config != NULL );
...@@ -509,12 +524,6 @@ void PCB_BASE_FRAME::LoadSettings() ...@@ -509,12 +524,6 @@ void PCB_BASE_FRAME::LoadSettings()
} }
/**
* Save PCB base frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
void PCB_BASE_FRAME::SaveSettings() void PCB_BASE_FRAME::SaveSettings()
{ {
wxASSERT( wxGetApp().m_EDA_Config != NULL ); wxASSERT( wxGetApp().m_EDA_Config != NULL );
...@@ -535,20 +544,11 @@ void PCB_BASE_FRAME::SaveSettings() ...@@ -535,20 +544,11 @@ void PCB_BASE_FRAME::SaveSettings()
} }
/**
* Function OnModify
* Must be called after a schematic change
* in order to set the "modify" flag of the current screen
* and update the date in frame reference
* do not forget to call this basic OnModify function to update info
* in derived OnModify functions
*/
void PCB_BASE_FRAME::OnModify( ) void PCB_BASE_FRAME::OnModify( )
{ {
GetScreen()->SetModify( ); GetScreen()->SetModify();
GetScreen()->SetSave();
wxString date = GenDate(); GetScreen()->m_Date = GenDate();
GetScreen()->m_Date = date;
} }
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#include "class_board.h" #include "class_board.h"
#define BACKUP_FILE_EXT wxT( "000" ) static const wxString pcbBackupFileExtension( wxT( "000" ) );
void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event ) void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event )
...@@ -96,7 +96,7 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event ) ...@@ -96,7 +96,7 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
else else
{ {
fn = GetScreen()->GetFileName(); fn = GetScreen()->GetFileName();
fn.SetExt( BACKUP_FILE_EXT ); fn.SetExt( pcbBackupFileExtension );
} }
if( !fn.FileExists() ) if( !fn.FileExists() )
...@@ -195,54 +195,7 @@ the changes?" ) ) ) ...@@ -195,54 +195,7 @@ the changes?" ) ) )
if( !aAppend ) if( !aAppend )
Clear_Pcb( false ); // pass false since we prompted above for a modified board Clear_Pcb( false ); // pass false since we prompted above for a modified board
// Check for board auto save file. CheckForAutoSaveFile( fileName, pcbBackupFileExtension );
wxFileName autoSaveFileName = fileName;
autoSaveFileName.SetName( wxT( "$" ) + autoSaveFileName.GetName() );
if( autoSaveFileName.FileExists() )
{
int response = wxMessageBox( _( "Well this is embarrassing! It appears that the last \
time you were editing this board the file was not save properly. Do you wish to restore the \
last edits you made?" ), wxGetApp().GetAppName(), wxYES_NO | wxICON_QUESTION, this );
// Make a backup of the current board file, delete the board file, and copy
// the auto save file to the board file name.
if( response == wxYES )
{
/* Get the backup file name */
wxFileName backupFileName = fileName;
backupFileName.SetExt( BACKUP_FILE_EXT );
/* If an old backup file exists, delete it. If an old board file exists, rename
* it to the backup file name
*/
if( fileName.FileExists() )
{
/* rename the "old" file" from xxx.brd to xxx.000 */
if( backupFileName.FileExists() ) /* Remove the old file xxx.000 (if exists) */
wxRemoveFile( backupFileName.GetFullPath() );
if( !wxRenameFile( fileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
msg = _( "Could not create backup file " ) + backupFileName.GetFullPath();
DisplayError( this, msg );
}
}
if( !wxRenameFile( autoSaveFileName.GetFullPath(), fileName.GetFullPath() ) )
{
wxMessageBox( _( "The auto save file could not be renamed to the board file \
name." ),
wxGetApp().GetAppName(), wxOK | wxICON_EXCLAMATION, this );
}
}
else
{
// Remove the auto save file when using the board file as is.
wxRemoveFile( autoSaveFileName.GetFullPath() );
}
}
GetScreen()->SetFileName( fileName.GetFullPath() ); GetScreen()->SetFileName( fileName.GetFullPath() );
...@@ -418,7 +371,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF ...@@ -418,7 +371,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
{ {
/* Get the backup file name */ /* Get the backup file name */
backupFileName = pcbFileName; backupFileName = pcbFileName;
backupFileName.SetExt( BACKUP_FILE_EXT ); backupFileName.SetExt( pcbBackupFileExtension );
/* If an old backup file exists, delete it. If an old board file exists, rename /* If an old backup file exists, delete it. If an old board file exists, rename
* it to the backup file name * it to the backup file name
...@@ -488,6 +441,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF ...@@ -488,6 +441,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
ClearMsgPanel(); ClearMsgPanel();
AppendMsgPanel( upperTxt, lowerTxt, CYAN ); AppendMsgPanel( upperTxt, lowerTxt, CYAN );
GetScreen()->ClrSave();
GetScreen()->ClrModify(); GetScreen()->ClrModify();
return true; return true;
} }
...@@ -501,12 +455,15 @@ bool PCB_EDIT_FRAME::doAutoSave() ...@@ -501,12 +455,15 @@ bool PCB_EDIT_FRAME::doAutoSave()
// Auto save file name is the normal file name prepended with $. // Auto save file name is the normal file name prepended with $.
fn.SetName( wxT( "$" ) + fn.GetName() ); fn.SetName( wxT( "$" ) + fn.GetName() );
wxLogTrace( traceAutoSave,
wxT( "Creating auto save file <" + fn.GetFullPath() ) + wxT( ">" ) );
if( SavePcbFile( fn.GetFullPath(), NO_BACKUP_FILE ) ) if( SavePcbFile( fn.GetFullPath(), NO_BACKUP_FILE ) )
{ {
OnModify(); GetScreen()->SetModify();
GetScreen()->SetSave(); // Set the flags m_FlagSave cleared by SetModify()
GetScreen()->SetFileName( tmpFileName.GetFullPath() ); GetScreen()->SetFileName( tmpFileName.GetFullPath() );
UpdateTitle(); UpdateTitle();
m_autoSaveState = false;
return true; return true;
} }
......
...@@ -413,9 +413,9 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME() ...@@ -413,9 +413,9 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
} }
bool PCB_EDIT_FRAME::isModified() const bool PCB_EDIT_FRAME::isAutoSaveRequired() const
{ {
return GetScreen()->IsModify(); return GetScreen()->IsSave();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment