diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index cef4c75dd5..a1bc1b0373 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -175,6 +175,7 @@ set( COMMON_WIDGET_SRCS
widgets/footprint_select_widget.cpp
widgets/gal_options_panel.cpp
widgets/grid_bitmap_toggle.cpp
+ widgets/grid_button.cpp
widgets/grid_color_swatch_helpers.cpp
widgets/grid_combobox.cpp
widgets/grid_icon_text_helpers.cpp
diff --git a/common/lib_table_grid_tricks.cpp b/common/lib_table_grid_tricks.cpp
index fec55799c7..59eb4ea3f3 100644
--- a/common/lib_table_grid_tricks.cpp
+++ b/common/lib_table_grid_tricks.cpp
@@ -51,7 +51,17 @@ void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
if( showDeactivate )
menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
- if( showActivate || showDeactivate )
+ bool showSettings = false;
+
+ if( m_sel_row_count == 1 && tbl->At( m_sel_row_start )->SupportsSettingsDialog() )
+ {
+ showSettings = true;
+ menu.Append( LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS,
+ wxString::Format( _( "Library settings for %s..." ),
+ tbl->GetValue( m_sel_row_start, 2 ) ) );
+ }
+
+ if( showActivate || showDeactivate || showSettings )
menu.AppendSeparator();
GRID_TRICKS::showPopupMenu( menu, aEvent );
@@ -61,12 +71,11 @@ void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
{
int menu_id = event.GetId();
+ LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
if( menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
|| menu_id == LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED )
{
- LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
-
bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
@@ -75,6 +84,12 @@ void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
// Ensure the new state (on/off) of the widgets is immediately shown:
m_grid->Refresh();
}
+ else if( menu_id == LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS )
+ {
+ LIB_TABLE_ROW* row = tbl->At( m_sel_row_start );
+ row->Refresh();
+ row->ShowSettingsDialog( m_grid->GetParent() );
+ }
else
{
GRID_TRICKS::doPopupSelection( event );
diff --git a/common/widgets/grid_button.cpp b/common/widgets/grid_button.cpp
new file mode 100644
index 0000000000..01119ef2fa
--- /dev/null
+++ b/common/widgets/grid_button.cpp
@@ -0,0 +1,53 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2023 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
+#include
+#include
+
+
+GRID_BUTTON_RENDERER::GRID_BUTTON_RENDERER( const wxString& aLabel ) :
+ wxGridCellRenderer(),
+ m_button( nullptr, wxID_ANY, aLabel )
+{
+}
+
+
+GRID_BUTTON_RENDERER* GRID_BUTTON_RENDERER::Clone() const
+{
+ GRID_BUTTON_RENDERER* clone = new GRID_BUTTON_RENDERER( m_button.GetLabel() );
+ return clone;
+}
+
+
+void GRID_BUTTON_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
+ const wxRect& aRect, int aRow, int aCol, bool aIsSelected )
+{
+ // erase background
+ wxGridCellRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected );
+
+ wxRendererNative::Get().DrawPushButton( &aGrid, aDc, aRect );
+}
+
+
+wxSize GRID_BUTTON_RENDERER::GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
+ int aRow, int aCol)
+{
+ return m_button.GetSize();
+}
diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index 7067946489..d5181d76b2 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -68,6 +68,8 @@ set( EESCHEMA_DLGS
dialogs/dialog_change_symbols.cpp
dialogs/dialog_change_symbols_base.cpp
dialogs/dialog_choose_symbol.cpp
+ dialogs/dialog_database_lib_settings_base.cpp
+ dialogs/dialog_database_lib_settings.cpp
dialogs/dialog_edit_symbols_libid.cpp
dialogs/dialog_edit_symbols_libid_base.cpp
dialogs/dialog_eeschema_page_settings.cpp
diff --git a/eeschema/dialogs/dialog_database_lib_settings.cpp b/eeschema/dialogs/dialog_database_lib_settings.cpp
new file mode 100644
index 0000000000..42af787a75
--- /dev/null
+++ b/eeschema/dialogs/dialog_database_lib_settings.cpp
@@ -0,0 +1,129 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2023 Jon Evans
+ * Copyright (C) 2023 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
+#include
+#include
+
+
+DIALOG_DATABASE_LIB_SETTINGS::DIALOG_DATABASE_LIB_SETTINGS( wxWindow* aParent,
+ SCH_DATABASE_PLUGIN* aPlugin ) :
+ DIALOG_DATABASE_LIB_SETTINGS_BASE( aParent ),
+ m_plugin( aPlugin )
+{
+ Layout();
+ SetupStandardButtons();
+ finishDialogSettings();
+}
+
+
+bool DIALOG_DATABASE_LIB_SETTINGS::TransferDataToWindow()
+{
+ wxCommandEvent dummy;
+ DATABASE_LIB_SETTINGS* settings = m_plugin->Settings();
+
+ m_txtConnectionString->SetValue( settings->m_Source.connection_string );
+
+ if( !settings->m_Source.connection_string.empty() )
+ {
+ m_rbConnectionString->SetValue( true );
+ OnConnectionStringSelected( dummy );
+ }
+ else
+ {
+ m_rbDSN->SetValue( true );
+ OnDSNSelected( dummy );
+ m_txtDSN->SetValue( settings->m_Source.dsn );
+ m_txtUser->SetValue( settings->m_Source.username );
+ m_txtPassword->SetValue( settings->m_Source.password );
+ }
+
+ m_spinCacheSize->SetValue( settings->m_Cache.max_size );
+ m_spinCacheTimeout->SetValue( settings->m_Cache.max_age );
+
+ if( hasPotentiallyValidConfig() )
+ OnBtnTest( dummy );
+
+ return true;
+}
+
+
+bool DIALOG_DATABASE_LIB_SETTINGS::TransferDataFromWindow()
+{
+ return true;
+}
+
+
+void DIALOG_DATABASE_LIB_SETTINGS::OnDSNSelected( wxCommandEvent& aEvent )
+{
+ m_txtConnectionString->Disable();
+ m_txtDSN->Enable();
+ m_txtUser->Enable();
+ m_txtPassword->Enable();
+}
+
+
+void DIALOG_DATABASE_LIB_SETTINGS::OnConnectionStringSelected( wxCommandEvent& aEvent )
+{
+ m_txtConnectionString->Enable();
+ m_txtDSN->Disable();
+ m_txtUser->Disable();
+ m_txtPassword->Disable();
+}
+
+
+void DIALOG_DATABASE_LIB_SETTINGS::OnBtnTest( wxCommandEvent& aEvent )
+{
+ wxString errorMsg;
+
+ if( m_plugin->TestConnection( &errorMsg ) )
+ {
+ m_stConnectionTestStatus->SetLabel( _( "Connected to database successfully" ) );
+
+ wxCommandEvent dummy;
+ OnBtnReloadConfig( dummy );
+ }
+ else
+ {
+ m_stConnectionTestStatus->SetLabel( wxString::Format( _( "Database connection failed: %s" ),
+ errorMsg ) );
+ }
+}
+
+
+void DIALOG_DATABASE_LIB_SETTINGS::OnBtnReloadConfig( wxCommandEvent& aEvent )
+{
+ if( !m_plugin->TestConnection() )
+ {
+ m_stLibrariesStatus->SetLabel( _( "No connection to database" ) );
+ return;
+ }
+
+ std::vector libs;
+ m_plugin->GetSubLibraryNames( libs );
+
+ m_stLibrariesStatus->SetLabel( wxString::Format( _( "Loaded %zu libraries" ), libs.size() ) );
+}
+
+
+bool DIALOG_DATABASE_LIB_SETTINGS::hasPotentiallyValidConfig()
+{
+ return ( m_rbDSN->GetValue() && !m_txtDSN->IsEmpty() ) || !m_txtConnectionString->IsEmpty();
+}
diff --git a/eeschema/dialogs/dialog_database_lib_settings.h b/eeschema/dialogs/dialog_database_lib_settings.h
new file mode 100644
index 0000000000..68a91e7222
--- /dev/null
+++ b/eeschema/dialogs/dialog_database_lib_settings.h
@@ -0,0 +1,50 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2023 Jon Evans
+ * Copyright (C) 2023 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 KICAD_DIALOG_DATABASE_LIB_SETTINGS_H
+#define KICAD_DIALOG_DATABASE_LIB_SETTINGS_H
+
+#include "dialog_database_lib_settings_base.h"
+
+class SCH_DATABASE_PLUGIN;
+
+class DIALOG_DATABASE_LIB_SETTINGS : public DIALOG_DATABASE_LIB_SETTINGS_BASE
+{
+public:
+ DIALOG_DATABASE_LIB_SETTINGS( wxWindow* aParent, SCH_DATABASE_PLUGIN* aPlugin );
+
+ virtual ~DIALOG_DATABASE_LIB_SETTINGS() {}
+
+ bool TransferDataFromWindow() override;
+ bool TransferDataToWindow() override;
+
+protected:
+ void OnDSNSelected( wxCommandEvent& aEvent ) override;
+ void OnConnectionStringSelected( wxCommandEvent& aEvent ) override;
+ void OnBtnTest( wxCommandEvent& aEvent ) override;
+ void OnBtnReloadConfig( wxCommandEvent& aEvent ) override;
+
+private:
+ bool hasPotentiallyValidConfig();
+
+ SCH_DATABASE_PLUGIN* m_plugin;
+};
+
+#endif //KICAD_DIALOG_DATABASE_LIB_SETTINGS_H
diff --git a/eeschema/dialogs/dialog_database_lib_settings_base.cpp b/eeschema/dialogs/dialog_database_lib_settings_base.cpp
new file mode 100644
index 0000000000..cf021657ae
--- /dev/null
+++ b/eeschema/dialogs/dialog_database_lib_settings_base.cpp
@@ -0,0 +1,201 @@
+///////////////////////////////////////////////////////////////////////////
+// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
+// http://www.wxformbuilder.org/
+//
+// PLEASE DO *NOT* EDIT THIS FILE!
+///////////////////////////////////////////////////////////////////////////
+
+#include "widgets/wx_infobar.h"
+
+#include "dialog_database_lib_settings_base.h"
+
+///////////////////////////////////////////////////////////////////////////
+
+DIALOG_DATABASE_LIB_SETTINGS_BASE::DIALOG_DATABASE_LIB_SETTINGS_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* bmainSizer;
+ bmainSizer = new wxBoxSizer( wxVERTICAL );
+
+ m_infoBar = new WX_INFOBAR( this );
+ m_infoBar->SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
+ m_infoBar->SetEffectDuration( 500 );
+ m_infoBar->Hide();
+
+ bmainSizer->Add( m_infoBar, 0, wxEXPAND|wxBOTTOM, 5 );
+
+ wxBoxSizer* bupperSizer;
+ bupperSizer = new wxBoxSizer( wxVERTICAL );
+
+ wxStaticBoxSizer* sbSizer4;
+ sbSizer4 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Connection") ), wxVERTICAL );
+
+ wxGridBagSizer* gbSizer2;
+ gbSizer2 = new wxGridBagSizer( 0, 0 );
+ gbSizer2->SetFlexibleDirection( wxBOTH );
+ gbSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
+
+ m_rbDSN = new wxRadioButton( sbSizer4->GetStaticBox(), wxID_ANY, _("DSN:"), wxDefaultPosition, wxDefaultSize, 0 );
+ gbSizer2->Add( m_rbDSN, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ m_txtDSN = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+ gbSizer2->Add( m_txtDSN, wxGBPosition( 0, 1 ), wxGBSpan( 1, 2 ), wxALL|wxEXPAND, 5 );
+
+ m_staticText2 = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Username:"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_staticText2->Wrap( -1 );
+ gbSizer2->Add( m_staticText2, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ m_txtUser = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+ m_txtUser->SetMinSize( wxSize( 150,-1 ) );
+
+ gbSizer2->Add( m_txtUser, wxGBPosition( 1, 2 ), wxGBSpan( 1, 1 ), wxALL|wxEXPAND, 5 );
+
+ m_staticText3 = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, _("Password:"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_staticText3->Wrap( -1 );
+ gbSizer2->Add( m_staticText3, wxGBPosition( 2, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ m_txtPassword = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+ m_txtPassword->SetMinSize( wxSize( 150,-1 ) );
+
+ gbSizer2->Add( m_txtPassword, wxGBPosition( 2, 2 ), wxGBSpan( 1, 1 ), wxALL|wxEXPAND, 5 );
+
+
+ gbSizer2->AddGrowableCol( 2 );
+
+ sbSizer4->Add( gbSizer2, 1, wxALL|wxEXPAND, 5 );
+
+ wxBoxSizer* bSizer4;
+ bSizer4 = new wxBoxSizer( wxVERTICAL );
+
+ m_rbConnectionString = new wxRadioButton( sbSizer4->GetStaticBox(), wxID_ANY, _("Connection String:"), wxDefaultPosition, wxDefaultSize, 0 );
+ bSizer4->Add( m_rbConnectionString, 0, wxALL, 5 );
+
+ m_txtConnectionString = new wxTextCtrl( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+ m_txtConnectionString->Enable( false );
+
+ bSizer4->Add( m_txtConnectionString, 0, wxALL|wxEXPAND, 5 );
+
+
+ sbSizer4->Add( bSizer4, 0, wxALL|wxEXPAND, 5 );
+
+ wxBoxSizer* bSizer5;
+ bSizer5 = new wxBoxSizer( wxHORIZONTAL );
+
+ m_btnTest = new wxButton( sbSizer4->GetStaticBox(), wxID_ANY, _("Test"), wxDefaultPosition, wxDefaultSize, 0 );
+ bSizer5->Add( m_btnTest, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ m_stConnectionTestStatus = new wxStaticText( sbSizer4->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+ m_stConnectionTestStatus->Wrap( -1 );
+ bSizer5->Add( m_stConnectionTestStatus, 1, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
+
+
+ sbSizer4->Add( bSizer5, 0, wxALL|wxEXPAND, 5 );
+
+
+ bupperSizer->Add( sbSizer4, 0, wxALL|wxEXPAND, 5 );
+
+ wxStaticBoxSizer* sbSizer2;
+ sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Libraries") ), wxHORIZONTAL );
+
+ wxBoxSizer* bSizer6;
+ bSizer6 = new wxBoxSizer( wxHORIZONTAL );
+
+ m_btnReloadConfig = new wxButton( sbSizer2->GetStaticBox(), wxID_ANY, _("Reload Configuration"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_btnReloadConfig->SetToolTip( _("Reload the database library configuration file") );
+
+ bSizer6->Add( m_btnReloadConfig, 0, wxALL, 5 );
+
+ m_stLibrariesStatus = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+ m_stLibrariesStatus->Wrap( -1 );
+ bSizer6->Add( m_stLibrariesStatus, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+
+ sbSizer2->Add( bSizer6, 1, wxALL|wxEXPAND, 5 );
+
+
+ bupperSizer->Add( sbSizer2, 0, wxALL|wxEXPAND, 5 );
+
+ wxStaticBoxSizer* sbSizer3;
+ sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Caching") ), wxVERTICAL );
+
+ wxFlexGridSizer* fgSizer1;
+ fgSizer1 = new wxFlexGridSizer( 0, 2, 0, 0 );
+ fgSizer1->SetFlexibleDirection( wxBOTH );
+ fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
+
+ m_staticText5 = new wxStaticText( sbSizer3->GetStaticBox(), wxID_ANY, _("Cache size:"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_staticText5->Wrap( -1 );
+ m_staticText5->SetToolTip( _("How many database queries to cache") );
+
+ fgSizer1->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ m_spinCacheSize = new wxSpinCtrl( sbSizer3->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 1024, 256 );
+ m_spinCacheSize->SetToolTip( _("How many database queries to cache") );
+
+ fgSizer1->Add( m_spinCacheSize, 0, wxALL, 5 );
+
+ m_staticText6 = new wxStaticText( sbSizer3->GetStaticBox(), wxID_ANY, _("Cache timeout:"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_staticText6->Wrap( -1 );
+ m_staticText6->SetToolTip( _("Time in seconds that database queries will be cached for") );
+
+ fgSizer1->Add( m_staticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+ m_spinCacheTimeout = new wxSpinCtrl( sbSizer3->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 600, 10 );
+ m_spinCacheTimeout->SetToolTip( _("Time in seconds that database queries will be cached for") );
+
+ fgSizer1->Add( m_spinCacheTimeout, 0, wxALL, 5 );
+
+
+ sbSizer3->Add( fgSizer1, 1, wxEXPAND, 5 );
+
+
+ bupperSizer->Add( sbSizer3, 1, wxALL|wxEXPAND, 5 );
+
+
+ bmainSizer->Add( bupperSizer, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 6 );
+
+ wxBoxSizer* m_buttonsSizer;
+ m_buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
+
+
+ m_buttonsSizer->Add( 0, 0, 1, wxEXPAND, 5 );
+
+ m_sdbSizer1 = new wxStdDialogButtonSizer();
+ m_sdbSizer1OK = new wxButton( this, wxID_OK );
+ m_sdbSizer1->AddButton( m_sdbSizer1OK );
+ m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
+ m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
+ m_sdbSizer1->Realize();
+
+ m_buttonsSizer->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 );
+
+
+ bmainSizer->Add( m_buttonsSizer, 0, wxEXPAND|wxLEFT, 5 );
+
+
+ this->SetSizer( bmainSizer );
+ this->Layout();
+
+ // Connect Events
+ this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnClose ) );
+ m_rbDSN->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnDSNSelected ), NULL, this );
+ m_rbConnectionString->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnConnectionStringSelected ), NULL, this );
+ m_btnTest->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnBtnTest ), NULL, this );
+ m_btnReloadConfig->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnBtnReloadConfig ), NULL, this );
+ m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnCloseClick ), NULL, this );
+ m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnApplyClick ), NULL, this );
+}
+
+DIALOG_DATABASE_LIB_SETTINGS_BASE::~DIALOG_DATABASE_LIB_SETTINGS_BASE()
+{
+ // Disconnect Events
+ this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnClose ) );
+ m_rbDSN->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnDSNSelected ), NULL, this );
+ m_rbConnectionString->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnConnectionStringSelected ), NULL, this );
+ m_btnTest->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnBtnTest ), NULL, this );
+ m_btnReloadConfig->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnBtnReloadConfig ), NULL, this );
+ m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnCloseClick ), NULL, this );
+ m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DATABASE_LIB_SETTINGS_BASE::OnApplyClick ), NULL, this );
+
+}
diff --git a/eeschema/dialogs/dialog_database_lib_settings_base.fbp b/eeschema/dialogs/dialog_database_lib_settings_base.fbp
new file mode 100644
index 0000000000..4b117c5725
--- /dev/null
+++ b/eeschema/dialogs/dialog_database_lib_settings_base.fbp
@@ -0,0 +1,1332 @@
+
+
+
+
+
diff --git a/eeschema/dialogs/dialog_database_lib_settings_base.h b/eeschema/dialogs/dialog_database_lib_settings_base.h
new file mode 100644
index 0000000000..f1189fe22c
--- /dev/null
+++ b/eeschema/dialogs/dialog_database_lib_settings_base.h
@@ -0,0 +1,84 @@
+///////////////////////////////////////////////////////////////////////////
+// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
+// http://www.wxformbuilder.org/
+//
+// PLEASE DO *NOT* EDIT THIS FILE!
+///////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+#include
+#include
+#include
+class WX_INFOBAR;
+
+#include "dialog_shim.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+///////////////////////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// Class DIALOG_DATABASE_LIB_SETTINGS_BASE
+///////////////////////////////////////////////////////////////////////////////
+class DIALOG_DATABASE_LIB_SETTINGS_BASE : public DIALOG_SHIM
+{
+ private:
+
+ protected:
+ WX_INFOBAR* m_infoBar;
+ wxRadioButton* m_rbDSN;
+ wxTextCtrl* m_txtDSN;
+ wxStaticText* m_staticText2;
+ wxTextCtrl* m_txtUser;
+ wxStaticText* m_staticText3;
+ wxTextCtrl* m_txtPassword;
+ wxRadioButton* m_rbConnectionString;
+ wxTextCtrl* m_txtConnectionString;
+ wxButton* m_btnTest;
+ wxButton* m_btnReloadConfig;
+ wxStaticText* m_staticText5;
+ wxSpinCtrl* m_spinCacheSize;
+ wxStaticText* m_staticText6;
+ wxSpinCtrl* m_spinCacheTimeout;
+ wxStdDialogButtonSizer* m_sdbSizer1;
+ wxButton* m_sdbSizer1OK;
+ wxButton* m_sdbSizer1Cancel;
+
+ // Virtual event handlers, override them in your derived class
+ virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
+ virtual void OnDSNSelected( wxCommandEvent& event ) { event.Skip(); }
+ virtual void OnConnectionStringSelected( wxCommandEvent& event ) { event.Skip(); }
+ virtual void OnBtnTest( wxCommandEvent& event ) { event.Skip(); }
+ virtual void OnBtnReloadConfig( wxCommandEvent& event ) { event.Skip(); }
+ virtual void OnCloseClick( wxCommandEvent& event ) { event.Skip(); }
+ virtual void OnApplyClick( wxCommandEvent& event ) { event.Skip(); }
+
+
+ public:
+ wxStaticText* m_stConnectionTestStatus;
+ wxStaticText* m_stLibrariesStatus;
+
+ DIALOG_DATABASE_LIB_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Database Library Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,600 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
+
+ ~DIALOG_DATABASE_LIB_SETTINGS_BASE();
+
+};
+
diff --git a/eeschema/sch_plugins/database/sch_database_plugin.cpp b/eeschema/sch_plugins/database/sch_database_plugin.cpp
index 7ea8f5de5a..7c72d19152 100644
--- a/eeschema/sch_plugins/database/sch_database_plugin.cpp
+++ b/eeschema/sch_plugins/database/sch_database_plugin.cpp
@@ -208,6 +208,20 @@ bool SCH_DATABASE_PLUGIN::CheckHeader( const wxString& aFileName )
}
+bool SCH_DATABASE_PLUGIN::TestConnection( wxString* aErrorMsg )
+{
+ if( m_conn && m_conn->IsConnected() )
+ return true;
+
+ connect();
+
+ if( aErrorMsg && m_conn && !m_conn->IsConnected() )
+ *aErrorMsg = m_conn->GetLastError();
+
+ return m_conn && m_conn->IsConnected();
+}
+
+
void SCH_DATABASE_PLUGIN::ensureSettings( const wxString& aSettingsPath )
{
auto tryLoad =
@@ -252,6 +266,24 @@ void SCH_DATABASE_PLUGIN::ensureConnection()
{
wxCHECK_RET( m_settings, "Call ensureSettings before ensureConnection!" );
+ connect();
+
+ if( !m_conn || !m_conn->IsConnected() )
+ {
+ wxString msg = wxString::Format(
+ _( "Could not load database library: could not connect to database %s (%s)" ),
+ m_settings->m_Source.dsn,
+ m_conn->GetLastError() );
+
+ THROW_IO_ERROR( msg );
+ }
+}
+
+
+void SCH_DATABASE_PLUGIN::connect()
+{
+ wxCHECK_RET( m_settings, "Call ensureSettings before connect()!" );
+
if( m_conn && !m_conn->IsConnected() )
m_conn.reset();
@@ -278,14 +310,8 @@ void SCH_DATABASE_PLUGIN::ensureConnection()
if( !m_conn->IsConnected() )
{
- wxString msg = wxString::Format(
- _( "Could not load database library: could not connect to database %s (%s)" ),
- m_settings->m_Source.dsn,
- m_conn->GetLastError() );
-
m_conn.reset();
-
- THROW_IO_ERROR( msg );
+ return;
}
m_conn->SetCacheParams( m_settings->m_Cache.max_size, m_settings->m_Cache.max_age );
diff --git a/eeschema/sch_plugins/database/sch_database_plugin.h b/eeschema/sch_plugins/database/sch_database_plugin.h
index 0c7b04873f..4241b64a58 100644
--- a/eeschema/sch_plugins/database/sch_database_plugin.h
+++ b/eeschema/sch_plugins/database/sch_database_plugin.h
@@ -94,11 +94,17 @@ public:
m_libTable = aTable;
}
+ DATABASE_LIB_SETTINGS* Settings() const { return m_settings.get(); }
+
+ bool TestConnection( wxString* aErrorMsg = nullptr );
+
private:
void ensureSettings( const wxString& aSettingsPath );
void ensureConnection();
+ void connect();
+
LIB_SYMBOL* loadSymbolFromRow( const wxString& aSymbolName,
const DATABASE_LIB_TABLE& aTable,
const DATABASE_CONNECTION::ROW& aRow );
diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp
index 612163cf2d..7f44d398ee 100644
--- a/eeschema/symbol_lib_table.cpp
+++ b/eeschema/symbol_lib_table.cpp
@@ -33,6 +33,8 @@
#include
#include
#include
+#include
+#include
#include
#include "sim/sim_model.h"
@@ -100,6 +102,19 @@ void SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames( std::vector& aNames ) c
}
+void SYMBOL_LIB_TABLE_ROW::ShowSettingsDialog( wxWindow* aParent ) const
+{
+ wxCHECK( plugin, /* void */ );
+
+ if( type != SCH_IO_MGR::SCH_DATABASE )
+ return;
+
+ DIALOG_DATABASE_LIB_SETTINGS dlg( aParent,
+ static_cast( ( SCH_PLUGIN* )plugin ) );
+ dlg.ShowModal();
+}
+
+
SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable ) :
LIB_TABLE( aFallBackTable )
{
diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h
index 18744a3e30..150151a6e0 100644
--- a/eeschema/symbol_lib_table.h
+++ b/eeschema/symbol_lib_table.h
@@ -80,10 +80,18 @@ public:
* @return true if a reload was required.
* @throw IO_ERROR if the reload was unsuccessful.
*/
- bool Refresh();
+ bool Refresh() override;
bool SupportsSubLibraries() const { return plugin ? plugin->SupportsSubLibraries() : false; }
+ bool SupportsSettingsDialog() const override
+ {
+ // Only database libraries have dialog-configurable options at the moment
+ return type == SCH_IO_MGR::SCH_FILE_T::SCH_DATABASE;
+ }
+
+ void ShowSettingsDialog( wxWindow* aWindow ) const override;
+
void GetSubLibraryNames( std::vector& aNames ) const;
/**
diff --git a/include/lib_table_base.h b/include/lib_table_base.h
index 41304a4a75..19d604aa0f 100644
--- a/include/lib_table_base.h
+++ b/include/lib_table_base.h
@@ -43,6 +43,7 @@ class LIB_TABLE_ROW;
class LIB_TABLE_GRID;
class LIB_TABLE;
class IO_ERROR;
+class wxWindow;
typedef boost::ptr_vector< LIB_TABLE_ROW > LIB_TABLE_ROWS;
@@ -129,6 +130,8 @@ public:
void SetVisible( bool aVisible = true ) { visible = aVisible; }
+ virtual bool Refresh() { return false; }
+
/**
* Return the type of library represented by this row.
*/
@@ -140,6 +143,10 @@ public:
*/
virtual void SetType( const wxString& aType ) = 0;
+ virtual bool SupportsSettingsDialog() const { return false; }
+
+ virtual void ShowSettingsDialog( wxWindow* aParent ) const {}
+
/**
* Return the full location specifying URI for the LIB, either in original UI form or
* in environment variable expanded form.
diff --git a/include/lib_table_grid.h b/include/lib_table_grid.h
index e2e498b708..9402a4e2ec 100644
--- a/include/lib_table_grid.h
+++ b/include/lib_table_grid.h
@@ -209,6 +209,11 @@ public:
return false;
}
+ LIB_TABLE_ROW* At( size_t aIndex )
+ {
+ return at( aIndex );
+ }
+
protected:
virtual LIB_TABLE_ROW* at( size_t aIndex ) = 0;
diff --git a/include/lib_table_grid_tricks.h b/include/lib_table_grid_tricks.h
index f5ed847d9c..7a1e4ac249 100644
--- a/include/lib_table_grid_tricks.h
+++ b/include/lib_table_grid_tricks.h
@@ -24,7 +24,8 @@ class LIB_TABLE_GRID_TRICKS : public GRID_TRICKS
enum
{
LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED = GRIDTRICKS_FIRST_CLIENT_ID,
- LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED
+ LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED,
+ LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS
};
public:
diff --git a/include/widgets/grid_button.h b/include/widgets/grid_button.h
new file mode 100644
index 0000000000..0ae49df1ae
--- /dev/null
+++ b/include/widgets/grid_button.h
@@ -0,0 +1,46 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2023 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 KICAD_GRID_BUTTON_H
+#define KICAD_GRID_BUTTON_H
+
+#include
+#include
+
+
+class GRID_BUTTON_RENDERER : public wxGridCellRenderer
+{
+public:
+ GRID_BUTTON_RENDERER( const wxString& aLabel );
+
+ virtual ~GRID_BUTTON_RENDERER() = default;
+
+ GRID_BUTTON_RENDERER* Clone() const override;
+
+ void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc, const wxRect& aRect,
+ int aRow, int aCol, bool aIsSelected ) override;
+
+ wxSize GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
+ int aRow, int aCol) override;
+
+private:
+ wxButton m_button;
+};
+
+#endif //KICAD_GRID_BUTTON_H