44#include <wx/clipbrd.h>
47#include <wx/splitter.h>
59 std::vector<PICKED_SYMBOL>& aHistoryList,
60 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
61 bool aAllowFieldEdits,
bool aShowFootprints,
bool& aCancelled,
62 std::function<
void()> aAcceptHandler,
63 std::function<
void()> aEscapeHandler ) :
64 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
95 for(
const wxString& nickname : liblist )
102 std::optional<LIBRARY_TABLE_ROW*> row = libmgr->
GetRow( nickname );
104 if( row.has_value() && !row.value()->Hidden() )
120 if (symbol && symbol->
IsPower())
135 std::vector<LIB_SYMBOL> history_list_storage;
136 std::vector<LIB_TREE_ITEM*> history_list;
137 std::vector<LIB_SYMBOL> already_placed_storage;
138 std::vector<LIB_TREE_ITEM*> already_placed;
142 [&](
const std::vector<PICKED_SYMBOL>& inputList,
143 std::vector<LIB_SYMBOL>& storageList,
144 std::vector<LIB_TREE_ITEM*>& resultList )
146 storageList.reserve( inputList.size() );
154 storageList.emplace_back( *symbol );
156 for(
const auto& [fieldType, fieldValue] : i.Fields )
158 SCH_FIELD* field = storageList.back().GetField( fieldType );
164 resultList.push_back( &storageList.back() );
171 std::sort( aAlreadyPlaced.begin(), aAlreadyPlaced.end(),
174 return a.LibId.GetLibItemName() < b.LibId.GetLibItemName();
177 processList( aHistoryList, history_list_storage, history_list );
178 processList( aAlreadyPlaced, already_placed_storage, already_placed );
180 adapter->
DoAddLibrary( wxT(
"-- " ) +
_(
"Recently Used" ) + wxT(
" --" ), wxEmptyString,
181 history_list,
false,
true )
184 if( !aHistoryList.empty() )
187 adapter->
DoAddLibrary( wxT(
"-- " ) +
_(
"Already Placed" ) + wxT(
" --" ), wxEmptyString,
188 already_placed,
false,
true )
197 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
203 m_hsplitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
204 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
213 m_vsplitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
214 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
217 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
223 wxPanel* detailsPanel =
new wxPanel(
m_vsplitter );
224 wxBoxSizer* detailsSizer =
new wxBoxSizer( wxVERTICAL );
225 detailsPanel->SetSizer( detailsSizer );
228 detailsSizer->Add(
m_details, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
229 detailsPanel->Layout();
230 detailsSizer->Fit( detailsPanel );
236 sizer->Add(
m_vsplitter, 1, wxEXPAND | wxBOTTOM, 5 );
240 wxBoxSizer* treeSizer =
new wxBoxSizer( wxVERTICAL );
241 treePanel->SetSizer( treeSizer );
246 treeSizer->Add(
m_tree, 1, wxALL | wxEXPAND, 5 );
248 treeSizer->Fit( treePanel );
318 cfg->m_SymChooserPanel.width = GetParent()->GetSize().x;
319 cfg->m_SymChooserPanel.height = GetParent()->GetSize().y;
321 cfg->m_SymChooserPanel.sash_pos_h =
m_hsplitter->GetSashPosition();
324 cfg->m_SymChooserPanel.sash_pos_v =
m_vsplitter->GetSashPosition();
326 cfg->m_SymChooserPanel.sort_mode =
m_tree->GetSortMode();
335 m_tree->BlockPreview(
true );
342 m_tree->BlockPreview(
false );
349 if( aEvent.GetKeyCode() == WXK_ESCAPE )
351 wxObject* eventSource = aEvent.GetEventObject();
353 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( eventSource ) )
356 if( textCtrl->GetValue() ==
m_tree->GetSearchString()
357 && !
m_tree->GetSearchString().IsEmpty() )
359 m_tree->SetSearchString( wxEmptyString );
378 backend =
m_frame->GetCanvas()->GetBackend();
382 wxPanel* panel =
new wxPanel( aParent );
383 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
393 sizer->Add(
m_fp_sel_ctrl, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
399 sizer->Add(
m_fp_preview, 10, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
406 panel->SetSizer( sizer );
418 auto horizPixelsFromDU =
422 return GetParent()->ConvertDialogToPixels( sz ).x;
427 int w = panelCfg.
width > 40 ? panelCfg.
width : horizPixelsFromDU( 440 );
428 int h = panelCfg.
height > 40 ? panelCfg.
height : horizPixelsFromDU( 340 );
430 GetParent()->SetSize( wxSize( w, h ) );
431 GetParent()->Layout();
437 panelCfg.
sash_pos_h = horizPixelsFromDU( 220 );
440 panelCfg.
sash_pos_v = horizPixelsFromDU( 230 );
463 if(
m_details && e.GetKeyCode() ==
'C' && e.ControlDown() &&
464 !e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
466 wxString txt =
m_details->SelectionToText();
469 if( wxTheClipboard->Open() )
471 wxTheClipboard->SetData(
new wxTextDataObject( txt ) );
472 wxTheClipboard->Flush();
473 wxTheClipboard->Close();
485 m_adapter->SetPreselectNode( aPreselect, 0 );
491 return m_tree->GetSelectedLibId( aUnit );
502 m_fp_preview->GetPreviewPanel()->GetCanvas()->SetEvtHandlerEnabled(
false );
503 m_fp_preview->GetPreviewPanel()->GetCanvas()->StopDrawing();
513 wxMouseState state = wxGetMouseState();
515 if( state.LeftIsDown() )
531 m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
548 wxLogError(
_(
"Error loading symbol %s from library '%s'." ) + wxS(
"\n%s" ),
558 wxString fp_name = fp_field ? fp_field->
GetFullText() : wxString(
"" );
569 if( aFootprint == wxEmptyString )
571 m_fp_preview->SetStatusText(
_(
"No footprint specified" ) );
577 if( lib_id.
Parse( aFootprint ) == -1 && lib_id.
IsValid() )
584 m_fp_preview->SetStatusText(
_(
"Invalid footprint specified" ) );
607 wxLogError(
_(
"Error loading symbol %s from library '%s'." ) + wxS(
"\n%s" ),
614 if( symbol !=
nullptr )
618 wxString fp_name = fp_field ? fp_field->
GetFullText() : wxString(
"" );
638 std::erase_if(
m_field_edits, []( std::pair<FIELD_T, wxString>
const& i )
678 if(
m_tree->GetSelectedLibId().IsValid() )
697 m_tree->Regenerate(
true );
700 m_tree->CenterLibId( savedSelection );
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ GAL_TYPE_OPENGL
OpenGL implementation.
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()
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
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< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
bool IsPower() const override
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
wxArrayString GetFPFilters() const
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.
wxTimer * m_dbl_click_timer
SYMBOL_PREVIEW_WIDGET * m_symbol_preview
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, bool &aCancelled, std::function< void()> aAcceptHandler, std::function< void()> aEscapeHandler)
Create dialog to choose symbol.
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.
std::vector< std::pair< FIELD_T, wxString > > m_field_edits
void onCloseTimer(wxTimerEvent &aEvent)
wxSplitterWindow * m_vsplitter
static SCH_BASE_FRAME * m_frame
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
The backing store for a PROJECT, in JSON format.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
wxString GetFullText(int unit=1) const
Return the text of a field.
void SetText(const wxString &aText) override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
Helper object to filter a list of libraries.
bool GetFilterPowerSymbols() const
const wxArrayString & GetAllowedLibList() const
void AddLibraries(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, SYMBOL_LIBRARY_ADAPTER *aLibs)
Factory function: create a model adapter in a reference-counting container.
void AddLibrary(wxString const &aLibNickname, bool pinned)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetAppSettings(const char *aFilename)
std::vector< wxString > pinned_symbol_libs
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".