Add initial support for database library settings UI

For now, just for diagnostic purposes (settings changes are not preserved)
This commit is contained in:
Jon Evans 2023-02-26 18:39:31 -05:00
parent dc57fa7042
commit dc847db19d
17 changed files with 1993 additions and 12 deletions

View File

@ -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

View File

@ -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 );

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <widgets/grid_button.h>
#include <wx/dc.h>
#include <wx/renderer.h>
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();
}

View File

@ -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

View File

@ -0,0 +1,129 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2023 Jon Evans <jon@craftyjon.com>
* 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 <http://www.gnu.org/licenses/>.
*/
#include <dialogs/dialog_database_lib_settings.h>
#include <sch_plugins/database/sch_database_plugin.h>
#include <database/database_lib_settings.h>
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<wxString> 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();
}

View File

@ -0,0 +1,50 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2023 Jon Evans <jon@craftyjon.com>
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -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 );
}

File diff suppressed because it is too large Load Diff

View File

@ -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 <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class WX_INFOBAR;
#include "dialog_shim.h"
#include <wx/infobar.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/radiobut.h>
#include <wx/textctrl.h>
#include <wx/stattext.h>
#include <wx/gbsizer.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/statbox.h>
#include <wx/spinctrl.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// 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();
};

View File

@ -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 );

View File

@ -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 );

View File

@ -33,6 +33,8 @@
#include <systemdirsappend.h>
#include <symbol_lib_table.h>
#include <lib_symbol.h>
#include <sch_plugins/database/sch_database_plugin.h>
#include <dialogs/dialog_database_lib_settings.h>
#include <wx/dir.h>
#include "sim/sim_model.h"
@ -100,6 +102,19 @@ void SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames( std::vector<wxString>& 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_DATABASE_PLUGIN*>( ( SCH_PLUGIN* )plugin ) );
dlg.ShowModal();
}
SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable ) :
LIB_TABLE( aFallBackTable )
{

View File

@ -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<wxString>& aNames ) const;
/**

View File

@ -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.

View File

@ -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;

View File

@ -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:

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef KICAD_GRID_BUTTON_H
#define KICAD_GRID_BUTTON_H
#include <wx/button.h>
#include <wx/grid.h>
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