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.
This commit is contained in:
Wayne Stambaugh 2011-10-15 09:25:57 -04:00
parent 8e6ac6c5a9
commit 121b65bfb8
23 changed files with 936 additions and 1606 deletions

View File

@ -1,10 +1,32 @@
/********************************************************/ /*
/* 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 @@
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()
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
} }
/* 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()
} }
/* 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 )
#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 )
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n"; NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
} }
#endif #endif

View File

@ -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 )
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 )
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() );
}
}

View File

@ -1,3 +1,31 @@
/*
* 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"

View File

@ -1,11 +1,36 @@
#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:
} }
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(); }

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// 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()
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
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
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
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
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;

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// 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
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
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
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();
}; };

View File

@ -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" ) );

View File

@ -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 )
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();

View File

@ -1,6 +1,31 @@
/****************************/ /*
/* 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 @@
#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 )
{ {
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 )
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 )
} }
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 )
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 )
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 )
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;
}

View File

@ -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

View File

@ -1,3 +1,28 @@
/*
* 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
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
{ {
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." );
{ {
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 );

View File

@ -1,11 +1,32 @@
///////////////////////////////////////////////////////////////////////////// /*
// 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()
} }
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() )

View File

@ -1,3 +1,28 @@
/*
* 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:
* 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:
*/ */
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();
/** /**

View File

@ -1,3 +1,28 @@
/*
* 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,
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()
} }
/**
* 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 )
} }
} }
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()
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 )
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 )
GetScreen()->SetCurItem( item ); GetScreen()->SetCurItem( item );
} }
} }
bool SCH_EDIT_FRAME::isAutoSaveRequired() const
{
SCH_SHEET_LIST SheetList;
return SheetList.IsAutoSaveRequired();
}

View File

@ -1,9 +1,31 @@
/********************** /*
* 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:
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
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:
} }
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>---------------------------------------------------------

View File

@ -1,3 +1,28 @@
/*
* 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.

View File

@ -90,9 +90,6 @@ public:
wxString m_UserLibraryPath; wxString m_UserLibraryPath;
wxArrayString m_ComponentLibFiles; wxArrayString m_ComponentLibFiles;
protected:
TEMPLATES m_TemplateFieldNames;
private: private:
wxString m_DefaultSchematicFileName; wxString m_DefaultSchematicFileName;
int m_TextFieldSize; int m_TextFieldSize;
@ -126,6 +123,23 @@ private:
static wxPoint m_lastSheetPinPosition; ///< Last sheet pin position. static wxPoint m_lastSheetPinPosition; ///< Last sheet pin position.
static int m_lastSheetPinEdge; ///< Last sheet edge a sheet pin was placed. static int m_lastSheetPinEdge; ///< Last sheet edge a sheet pin was placed.
protected:
TEMPLATES m_TemplateFieldNames;
/**
* Function doAutoSave
* saves the schematic files that have been modified and not yet saved.
*
* @return true if the auto save was successful otherwise false.
*/
virtual bool doAutoSave();
/**
* Function autoSaveRequired
* returns true if the schematic has been modified.
*/
virtual bool isAutoSaveRequired() const;
public: public:
SCH_EDIT_FRAME( wxWindow* father, SCH_EDIT_FRAME( wxWindow* father,
@ -135,13 +149,13 @@ public:
~SCH_EDIT_FRAME(); ~SCH_EDIT_FRAME();
void OnCloseWindow( wxCloseEvent& Event ); void OnCloseWindow( wxCloseEvent& Event );
void Process_Special_Functions( wxCommandEvent& event ); void Process_Special_Functions( wxCommandEvent& event );
void OnColorConfig( wxCommandEvent& aEvent ); void OnColorConfig( wxCommandEvent& aEvent );
void Process_Config( wxCommandEvent& event ); void Process_Config( wxCommandEvent& event );
void OnSelectTool( wxCommandEvent& aEvent ); void OnSelectTool( wxCommandEvent& aEvent );
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/** /**
* Function GetProjectFileParameters * Function GetProjectFileParameters
@ -240,18 +254,17 @@ public:
*/ */
PARAM_CFG_ARRAY& GetConfigurationSettings( void ); PARAM_CFG_ARRAY& GetConfigurationSettings( void );
void LoadSettings(); void LoadSettings();
void SaveSettings(); void SaveSettings();
void RedrawActiveWindow( wxDC* DC, bool EraseBg ); void RedrawActiveWindow( wxDC* DC, bool EraseBg );
void CreateScreens(); void CreateScreens();
void ReCreateHToolbar(); void ReCreateHToolbar();
void ReCreateVToolbar(); void ReCreateVToolbar();
void ReCreateOptToolbar(); void ReCreateOptToolbar();
void ReCreateMenuBar(); void ReCreateMenuBar();
void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL );
EDA_ITEM* aItem = NULL );
/** /**
* Function OnModify * Function OnModify
@ -259,21 +272,21 @@ public:
* in order to set the "modify" flag of the current screen * in order to set the "modify" flag of the current screen
* and update the date in frame reference * and update the date in frame reference
*/ */
void OnModify(); void OnModify();
SCH_SHEET_PATH* GetSheet(); SCH_SHEET_PATH* GetSheet();
SCH_SCREEN* GetScreen() const; SCH_SCREEN* GetScreen() const;
virtual wxString GetScreenDesc(); virtual wxString GetScreenDesc();
void InstallConfigFrame( wxCommandEvent& event ); void InstallConfigFrame( wxCommandEvent& event );
void OnLeftClick( wxDC* aDC, const wxPoint& aPosition ); void OnLeftClick( wxDC* aDC, const wxPoint& aPosition );
void OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ); void OnLeftDClick( wxDC* aDC, const wxPoint& aPosition );
bool OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ); bool OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu );
void OnSelectOptionToolbar( wxCommandEvent& event ); void OnSelectOptionToolbar( wxCommandEvent& event );
double BestZoom(); double BestZoom();
/** /**
* Function LocateAndShowItem * Function LocateAndShowItem
@ -326,17 +339,17 @@ public:
*/ */
bool DeleteItemAtCrossHair( wxDC* aDC ); bool DeleteItemAtCrossHair( wxDC* aDC );
SCH_ITEM* FindComponentAndItem( const wxString& component_reference, SCH_ITEM* FindComponentAndItem( const wxString& component_reference,
bool Find_in_hierarchy, bool Find_in_hierarchy,
int SearchType, int SearchType,
const wxString& text_to_find, const wxString& text_to_find,
bool mouseWarp ); bool mouseWarp );
/* Cross probing with Pcbnew */ /* Cross probing with Pcbnew */
void SendMessageToPCBNEW( EDA_ITEM* objectToSync, SCH_COMPONENT* LibItem ); void SendMessageToPCBNEW( EDA_ITEM* objectToSync, SCH_COMPONENT* LibItem );
/* netlist generation */ /* netlist generation */
void BuildNetListBase(); void BuildNetListBase();
/** /**
* Function CreateNetlist * Function CreateNetlist
@ -352,10 +365,10 @@ public:
* @param aUsePrefix Prefix reference designator with an 'X' for spice output. * @param aUsePrefix Prefix reference designator with an 'X' for spice output.
* @return true if success. * @return true if success.
*/ */
bool CreateNetlist( int aFormat, bool CreateNetlist( int aFormat,
const wxString& aFullFileName, const wxString& aFullFileName,
bool aUse_netnames, bool aUse_netnames,
bool aUsePrefix ); bool aUsePrefix );
/** /**
* Function WriteNetListFile * Function WriteNetListFile
@ -367,10 +380,10 @@ public:
* bool aUse_netnames is used only for Spice netlist * bool aUse_netnames is used only for Spice netlist
* @return true if success. * @return true if success.
*/ */
bool WriteNetListFile( int aFormat, bool WriteNetListFile( int aFormat,
const wxString& aFullFileName, const wxString& aFullFileName,
bool aUse_netnames, bool aUse_netnames,
bool aUsePrefix ); bool aUsePrefix );
/** /**
* Function DeleteAnnotation * Function DeleteAnnotation
@ -432,7 +445,7 @@ public:
* Function DisplayCurrentSheet * Function DisplayCurrentSheet
* draws the current sheet on the display. * draws the current sheet on the display.
*/ */
void DisplayCurrentSheet(); void DisplayCurrentSheet();
/** /**
* Function GetUniqueFilenameForCurrentSheet * Function GetUniqueFilenameForCurrentSheet
@ -445,7 +458,7 @@ public:
* Name is &ltroot sheet filename&gt-&ltsheet path&gt and has no extension. * Name is &ltroot sheet filename&gt-&ltsheet path&gt and has no extension.
* However if filename is too long name is &ltsheet filename&gt-&ltsheet number&gt * However if filename is too long name is &ltsheet filename&gt-&ltsheet number&gt
*/ */
wxString GetUniqueFilenameForCurrentSheet(); wxString GetUniqueFilenameForCurrentSheet();
/** /**
* Function SetSheetNumberAndCount * Function SetSheetNumberAndCount
@ -453,41 +466,41 @@ public:
* must be called after a delete or add sheet command, and when entering * must be called after a delete or add sheet command, and when entering
* a sheet * a sheet
*/ */
void SetSheetNumberAndCount(); void SetSheetNumberAndCount();
/** /**
* Show the print dialog * Show the print dialog
*/ */
void OnPrint( wxCommandEvent& event ); void OnPrint( wxCommandEvent& event );
wxPageSetupDialogData& GetPageSetupData() { return m_pageSetupData; } wxPageSetupDialogData& GetPageSetupData() { return m_pageSetupData; }
void SetPreviewPosition( const wxPoint& aPoint ) { m_previewPosition = aPoint; } void SetPreviewPosition( const wxPoint& aPoint ) { m_previewPosition = aPoint; }
void SetPreviewSize( const wxSize& aSize ) { m_previewSize = aSize; } void SetPreviewSize( const wxSize& aSize ) { m_previewSize = aSize; }
const wxPoint& GetPreviewPosition() { return m_previewPosition; } const wxPoint& GetPreviewPosition() { return m_previewPosition; }
const wxSize& GetPreviewSize() { return m_previewSize; } const wxSize& GetPreviewSize() { return m_previewSize; }
void SetPrintDialogPosition( const wxPoint& aPoint ) void SetPrintDialogPosition( const wxPoint& aPoint )
{ {
m_printDialogPosition = aPoint; m_printDialogPosition = aPoint;
} }
void SetPrintDialogSize( const wxSize& aSize ) { m_printDialogSize = aSize; } void SetPrintDialogSize( const wxSize& aSize ) { m_printDialogSize = aSize; }
const wxPoint& GetPrintDialogPosition() { return m_printDialogPosition; } const wxPoint& GetPrintDialogPosition() { return m_printDialogPosition; }
const wxSize& GetPrintDialogSize() { return m_printDialogSize; } const wxSize& GetPrintDialogSize() { return m_printDialogSize; }
bool GetPrintMonochrome() { return m_printMonochrome; } bool GetPrintMonochrome() { return m_printMonochrome; }
void SetPrintMonochrome( bool aMonochrome ) { m_printMonochrome = aMonochrome; } void SetPrintMonochrome( bool aMonochrome ) { m_printMonochrome = aMonochrome; }
bool GetPrintSheetReference() { return m_printSheetReference; } bool GetPrintSheetReference() { return m_printSheetReference; }
void SetPrintSheetReference( bool aShow ) { m_printSheetReference = aShow; } void SetPrintSheetReference( bool aShow ) { m_printSheetReference = aShow; }
void SVG_Print( wxCommandEvent& event ); void SVG_Print( wxCommandEvent& event );
// Plot functions: // Plot functions:
void ToPlot_PS( wxCommandEvent& event ); void ToPlot_PS( wxCommandEvent& event );
void ToPlot_HPGL( wxCommandEvent& event ); void ToPlot_HPGL( wxCommandEvent& event );
void ToPlot_DXF( wxCommandEvent& event ); void ToPlot_DXF( wxCommandEvent& event );
void ToPostProcess( wxCommandEvent& event ); void ToPostProcess( wxCommandEvent& event );
// read and save files // read and save files
void Save_File( wxCommandEvent& event ); void Save_File( wxCommandEvent& event );
@ -527,7 +540,7 @@ public:
*/ */
bool LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFileName ); bool LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFileName );
bool ReadInputStuffFile(); bool ReadInputStuffFile();
/** /**
* Function ProcessStuffFile * Function ProcessStuffFile
@ -545,7 +558,7 @@ public:
* @param aSetFieldsAttributeToVisible = true to set the footprint field flag to visible * @param aSetFieldsAttributeToVisible = true to set the footprint field flag to visible
* @return bool - true if success, else true. * @return bool - true if success, else true.
*/ */
bool ProcessStuffFile( FILE* aFilename, bool aSetFieldsAttributeToVisible ); bool ProcessStuffFile( FILE* aFilename, bool aSetFieldsAttributeToVisible );
/** /**
* Function SaveEEFile * Function SaveEEFile
@ -554,61 +567,63 @@ public:
* @param aScreen A pointer to the SCH_SCREEN object to save. A NULL pointer saves * @param aScreen A pointer to the SCH_SCREEN object to save. A NULL pointer saves
* the current screen. * the current screen.
* @param aSaveType Controls how the file is to be saved. * @param aSaveType Controls how the file is to be saved.
* @param aCreateBackupFile Creates a back of the file associated with \a aScreen
* if true. Helper definitions #CREATE_BACKUP_FILE and
* #NO_BACKUP_FILE are defined for improved code readability.
* @return True if the file has been saved. * @return True if the file has been saved.
*/ */
bool SaveEEFile( SCH_SCREEN* aScreen, int aSaveType ); bool SaveEEFile( SCH_SCREEN* aScreen,
int aSaveType,
bool aCreateBackupFile = CREATE_BACKUP_FILE );
// General search: // General search:
private: private:
void OnMoveItem( wxCommandEvent& aEvent ); void OnMoveItem( wxCommandEvent& aEvent );
void OnExit( wxCommandEvent& event ); void OnExit( wxCommandEvent& event );
void OnAnnotate( wxCommandEvent& event ); void OnAnnotate( wxCommandEvent& event );
void OnErc( wxCommandEvent& event ); void OnErc( wxCommandEvent& event );
void OnCreateNetlist( wxCommandEvent& event ); void OnCreateNetlist( wxCommandEvent& event );
void OnCreateBillOfMaterials( wxCommandEvent& event ); void OnCreateBillOfMaterials( wxCommandEvent& event );
void OnFindItems( wxCommandEvent& event ); void OnFindItems( wxCommandEvent& event );
void OnFindDialogClose( wxFindDialogEvent& event ); void OnFindDialogClose( wxFindDialogEvent& event );
void OnFindDrcMarker( wxFindDialogEvent& event ); void OnFindDrcMarker( wxFindDialogEvent& event );
void OnFindCompnentInLib( wxFindDialogEvent& event ); void OnFindCompnentInLib( wxFindDialogEvent& event );
void OnFindSchematicItem( wxFindDialogEvent& event ); void OnFindSchematicItem( wxFindDialogEvent& event );
void OnLoadFile( wxCommandEvent& event ); void OnLoadFile( wxCommandEvent& event );
void OnLoadStuffFile( wxCommandEvent& event ); void OnLoadStuffFile( wxCommandEvent& event );
void OnNewProject( wxCommandEvent& event ); void OnNewProject( wxCommandEvent& event );
void OnLoadProject( wxCommandEvent& event ); void OnLoadProject( wxCommandEvent& event );
void OnOpenPcbnew( wxCommandEvent& event ); void OnOpenPcbnew( wxCommandEvent& event );
void OnOpenCvpcb( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event );
void OnOpenLibraryViewer( wxCommandEvent& event ); void OnOpenLibraryViewer( wxCommandEvent& event );
void OnOpenLibraryEditor( wxCommandEvent& event ); void OnOpenLibraryEditor( wxCommandEvent& event );
void OnSetOptions( wxCommandEvent& event ); void OnSetOptions( wxCommandEvent& event );
void OnCancelCurrentCommand( wxCommandEvent& aEvent ); void OnCancelCurrentCommand( wxCommandEvent& aEvent );
void OnSelectItem( wxCommandEvent& aEvent ); void OnSelectItem( wxCommandEvent& aEvent );
/* edition events functions */ /* edition events functions */
void OnCopySchematicItemRequest( wxCommandEvent& event ); void OnCopySchematicItemRequest( wxCommandEvent& event );
/* User interface update event handlers. */ /* User interface update event handlers. */
void OnUpdateBlockSelected( wxUpdateUIEvent& event ); void OnUpdateBlockSelected( wxUpdateUIEvent& event );
void OnUpdatePaste( wxUpdateUIEvent& event ); void OnUpdatePaste( wxUpdateUIEvent& event );
void OnUpdateHiddenPins( wxUpdateUIEvent& event ); void OnUpdateHiddenPins( wxUpdateUIEvent& event );
void OnUpdateBusOrientation( wxUpdateUIEvent& event ); void OnUpdateBusOrientation( wxUpdateUIEvent& event );
void OnUpdateSelectTool( wxUpdateUIEvent& aEvent ); void OnUpdateSelectTool( wxUpdateUIEvent& aEvent );
/** /**
* Function SetLanguage * Function SetLanguage
* called on a language menu selection * called on a language menu selection
*/ */
void SetLanguage( wxCommandEvent& event ); void SetLanguage( wxCommandEvent& event );
// Bus Entry // Bus Entry
SCH_BUS_ENTRY* CreateBusEntry( wxDC* DC, int entry_type ); SCH_BUS_ENTRY* CreateBusEntry( wxDC* DC, int entry_type );
void SetBusEntryShape( wxDC* DC, void SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_type );
SCH_BUS_ENTRY* BusEntry, int GetBusEntryShape( SCH_BUS_ENTRY* BusEntry );
int entry_type ); void StartMoveBusEntry( SCH_BUS_ENTRY* DrawLibItem, wxDC* DC );
int GetBusEntryShape( SCH_BUS_ENTRY* BusEntry );
void StartMoveBusEntry( SCH_BUS_ENTRY* DrawLibItem,
wxDC* DC );
/** /**
* Function AddNoConnect * Function AddNoConnect
@ -620,13 +635,13 @@ private:
SCH_NO_CONNECT* AddNoConnect( wxDC* aDC, const wxPoint& aPosition ); SCH_NO_CONNECT* AddNoConnect( wxDC* aDC, const wxPoint& aPosition );
// Junction // Junction
SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = FALSE ); SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = FALSE );
// Text, label, glabel // Text, label, glabel
SCH_TEXT* CreateNewText( wxDC* aDC, int aType ); SCH_TEXT* CreateNewText( wxDC* aDC, int aType );
void EditSchematicText( SCH_TEXT* TextStruct ); void EditSchematicText( SCH_TEXT* TextStruct );
void ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC ); void ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC );
void MoveText( SCH_TEXT* aTextItem, wxDC* aDC ); void MoveText( SCH_TEXT* aTextItem, wxDC* aDC );
/** /**
* Function OnCovertTextType * Function OnCovertTextType
@ -637,21 +652,21 @@ private:
void OnConvertTextType( wxCommandEvent& aEvent ); void OnConvertTextType( wxCommandEvent& aEvent );
// Wire, Bus // Wire, Bus
void BeginSegment( wxDC* DC, int type ); void BeginSegment( wxDC* DC, int type );
void EndSegment( wxDC* DC ); void EndSegment( wxDC* DC );
void DeleteCurrentSegment( wxDC* DC ); void DeleteCurrentSegment( wxDC* DC );
void DeleteConnection( bool DeleteFullConnection ); void DeleteConnection( bool DeleteFullConnection );
// graphic lines // graphic lines
void Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC ); void Edge( DRAWSEGMENT* Segment, wxDC* DC );
void Drawing_SetNewWidth( DRAWSEGMENT* DrawSegm, wxDC* DC ); void SetNewWidth( DRAWSEGMENT* DrawSegm, wxDC* DC );
void Delete_Drawings_All_Layer( DRAWSEGMENT* Segment, wxDC* DC ); void Layer( DRAWSEGMENT* Segment, wxDC* DC );
DRAWSEGMENT* Begin_Edge( DRAWSEGMENT* Segment, wxDC* DC ); DRAWSEGMENT* Begin_Edge( DRAWSEGMENT* Segment, wxDC* DC );
// Images: // Images:
SCH_BITMAP* CreateNewImage( wxDC* aDC ); SCH_BITMAP* CreateNewImage( wxDC* aDC );
void MoveImage( SCH_BITMAP* aItem, wxDC* aDC ); void MoveImage( SCH_BITMAP* aItem, wxDC* aDC );
void RotateImage( SCH_BITMAP* aItem ); void RotateImage( SCH_BITMAP* aItem );
/** /**
* Function MirrorImage * Function MirrorImage
* Mirror a bitmap * Mirror a bitmap
@ -659,18 +674,18 @@ private:
* @param Is_X_axis = true to mirror relative to Horizontal axis * @param Is_X_axis = true to mirror relative to Horizontal axis
* false to mirror relative to vertical axis * false to mirror relative to vertical axis
*/ */
void MirrorImage( SCH_BITMAP* aItem, bool Is_X_axis ); void MirrorImage( SCH_BITMAP* aItem, bool Is_X_axis );
void EditImage( SCH_BITMAP* aItem ); void EditImage( SCH_BITMAP* aItem );
// Hierarchical Sheet & PinSheet // Hierarchical Sheet & PinSheet
void InstallHierarchyFrame( wxDC* DC, wxPoint& pos ); void InstallHierarchyFrame( wxDC* DC, wxPoint& pos );
SCH_SHEET* CreateSheet( wxDC* DC ); SCH_SHEET* CreateSheet( wxDC* DC );
void ReSizeSheet( SCH_SHEET* Sheet, wxDC* DC ); void ReSizeSheet( SCH_SHEET* Sheet, wxDC* DC );
/** /**
* Use the component viewer to select component to import into schematic. * Use the component viewer to select component to import into schematic.
*/ */
wxString SelectFromLibBrowser( void ); wxString SelectFromLibBrowser( void );
public: public:
/** /**
@ -703,7 +718,7 @@ public:
int GetLastSheetPinEdge() const { return m_lastSheetPinEdge; } int GetLastSheetPinEdge() const { return m_lastSheetPinEdge; }
private: private:
void StartMoveSheet( SCH_SHEET* sheet, wxDC* DC ); void StartMoveSheet( SCH_SHEET* sheet, wxDC* DC );
/** /**
* Function CreateSheetPin * Function CreateSheetPin
@ -758,7 +773,7 @@ private:
const wxString& libname, const wxString& libname,
wxArrayString& List, wxArrayString& List,
bool UseLibBrowser ); bool UseLibBrowser );
void StartMovePart( SCH_COMPONENT* DrawLibItem, wxDC* DC ); void StartMovePart( SCH_COMPONENT* DrawLibItem, wxDC* DC );
/** /**
* Function EditComponent * Function EditComponent
@ -772,15 +787,15 @@ public:
void OnChangeComponentOrientation( wxCommandEvent& aEvent ); void OnChangeComponentOrientation( wxCommandEvent& aEvent );
private: private:
void OnSelectUnit( wxCommandEvent& aEvent ); void OnSelectUnit( wxCommandEvent& aEvent );
void ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC ); void ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC );
void SetInitCmp( SCH_COMPONENT* DrawComponent, wxDC* DC ); void SetInitCmp( SCH_COMPONENT* DrawComponent, wxDC* DC );
void MoveField( SCH_FIELD* aField, wxDC* aDC ); void MoveField( SCH_FIELD* aField, wxDC* aDC );
void EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC ); void EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC );
void RotateField( SCH_FIELD* aField, wxDC* aDC ); void RotateField( SCH_FIELD* aField, wxDC* aDC );
void PasteListOfItems( wxDC* DC ); void PasteListOfItems( wxDC* DC );
/* Undo - redo */ /* Undo - redo */
public: public:
@ -848,7 +863,7 @@ private:
* - Get an old version of the schematic from Redo list * - Get an old version of the schematic from Redo list
* @return none * @return none
*/ */
void GetSchematicFromRedoList( wxCommandEvent& event ); void GetSchematicFromRedoList( wxCommandEvent& event );
/** /**
* Function GetSchematicFromUndoList * Function GetSchematicFromUndoList
@ -856,7 +871,7 @@ private:
* - Save the current schematic in Redo list * - Save the current schematic in Redo list
* - Get an old version of the schematic from Undo list * - Get an old version of the schematic from Undo list
*/ */
void GetSchematicFromUndoList( wxCommandEvent& event ); void GetSchematicFromUndoList( wxCommandEvent& event );
/** /**
* Function copyBlockItems * Function copyBlockItems
@ -875,11 +890,11 @@ private:
void addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction ); void addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction );
public: public:
void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct ); void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct );
/* Block operations. */ /* Block operations. */
void InitBlockPasteInfos(); void InitBlockPasteInfos();
void HandleBlockEndByPopUp( int Command, wxDC* DC ); void HandleBlockEndByPopUp( int Command, wxDC* DC );
/** /**
* Function ReturnBlockCommand * Function ReturnBlockCommand
@ -912,7 +927,7 @@ public:
*/ */
virtual bool HandleBlockEnd( wxDC* DC ); virtual bool HandleBlockEnd( wxDC* DC );
void RepeatDrawItem( wxDC* DC ); void RepeatDrawItem( wxDC* DC );
void SetRepeatItem( SCH_ITEM* aItem ) { m_itemToRepeat = aItem; } void SetRepeatItem( SCH_ITEM* aItem ) { m_itemToRepeat = aItem; }

View File

@ -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:
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

View File

@ -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 {
}; };
/// 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:
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:
* @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 );
}; };

View File

@ -1,6 +1,31 @@
/********************/ /*
/* 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" ) );
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()
} }
/**
* 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()
} }
/**
* 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()
} }
/**
* 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;
} }

View File

@ -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 )
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?" ) ) )
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
{ {
/* 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
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()
// 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;
} }

View File

@ -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();
} }