Commit 70569edb authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Pcbnew auto save improvements.

* Factor auto save common code into base frame class so all frame windows
  can take advantage of the shiny new auto save goodness.
* Use a timer instead of depending on mouse and keyboard events to trigger
  an auto save.
* Check for auto save file when opening a board and ask user if they
  wish to use the auto save file or the last saved board file.
* Protect all base frame public members.
parent 0dff6b9b
Loading
Loading
Loading
Loading
+31 −7
Original line number Diff line number Diff line
/********************/
/*	3d_toolbar.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 3d_toolbar.cpp
 */

#include "fctsys.h"

@@ -105,10 +130,9 @@ void EDA_3D_FRAME::ReCreateMenuBar()
{
    bool full_options = true;

    // If called from the display frame of cvpcb, only some options are
    // relevant
    if( m_Parent->m_FrameName == wxT( "CmpFrame" ) )
    // Called from cvpcb: do not display all options
    // If called from the display frame of CvPcb, only some options are relevant
    if( m_Parent->GetName() == wxT( "CmpFrame" ) )
    // Called from CvPcb: do not display all options
        full_options = false;

    wxMenuBar* menuBar = new wxMenuBar;
+114 −59
Original line number Diff line number Diff line
/*
 * 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
 */

/**
 * EDA_BASE_FRAME Class Functions
 * @file basicframe.cpp
 * @brief EDA_BASE_FRAME class implementation.
 */

#include <wx/aboutdlg.h>
@@ -20,9 +45,13 @@
#include "macros.h"


/*
 * Class constructor for EDA_BASE_FRAME general options
 */
/// The default auto save interval is 10 minutes.
#define DEFAULT_AUTO_SAVE_INTERVAL 600


static const wxChar* entryAutoSaveInterval = wxT( "AutoSaveInterval" );


EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* father,
                                int idtype,
                                const wxString& title,
@@ -35,7 +64,11 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* father,

    m_Ident = idtype;
    m_HToolBar = NULL;
    m_FrameIsActive  = TRUE;
    m_FrameIsActive = true;
    m_hasAutoSave = false;
    m_autoSaveState = false;
    m_autoSaveInterval = -1;
    m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );

    m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();

@@ -48,8 +81,7 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* father,
        SetSize( 0, 0, minsize.x, minsize.y );

    // Create child subwindows.
    GetClientSize( &m_FrameSize.x, &m_FrameSize.y ); /* dimensions of the user
                                                      * area of the main
    GetClientSize( &m_FrameSize.x, &m_FrameSize.y ); /* dimensions of the user area of the main
                                                      * window */
    m_FramePos.x = m_FramePos.y = 0;
    m_FrameSize.y -= m_MsgFrameHeight;
@@ -57,6 +89,9 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* father,
    Connect( ID_HELP_COPY_VERSION_STRING,
             wxEVT_COMMAND_MENU_SELECTED,
             wxCommandEventHandler( EDA_BASE_FRAME::CopyVersionInfoToClipboard ) );

    Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
             wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
}


@@ -64,8 +99,11 @@ EDA_BASE_FRAME::~EDA_BASE_FRAME()
{
    if( wxGetApp().m_HtmlCtrl )
        delete wxGetApp().m_HtmlCtrl;

    wxGetApp().m_HtmlCtrl = NULL;

    delete m_autoSaveTimer;

    /* This needed for OSX: avoids further OnDraw processing after this
     * destructor and before the native window is destroyed
     */
@@ -73,19 +111,47 @@ EDA_BASE_FRAME::~EDA_BASE_FRAME()
}


/*
 * Virtual function
 */
void EDA_BASE_FRAME::ReCreateMenuBar()
bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
{
    if( !wxFrame::ProcessEvent( aEvent ) )
        return false;

    if( m_hasAutoSave && (m_autoSaveState != isModified()) && (m_autoSaveInterval > 0) )
    {
        if( !m_autoSaveState )
        {
            m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
            m_autoSaveState = true;
        }
        else
        {
            m_autoSaveTimer->Stop();
            m_autoSaveState = false;
        }
    }

    return true;
}

/**
 * Function SetLanguage (virtual)
 * called on a language menu selection
 * when using a derived function, do not forget to call this one
 */

void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
{
    if( !doAutoSave() )
        m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
}


bool EDA_BASE_FRAME::doAutoSave()
{
    wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden.  Bad programmer!" ) );
}


void EDA_BASE_FRAME::ReCreateMenuBar()
{
}


void EDA_BASE_FRAME::SetLanguage( wxCommandEvent& event )
{
    int id = event.GetId();
@@ -97,13 +163,6 @@ void EDA_BASE_FRAME::SetLanguage( wxCommandEvent& event )
}


/**
 * Load common frame parameters from configuration.
 *
 * The method is virtual so you can override it to load frame specific
 * parameters.  Don't forget to call the base method or your frames won't
 * remember their positions and sizes.
 */
void EDA_BASE_FRAME::LoadSettings()
{
    wxString  text;
@@ -113,6 +172,7 @@ void EDA_BASE_FRAME::LoadSettings()
    config = wxGetApp().m_EDA_Config;

    int maximized = 0;

    if( config )
    {
        text = m_FrameName + wxT( "Pos_x" );
@@ -125,6 +185,12 @@ void EDA_BASE_FRAME::LoadSettings()
        config->Read( text, &m_FrameSize.y, 400 );
        text = m_FrameName + wxT( "Maximized" );
        config->Read( text, &maximized, 0 );

        if( m_hasAutoSave )
        {
            text = m_FrameName + entryAutoSaveInterval;
            config->Read( text, &m_autoSaveInterval, DEFAULT_AUTO_SAVE_INTERVAL );
        }
    }

    // Ensure Window title bar is visible
@@ -143,13 +209,6 @@ void EDA_BASE_FRAME::LoadSettings()
}


/**
 * Save common frame parameters from configuration.
 *
 * The method is virtual so you can override it to save frame specific
 * parameters.  Don't forget to call the base method or your frames won't
 * remember their positions and sizes.
 */
void EDA_BASE_FRAME::SaveSettings()
{
    wxString text;
@@ -173,6 +232,12 @@ void EDA_BASE_FRAME::SaveSettings()
    config->Write( text, (long) m_FrameSize.y );
    text = m_FrameName + wxT( "Maximized" );
    config->Write( text, IsMaximized() );

    if( m_hasAutoSave )
    {
        text = m_FrameName + entryAutoSaveInterval;
        config->Write( text, m_autoSaveInterval );
    }
}


@@ -182,9 +247,6 @@ void EDA_BASE_FRAME::PrintMsg( const wxString& text )
}


/*
 * Display a bargraph (0 to 50 point length) for a PerCent value from 0 to 100
 */
void EDA_BASE_FRAME::DisplayActivity( int PerCent, const wxString& Text )
{
    wxString Line;
@@ -194,6 +256,7 @@ void EDA_BASE_FRAME::DisplayActivity( int PerCent, const wxString& Text )
    PerCent  = (PerCent < 0) ? 0 : PerCent;
    PerCent  = (PerCent > 100) ? 100 : PerCent;
    PerCent /= 2;   // Bargraph is 0 .. 50 points from 0% to 100%

    if( PerCent )
        Line.Pad( PerCent, '*' );

@@ -201,13 +264,11 @@ void EDA_BASE_FRAME::DisplayActivity( int PerCent, const wxString& Text )
}


/*
 * Update the list of recent opened files.
 */
void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName,
                                        wxFileHistory * aFileHistory )
{
    wxFileHistory * fileHistory = aFileHistory;

    if( fileHistory == NULL )
        fileHistory = & wxGetApp().m_fileHistory;

@@ -215,28 +276,26 @@ void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName,
}


/*
 * Fetch the file name from the file history list.
 */
wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
                                             wxFileHistory * aFileHistory )
{
    wxString fn, msg;
    size_t   i;
    wxFileHistory * fileHistory = aFileHistory;

    if( fileHistory == NULL )
        fileHistory = & wxGetApp().m_fileHistory;

    int baseId = fileHistory->GetBaseId();

    wxASSERT( cmdId >= baseId
              && cmdId < baseId + ( int )fileHistory->GetCount() );
    wxASSERT( cmdId >= baseId && cmdId < baseId + ( int )fileHistory->GetCount() );

    i = ( size_t )( cmdId - baseId );

    if( i < fileHistory->GetCount() )
    {
        fn = fileHistory->GetHistoryFile( i );

        if( !wxFileName::FileExists( fn ) )
        {
            msg = type + _( " file <" ) + fn + _( "> was not found." );
@@ -250,9 +309,6 @@ wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
}


/*
 *
 */
void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
{
    wxString msg;
@@ -269,6 +325,7 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
        wxString tmp = wxGetApp().m_HelpFileName;
        wxGetApp().m_HelpFileName = wxT( "Getting_Started_in_KiCad.pdf" );
        wxString helpFile = wxGetApp().GetHelpFile();

        if( !helpFile )
        {
            msg.Printf( _( "Help file %s could not be found." ),
@@ -276,7 +333,10 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
            DisplayError( this, msg );
        }
        else
        {
            GetAssociatedDocument( this, helpFile );
        }

        wxGetApp().m_HelpFileName = tmp;
        return;
    }
@@ -302,6 +362,7 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )

#elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
    wxString helpFile = wxGetApp().GetHelpFile();

    if( !helpFile )
    {
        msg.Printf( _( "Help file %s could not be found." ),
@@ -309,19 +370,16 @@ void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
        DisplayError( this, msg );
    }
    else
    {
        GetAssociatedDocument( this, helpFile );
    }

#else
#   error Help files format not defined
#endif
}

/*
 * Function OnSelectPreferredEditor
 * Open a dialog to select the preferred editor that will be used in KiCad
 * to edit or display files (reports ... )
 * The full filename editor is saved in configuration (global params)
 */

void EDA_BASE_FRAME::OnSelectPreferredEditor( wxCommandEvent& event )
{
    wxFileName fn = wxGetApp().m_EditorName;
@@ -333,7 +391,7 @@ void EDA_BASE_FRAME::OnSelectPreferredEditor( wxCommandEvent& event )

    wildcard = _( "Executable file (" ) + wildcard + wxT( ")|" ) + wildcard;

    wxFileDialog dlg( this, _( "Select Prefered Editor" ), fn.GetPath(),
    wxFileDialog dlg( this, _( "Select Preferred Editor" ), fn.GetPath(),
                      fn.GetFullName(), wildcard,
                      wxFD_OPEN | wxFD_FILE_MUST_EXIST );

@@ -348,9 +406,6 @@ void EDA_BASE_FRAME::OnSelectPreferredEditor( wxCommandEvent& event )
}


/*
 *
 */
void EDA_BASE_FRAME::GetKicadAbout( wxCommandEvent& event )
{
    bool ShowAboutDialog(wxWindow * parent);
+26 −1
Original line number Diff line number Diff line
/*
 * 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 drawpanel.cpp
 */
@@ -841,7 +866,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
    if( !IsMouseCaptured() )          // No mouse capture in progress.
        m_AutoPAN_Request = false;

    if( GetParent()->m_FrameIsActive )
    if( GetParent()->IsActive() )
        SetFocus();
    else
        return;
+29 −7
Original line number Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////
// Name:        dialog_svg_print.cpp
// Author:      jean-pierre Charras
// Modified by:
// Licence: GPL
/////////////////////////////////////////////////////////////////////////////
/*
 * 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 dialog_SVG_print.cpp
 */

#include "fctsys.h"
#include "appl_wxstruct.h"
@@ -100,7 +122,7 @@ void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref )

    SCH_SCREEN* screen = (SCH_SCREEN*) m_Parent->GetScreen();

    if( aPrintAll && m_Parent->m_Ident == SCHEMATIC_FRAME )
    if( aPrintAll && m_Parent->IsType( SCHEMATIC_FRAME ) )
    {
        SCH_EDIT_FRAME*  schframe = (SCH_EDIT_FRAME*) m_Parent;
        SCH_SHEET_PATH*  sheetpath, * oldsheetpath = schframe->GetSheet();
+29 −4
Original line number Diff line number Diff line
/***************/
/* lib_pin.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) 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 lib_pin.cpp
 */

#include "fctsys.h"
#include "appl_wxstruct.h"
@@ -804,7 +829,7 @@ void LIB_PIN::drawGraphic( EDA_DRAW_PANEL* aPanel,
        if( aPanel && aPanel->GetParent() )
            frame = (EDA_DRAW_FRAME*)aPanel->GetParent();

        if( frame && frame->m_Ident == SCHEMATIC_FRAME &&
        if( frame && frame->IsType( SCHEMATIC_FRAME ) &&
            ! ((SCH_EDIT_FRAME*)frame)->m_ShowAllPins )
            return;

Loading