From 7bf9f8e1c71ff9edfb5f53b6cf79d37c74a84f4c Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 4 Aug 2017 14:46:28 -0400 Subject: [PATCH] Eeschema: add global symbol library configuration dialog. Create a dialog to give the user options to configure the global symbol library table the first time Eeschema is run when no global symbol library table exists. --- eeschema/CMakeLists.txt | 2 + .../dialog_global_sym_lib_table_config.cpp | 167 ++++ .../dialog_global_sym_lib_table_config.h | 42 + ...ialog_global_sym_lib_table_config_base.cpp | 88 ++ ...ialog_global_sym_lib_table_config_base.fbp | 756 ++++++++++++++++++ .../dialog_global_sym_lib_table_config_base.h | 63 ++ eeschema/eeschema.cpp | 62 +- eeschema/symbol_lib_table.h | 6 +- 8 files changed, 1155 insertions(+), 31 deletions(-) create mode 100644 eeschema/dialogs/dialog_global_sym_lib_table_config.cpp create mode 100644 eeschema/dialogs/dialog_global_sym_lib_table_config.h create mode 100644 eeschema/dialogs/dialog_global_sym_lib_table_config_base.cpp create mode 100644 eeschema/dialogs/dialog_global_sym_lib_table_config_base.fbp create mode 100644 eeschema/dialogs/dialog_global_sym_lib_table_config_base.h diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index d88d29fad9..b4ed4a4ab1 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -72,6 +72,8 @@ set( EESCHEMA_DLGS dialogs/dialog_schematic_find_base.cpp dialogs/dialog_symbol_remap.cpp dialogs/dialog_symbol_remap_base.cpp + dialogs/dialog_global_sym_lib_table_config.cpp + dialogs/dialog_global_sym_lib_table_config_base.cpp ) set( EESCHEMA_WIDGETS diff --git a/eeschema/dialogs/dialog_global_sym_lib_table_config.cpp b/eeschema/dialogs/dialog_global_sym_lib_table_config.cpp new file mode 100644 index 0000000000..e30d264bc2 --- /dev/null +++ b/eeschema/dialogs/dialog_global_sym_lib_table_config.cpp @@ -0,0 +1,167 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 Wayne Stambaugh + * Copyright (C) 2017 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 . + */ + +#include "dialog_global_sym_lib_table_config.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include "symbol_lib_table.h" + + +DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG( wxWindow* aParent ) : + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE( aParent ) +{ + wxFileName fn = SYMBOL_LIB_TABLE::GetGlobalTableFileName(); + + // Attempt to find the default global file table from the KiCad template folder. + wxString fileName = Kiface().KifaceSearch().FindValidPath( fn.GetName() ); + + m_defaultFileFound = wxFileName::FileExists( fileName ); + m_filePicker1->SetFileName( wxFileName( fileName ) ); + + wxButton* okButton = (wxButton *) FindWindowById( wxID_OK ); + + if( okButton ) + okButton->SetDefault(); + + FinishDialogSettings(); +} + + +DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::~DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG() +{ +} + + +void DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::onUpdateFilePicker( wxUpdateUIEvent& aEvent ) +{ + aEvent.Enable( m_customRb->GetValue() ); +} + + +void DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::onUpdateDefaultSelection( wxUpdateUIEvent& aEvent ) +{ + aEvent.Enable( m_defaultFileFound ); +} + + +bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow() +{ + // Create an empty table if requested by the user. + if( m_emptyRb->GetValue() ) + { + SYMBOL_LIB_TABLE emptyTable; + + try + { + emptyTable.Save( SYMBOL_LIB_TABLE::GetGlobalTableFileName() ); + } + catch( const IO_ERROR& ioe ) + { + DisplayError( this, + wxString::Format( _( "Error occurred writing empty symbol library table " + "file.\n\n%s" ), + SYMBOL_LIB_TABLE::GetGlobalTableFileName(), + ioe.What() ) ); + return false; + } + + return true; + } + + wxString fileName = m_filePicker1->GetPath(); + + if( fileName.IsEmpty() ) + { + DisplayError( this, _( "Please select a symbol library table file." ) ); + return false; + } + + wxFileName fn = fileName; + + // Make sure the symbol library table to copy actually exists. + if( !fn.FileExists() ) + { + DisplayError( this, + wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) ); + return false; + } + + // Make sure the symbol library table to copy is a valid symbol library table file. + SYMBOL_LIB_TABLE tmpTable; + + try + { + tmpTable.Load( fn.GetFullPath() ); + } + catch( const IO_ERROR& ioe ) + { + DisplayError( this, + wxString::Format( _( "File '%s' is not a valid symbol library table " + "file.\n\n%s" ), fn.GetFullPath(), ioe.What() ) ); + return false; + } + + // Create the config path if it doesn't already exist. + wxFileName symTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName(); + + if( !symTableFileName.DirExists() && !symTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) ) + { + DisplayError( this, + wxString::Format( _( "Cannot create global library table path '%s'." ), + symTableFileName.GetPath() ) ); + return false; + } + + // Copy the global symbol library table file to the user config. + if( !::wxCopyFile( fn.GetFullPath(), symTableFileName.GetFullPath() ) ) + { + DisplayError( this, + wxString::Format( _( "Cannot copy global symbol library table " + "file:\n\n '%s'\n\n:to:\n\n%s." ), + fn.GetFullPath(), symTableFileName.GetFullPath() ) ); + return false; + } + + // Load the successfully copied symbol 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( !SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE::GetGlobalLibTable() ) ) + return false; + } + catch( const IO_ERROR& ioe ) + { + DisplayError( this, + wxString::Format( _( "Error occurred loading global symbol library table:" + "\n\n%s" ), ioe.What() ) ); + return false; + } + + return true; +} diff --git a/eeschema/dialogs/dialog_global_sym_lib_table_config.h b/eeschema/dialogs/dialog_global_sym_lib_table_config.h new file mode 100644 index 0000000000..96aad17223 --- /dev/null +++ b/eeschema/dialogs/dialog_global_sym_lib_table_config.h @@ -0,0 +1,42 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 Wayne Stambaugh + * Copyright (C) 2017 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 . + */ + +#ifndef _DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_H_ +#define _DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_H_ + +#include "dialog_global_sym_lib_table_config_base.h" + +class DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG : public DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE +{ +private: + bool m_defaultFileFound; + +public: + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG( wxWindow* aParent ); + virtual ~DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG(); + + bool TransferDataFromWindow() override; + +protected: + virtual void onUpdateFilePicker( wxUpdateUIEvent& aEvent ) override; + virtual void onUpdateDefaultSelection( wxUpdateUIEvent& aEvent ) override; +}; + +#endif // _DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_H_ diff --git a/eeschema/dialogs/dialog_global_sym_lib_table_config_base.cpp b/eeschema/dialogs/dialog_global_sym_lib_table_config_base.cpp new file mode 100644 index 0000000000..a456520bbd --- /dev/null +++ b/eeschema/dialogs/dialog_global_sym_lib_table_config_base.cpp @@ -0,0 +1,88 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jul 29 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_global_sym_lib_table_config_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE::DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizer1; + bSizer1 = new wxBoxSizer( wxHORIZONTAL ); + + wxBoxSizer* bSizer2; + bSizer2 = new wxBoxSizer( wxVERTICAL ); + + m_staticText1 = new wxStaticText( this, wxID_ANY, _("KiCad has been run for the first time using the new symbol library table for accessing symbol libraries. In order for KiCad to access symbol libraries, you must configure your global symbol library table. Please select from one of the options below. If you are not sure which option to select, please use the default selection."), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText1->Wrap( 500 ); + bSizer2->Add( m_staticText1, 0, wxALL, 5 ); + + + bSizer2->Add( 0, 0, 0, wxALL|wxEXPAND, 5 ); + + m_defaultRb = new wxRadioButton( this, wxID_ANY, _("Copy default global symbol library table (recommended)"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); + m_defaultRb->SetValue( true ); + m_defaultRb->SetToolTip( _("Select this option if you not sure about configuring the global symbol library table") ); + + bSizer2->Add( m_defaultRb, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); + + m_customRb = new wxRadioButton( this, wxID_ANY, _("Copy custom global symbol library table"), wxDefaultPosition, wxDefaultSize, 0 ); + m_customRb->SetToolTip( _("Select this option to copy a symbol library table file other than the default") ); + + bSizer2->Add( m_customRb, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); + + m_emptyRb = new wxRadioButton( this, wxID_ANY, _("Create an empty global symbol library table"), wxDefaultPosition, wxDefaultSize, 0 ); + m_emptyRb->SetToolTip( _("Select this option to define symbol libraries in project specific library tables") ); + + bSizer2->Add( m_emptyRb, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); + + + bSizer2->Add( 0, 0, 0, wxALL|wxEXPAND, 5 ); + + m_staticText2 = new wxStaticText( this, wxID_ANY, _("Select global symbol library table file:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText2->Wrap( -1 ); + bSizer2->Add( m_staticText2, 0, wxALL, 5 ); + + m_filePicker1 = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Select a file"), wxT("*.*"), wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN ); + m_filePicker1->Enable( false ); + + bSizer2->Add( m_filePicker1, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); + + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bSizer2->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); + + m_sdbSizer1 = new wxStdDialogButtonSizer(); + m_sdbSizer1OK = new wxButton( this, wxID_OK ); + m_sdbSizer1->AddButton( m_sdbSizer1OK ); + m_sdbSizer1->Realize(); + + bSizer2->Add( m_sdbSizer1, 1, wxEXPAND, 5 ); + + + bSizer1->Add( bSizer2, 1, wxALL|wxEXPAND, 5 ); + + + this->SetSizer( bSizer1 ); + this->Layout(); + bSizer1->Fit( this ); + + this->Centre( wxBOTH ); + + // Connect Events + m_defaultRb->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE::onUpdateDefaultSelection ), NULL, this ); + m_filePicker1->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE::onUpdateFilePicker ), NULL, this ); +} + +DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE::~DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE() +{ + // Disconnect Events + m_defaultRb->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE::onUpdateDefaultSelection ), NULL, this ); + m_filePicker1->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE::onUpdateFilePicker ), NULL, this ); + +} diff --git a/eeschema/dialogs/dialog_global_sym_lib_table_config_base.fbp b/eeschema/dialogs/dialog_global_sym_lib_table_config_base.fbp new file mode 100644 index 0000000000..d6d5b08523 --- /dev/null +++ b/eeschema/dialogs/dialog_global_sym_lib_table_config_base.fbp @@ -0,0 +1,756 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_global_sym_lib_table_config_base + 1000 + none + 1 + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE + + + wxCAPTION|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Configure Global Symbol Library Table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizer1 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + + bSizer2 + wxVERTICAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + KiCad has been run for the first time using the new symbol library table for accessing symbol libraries. In order for KiCad to access symbol libraries, you must configure your global symbol library table. Please select from one of the options below. If you are not sure which option to select, please use the default selection. + + 0 + + + 0 + + 1 + m_staticText1 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + 500 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 0 + protected + 0 + + + + 5 + wxBOTTOM|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Copy default global symbol library table (recommended) + + 0 + + + 0 + + 1 + m_defaultRb + 1 + + + protected + 1 + + Resizable + 1 + + wxRB_GROUP + + 0 + Select this option if you not sure about configuring the global symbol library table + + wxFILTER_NONE + wxDefaultValidator + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + onUpdateDefaultSelection + + + + 5 + wxBOTTOM|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Copy custom global symbol library table + + 0 + + + 0 + + 1 + m_customRb + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + Select this option to copy a symbol library table file other than the default + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxBOTTOM|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Create an empty global symbol library table + + 0 + + + 0 + + 1 + m_emptyRb + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + Select this option to define symbol libraries in project specific library tables + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + 0 + protected + 0 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Select global symbol library table file: + + 0 + + + 0 + + 1 + m_staticText2 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + Select a file + + 0 + + 1 + m_filePicker1 + 1 + + + protected + 1 + + Resizable + 1 + + wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + *.* + + + + + + + + + + + + + + + + + + + + + + + + + + + onUpdateFilePicker + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer1 + protected + + + + + + + + + + + + + + + + diff --git a/eeschema/dialogs/dialog_global_sym_lib_table_config_base.h b/eeschema/dialogs/dialog_global_sym_lib_table_config_base.h new file mode 100644 index 0000000000..1583699fcd --- /dev/null +++ b/eeschema/dialogs/dialog_global_sym_lib_table_config_base.h @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jul 29 2017) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE_H__ +#define __DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE_H__ + +#include +#include +#include +class DIALOG_SHIM; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticText* m_staticText1; + wxRadioButton* m_defaultRb; + wxRadioButton* m_customRb; + wxRadioButton* m_emptyRb; + wxStaticText* m_staticText2; + wxFilePickerCtrl* m_filePicker1; + wxStaticLine* m_staticline1; + wxStdDialogButtonSizer* m_sdbSizer1; + wxButton* m_sdbSizer1OK; + + // Virtual event handlers, overide them in your derived class + virtual void onUpdateDefaultSelection( wxUpdateUIEvent& event ) { event.Skip(); } + virtual void onUpdateFilePicker( wxUpdateUIEvent& event ) { event.Skip(); } + + + public: + + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Configure Global Symbol Library Table"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAPTION|wxRESIZE_BORDER ); + ~DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE(); + +}; + +#endif //__DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG_BASE_H__ diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 768deb21d6..44c1668a06 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2008-2011 Wayne Stambaugh - * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2008 Wayne Stambaugh + * Copyright (C) 2004-2017 KiCad Developers, see change_log.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 @@ -46,6 +46,7 @@ #include #include #include +#include "dialogs/dialog_global_sym_lib_table_config.h" #include #include @@ -244,35 +245,36 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) wxConfigLoadSetups( KifaceSettings(), cfg_params() ); - 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( !SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE::GetGlobalLibTable() ) ) - { - DisplayInfoMessage( NULL, _( - "You have run Eeschema for the first time using the new symbol library table " - "method for finding symbols.\n\n" - "Eeschema has either copied the default table or created an empty table in the " - "kicad configuration folder.\n\n" - "You must first configure the library table to include all symbol libraries you " - "want to use.\n\n" - "See the \"Symbol Library Table\" section of Eeschema documentation for more " - "information." ) ); - } - } - catch( const IO_ERROR& ioe ) - { - // if we are here, a incorrect global symbol library table was found. - // 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 symbol library table.\n" - "Please edit this global symbol library table in Preferences menu" - ); + wxFileName fn = SYMBOL_LIB_TABLE::GetGlobalTableFileName(); - DisplayErrorMessage( NULL, msg, ioe.What() ); + if( !fn.FileExists() ) + { + DIALOG_GLOBAL_SYM_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( !SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE::GetGlobalLibTable() ) ) + return false; + } + catch( const IO_ERROR& ioe ) + { + // if we are here, a incorrect global symbol library table was found. + // 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 symbol library table.\n" + "Please edit this global symbol library table in Preferences menu." + ); + + DisplayErrorMessage( NULL, msg, ioe.What() ); + } } return true; diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index e64ca7281e..f23f8870bc 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -27,8 +27,11 @@ #include #include +#include class LIB_PART; +class SYMBOL_LIB_TABLE_GRID; + /** * Hold a record identifying a symbol library accessed by the appropriate symbol library @@ -94,8 +97,9 @@ private: class SYMBOL_LIB_TABLE : public LIB_TABLE { -public: + friend class SYMBOL_LIB_TABLE_GRID; +public: virtual void Parse( LIB_TABLE_LEXER* aLexer ) override; virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;