40#include <wx/clipbrd.h>
43#include <wx/splitter.h>
54 std::vector<PICKED_SYMBOL>& aHistoryList,
55 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
56 bool aAllowFieldEdits,
bool aShowFootprints,
57 std::function<
void()> aCloseHandler ) :
58 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
59 m_symbol_preview( nullptr ),
60 m_hsplitter( nullptr ),
61 m_vsplitter( nullptr ),
62 m_fp_sel_ctrl( nullptr ),
63 m_fp_preview( nullptr ),
67 m_closeHandler(
std::
move( aCloseHandler ) ),
69 m_allow_field_edits( aAllowFieldEdits ),
70 m_show_footprints( aShowFootprints )
88 for(
const wxString& nickname : liblist )
121 std::vector<LIB_SYMBOL> history_list_storage;
122 std::vector<LIB_TREE_ITEM*> history_list;
123 std::vector<LIB_SYMBOL> already_placed_storage;
124 std::vector<LIB_TREE_ITEM*> already_placed;
127 auto processList = [&](
const std::vector<PICKED_SYMBOL>& inputList,
128 std::vector<LIB_SYMBOL>& storageList,
129 std::vector<LIB_TREE_ITEM*>& resultList )
131 storageList.reserve( inputList.size() );
139 storageList.emplace_back( *symbol );
141 for(
const std::pair<int, wxString>& fieldDef : i.Fields )
143 LIB_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
146 field->
SetText( fieldDef.second );
149 resultList.push_back( &storageList.back() );
154 processList( aHistoryList, history_list_storage, history_list );
155 processList( aAlreadyPlaced, already_placed_storage, already_placed );
157 adapter->
DoAddLibrary( wxT(
"-- " ) +
_(
"Recently Used" ) + wxT(
" --" ), wxEmptyString,
158 history_list,
false,
true );
160 if( !aHistoryList.empty() )
163 adapter->
DoAddLibrary( wxT(
"-- " ) +
_(
"Already Placed" ) + wxT(
" --" ), wxEmptyString,
164 already_placed,
false,
true );
166 const std::vector< wxString > libNicknames = libs->
GetLogicalLibs();
181 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
187 m_hsplitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
188 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
197 m_vsplitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
198 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
201 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
207 wxPanel* detailsPanel =
new wxPanel(
m_vsplitter );
208 wxBoxSizer* detailsSizer =
new wxBoxSizer( wxVERTICAL );
209 detailsPanel->SetSizer( detailsSizer );
212 detailsSizer->Add(
m_details, 1, wxEXPAND, 5 );
213 detailsPanel->Layout();
214 detailsSizer->Fit( detailsPanel );
224 wxBoxSizer* treeSizer =
new wxBoxSizer( wxVERTICAL );
225 treePanel->SetSizer( treeSizer );
230 treeSizer->Add(
m_tree, 1, wxEXPAND, 5 );
232 treeSizer->Fit( treePanel );
299 cfg->m_SymChooserPanel.width = GetParent()->GetSize().x;
300 cfg->m_SymChooserPanel.height = GetParent()->GetSize().y;
302 cfg->m_SymChooserPanel.sash_pos_h =
m_hsplitter->GetSashPosition();
305 cfg->m_SymChooserPanel.sash_pos_v =
m_vsplitter->GetSashPosition();
326 wxPanel* panel =
new wxPanel( aParent );
327 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
348 sizer->Add(
m_fp_sel_ctrl, 0, wxEXPAND | wxTOP | wxBOTTOM, 4 );
358 panel->SetSizer( sizer );
370 auto horizPixelsFromDU =
374 return GetParent()->ConvertDialogToPixels( sz ).x;
379 int w = panelCfg.
width > 40 ? panelCfg.
width : horizPixelsFromDU( 440 );
380 int h = panelCfg.
height > 40 ? panelCfg.
height : horizPixelsFromDU( 340 );
382 GetParent()->SetSize( wxSize( w, h ) );
383 GetParent()->Layout();
389 panelCfg.
sash_pos_h = horizPixelsFromDU( 220 );
392 panelCfg.
sash_pos_v = horizPixelsFromDU( 230 );
415 if(
m_details && e.GetKeyCode() ==
'C' && e.ControlDown() &&
416 !e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
418 wxString txt =
m_details->SelectionToText();
421 if( wxTheClipboard->Open() )
423 wxTheClipboard->SetData(
new wxTextDataObject( txt ) );
424 wxTheClipboard->Flush();
425 wxTheClipboard->Close();
437 m_adapter->SetPreselectNode( aPreselect, 0 );
452 wxMouseState state = wxGetMouseState();
454 if( state.LeftIsDown() )
480 wxLogError(
_(
"Error loading symbol %s from library '%s'." ) + wxS(
"\n%s" ),
490 wxString fp_name = fp_field ? fp_field->
GetFullText() : wxString(
"" );
501 if( aFootprint == wxEmptyString )
509 if( lib_id.
Parse( aFootprint ) == -1 && lib_id.
IsValid() )
539 wxLogError(
_(
"Error loading symbol %s from library '%s'." ) + wxS(
"\n%s" ),
546 if( symbol !=
nullptr )
550 wxString fp_name = fp_field ? fp_field->
GetFullText() : wxString(
"" );
554 symbol->
GetPins( temp_pins, 0, 1 );
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
virtual void SetText(const wxString &aText)
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.
Field object used in symbol libraries.
wxString GetFullText(int unit=1) const
Return the text of a field.
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.
LIB_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
wxArrayString GetFPFilters() const
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0) const
Return a list of pin object pointers from the draw item list.
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
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 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 AssignIntrinsicRanks()
Sort the tree and assign ranks after adding libraries.
void SetFilter(std::function< bool(LIB_TREE_NODE &aNode)> *aFilter)
Set the symbol filter type.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
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.
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.
wxSplitterWindow * m_hsplitter
FOOTPRINT_SELECT_WIDGET * m_fp_sel_ctrl
static wxString g_symbolSearchString
std::function< void()> m_closeHandler
void onCloseTimer(wxTimerEvent &aEvent)
wxSplitterWindow * m_vsplitter
std::vector< std::pair< int, wxString > > m_field_edits
void OnCharHook(wxKeyEvent &aEvt)
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 onFootprintSelected(wxCommandEvent &aEvent)
static wxString g_powerSearchString
void SetPreselect(const LIB_ID &aPreselect)
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()> aCloseHandler)
Create dialog to choose symbol.
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)
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.
Helper object to filter a list of libraries.
bool GetFilterPowerSymbols() const
const wxArrayString & GetAllowedLibList() const
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...
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
bool AddLibraries(const std::vector< wxString > &aNicknames, SCH_BASE_FRAME *aFrame)
Add all the libraries in a SYMBOL_LIB_TABLE to the model.
void AddLibrary(wxString const &aLibNickname, bool pinned)
EDA_UNITS GetUserUnits() const
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
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.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
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".