KiCad PCB EDA Suite
sch_base_frame.cpp File Reference
#include <base_units.h>
#include <kiway.h>
#include <pgm_base.h>
#include <eeschema_settings.h>
#include <libedit_settings.h>
#include <sch_draw_panel.h>
#include <sch_view.h>
#include <sch_painter.h>
#include <settings/settings_manager.h>
#include <gal/graphics_abstraction_layer.h>
#include <confirm.h>
#include <preview_items/selection_area.h>
#include <class_library.h>
#include <sch_base_frame.h>
#include <symbol_lib_table.h>
#include <tool/action_toolbar.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h>
#include <default_values.h>

Go to the source code of this file.


LIB_PARTSchGetLibPart (const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, PART_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
 Load symbol from symbol library table. More...

Function Documentation

◆ SchGetLibPart()

LIB_PART* SchGetLibPart ( const LIB_ID aLibId,
PART_LIB aCacheLib = NULL,
wxWindow *  aParent = NULL,
bool  aShowErrorMsg = false 

Load symbol from symbol library table.

Check the symbol library table for the part defined by aLibId and optionally check the optional cache library.

aLibIdis the symbol library identifier to load.
aLibTableis the #SYMBOL_LIBRARY_TABLE to load the alias from.
aCacheLibis an optional cache library.
aParentis an optiona parent window when displaying an error message.
aShowErrorMessageset to true to show any error messages.
The symbol found in the library or NULL if the symbol was not found.

Definition at line 48 of file sch_base_frame.cpp.

50 {
51  wxCHECK_MSG( aLibTable, nullptr, "Invalid symbol library table." );
53  LIB_PART* symbol = nullptr;
55  try
56  {
57  symbol = aLibTable->LoadSymbol( aLibId );
59  if( !symbol && aCacheLib )
60  {
61  wxCHECK_MSG( aCacheLib->IsCache(), nullptr, "Invalid cache library." );
63  wxString cacheName = aLibId.GetLibNickname().wx_str();
64  cacheName += "_" + aLibId.GetLibItemName();
65  symbol = aCacheLib->FindPart( cacheName );
66  }
67  }
68  catch( const IO_ERROR& ioe )
69  {
70  if( aShowErrorMsg )
71  {
72  wxString msg = wxString::Format( _( "Error loading symbol '%s' from library '%s'." ),
73  aLibId.GetLibItemName().wx_str(),
74  aLibId.GetLibNickname().wx_str() );
75  DisplayErrorMessage( aParent, msg, ioe.What() );
76  }
77  }
79  return symbol;
80 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:253
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
Define a library symbol object.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
LIB_PART * FindPart(const wxString &aName) const
Find LIB_PART by aName.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
bool IsCache() const

References _, DisplayErrorMessage(), PART_LIB::FindPart(), Format(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), PART_LIB::IsCache(), SYMBOL_LIB_TABLE::LoadSymbol(), IO_ERROR::What(), and UTF8::wx_str().

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SCH_BASE_FRAME::GetLibPart(), and ERC_TESTER::TestLibSymbolIssues().