2023-09-28 13:09:45 +00:00
|
|
|
/*
|
|
|
|
* 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 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <kiplatform/ui.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <sch_base_frame.h>
|
|
|
|
#include <eeschema_settings.h>
|
|
|
|
#include <widgets/panel_symbol_chooser.h>
|
|
|
|
#include <symbol_chooser_frame.h>
|
|
|
|
|
|
|
|
|
|
|
|
static std::vector<PICKED_SYMBOL> s_SymbolHistoryList;
|
|
|
|
static unsigned s_SymbolHistoryMaxCount = 8;
|
|
|
|
|
|
|
|
static void AddSymbolToHistory( const PICKED_SYMBOL& aSymbol )
|
|
|
|
{
|
|
|
|
// Remove duplicates
|
|
|
|
alg::delete_if( s_SymbolHistoryList,
|
|
|
|
[&]( const PICKED_SYMBOL& candidate ) -> bool
|
|
|
|
{
|
|
|
|
return candidate.LibId == aSymbol.LibId
|
|
|
|
&& candidate.Unit == aSymbol.Unit
|
|
|
|
&& candidate.Convert == aSymbol.Convert;
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Add the new name at the beginning of the history list
|
|
|
|
s_SymbolHistoryList.insert( s_SymbolHistoryList.begin(), aSymbol );
|
|
|
|
|
|
|
|
// Remove extra names
|
|
|
|
while( s_SymbolHistoryList.size() > s_SymbolHistoryMaxCount )
|
|
|
|
s_SymbolHistoryList.resize( s_SymbolHistoryMaxCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( SYMBOL_CHOOSER_FRAME, SCH_BASE_FRAME )
|
|
|
|
// Menu (and/or hotkey) events
|
|
|
|
EVT_MENU( wxID_CLOSE, SYMBOL_CHOOSER_FRAME::CloseSymbolChooser )
|
|
|
|
EVT_BUTTON( wxID_OK, SYMBOL_CHOOSER_FRAME::OnOK )
|
|
|
|
EVT_BUTTON( wxID_CANCEL, SYMBOL_CHOOSER_FRAME::CloseSymbolChooser )
|
|
|
|
EVT_PAINT( SYMBOL_CHOOSER_FRAME::OnPaint )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2023-10-03 13:48:27 +00:00
|
|
|
#define MODAL_FRAME ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
|
|
|
|
| wxWANTS_CHARS | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP )
|
2023-09-28 13:09:45 +00:00
|
|
|
|
|
|
|
SYMBOL_CHOOSER_FRAME::SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|
|
|
SCH_BASE_FRAME( aKiway, aParent, FRAME_SYMBOL_CHOOSER, _( "Symbol Chooser" ),
|
2023-10-03 13:48:27 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, MODAL_FRAME, SYMBOL_CHOOSER_FRAME_NAME )
|
2023-09-28 13:09:45 +00:00
|
|
|
{
|
|
|
|
SetModal( true );
|
|
|
|
|
2024-02-16 20:15:59 +00:00
|
|
|
m_messagePanel->Hide();
|
|
|
|
|
2024-02-16 20:18:11 +00:00
|
|
|
wxBoxSizer* frameSizer = new wxBoxSizer( wxVERTICAL );
|
2021-03-13 22:13:47 +00:00
|
|
|
|
|
|
|
std::vector<PICKED_SYMBOL> dummyAlreadyPlaced;
|
|
|
|
m_chooserPanel =
|
|
|
|
new PANEL_SYMBOL_CHOOSER( this, this, nullptr /* no filter */, s_SymbolHistoryList,
|
|
|
|
dummyAlreadyPlaced, false, false,
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
OnOK( dummy );
|
2023-12-10 17:58:21 +00:00
|
|
|
},
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
DismissModal( false );
|
2021-03-13 22:13:47 +00:00
|
|
|
} );
|
2023-09-28 13:09:45 +00:00
|
|
|
|
2023-12-10 17:58:21 +00:00
|
|
|
|
2024-02-16 20:18:11 +00:00
|
|
|
frameSizer->Add( m_chooserPanel, 1, wxEXPAND );
|
|
|
|
|
|
|
|
wxPanel* bottomPanel = new wxPanel( this );
|
|
|
|
wxBoxSizer* bottomSizer = new wxBoxSizer( wxVERTICAL );
|
2023-09-28 13:09:45 +00:00
|
|
|
|
|
|
|
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
2024-02-16 20:18:11 +00:00
|
|
|
wxButton* okButton = new wxButton( bottomPanel, wxID_OK );
|
|
|
|
wxButton* cancelButton = new wxButton( bottomPanel, wxID_CANCEL );
|
2023-09-28 13:09:45 +00:00
|
|
|
sdbSizer->AddButton( okButton );
|
|
|
|
sdbSizer->AddButton( cancelButton );
|
|
|
|
sdbSizer->Realize();
|
|
|
|
|
2024-02-16 20:18:11 +00:00
|
|
|
bottomSizer->Add( sdbSizer, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
|
|
|
|
bottomPanel->SetSizer( bottomSizer );
|
|
|
|
frameSizer->Add( bottomPanel, 0, wxEXPAND );
|
|
|
|
|
|
|
|
SetSizer( frameSizer );
|
2023-09-28 13:09:45 +00:00
|
|
|
|
|
|
|
SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
|
|
|
|
m_chooserPanel->GetItemCount() ) );
|
|
|
|
|
|
|
|
Layout();
|
|
|
|
m_chooserPanel->FinishSetup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SYMBOL_CHOOSER_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
|
|
|
|
{
|
|
|
|
if( aSymbol && !aSymbol->IsEmpty() )
|
|
|
|
{
|
|
|
|
LIB_ID libid;
|
|
|
|
|
|
|
|
libid.Parse( *aSymbol, true );
|
|
|
|
|
|
|
|
if( libid.IsValid() )
|
|
|
|
m_chooserPanel->SetPreselect( libid );
|
|
|
|
}
|
|
|
|
|
|
|
|
return KIWAY_PLAYER::ShowModal( aSymbol, aParent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_CHOOSER_FRAME::doCloseWindow()
|
|
|
|
{
|
|
|
|
// Only dismiss a modal frame once, so that the return values set by
|
|
|
|
// the prior DismissModal() are not bashed for ShowModal().
|
|
|
|
if( !IsDismissed() )
|
|
|
|
DismissModal( false );
|
|
|
|
|
|
|
|
// window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_CHOOSER_FRAME::OnPaint( wxPaintEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_firstPaintEvent )
|
|
|
|
{
|
|
|
|
KIPLATFORM::UI::FixupCancelButtonCmdKeyCollision( this );
|
|
|
|
KIPLATFORM::UI::ForceFocus( m_chooserPanel->GetFocusTarget() );
|
|
|
|
|
|
|
|
m_firstPaintEvent = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_CHOOSER_FRAME::OnOK( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
LIB_ID libId = m_chooserPanel->GetSelectedLibId();
|
|
|
|
|
|
|
|
if( libId.IsValid() )
|
|
|
|
{
|
|
|
|
PICKED_SYMBOL symbol;
|
|
|
|
symbol.LibId = libId;
|
|
|
|
|
|
|
|
AddSymbolToHistory( symbol );
|
|
|
|
DismissModal( true, libId.Format() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DismissModal( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WINDOW_SETTINGS* SYMBOL_CHOOSER_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
|
|
|
|
{
|
2023-09-28 17:18:19 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
2023-09-28 13:09:45 +00:00
|
|
|
wxASSERT( cfg );
|
|
|
|
return &cfg->m_LibViewPanel.window;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOL_CHOOSER_FRAME::CloseSymbolChooser( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
Close( false );
|
|
|
|
}
|