42#include <wx/clipbrd.h>
45#include <wx/splitter.h>
57 std::vector<PICKED_SYMBOL>& aHistoryList,
58 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
59 bool aAllowFieldEdits,
bool aShowFootprints,
60 std::function<
void()> aAcceptHandler,
61 std::function<
void()> aEscapeHandler ) :
62 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
63 m_symbol_preview( nullptr ),
64 m_hsplitter( nullptr ),
65 m_vsplitter( nullptr ),
66 m_fp_sel_ctrl( nullptr ),
67 m_fp_preview( nullptr ),
71 m_acceptHandler(
std::
move( aAcceptHandler ) ),
72 m_escapeHandler(
std::
move( aEscapeHandler ) ),
74 m_allow_field_edits( aAllowFieldEdits ),
75 m_show_footprints( aShowFootprints )
93 for(
const wxString& nickname : liblist )
128 std::vector<LIB_SYMBOL> history_list_storage;
129 std::vector<LIB_TREE_ITEM*> history_list;
130 std::vector<LIB_SYMBOL> already_placed_storage;
131 std::vector<LIB_TREE_ITEM*> already_placed;
135 [&](
const std::vector<PICKED_SYMBOL>& inputList,
136 std::vector<LIB_SYMBOL>& storageList,
137 std::vector<LIB_TREE_ITEM*>& resultList )
139 storageList.reserve( inputList.size() );
147 storageList.emplace_back( *symbol );
149 for(
const std::pair<int, wxString>& fieldDef : i.Fields )
151 SCH_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
154 field->
SetText( fieldDef.second );
157 resultList.push_back( &storageList.back() );
164 std::sort( aAlreadyPlaced.begin(), aAlreadyPlaced.end(),
167 return a.LibId.GetLibItemName() < b.LibId.GetLibItemName();
170 processList( aHistoryList, history_list_storage, history_list );
171 processList( aAlreadyPlaced, already_placed_storage, already_placed );
173 adapter->
DoAddLibrary( wxT(
"-- " ) +
_(
"Recently Used" ) + wxT(
" --" ), wxEmptyString,
174 history_list,
false,
true )
177 if( !aHistoryList.empty() )
180 adapter->
DoAddLibrary( wxT(
"-- " ) +
_(
"Already Placed" ) + wxT(
" --" ), wxEmptyString,
181 already_placed,
false,
true )
184 const std::vector< wxString > libNicknames = libs->
GetLogicalLibs();
199 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
205 m_hsplitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
206 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
215 m_vsplitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
216 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
219 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
225 wxPanel* detailsPanel =
new wxPanel(
m_vsplitter );
226 wxBoxSizer* detailsSizer =
new wxBoxSizer( wxVERTICAL );
227 detailsPanel->SetSizer( detailsSizer );
230 detailsSizer->Add(
m_details, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
231 detailsPanel->Layout();
232 detailsSizer->Fit( detailsPanel );
238 sizer->Add(
m_vsplitter, 1, wxEXPAND | wxBOTTOM, 5 );
242 wxBoxSizer* treeSizer =
new wxBoxSizer( wxVERTICAL );
243 treePanel->SetSizer( treeSizer );
248 treeSizer->Add(
m_tree, 1, wxALL | wxEXPAND, 5 );
250 treeSizer->Fit( treePanel );
336 cfg->m_SymChooserPanel.width = GetParent()->GetSize().x;
337 cfg->m_SymChooserPanel.height = GetParent()->GetSize().y;
339 cfg->m_SymChooserPanel.sash_pos_h =
m_hsplitter->GetSashPosition();
342 cfg->m_SymChooserPanel.sash_pos_v =
m_vsplitter->GetSashPosition();
365 if( aEvent.GetKeyCode() == WXK_ESCAPE )
367 wxObject* eventSource = aEvent.GetEventObject();
369 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( eventSource ) )
405 wxPanel* panel =
new wxPanel( aParent );
406 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
427 sizer->Add(
m_fp_sel_ctrl, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
430 sizer->Add(
m_fp_preview, 10, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
437 panel->SetSizer( sizer );
449 auto horizPixelsFromDU =
453 return GetParent()->ConvertDialogToPixels( sz ).x;
458 int w = panelCfg.
width > 40 ? panelCfg.
width : horizPixelsFromDU( 440 );
459 int h = panelCfg.
height > 40 ? panelCfg.
height : horizPixelsFromDU( 340 );
461 GetParent()->SetSize( wxSize( w, h ) );
462 GetParent()->Layout();
468 panelCfg.
sash_pos_h = horizPixelsFromDU( 220 );
471 panelCfg.
sash_pos_v = horizPixelsFromDU( 230 );
494 if(
m_details && e.GetKeyCode() ==
'C' && e.ControlDown() &&
495 !e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
497 wxString txt =
m_details->SelectionToText();
500 if( wxTheClipboard->Open() )
502 wxTheClipboard->SetData(
new wxTextDataObject( txt ) );
503 wxTheClipboard->Flush();
504 wxTheClipboard->Close();
516 m_adapter->SetPreselectNode( aPreselect, 0 );
531 wxMouseState state = wxGetMouseState();
533 if( state.LeftIsDown() )
549 m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
566 wxLogError(
_(
"Error loading symbol %s from library '%s'." ) + wxS(
"\n%s" ),
576 wxString fp_name = fp_field ? fp_field->
GetFullText() : wxString(
"" );
587 if( aFootprint == wxEmptyString )
595 if( lib_id.
Parse( aFootprint ) == -1 && lib_id.
IsValid() )
625 wxLogError(
_(
"Error loading symbol %s from library '%s'." ) + wxS(
"\n%s" ),
632 if( symbol !=
nullptr )
634 int pinCount = symbol->
GetPins( 0 , 1 ).size();
636 wxString fp_name = fp_field ? fp_field->
GetFullText() : wxString(
"" );
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
Add dark theme support to wxHtmlWindow.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
bool IsValid() const
Check if this LID_ID is valid.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
std::vector< SCH_PIN * > GetPins(int aUnit, int aBodyStyle) const
Return a list of pin object pointers from the draw item list.
SCH_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
wxArrayString GetFPFilters() const
bool GetIsVisible() const
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void SetPreselectNode(const LIB_ID &aLibId, int aUnit)
Set the symbol name to be selected if there are no search results.
void AssignIntrinsicRanks()
Sort the tree and assign ranks after adding libraries.
LIB_TREE_NODE_LIBRARY & DoAddLibrary(const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool pinned, bool presorted)
Add the given list of symbols by alias.
void SetFilter(std::function< bool(LIB_TREE_NODE &aNode)> *aFilter)
Set the filter.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
bool m_IsAlreadyPlacedGroup
bool m_IsRecentlyUsedGroup
Widget displaying a tree of symbols with optional search text control and description panel.
LIB_TREE_NODE * GetCurrentTreeNode() const
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
wxString GetSearchString() const
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
void BlockPreview(bool aBlock)
PANEL_SYMBOL_CHOOSER(SCH_BASE_FRAME *aFrame, wxWindow *aParent, const SYMBOL_LIBRARY_FILTER *aFilter, std::vector< PICKED_SYMBOL > &aHistoryList, std::vector< PICKED_SYMBOL > &aAlreadyPlaced, bool aAllowFieldEdits, bool aShowFootprints, std::function< void()> aAcceptHandler, std::function< void()> aEscapeHandler)
Create dialog to choose symbol.
wxTimer * m_dbl_click_timer
SYMBOL_PREVIEW_WIDGET * m_symbol_preview
void onSymbolSelected(wxCommandEvent &aEvent)
void showFootprintFor(const LIB_ID &aLibId)
Look up the footprint for a given symbol specified in the LIB_ID and display it.
void onMenuClose(wxMenuEvent &aEvent)
wxSplitterWindow * m_hsplitter
FOOTPRINT_SELECT_WIDGET * m_fp_sel_ctrl
std::function< void()> m_escapeHandler
void OnDetailsCharHook(wxKeyEvent &aEvt)
static wxString g_symbolSearchString
void onMenuOpen(wxMenuEvent &aEvent)
Handle parent frame menu events to block tree preview.
void onCloseTimer(wxTimerEvent &aEvent)
wxSplitterWindow * m_vsplitter
std::vector< std::pair< int, wxString > > m_field_edits
wxTimer * m_open_libs_timer
void showFootprint(const wxString &aFootprint)
Display the given footprint by name.
void populateFootprintSelector(const LIB_ID &aLibId)
Populate the footprint selector for a given alias.
void onOpenLibsTimer(wxTimerEvent &aEvent)
void onFootprintSelected(wxCommandEvent &aEvent)
static wxString g_powerSearchString
void OnChar(wxKeyEvent &aEvent)
void SetPreselect(const LIB_ID &aPreselect)
std::function< void()> m_acceptHandler
static constexpr int DBLCLICK_DELAY
FOOTPRINT_PREVIEW_WIDGET * m_fp_preview
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
void onSymbolChosen(wxCommandEvent &aEvent)
Handle the selection of an item.
wxPanel * constructRightPanel(wxWindow *aParent)
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
The backing store for a PROJECT, in JSON format.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual PROJECT_FILE & GetProjectFile() const
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
LIB_SYMBOL * GetLibSymbol(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
Load symbol from symbol library table.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
wxString GetFullText(int unit=1) const
Return the text of a field.
void SetText(const wxString &aText) override
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
Helper object to filter a list of libraries.
bool GetFilterPowerSymbols() const
const wxArrayString & GetAllowedLibList() const
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
bool AddLibraries(const std::vector< wxString > &aNicknames, SCH_BASE_FRAME *aFrame)
Add all the libraries in a SYMBOL_LIB_TABLE to the model.
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(SCH_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
void AddLibrary(wxString const &aLibNickname, bool pinned)
EDA_UNITS GetUserUnits() const
void delete_if(_Container &__c, _Function &&__f)
Deletes all values from __c for which __f returns true.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< wxString > pinned_symbol_libs
Definition for symbol library class.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".