Browse Source
Push most of DIALOG_CHOOSE_SYMBOL down into PANEL_SYMBOL_CHOOSER.
Push most of DIALOG_CHOOSE_SYMBOL down into PANEL_SYMBOL_CHOOSER.
Includes a dialog wrapper (DIALOG_SYMBOL_CHOOSER) and a frame wrapper (SYMBOL_CHOOSER_FRAME).newinvert
36 changed files with 928 additions and 755 deletions
-
3common/dialogs/dialog_page_settings.cpp
-
1common/dialogs/panel_grid_settings.cpp
-
2common/kiway.cpp
-
3common/tool/common_tools.cpp
-
2common/widgets/grid_text_button_helpers.cpp
-
6common/widgets/lib_tree.cpp
-
4eeschema/CMakeLists.txt
-
4eeschema/dialogs/dialog_change_symbols.cpp
-
233eeschema/dialogs/dialog_choose_symbol.h
-
19eeschema/dialogs/dialog_edit_symbols_libid.cpp
-
126eeschema/dialogs/dialog_symbol_chooser.cpp
-
86eeschema/dialogs/dialog_symbol_chooser.h
-
12eeschema/eeschema.cpp
-
1eeschema/eeschema_id.h
-
167eeschema/picksymbol.cpp
-
3eeschema/sch_base_frame.cpp
-
28eeschema/sch_base_frame.h
-
7eeschema/sch_edit_frame.cpp
-
174eeschema/symbol_chooser_frame.cpp
-
87eeschema/symbol_chooser_frame.h
-
96eeschema/symbol_viewer_frame.cpp
-
4eeschema/symbol_viewer_frame.h
-
4eeschema/toolbars_symbol_viewer.cpp
-
2eeschema/tools/ee_inspection_tool.cpp
-
4eeschema/tools/sch_drawing_tools.cpp
-
2eeschema/tools/symbol_editor_control.cpp
-
396eeschema/widgets/panel_symbol_chooser.cpp
-
162eeschema/widgets/panel_symbol_chooser.h
-
2include/eda_draw_frame.h
-
2include/frame_type.h
-
2pcbnew/dialogs/dialog_footprint_chooser.cpp
-
2pcbnew/footprint_chooser_frame.cpp
-
2pcbnew/load_select_footprint.cpp
-
7pcbnew/pcb_edit_frame.cpp
-
22pcbnew/widgets/panel_footprint_chooser.cpp
-
6pcbnew/widgets/panel_footprint_chooser.h
@ -1,233 +0,0 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org> |
|||
* Copyright (C) 2014-2022 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 |
|||
*/ |
|||
#ifndef DIALOG_CHOOSE_SYMBOL_H |
|||
#define DIALOG_CHOOSE_SYMBOL_H |
|||
|
|||
#include "dialog_shim.h" |
|||
#include <symbol_tree_model_adapter.h> |
|||
#include <footprint_info.h> |
|||
#include <widgets/html_window.h> |
|||
|
|||
class wxCheckBox; |
|||
class wxStaticBitmap; |
|||
class wxTextCtrl; |
|||
class wxStdDialogButtonSizer; |
|||
class wxDataViewCtrl; |
|||
class wxHtmlLinkEvent; |
|||
class wxPanel; |
|||
class wxChoice; |
|||
class wxButton; |
|||
class wxTimer; |
|||
class wxSplitterWindow; |
|||
|
|||
class LIB_TREE; |
|||
class SYMBOL_PREVIEW_WIDGET; |
|||
class FOOTPRINT_PREVIEW_WIDGET; |
|||
class FOOTPRINT_SELECT_WIDGET; |
|||
class LIB_ALIAS; |
|||
class SCH_BASE_FRAME; |
|||
class SCH_DRAW_PANEL; |
|||
|
|||
|
|||
/** |
|||
* Dialog class to select a symbol from the libraries. This is the master View class in a |
|||
* Model-View-Adapter (mediated MVC) architecture. The other pieces are in: |
|||
* |
|||
* - Adapter: SYM_TREE_MODEL_ADAPTER in common/cmp_tree_model_adapter.h |
|||
* - Model: SYM_TREE_NODE and descendants in common/cmp_tree_model.h |
|||
* |
|||
* Because everything is tied together in the adapter class, see that file |
|||
* for thorough documentation. A simple example usage follows: |
|||
* |
|||
* // Create the adapter class |
|||
* auto adapter( SYMBOL_TREE_MODEL_ADAPTER::Create( PROJECT_SCH::SchSymbolLibTable( &Prj() ) ); |
|||
* |
|||
* // Perform any configuration of adapter properties here |
|||
* adapter->SetPreselectNode( "LIB_NICKNAME", "SYMBO_NAME", 2 ); |
|||
* |
|||
* // Initialize model from #SYMBOL_LIB_TABLE |
|||
* libNicknames = libs->GetLogicalLibs(); |
|||
* |
|||
* for( auto nickname : libNicknames ) |
|||
* adapter->AddLibrary( nickname ); |
|||
* |
|||
* // Create and display dialog |
|||
* DIALOG_CHOOSE_SYMBOL dlg( this, title, adapter, 1 ); |
|||
* bool selected = ( dlg.ShowModal() != wxID_CANCEL ); |
|||
* |
|||
* // Receive part |
|||
* if( selected ) |
|||
* { |
|||
* int unit; |
|||
* #LIB_ID id = dlg.GetSelectedAlias( &unit ); |
|||
* do_something( id, unit ); |
|||
* } |
|||
* |
|||
*/ |
|||
class DIALOG_CHOOSE_SYMBOL : public DIALOG_SHIM |
|||
{ |
|||
public: |
|||
/** |
|||
* Create dialog to choose symbol. |
|||
* |
|||
* @param aParent a SCH_BASE_FRAME parent window. |
|||
* @param aTitle Dialog title. |
|||
* @param aAdapter SYMBOL_TREE_MODEL_ADAPTER::PTR. See SYM_TREE_MODEL_ADAPTER |
|||
* for documentation. |
|||
* @param aDeMorganConvert preferred deMorgan conversion. |
|||
* (TODO: should happen in dialog) |
|||
* @param aAllowFieldEdits if false, all functions that allow the user to edit fields |
|||
* (currently just footprint selection) will not be available. |
|||
* @param aShowFootprints if false, all footprint preview and selection features are |
|||
* disabled. This forces aAllowFieldEdits false too. |
|||
* @param aAllowBrowser show a Select with Browser button. |
|||
*/ |
|||
DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxString& aTitle, |
|||
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, |
|||
int aDeMorganConvert, bool aAllowFieldEdits, bool aShowFootprints, |
|||
bool aAllowBrowser ); |
|||
|
|||
~DIALOG_CHOOSE_SYMBOL(); |
|||
|
|||
/** |
|||
* To be called after this dialog returns from ShowModal(). |
|||
* |
|||
* For multi-unit symbols, if the user selects the symbol itself rather than picking |
|||
* an individual unit, 0 will be returned in aUnit. |
|||
* Beware that this is an invalid unit number - this should be replaced with whatever |
|||
* default is desired (usually 1). |
|||
* |
|||
* @param aUnit if not NULL, the selected unit is filled in here. |
|||
* @return the #LIB_ID of the symbol that has been selected. |
|||
*/ |
|||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const; |
|||
|
|||
/** |
|||
* To be called after this dialog returns from ShowModal() |
|||
* |
|||
* In the case of multi-unit symbols, this preferences asks to iterate through |
|||
* all units of the symbol, one per click. |
|||
* |
|||
* @return The value of the dialog preference checkbox. |
|||
*/ |
|||
bool GetUseAllUnits() const; |
|||
|
|||
/** |
|||
* To be called after this dialog returns from ShowModal() |
|||
* |
|||
* Keeps a new copy of the symbol on the mouse cursor, allowing the user to rapidly |
|||
* place multiple copies of the same symbol on their schematic. |
|||
* |
|||
* @return The value of the keep symbol preference checkbox. |
|||
*/ |
|||
bool GetKeepSymbol() const; |
|||
|
|||
/** |
|||
* Get a list of fields edited by the user. |
|||
* |
|||
* @return vector of pairs; each.first = field ID, each.second = new value. |
|||
*/ |
|||
std::vector<std::pair<int, wxString>> GetFields() const |
|||
{ |
|||
return m_field_edits; |
|||
} |
|||
|
|||
/** |
|||
* @return true if the user requested the symbol browser. |
|||
*/ |
|||
bool IsExternalBrowserSelected() const |
|||
{ |
|||
return m_external_browser_requested; |
|||
} |
|||
|
|||
protected: |
|||
static constexpr int DblClickDelay = 100; // milliseconds |
|||
|
|||
wxPanel* ConstructRightPanel( wxWindow* aParent ); |
|||
|
|||
void OnInitDialog( wxInitDialogEvent& aEvent ); |
|||
void OnCharHook( wxKeyEvent& aEvt ) override; |
|||
void OnCloseTimer( wxTimerEvent& aEvent ); |
|||
void OnUseBrowser( wxCommandEvent& aEvent ); |
|||
|
|||
void OnFootprintSelected( wxCommandEvent& aEvent ); |
|||
void OnComponentPreselected( wxCommandEvent& aEvent ); |
|||
|
|||
/** |
|||
* Handle the selection of an item. This is called when either the search box or the tree |
|||
* receive an Enter, or the tree receives a double click. |
|||
* If the item selected is a category, it is expanded or collapsed; if it is a symbol, the |
|||
* symbol is picked. |
|||
*/ |
|||
void OnComponentSelected( wxCommandEvent& aEvent ); |
|||
|
|||
/** |
|||
* Look up the footprint for a given symbol specified in the #LIB_ID and display it. |
|||
*/ |
|||
void ShowFootprintFor( const LIB_ID& aLibId ); |
|||
|
|||
/** |
|||
* Display the given footprint by name. |
|||
*/ |
|||
void ShowFootprint( const wxString& aFootprint ); |
|||
|
|||
/** |
|||
* Populate the footprint selector for a given alias. |
|||
* |
|||
* @param aLibId the #LIB_ID of the selection or invalid to clear. |
|||
*/ |
|||
void PopulateFootprintSelector( const LIB_ID& aLibId ); |
|||
|
|||
public: |
|||
static std::mutex g_Mutex; |
|||
|
|||
protected: |
|||
static wxString g_symbolSearchString; |
|||
static wxString g_powerSearchString; |
|||
|
|||
wxTimer* m_dbl_click_timer; |
|||
SYMBOL_PREVIEW_WIDGET* m_symbol_preview; |
|||
wxButton* m_browser_button; |
|||
wxSplitterWindow* m_hsplitter; |
|||
wxSplitterWindow* m_vsplitter; |
|||
|
|||
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl; |
|||
FOOTPRINT_PREVIEW_WIDGET* m_fp_preview; |
|||
wxCheckBox* m_keepSymbol; |
|||
wxCheckBox* m_useUnits; |
|||
LIB_TREE* m_tree; |
|||
HTML_WINDOW* m_details; |
|||
|
|||
SCH_BASE_FRAME* m_parent; |
|||
bool m_showPower; |
|||
int m_deMorganConvert; |
|||
bool m_allow_field_edits; |
|||
bool m_show_footprints; |
|||
bool m_external_browser_requested; |
|||
wxString m_fp_override; |
|||
|
|||
std::vector<std::pair<int, wxString>> m_field_edits; |
|||
}; |
|||
|
|||
#endif /* DIALOG_CHOOSE_SYMBOL_H */ |
|||
@ -0,0 +1,126 @@ |
|||
/*
|
|||
* 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 <symbol_library.h>
|
|||
#include <dialog_symbol_chooser.h>
|
|||
#include <widgets/panel_symbol_chooser.h>
|
|||
#include <eeschema_settings.h>
|
|||
#include <kiface_base.h>
|
|||
#include <sch_base_frame.h>
|
|||
#include <core/kicad_algo.h>
|
|||
#include <template_fieldnames.h>
|
|||
#include <widgets/footprint_preview_widget.h>
|
|||
#include <widgets/footprint_select_widget.h>
|
|||
#include <widgets/symbol_preview_widget.h>
|
|||
#include <wx/button.h>
|
|||
#include <wx/checkbox.h>
|
|||
#include <wx/sizer.h>
|
|||
|
|||
std::mutex DIALOG_SYMBOL_CHOOSER::g_Mutex; |
|||
|
|||
DIALOG_SYMBOL_CHOOSER::DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect, |
|||
const SYMBOL_LIBRARY_FILTER* aFilter, |
|||
std::vector<PICKED_SYMBOL>& aHistoryList, |
|||
bool aAllowFieldEdits, bool aShowFootprints ) : |
|||
DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize, |
|||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) |
|||
{ |
|||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL ); |
|||
m_chooserPanel = new PANEL_SYMBOL_CHOOSER( aParent, this, aFilter, aHistoryList, |
|||
aAllowFieldEdits, aShowFootprints, |
|||
[this]() |
|||
{ |
|||
EndModal( wxID_OK ); |
|||
} ); |
|||
|
|||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 ); |
|||
|
|||
if( aPreselect && aPreselect->IsValid() ) |
|||
m_chooserPanel->SetPreselect( *aPreselect ); |
|||
|
|||
if( aFilter->GetFilterPowerSymbols() ) |
|||
SetTitle( _( "Choose Power Symbol" ) ); |
|||
|
|||
SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ), |
|||
m_chooserPanel->GetItemCount() ) ); |
|||
|
|||
wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL ); |
|||
|
|||
m_keepSymbol = new wxCheckBox( this, wxID_ANY, _( "Place repeated copies" ) ); |
|||
m_keepSymbol->SetToolTip( _( "Keep the symbol selected for subsequent clicks." ) ); |
|||
|
|||
m_useUnits = new wxCheckBox( this, wxID_ANY, _( "Place all units" ) ); |
|||
m_useUnits->SetToolTip( _( "Sequentially place all units of the symbol." ) ); |
|||
|
|||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) ) |
|||
{ |
|||
m_keepSymbol->SetValue( cfg->m_SymChooserPanel.keep_symbol ); |
|||
m_useUnits->SetValue( cfg->m_SymChooserPanel.place_all_units ); |
|||
} |
|||
|
|||
buttonsSizer->Add( m_keepSymbol, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 ); |
|||
buttonsSizer->Add( m_useUnits, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 30 ); |
|||
|
|||
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer(); |
|||
wxButton* okButton = new wxButton( this, wxID_OK ); |
|||
wxButton* cancelButton = new wxButton( this, wxID_CANCEL ); |
|||
|
|||
sdbSizer->AddButton( okButton ); |
|||
sdbSizer->AddButton( cancelButton ); |
|||
sdbSizer->Realize(); |
|||
|
|||
buttonsSizer->Add( sdbSizer, 1, wxALL, 5 ); |
|||
|
|||
sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 ); |
|||
SetSizer( sizer ); |
|||
|
|||
SetInitialFocus( m_chooserPanel->GetFocusTarget() ); |
|||
SetupStandardButtons(); |
|||
|
|||
m_chooserPanel->FinishSetup(); |
|||
Layout(); |
|||
} |
|||
|
|||
|
|||
DIALOG_SYMBOL_CHOOSER::~DIALOG_SYMBOL_CHOOSER() |
|||
{ |
|||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) ) |
|||
{ |
|||
cfg->m_SymChooserPanel.keep_symbol = m_keepSymbol->GetValue(); |
|||
cfg->m_SymChooserPanel.place_all_units = m_useUnits->GetValue(); |
|||
} |
|||
} |
|||
|
|||
|
|||
LIB_ID DIALOG_SYMBOL_CHOOSER::GetSelectedLibId( int* aUnit ) const |
|||
{ |
|||
return m_chooserPanel->GetSelectedLibId( aUnit ); |
|||
} |
|||
|
|||
|
|||
std::vector<std::pair<int, wxString>> DIALOG_SYMBOL_CHOOSER::GetFields() const |
|||
{ |
|||
return m_chooserPanel->GetFields(); |
|||
} |
|||
|
|||
|
|||
@ -0,0 +1,86 @@ |
|||
/* |
|||
* 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 |
|||
*/ |
|||
#ifndef DIALOG_SYMBOL_CHOOSER_H |
|||
#define DIALOG_SYMBOL_CHOOSER_H |
|||
|
|||
#include "dialog_shim.h" |
|||
#include <symbol_tree_model_adapter.h> |
|||
#include <footprint_info.h> |
|||
#include <widgets/html_window.h> |
|||
#include <wx/checkbox.h> |
|||
|
|||
|
|||
class SCH_BASE_FRAME; |
|||
class PANEL_SYMBOL_CHOOSER; |
|||
struct PICKED_SYMBOL; |
|||
|
|||
|
|||
class DIALOG_SYMBOL_CHOOSER : public DIALOG_SHIM |
|||
{ |
|||
public: |
|||
/** |
|||
* Create dialog to choose symbol. |
|||
* |
|||
* @param aParent a SCH_BASE_FRAME parent window. |
|||
* @param aAllowFieldEdits if false, all functions that allow the user to edit fields |
|||
* (currently just footprint selection) will not be available. |
|||
* @param aShowFootprints if false, all footprint preview and selection features are |
|||
* disabled. This forces aAllowFieldEdits false too. |
|||
*/ |
|||
DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB_ID* aPreselect, |
|||
const SYMBOL_LIBRARY_FILTER* aFilter, |
|||
std::vector<PICKED_SYMBOL>& aHistoryList, |
|||
bool aAllowFieldEdits, bool aShowFootprints ); |
|||
|
|||
~DIALOG_SYMBOL_CHOOSER(); |
|||
|
|||
/** |
|||
* To be called after this dialog returns from ShowModal(). |
|||
* |
|||
* For multi-unit symbols, if the user selects the symbol itself rather than picking |
|||
* an individual unit, 0 will be returned in aUnit. |
|||
* Beware that this is an invalid unit number - this should be replaced with whatever |
|||
* default is desired (usually 1). |
|||
* |
|||
* @param aUnit if not NULL, the selected unit is filled in here. |
|||
* @return the #LIB_ID of the symbol that has been selected. |
|||
*/ |
|||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const; |
|||
|
|||
/** |
|||
* Get a list of fields edited by the user. |
|||
* |
|||
* @return vector of pairs; each.first = field ID, each.second = new value. |
|||
*/ |
|||
std::vector<std::pair<int, wxString>> GetFields() const; |
|||
|
|||
public: |
|||
static std::mutex g_Mutex; |
|||
|
|||
protected: |
|||
PANEL_SYMBOL_CHOOSER* m_chooserPanel; |
|||
wxCheckBox* m_keepSymbol; |
|||
wxCheckBox* m_useUnits; |
|||
}; |
|||
|
|||
#endif /* DIALOG_SYMBOL_CHOOSER_H */ |
|||
@ -0,0 +1,174 @@ |
|||
/*
|
|||
* 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() |
|||
|
|||
|
|||
#define PARENT_STYLE ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
|
|||
| wxWANTS_CHARS | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT ) |
|||
|
|||
SYMBOL_CHOOSER_FRAME::SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ) : |
|||
SCH_BASE_FRAME( aKiway, aParent, FRAME_SYMBOL_CHOOSER, _( "Symbol Chooser" ), |
|||
wxDefaultPosition, wxDefaultSize, PARENT_STYLE, SYMBOL_CHOOSER_FRAME_NAME ) |
|||
{ |
|||
SetModal( true ); |
|||
|
|||
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL ); |
|||
m_chooserPanel = new PANEL_SYMBOL_CHOOSER( this, this, nullptr /* no filter */, |
|||
s_SymbolHistoryList, false, false, |
|||
[this]() |
|||
{ |
|||
wxCommandEvent dummy; |
|||
OnOK( dummy ); |
|||
} ); |
|||
|
|||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 ); |
|||
|
|||
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer(); |
|||
wxButton* okButton = new wxButton( this, wxID_OK ); |
|||
wxButton* cancelButton = new wxButton( this, wxID_CANCEL ); |
|||
sdbSizer->AddButton( okButton ); |
|||
sdbSizer->AddButton( cancelButton ); |
|||
sdbSizer->Realize(); |
|||
|
|||
sizer->Add( sdbSizer, 0, wxEXPAND | wxALL, 5 ); |
|||
SetSizer( sizer ); |
|||
|
|||
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 ) |
|||
{ |
|||
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg ); |
|||
wxASSERT( cfg ); |
|||
return &cfg->m_LibViewPanel.window; |
|||
} |
|||
|
|||
|
|||
void SYMBOL_CHOOSER_FRAME::CloseSymbolChooser( wxCommandEvent& event ) |
|||
{ |
|||
Close( false ); |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
/* |
|||
* 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 |
|||
*/ |
|||
|
|||
|
|||
#ifndef SYMBOL_CHOOSER_FRAME_H |
|||
#define SYMBOL_CHOOSER_FRAME_H |
|||
|
|||
#include <sch_base_frame.h> |
|||
|
|||
class PANEL_SYMBOL_CHOOSER; |
|||
|
|||
|
|||
/** |
|||
* Symbol library viewer main window. |
|||
*/ |
|||
class SYMBOL_CHOOSER_FRAME : public SCH_BASE_FRAME |
|||
{ |
|||
public: |
|||
/** |
|||
* @param aKiway |
|||
* @param aParent is the parent frame of the viewer. |
|||
* @param aFrameType must be either #FRAME_SCH_LIB_VIEWER or #FRAME_SCH_LIB_VIEWER_MODAL. |
|||
* @param aLibrary is the library to open when starting (default = NULL). |
|||
*/ |
|||
SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ); |
|||
|
|||
~SYMBOL_CHOOSER_FRAME() {}; |
|||
|
|||
/** |
|||
* Runs the symbol viewer as a modal dialog. |
|||
* |
|||
* @param aSymbol an optional FPID string to initialize the viewer with and to |
|||
* return a selected footprint through. |
|||
*/ |
|||
bool ShowModal( wxString* aSymbol, wxWindow* aParent ) override; |
|||
|
|||
/** |
|||
* Set a filter to display only libraries and/or symbols which match the filter. |
|||
* |
|||
* @param aFilter is a filter to pass the allowed library name list and/or some other filter |
|||
* see SCH_BASE_FRAME::SelectSymbolFromLibrary() for details. |
|||
* if aFilter == NULL, remove all filtering. |
|||
*/ |
|||
void SetFilter( const SYMBOL_LIBRARY_FILTER* aFilter ); |
|||
|
|||
private: |
|||
void OnPaint( wxPaintEvent& aEvent ); |
|||
void OnOK( wxCommandEvent& aEvent ); |
|||
|
|||
void doCloseWindow() override; |
|||
void CloseSymbolChooser( wxCommandEvent& aEvent ); |
|||
|
|||
WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override; |
|||
|
|||
DECLARE_EVENT_TABLE() |
|||
|
|||
private: |
|||
PANEL_SYMBOL_CHOOSER* m_chooserPanel; |
|||
|
|||
// On MacOS (at least) SetFocus() calls made in the constructor will fail because a |
|||
// window that isn't yet visible will return false to AcceptsFocus(). So we must delay |
|||
// the initial-focus SetFocus() call to the first paint event. |
|||
bool m_firstPaintEvent; |
|||
}; |
|||
|
|||
#endif // SYMBOL_CHOOSER_FRAME_H |
|||
|
|||
@ -0,0 +1,162 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org> |
|||
* Copyright (C) 2014-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 |
|||
*/ |
|||
#ifndef PANEL_SYMBOL_CHOOSER_H |
|||
#define PANEL_SYMBOL_CHOOSER_H |
|||
|
|||
#include <widgets/lib_tree.h> |
|||
#include <symbol_tree_model_adapter.h> |
|||
#include <footprint_info.h> |
|||
#include <widgets/html_window.h> |
|||
|
|||
class wxPanel; |
|||
class wxTimer; |
|||
class wxSplitterWindow; |
|||
|
|||
class SYMBOL_PREVIEW_WIDGET; |
|||
class FOOTPRINT_PREVIEW_WIDGET; |
|||
class FOOTPRINT_SELECT_WIDGET; |
|||
class SCH_BASE_FRAME; |
|||
struct PICKED_SYMBOL; |
|||
|
|||
|
|||
class PANEL_SYMBOL_CHOOSER : public wxPanel |
|||
{ |
|||
public: |
|||
/** |
|||
* Create dialog to choose symbol. |
|||
* |
|||
* @param aFrame the parent frame (usually a SCH_EDIT_FRAME or SYMBOL_CHOOSER_FRAME) |
|||
* @param aParent the parent window (usually a DIALOG_SHIM or SYMBOL_CHOOSER_FRAME) |
|||
* @param aAllowFieldEdits if false, all functions that allow the user to edit fields |
|||
* (currently just footprint selection) will not be available. |
|||
* @param aShowFootprints if false, all footprint preview and selection features are |
|||
* disabled. This forces aAllowFieldEdits false too. |
|||
* @param aCloseHandler a handler to be called on double-click of a footprint |
|||
*/ |
|||
PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent, |
|||
const SYMBOL_LIBRARY_FILTER* aFilter, |
|||
std::vector<PICKED_SYMBOL>& aHistoryList, |
|||
bool aAllowFieldEdits, bool aShowFootprints, |
|||
std::function<void()> aCloseHandler ); |
|||
|
|||
~PANEL_SYMBOL_CHOOSER(); |
|||
|
|||
void FinishSetup(); |
|||
|
|||
void SetPreselect( const LIB_ID& aPreselect ); |
|||
|
|||
/** |
|||
* To be called after this dialog returns from ShowModal(). |
|||
* |
|||
* For multi-unit symbols, if the user selects the symbol itself rather than picking |
|||
* an individual unit, 0 will be returned in aUnit. |
|||
* Beware that this is an invalid unit number - this should be replaced with whatever |
|||
* default is desired (usually 1). |
|||
* |
|||
* @param aUnit if not NULL, the selected unit is filled in here. |
|||
* @return the #LIB_ID of the symbol that has been selected. |
|||
*/ |
|||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const; |
|||
|
|||
int GetItemCount() const { return m_adapter->GetItemCount(); } |
|||
|
|||
wxWindow* GetFocusTarget() const { return m_tree->GetFocusTarget(); } |
|||
|
|||
/** |
|||
* Get a list of fields edited by the user. |
|||
* |
|||
* @return vector of pairs; each.first = field ID, each.second = new value. |
|||
*/ |
|||
std::vector<std::pair<int, wxString>> GetFields() const |
|||
{ |
|||
return m_field_edits; |
|||
} |
|||
|
|||
protected: |
|||
static constexpr int DblClickDelay = 100; // milliseconds |
|||
|
|||
wxPanel* ConstructRightPanel( wxWindow* aParent ); |
|||
|
|||
void OnCharHook( wxKeyEvent& aEvt ); |
|||
void OnCloseTimer( wxTimerEvent& aEvent ); |
|||
|
|||
void OnFootprintSelected( wxCommandEvent& aEvent ); |
|||
void OnComponentPreselected( wxCommandEvent& aEvent ); |
|||
|
|||
/** |
|||
* Handle the selection of an item. This is called when either the search box or the tree |
|||
* receive an Enter, or the tree receives a double click. |
|||
* If the item selected is a category, it is expanded or collapsed; if it is a symbol, the |
|||
* symbol is picked. |
|||
*/ |
|||
void OnComponentSelected( wxCommandEvent& aEvent ); |
|||
|
|||
/** |
|||
* Look up the footprint for a given symbol specified in the #LIB_ID and display it. |
|||
*/ |
|||
void ShowFootprintFor( const LIB_ID& aLibId ); |
|||
|
|||
/** |
|||
* Display the given footprint by name. |
|||
*/ |
|||
void ShowFootprint( const wxString& aFootprint ); |
|||
|
|||
/** |
|||
* Populate the footprint selector for a given alias. |
|||
* |
|||
* @param aLibId the #LIB_ID of the selection or invalid to clear. |
|||
*/ |
|||
void PopulateFootprintSelector( const LIB_ID& aLibId ); |
|||
|
|||
public: |
|||
static std::mutex g_Mutex; |
|||
|
|||
protected: |
|||
static wxString g_symbolSearchString; |
|||
static wxString g_powerSearchString; |
|||
|
|||
wxTimer* m_dbl_click_timer; |
|||
SYMBOL_PREVIEW_WIDGET* m_symbol_preview; |
|||
wxSplitterWindow* m_hsplitter; |
|||
wxSplitterWindow* m_vsplitter; |
|||
|
|||
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter; |
|||
|
|||
FOOTPRINT_SELECT_WIDGET* m_fp_sel_ctrl; |
|||
FOOTPRINT_PREVIEW_WIDGET* m_fp_preview; |
|||
LIB_TREE* m_tree; |
|||
HTML_WINDOW* m_details; |
|||
|
|||
SCH_BASE_FRAME* m_frame; |
|||
std::function<void()> m_closeHandler; |
|||
|
|||
bool m_showPower; |
|||
bool m_allow_field_edits; |
|||
bool m_show_footprints; |
|||
wxString m_fp_override; |
|||
|
|||
std::vector<std::pair<int, wxString>> m_field_edits; |
|||
}; |
|||
|
|||
#endif /* PANEL_SYMBOL_CHOOSER_H */ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue