Initial global footprint library table fixes.
Fix bug when pcbnew is launched from a folder containing an existing fp-lib-table file by using same method as setting the initial global symbol library table. Fixes lp:1810169 https://bugs.launchpad.net/kicad/+bug/1810169 Fixes lp:1738871 https://bugs.launchpad.net/kicad/+bug/1738871
This commit is contained in:
parent
2dcba4723d
commit
b13efdb0f2
|
@ -100,6 +100,7 @@ set( PCBNEW_DIALOGS
|
|||
dialogs/dialog_global_edit_tracks_and_vias_base.cpp
|
||||
dialogs/dialog_global_edit_text_and_graphics.cpp
|
||||
dialogs/dialog_global_edit_text_and_graphics_base.cpp
|
||||
dialogs/dialog_global_fp_lib_table_config.cpp
|
||||
dialogs/dialog_push_pad_properties.cpp
|
||||
dialogs/dialog_push_pad_properties_base.cpp
|
||||
dialogs/dialog_graphic_item_properties.cpp
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2019 Wayne Stambaugh <stambaughw@gmail.com>
|
||||
* Copyright (C) 2019 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dialog_global_fp_lib_table_config.h"
|
||||
|
||||
#include <confirm.h>
|
||||
#include <kiface_i.h>
|
||||
#include <macros.h>
|
||||
|
||||
#include "fp_lib_table.h"
|
||||
|
||||
|
||||
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG( wxWindow* aParent ) :
|
||||
DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, "footprint" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::~DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
wxFileName DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::GetGlobalTableFileName()
|
||||
{
|
||||
return FP_LIB_TABLE::GetGlobalTableFileName();
|
||||
}
|
||||
|
||||
|
||||
bool DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow()
|
||||
{
|
||||
// Create an empty table if requested by the user.
|
||||
if( m_emptyRb->GetValue() )
|
||||
{
|
||||
FP_LIB_TABLE emptyTable;
|
||||
|
||||
try
|
||||
{
|
||||
emptyTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this,
|
||||
wxString::Format( _( "Error occurred writing empty footprint library "
|
||||
"table file.\n\n%s" ),
|
||||
FP_LIB_TABLE::GetGlobalTableFileName(),
|
||||
ioe.What() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
wxString fileName = m_filePicker1->GetPath();
|
||||
|
||||
if( fileName.IsEmpty() )
|
||||
{
|
||||
DisplayError( this, _( "Please select a footprint library table file." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
wxFileName fn = fileName;
|
||||
|
||||
// Make sure the footprint library table to copy actually exists.
|
||||
if( !fn.FileExists() )
|
||||
{
|
||||
DisplayError( this,
|
||||
wxString::Format( _( "File \"%s\" not found." ), fn.GetFullPath() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the footprint library table to copy is a valid footprint library table file.
|
||||
FP_LIB_TABLE tmpTable;
|
||||
|
||||
try
|
||||
{
|
||||
tmpTable.Load( fn.GetFullPath() );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this,
|
||||
wxString::Format( _( "File \"%s\" is not a valid footprint library table "
|
||||
"file.\n\n%s" ), fn.GetFullPath(), ioe.What() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the config path if it doesn't already exist.
|
||||
wxFileName fpTableFileName = FP_LIB_TABLE::GetGlobalTableFileName();
|
||||
|
||||
if( !fpTableFileName.DirExists() && !fpTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
|
||||
{
|
||||
DisplayError( this,
|
||||
wxString::Format( _( "Cannot create global library table path \"%s\"." ),
|
||||
fpTableFileName.GetPath() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the global footprint library table file to the user config.
|
||||
if( !::wxCopyFile( fn.GetFullPath(), fpTableFileName.GetFullPath() ) )
|
||||
{
|
||||
DisplayError( this,
|
||||
wxString::Format( _( "Cannot copy global footprint library table "
|
||||
"file:\n\n \"%s\"\n\n:to:\n\n\"%s\"." ),
|
||||
fn.GetFullPath(), fpTableFileName.GetFullPath() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the successfully copied footprint library table file. This should not fail
|
||||
// since the file was tested above. Check for failure anyway to keep the compiler
|
||||
// from complaining.
|
||||
try
|
||||
{
|
||||
if( !FP_LIB_TABLE::LoadGlobalTable( GFootprintTable ) )
|
||||
return false;
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
DisplayError( this,
|
||||
wxString::Format( _( "Error occurred loading global footprint library table:"
|
||||
"\n\n%s" ), ioe.What() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2019 Wayne Stambaugh <stambaughw@gmail.com>
|
||||
* Copyright (C) 2019 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG_H_
|
||||
#define _DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG_H_
|
||||
|
||||
#include "dialog_global_lib_table_config.h"
|
||||
|
||||
|
||||
class DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG : public DIALOG_GLOBAL_LIB_TABLE_CONFIG
|
||||
{
|
||||
public:
|
||||
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG( wxWindow* aParent );
|
||||
virtual ~DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG();
|
||||
|
||||
bool TransferDataFromWindow() override;
|
||||
|
||||
virtual wxFileName GetGlobalTableFileName() override;
|
||||
};
|
||||
|
||||
#endif // _DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG_H_
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2019 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
|
||||
|
@ -62,6 +62,7 @@
|
|||
#include <footprint_info_impl.h>
|
||||
#include <gl_context_mgr.h>
|
||||
#include "invoke_pcb_dialog.h"
|
||||
#include "dialog_global_fp_lib_table_config.h"
|
||||
|
||||
extern bool IsWxPythonLoaded();
|
||||
|
||||
|
@ -233,7 +234,7 @@ static bool scriptingSetup()
|
|||
kipython = fn.GetPath();
|
||||
|
||||
// If our python install is existing inside kicad, use it
|
||||
// Note: this is usefull only when another python version is installed
|
||||
// Note: this is useful only when another python version is installed
|
||||
if( wxDirExists( kipython ) )
|
||||
{
|
||||
// clear any PYTHONPATH and PYTHONHOME env var definition: the default
|
||||
|
@ -343,38 +344,37 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits )
|
|||
// display the real hotkeys in menus or tool tips
|
||||
ReadHotkeyConfig( PCB_EDIT_FRAME_NAME, g_Board_Editor_Hotkeys_Descr );
|
||||
|
||||
wxFileName fn = FP_LIB_TABLE::GetGlobalTableFileName();
|
||||
|
||||
if( !fn.FileExists() )
|
||||
{
|
||||
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG fpDialog( NULL );
|
||||
|
||||
fpDialog.ShowModal();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// The global table is not related to a specific project. All projects
|
||||
// will use the same global table. So the KIFACE::OnKifaceStart() contract
|
||||
// of avoiding anything project specific is not violated here.
|
||||
|
||||
if( !FP_LIB_TABLE::LoadGlobalTable( GFootprintTable ) )
|
||||
{
|
||||
DisplayInfoMessage( NULL, _(
|
||||
"You have run Pcbnew for the first time using the "
|
||||
"new footprint library table method for finding footprints.\n"
|
||||
"Pcbnew has either copied the default "
|
||||
"table or created an empty table in the kicad configuration folder.\n"
|
||||
"You must first configure the library "
|
||||
"table to include all footprint libraries you want to use.\n"
|
||||
"See the \"Footprint Library Table\" section of "
|
||||
"the CvPcb or Pcbnew documentation for more information." ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
// if we are here, a incorrect global footprint library table was found.
|
||||
// Incorrect global footprint library table is not a fatal error:
|
||||
// Incorrect global symbol library table is not a fatal error:
|
||||
// the user just has to edit the (partially) loaded table.
|
||||
|
||||
wxString msg = _(
|
||||
"An error occurred attempting to load the global footprint library table:\n"
|
||||
"Please edit this global footprint library table in Preferences menu"
|
||||
"An error occurred attempting to load the global footprint library table.\n"
|
||||
"Please edit this global symbol library table in Preferences menu."
|
||||
);
|
||||
|
||||
DisplayErrorMessage( NULL, msg, ioe.What() );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( KICAD_SCRIPTING )
|
||||
scriptingSetup();
|
||||
|
|
Loading…
Reference in New Issue