63#include <wx/srchctrl.h>
109 m_unitChoice(
nullptr ),
110 m_libList(
nullptr ),
111 m_symbolList(
nullptr )
113 m_aboutTitle =
_HKI(
"KiCad Symbol Library Browser" );
125 m_libListWidth = 200;
126 m_symbolListWidth = 300;
127 m_listPowerOnly =
false;
130 GetScreen()->m_Center =
true;
147 m_toolbarSettings = GetToolbarSettings<SYMBOL_VIEWER_TOOLBAR_SETTINGS>(
"symbol_viewer-toolbars" );
153 wxPanel* libPanel =
new wxPanel(
this );
154 wxSizer* libSizer =
new wxBoxSizer( wxVERTICAL );
157 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
158 m_libFilter->SetDescriptiveText(
_(
"Filter" ) );
159 libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
162 0,
nullptr, wxLB_HSCROLL | wxNO_BORDER );
163 libSizer->Add( m_libList, 1, wxEXPAND, 5 );
165 libPanel->SetSizer( libSizer );
168 wxPanel* symbolPanel =
new wxPanel(
this );
169 wxSizer* symbolSizer =
new wxBoxSizer( wxVERTICAL );
172 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
173 m_symbolFilter->SetDescriptiveText(
_(
"Filter" ) );
174 m_symbolFilter->SetToolTip(
175 _(
"Filter on symbol name, keywords, description and pin count.\n"
176 "Search terms are separated by spaces. All search terms must match.\n"
177 "A term which is a number will also match against the pin count." ) );
178 symbolSizer->Add( m_symbolFilter, 0, wxEXPAND, 5 );
183 m_libFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
184 m_symbolFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
188 wxDefaultSize, 0,
nullptr, wxLB_HSCROLL | wxNO_BORDER );
189 symbolSizer->Add( m_symbolList, 1, wxEXPAND, 5 );
191 symbolPanel->SetSizer( symbolSizer );
198 m_selection_changed =
false;
202 m_auimgr.SetManagedWindow(
this );
207 m_auimgr.AddPane( m_tbTopMain,
EDA_PANE().HToolbar().Name(
"TopMainToolbar" ).Top().Layer(6) );
208 m_auimgr.AddPane( m_messagePanel,
EDA_PANE().Messages().Name(
"MsgPanel" ) .Bottom().Layer(6) );
210 m_auimgr.AddPane( libPanel,
EDA_PANE().Palette().Name(
"Libraries" ).Left().Layer(2)
211 .CaptionVisible(
false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
212 m_auimgr.AddPane( symbolPanel,
EDA_PANE().Palette().Name(
"Symbols" ).Left().Layer(1)
213 .CaptionVisible(
false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
215 m_auimgr.AddPane( GetCanvas(),
EDA_PANE().Canvas().Name(
"DrawFrame" ).Center() );
219 if( m_libListWidth > 0 )
220 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane(
"Libraries" ), m_libListWidth, -1 );
222 if( m_symbolListWidth > 0 )
223 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane(
"Symbols" ), m_symbolListWidth, -1 );
225 FinishAUIInitialization();
231 GetCanvas()->SetCanFocus(
false );
240 bbox.
SetOrigin( -max_size_x / 2, -max_size_y / 2 );
241 bbox.
SetSize( max_size_x, max_size_y );
242 GetCanvas()->GetView()->SetBoundary( bbox );
246 wxString symbName = m_symbolList->GetStringSelection();
248 if( !symbName.IsEmpty() )
250 SetSelectedSymbol( symbName );
251 updatePreviewSymbol();
274 std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter =
nullptr;
278 progressReporter = std::make_unique<WX_PROGRESS_REPORTER>(
this,
_(
"Load Symbol Libraries" ),
285 std::unordered_map<wxString, std::vector<LIB_SYMBOL*>> loadedSymbols;
288 nullptr, progressReporter.get() );
294 while( !loader.
Done() )
296 if( progressReporter && !progressReporter->KeepRefreshing() )
313 msg.Replace(
"\n",
"<BR>" );
357#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
358#define CHECK( x ) ACTION_CONDITIONS().Check( x )
362 auto electricalTypesShownCondition =
368 auto pinNumbersShownCondition =
381 auto demorganStandardCond =
387 auto demorganAlternateCond =
393 auto haveDatasheetCond =
414 m_unit = aUnit > 0 ? aUnit : 1;
415 m_bodyStyle = aBodyStyle > 0 ? aBodyStyle : BODY_STYLE::BASE;
455 std::shared_ptr<LIB_SYMBOL> parent = symbol->
GetParent().lock();
458 parentName = parent->GetName();
509 for(
int ii = 0; ii < unit_count; ii++ )
538 std::vector<wxString> pinnedMatches;
539 std::vector<wxString> otherMatches;
542 [&](
const wxString& aLib )
547 pinnedMatches.push_back( aLib );
551 otherMatches.push_back( aLib );
556 [&](
const wxString& aLib )
568 wxArrayString aliasNames;
574 if( aliasNames.IsEmpty() )
587 std::vector<wxString> subLibraries;
590 for(
const wxString& lib : subLibraries )
592 wxString suffix = lib.IsEmpty() ? wxString( wxT(
"" ) )
593 : wxString::Format( wxT(
" - %s" ), lib );
594 wxString
name = wxString::Format( wxT(
"%s%s" ), aLib, suffix );
607 for(
const wxString& lib : libs )
612 wxStringTokenizer tokenizer(
m_libFilter->GetValue() );
614 while( tokenizer.HasMoreTokens() )
616 const wxString term = tokenizer.GetNextToken().Lower();
619 for(
const wxString& lib : libs )
621 if( matcher.
Find( lib.Lower() ) )
630 for(
const wxString&
name : pinnedMatches )
633 for(
const wxString&
name : otherMatches )
640 if( index != wxNOT_FOUND )
672 if( libName.IsEmpty() )
675 std::vector<LIB_SYMBOL*> symbols;
686 std::set<wxString> excludes;
692 while( tokenizer.HasMoreTokens() )
694 const wxString filterTerm = tokenizer.GetNextToken().Lower();
699 std::vector<SEARCH_TERM> searchTerms = symbol->GetSearchTerms();
700 int matched = matcher.
ScoreTerms( searchTerms );
702 if( filterTerm.IsNumber() && wxAtoi( filterTerm ) == (
int)symbol->GetPinCount() )
706 excludes.insert( symbol->GetName() );
716 && !subLib.IsSameAs( symbol->GetLibId().GetSubLibraryName() ) )
721 if( !excludes.count( symbol->GetName() ) )
735 bool changed =
false;
737 if( index == wxNOT_FOUND )
766 && selection.Find(
'-' ) != wxNOT_FOUND )
770 selection = selection.BeforeLast(
'-', &sublib ).Trim();
771 sublib.Trim(
false );
782 const wxString& aSubLibName )
872 int maxWidth = cfg->m_LibViewPanel.window.state.size_x - 80;
899 cfg->m_LibViewPanel.show_pin_electrical_type = renderSettings->m_ShowPinsElectricalType;
900 cfg->m_LibViewPanel.show_pin_numbers = renderSettings->m_ShowPinNumbers;
909 return &cfg->m_LibViewPanel.window;
911 wxFAIL_MSG( wxT(
"SYMBOL_VIEWER not running with EESCHEMA_SETTINGS" ) );
934 if( event.GetActive() )
998 if( aEvent.GetKeyCode() == WXK_UP )
1002 int prev =
m_libList->GetSelection() - 1;
1009 wxCommandEvent
dummy;
1015 wxCommandEvent
dummy;
1019 else if( aEvent.GetKeyCode() == WXK_DOWN )
1030 wxCommandEvent
dummy;
1036 wxCommandEvent
dummy;
1040 else if( aEvent.GetKeyCode() == WXK_TAB &&
m_libFilter->HasFocus() )
1042 if( !aEvent.ShiftDown() )
1047 else if( aEvent.GetKeyCode() == WXK_TAB &&
m_symbolFilter->HasFocus() )
1049 if( aEvent.ShiftDown() )
1054 else if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
1057 wxCommandEvent
dummy;
1073 if( ii != wxNOT_FOUND && ii < (
int) (
m_symbolList->GetCount() - 1 ) )
1087 if( ii != wxNOT_FOUND && ii != 0 )
1117 wxString title = row ? row->
GetFullURI(
true ) :
_(
"[no library selected]" );
1119 title += wxT(
" \u2014 " ) +
_(
"Symbol Library Browser" );
1146 wxCHECK2( tbl && symbol,
break );
1153 wxString libfullname = row->
GetFullURI(
true );
1156 wxLogTrace(
"KICAD_LIB_WATCH",
"Received refresh symbol request for %s, current symbols "
1157 "is %s", lib, libfullname );
1159 if( lib == libfullname )
1161 wxLogTrace(
"KICAD_LIB_WATCH",
"Refreshing symbol %s", symbol->
GetName() );
constexpr EDA_IU_SCALE schIUScale
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
static TOOL_ACTION toggleGrid
static TOOL_ACTION showDatasheet
static TOOL_ACTION zoomFitScreen
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
constexpr void SetOrigin(const Vec &pos)
constexpr void SetSize(const SizeVec &size)
COLOR4D GetColor(int aLayer) const
Handle actions that are shared between different applications.
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
int ScoreTerms(std::vector< SEARCH_TERM > &aWeightedTerms)
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Look in all existing matchers, return the earliest match of any of the existing.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
COLOR_SETTINGS * m_colorSettings
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, etc).
Specialization of the wxAuiPaneInfo class for KiCad panels.
virtual const wxString & GetText() const
Return the string associated with the text object.
Class that groups generic conditions for editor states.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
double m_gridMinSpacing
Whether or not to draw the coordinate system axes.
bool m_axesEnabled
Fullscreen crosshair or small cross.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
static void CreateNilUuids(bool aNil=true)
A performance optimization which disables/enables the generation of pseudo-random UUIDs.
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
MAIL_T Command()
Returns the MAIL_T associated with this mail.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
bool IsValid() const
Check if this LID_ID is valid.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
void SetSubLibraryName(const UTF8 &aName)
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const wxString GetUniStringLibNickname() const
UTF8 GetSubLibraryName() const
Some LIB_IDs can have a sub-library identifier in addition to a library nickname.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
const wxString GetFullLibraryName() const
Define a library symbol object.
const LIB_ID & GetLibId() const override
SCH_FIELD & GetDatasheetField()
Return reference to the datasheet field.
bool HasAlternateBodyStyle() const override
Test if symbol has more than one body conversion type (DeMorgan).
wxString GetName() const override
LIB_SYMBOL_SPTR SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
LIB_SYMBOL_REF & GetParent()
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the user-defined display name for aUnit for symbols with units.
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
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.
static const wxString GetPinningSymbol()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
virtual COMMON_SETTINGS * GetCommonSettings() 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
Gather all the actions that are shared by tools.
static TOOL_ACTION showDeMorganAlternate
static TOOL_ACTION showElectricalTypes
static TOOL_ACTION showPinNumbers
static TOOL_ACTION showDeMorganStandard
static TOOL_ACTION addSymbolToSchematic
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_RENDER_SETTINGS * GetRenderSettings()
void doCloseWindow() override
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
bool m_ShowPinsElectricalType
const wxString & GetErrors() const
void Start()
Spin up threads to load all the libraries in m_nicknames.
bool Join()
Finalize the threads and combines the output into the target output map.
Handle actions for the various symbol editor and viewers.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
void GetSubLibraryNames(std::vector< wxString > &aNames) const
bool SupportsSubLibraries() const
void LoadSymbolLib(std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
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...
Symbol library viewer main window.
void OnLibFilter(wxCommandEvent &aEvent)
void updatePreviewSymbol()
std::unique_ptr< LIB_SYMBOL > m_previewItem
void CloseLibraryViewer(wxCommandEvent &event)
wxArrayString m_allowedLibs
void onSelectNextSymbol(wxCommandEvent &aEvent)
wxSearchCtrl * m_libFilter
void SetSelectedLibrary(const wxString &aLibName, const wxString &aSubLibName=wxEmptyString)
Set the selected library in the library window.
void ClickOnLibList(wxCommandEvent &event)
void onUpdateUnitChoice(wxUpdateUIEvent &aEvent)
void DClickOnSymbolList(wxCommandEvent &event)
void OnActivate(wxActivateEvent &event)
Called when the frame is activated to reload the libraries and symbol lists that can be changed by th...
void OnSymFilter(wxCommandEvent &aEvent)
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void doCloseWindow() override
void SetSelectedSymbol(const wxString &aSymbolName)
Set the selected symbol.
static bool m_show_progress
WX_LISTBOX * m_symbolList
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Receive KIWAY_EXPRESS messages from other players.
bool ReCreateLibList()
Create o recreates a sorted list of currently loaded libraries.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void ClickOnSymbolList(wxCommandEvent &event)
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box of document with option to not include some items.
void SetUnitAndBodyStyle(int aUnit, int aBodyStyle)
Set unit and convert, and set flag preventing them from automatically resetting to 1.
wxSearchCtrl * m_symbolFilter
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
static LIB_ID m_currentSymbol
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void OnCharHook(wxKeyEvent &aEvent) override
Capture the key event before it is sent to the GUI.
LIB_SYMBOL * GetSelectedSymbol() const
void onSelectSymbolUnit(wxCommandEvent &aEvent)
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void onSelectPreviousSymbol(wxCommandEvent &aEvent)
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
bool m_selection_changed
Updated to true if a list rewrite on GUI activation resulted in the symbol selection changing,...
bool ReCreateSymbolList()
Create or recreate the list of symbols in the currently selected library.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
wxString GetBaseString(int n) const
int FindString(const wxString &s, bool bCase=false) const override
bool SetStringSelection(const wxString &s) override
This file is part of the common library.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define LIB_VIEW_FRAME_NAME
Abstract pattern-matching tool and implementations.
@ ID_LIBVIEW_SELECT_UNIT_NUMBER
@ LAYER_SCHEMATIC_GRID_AXES
Message panel definition file.
@ ALL
All except INITIAL_ADD.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
static PGM_BASE * process
PGM_BASE & Pgm()
The global program "get" accessor.
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
std::vector< wxString > pinned_symbol_libs
constexpr int mmToIU(double mm) const
Store the common settings that are saved and loaded for each window / frame.
VECTOR2< int32_t > VECTOR2I
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.