2013-09-14 20:33:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jean-pierre.charras
|
|
|
|
* 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 cfg.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <id.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <param_config.h>
|
2013-05-31 17:33:46 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2013-09-14 20:33:22 +00:00
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <confirm.h>
|
2013-05-31 17:33:46 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cvpcb.h>
|
|
|
|
#include <cvpcb_mainframe.h>
|
2013-10-13 16:29:20 +00:00
|
|
|
#include <class_DisplayFootprintsFrame.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
#define GROUP wxT("/cvpcb")
|
|
|
|
#define GROUPLIB wxT("/pcbnew/libraries")
|
|
|
|
#define GROUPEQU wxT("/cvpcb/libraries")
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
PARAM_CFG_ARRAY& CVPCB_MAINFRAME::GetProjectFileParameters( void )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
if( !m_projectFileParams.empty() )
|
2009-04-23 15:02:18 +00:00
|
|
|
return m_projectFileParams;
|
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
m_projectFileParams.push_back( new PARAM_CFG_BASE( GROUPLIB,
|
|
|
|
PARAM_COMMAND_ERASE ) );
|
|
|
|
m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ),
|
|
|
|
&m_ModuleLibNames,
|
|
|
|
GROUPLIB ) );
|
|
|
|
m_projectFileParams.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "EquName" ),
|
|
|
|
&m_AliasLibNames,
|
|
|
|
GROUPEQU ) );
|
|
|
|
m_projectFileParams.push_back( new PARAM_CFG_WXSTRING( wxT( "NetIExt" ),
|
|
|
|
&m_NetlistFileExtension ) );
|
2011-02-26 08:35:22 +00:00
|
|
|
m_projectFileParams.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ),
|
2009-05-21 17:42:42 +00:00
|
|
|
&m_UserLibraryPath,
|
|
|
|
GROUPLIB ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
|
|
|
return m_projectFileParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-08-24 19:44:05 +00:00
|
|
|
wxFileName fn = aFileName;
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
m_ModuleLibNames.Clear();
|
|
|
|
m_AliasLibNames.Clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fn.GetExt() != ProjectFileExtension )
|
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
wxGetApp().RemoveLibraryPath( m_UserLibraryPath );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters(), false );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( m_NetlistFileExtension.IsEmpty() )
|
|
|
|
m_NetlistFileExtension = wxT( "net" );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
// User library path takes precedent over default library search paths.
|
2009-04-23 15:02:18 +00:00
|
|
|
wxGetApp().InsertLibraryPath( m_UserLibraryPath, 1 );
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
#if defined( USE_FP_LIB_TABLE )
|
|
|
|
delete m_footprintLibTable;
|
|
|
|
|
|
|
|
// Attempt to load the project footprint library table if it exists.
|
|
|
|
m_footprintLibTable = new FP_LIB_TABLE();
|
|
|
|
|
2013-10-13 16:29:20 +00:00
|
|
|
if( m_DisplayFootprintFrame )
|
|
|
|
m_DisplayFootprintFrame->SetFootprintLibTable( m_footprintLibTable );
|
|
|
|
|
|
|
|
wxFileName projectFpLibTableFileName;
|
|
|
|
|
|
|
|
projectFpLibTableFileName = FP_LIB_TABLE::GetProjectFileName( fn );
|
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
try
|
|
|
|
{
|
2013-10-13 16:29:20 +00:00
|
|
|
m_footprintLibTable->Load( projectFpLibTableFileName, m_globalFootprintTable );
|
|
|
|
FP_LIB_TABLE::SetProjectPathEnvVariable( projectFpLibTableFileName );
|
2013-09-14 20:33:22 +00:00
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
}
|
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
void CVPCB_MAINFRAME::SaveProjectFile( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-08-24 19:44:05 +00:00
|
|
|
wxFileName fn = m_NetlistFileName;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
fn.SetExt( ProjectFileExtension );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( aEvent.GetId() == ID_SAVE_PROJECT_AS || !m_NetlistFileName.IsOk() )
|
|
|
|
{
|
|
|
|
wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(),
|
|
|
|
wxEmptyString, ProjectFileWildcard, wxFD_SAVE );
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
fn = dlg.GetPath();
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( !fn.HasExt() )
|
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
}
|
2008-03-04 04:22:27 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( !IsWritable( fn ) )
|
2008-03-04 04:22:27 +00:00
|
|
|
return;
|
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
wxGetApp().WriteProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters() );
|
2008-03-04 04:22:27 +00:00
|
|
|
}
|