Tear out the eeschema conditional compile of PROJECT

This commit is contained in:
Marek Roszko 2023-09-27 23:04:53 -04:00
parent c772d116b2
commit 8c6899b0d3
37 changed files with 263 additions and 193 deletions

View File

@ -146,6 +146,12 @@ const wxString PROJECT::GetProjectPath() const
} }
const wxString PROJECT::GetProjectDirectory() const
{
return m_project_name.GetPath();
}
const wxString PROJECT::GetProjectName() const const wxString PROJECT::GetProjectName() const
{ {
return m_project_name.GetName(); return m_project_name.GetName();

View File

@ -329,8 +329,8 @@ set( EESCHEMA_SRCS
net_navigator.cpp net_navigator.cpp
pin_numbers.cpp pin_numbers.cpp
pin_type.cpp pin_type.cpp
project_sch.cpp
project_rescue.cpp project_rescue.cpp
project_sch_specific.cpp
sch_base_frame.cpp sch_base_frame.cpp
sch_bitmap.cpp sch_bitmap.cpp
sch_bus_entry.cpp sch_bus_entry.cpp

View File

@ -29,6 +29,7 @@
#include <sch_base_frame.h> #include <sch_base_frame.h>
#include <core/kicad_algo.h> #include <core/kicad_algo.h>
#include <template_fieldnames.h> #include <template_fieldnames.h>
#include <project_sch.h>
#include <widgets/footprint_preview_widget.h> #include <widgets/footprint_preview_widget.h>
#include <widgets/footprint_select_widget.h> #include <widgets/footprint_select_widget.h>
#include <widgets/lib_tree.h> #include <widgets/lib_tree.h>
@ -127,7 +128,8 @@ DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxStr
treePanel->SetSizer( treeSizer ); treePanel->SetSizer( treeSizer );
m_tree = new LIB_TREE( treePanel, m_showPower ? wxT( "power" ) : wxT( "symbols" ), m_tree = new LIB_TREE( treePanel, m_showPower ? wxT( "power" ) : wxT( "symbols" ),
Prj().SchSymbolLibTable(), aAdapter, LIB_TREE::FLAGS::ALL_WIDGETS, PROJECT_SCH::SchSymbolLibTable( &Prj() ), aAdapter,
LIB_TREE::FLAGS::ALL_WIDGETS,
m_details ); m_details );
treeSizer->Add( m_tree, 1, wxEXPAND | wxALL, 5 ); treeSizer->Add( m_tree, 1, wxEXPAND | wxALL, 5 );
@ -410,7 +412,7 @@ void DIALOG_CHOOSE_SYMBOL::ShowFootprintFor( LIB_ID const& aLibId )
try try
{ {
symbol = Prj().SchSymbolLibTable()->LoadSymbol( aLibId ); symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( aLibId );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
@ -469,7 +471,7 @@ void DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector( LIB_ID const& aLibId )
{ {
try try
{ {
symbol = Prj().SchSymbolLibTable()->LoadSymbol( aLibId ); symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( aLibId );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {

View File

@ -61,7 +61,7 @@ class SCH_DRAW_PANEL;
* for thorough documentation. A simple example usage follows: * for thorough documentation. A simple example usage follows:
* *
* // Create the adapter class * // Create the adapter class
* auto adapter( SYMBOL_TREE_MODEL_ADAPTER::Create( Prj().SchSymbolLibTable() ) ); * auto adapter( SYMBOL_TREE_MODEL_ADAPTER::Create( PROJECT_SCH::SchSymbolLibTable( &Prj() ) );
* *
* // Perform any configuration of adapter properties here * // Perform any configuration of adapter properties here
* adapter->SetPreselectNode( "LIB_NICKNAME", "SYMBO_NAME", 2 ); * adapter->SetPreselectNode( "LIB_NICKNAME", "SYMBO_NAME", 2 );

View File

@ -45,6 +45,7 @@
#include <widgets/grid_text_button_helpers.h> #include <widgets/grid_text_button_helpers.h>
#include <kiplatform/ui.h> #include <kiplatform/ui.h>
#include <string_utils.h> #include <string_utils.h>
#include <project_sch.h>
#define COL_REFS 0 #define COL_REFS 0
@ -572,7 +573,7 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onCellBrowseLib( wxGridEvent& event )
void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event ) void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
{ {
std::vector<wxString> libs = Prj().SchSymbolLibTable()->GetLogicalLibs(); std::vector<wxString> libs = PROJECT_SCH::SchSymbolLibTable( &Prj() )->GetLogicalLibs();
wxArrayString aliasNames; wxArrayString aliasNames;
wxArrayString candidateSymbNames; wxArrayString candidateSymbNames;
@ -601,7 +602,7 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
try try
{ {
Prj().SchSymbolLibTable()->EnumerateSymbolLib( lib, aliasNames ); PROJECT_SCH::SchSymbolLibTable( &Prj() )->EnumerateSymbolLib( lib, aliasNames );
} }
catch( const IO_ERROR& ) {} // ignore, it is handled below catch( const IO_ERROR& ) {} // ignore, it is handled below
@ -736,7 +737,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow()
try try
{ {
symbol = Prj().SchSymbolLibTable()->LoadSymbol( id ); symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( id );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {

View File

@ -34,6 +34,7 @@
#include <widgets/wx_grid.h> #include <widgets/wx_grid.h>
#include <widgets/std_bitmap_button.h> #include <widgets/std_bitmap_button.h>
#include <string_utils.h> #include <string_utils.h>
#include <project_sch.h>
#include <dialog_sim_model.h> #include <dialog_sim_model.h>
@ -75,7 +76,7 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a
m_grid->ShowHideColumns( cfg->m_EditSymbolVisibleColumns ); m_grid->ShowHideColumns( cfg->m_EditSymbolVisibleColumns );
wxGridCellAttr* attr = new wxGridCellAttr; wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_URL_EDITOR( this, Prj().SchSearchS() ) ); attr->SetEditor( new GRID_CELL_URL_EDITOR( this, PROJECT_SCH::SchSearchS( &Prj() ) ) );
m_grid->SetAttr( DATASHEET_FIELD, FDC_VALUE, attr ); m_grid->SetAttr( DATASHEET_FIELD, FDC_VALUE, attr );
m_SymbolNameCtrl->SetValidator( FIELD_VALIDATOR( VALUE_FIELD ) ); m_SymbolNameCtrl->SetValidator( FIELD_VALIDATOR( VALUE_FIELD ) );

View File

@ -54,6 +54,7 @@
#include "dialog_symbol_fields_table.h" #include "dialog_symbol_fields_table.h"
#include <fields_data_model.h> #include <fields_data_model.h>
#include <eda_list_dialog.h> #include <eda_list_dialog.h>
#include <project_sch.h>
wxDEFINE_EVENT( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxCommandEvent ); wxDEFINE_EVENT( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxCommandEvent );
@ -121,7 +122,8 @@ protected:
{ {
wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
DATASHEET_FIELD ); DATASHEET_FIELD );
GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(), m_dlg->Prj().SchSearchS() ); GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(),
PROJECT_SCH::SchSearchS( &m_dlg->Prj() ) );
} }
else else
{ {
@ -338,7 +340,8 @@ void DIALOG_SYMBOL_FIELDS_TABLE::SetupColumnProperties( int aCol )
== TEMPLATE_FIELDNAME::GetDefaultFieldName( DATASHEET_FIELD ) ) == TEMPLATE_FIELDNAME::GetDefaultFieldName( DATASHEET_FIELD ) )
{ {
// set datasheet column viewer button // set datasheet column viewer button
attr->SetEditor( new GRID_CELL_URL_EDITOR( this, Prj().SchSearchS() ) ); attr->SetEditor(
new GRID_CELL_URL_EDITOR( this, PROJECT_SCH::SchSearchS( &Prj() ) ) );
m_grid->SetColAttr( aCol, attr ); m_grid->SetColAttr( aCol, attr );
} }
else if( m_dataModel->ColIsQuantity( aCol ) || m_dataModel->ColIsItemNumber( aCol ) ) else if( m_dataModel->ColIsQuantity( aCol ) || m_dataModel->ColIsItemNumber( aCol ) )

View File

@ -44,6 +44,7 @@
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <env_paths.h> #include <env_paths.h>
#include <project_sch.h>
#include <dialog_symbol_remap.h> #include <dialog_symbol_remap.h>
@ -123,7 +124,7 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent )
createProjectSymbolLibTable( m_messagePanel->Reporter() ); createProjectSymbolLibTable( m_messagePanel->Reporter() );
Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
Prj().SchSymbolLibTable(); PROJECT_SCH::SchSymbolLibTable( &Prj() );
remapSymbolsToLibTable( m_messagePanel->Reporter() ); remapSymbolsToLibTable( m_messagePanel->Reporter() );
@ -135,7 +136,7 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent )
// Reload the cache symbol library. // Reload the cache symbol library.
Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr ); Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
Prj().SchLibs(); PROJECT_SCH::SchLibs( &Prj() );
Raise(); Raise();
m_remapped = true; m_remapped = true;
@ -144,7 +145,7 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent )
size_t DIALOG_SYMBOL_REMAP::getLibsNotInGlobalSymbolLibTable( std::vector< SYMBOL_LIB* >& aLibs ) size_t DIALOG_SYMBOL_REMAP::getLibsNotInGlobalSymbolLibTable( std::vector< SYMBOL_LIB* >& aLibs )
{ {
SYMBOL_LIBS* libs = Prj().SchLibs(); SYMBOL_LIBS* libs = PROJECT_SCH::SchLibs( &Prj() );
for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it ) for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
{ {
@ -288,7 +289,7 @@ bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_SYMBOL* aSymbol )
wxCHECK_MSG( !aSymbol->GetLibId().GetLibItemName().empty(), false, wxCHECK_MSG( !aSymbol->GetLibId().GetLibItemName().empty(), false,
"The symbol LIB_ID name is empty." ); "The symbol LIB_ID name is empty." );
SYMBOL_LIBS* libs = Prj().SchLibs(); SYMBOL_LIBS* libs = PROJECT_SCH::SchLibs( &Prj() );
for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it ) for( SYMBOL_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it )
{ {
@ -306,7 +307,7 @@ bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_SYMBOL* aSymbol )
// Find the same library in the symbol library table using the full path and file name. // Find the same library in the symbol library table using the full path and file name.
wxString libFileName = it->GetFullFileName(); wxString libFileName = it->GetFullFileName();
const LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRowByURI( libFileName ); const LIB_TABLE_ROW* row = PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRowByURI( libFileName );
if( row ) if( row )
{ {

View File

@ -49,6 +49,7 @@
#include <widgets/std_bitmap_button.h> #include <widgets/std_bitmap_button.h>
#include <sch_file_versions.h> #include <sch_file_versions.h>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <project_sch.h>
@ -1134,7 +1135,7 @@ void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent )
// Don't allow editing project tables if no project is open // Don't allow editing project tables if no project is open
if( !aKiway->Prj().IsNullProject() ) if( !aKiway->Prj().IsNullProject() )
projectTable = aKiway->Prj().SchSymbolLibTable(); projectTable = PROJECT_SCH::SchSymbolLibTable( &aKiway->Prj() );
if( symbolEditor ) if( symbolEditor )
{ {

View File

@ -37,7 +37,6 @@
#include <widgets/properties_panel.h> #include <widgets/properties_panel.h>
#include <settings/app_settings.h> #include <settings/app_settings.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <symbol_lib_table.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <drawing_sheet/ds_data_model.h> #include <drawing_sheet/ds_data_model.h>
#include <zoom_defines.h> #include <zoom_defines.h>
@ -282,53 +281,4 @@ void SCH_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) ); wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
EDA_DRAW_FRAME::SaveSettings( aCfg ); EDA_DRAW_FRAME::SaveSettings( aCfg );
} }
static std::mutex s_symbolTableMutex;
SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
{
std::lock_guard<std::mutex> lock( s_symbolTableMutex );
// This is a lazy loading function, it loads the project specific table when
// that table is asked for, not before.
SYMBOL_LIB_TABLE* tbl = (SYMBOL_LIB_TABLE*) GetElem( ELEM_SYMBOL_LIB_TABLE );
// its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
if( !tbl )
{
// Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
// ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
// stack this way, all using the same global fallback table.
tbl = new SYMBOL_LIB_TABLE( &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
SetElem( ELEM_SYMBOL_LIB_TABLE, tbl );
wxString prjPath;
wxGetEnv( PROJECT_VAR_NAME, &prjPath );
if( !prjPath.IsEmpty() )
{
wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
try
{
tbl->Load( fn.GetFullPath() );
}
catch( const IO_ERROR& ioe )
{
wxString msg;
msg.Printf( _( "Error loading the symbol library table '%s'." ),
fn.GetFullPath() );
DisplayErrorMessage( nullptr, msg, ioe.What() );
}
}
}
return tbl;
}

View File

@ -34,6 +34,7 @@
#include <gal/graphics_abstraction_layer.h> #include <gal/graphics_abstraction_layer.h>
#include <string_utils.h> #include <string_utils.h>
#include <lib_pin.h> #include <lib_pin.h>
#include <project_sch.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <sch_marker.h> #include <sch_marker.h>
#include <sch_reference_list.h> #include <sch_reference_list.h>
@ -885,7 +886,7 @@ int ERC_TESTER::TestLibSymbolIssues()
{ {
wxCHECK( m_schematic, 0 ); wxCHECK( m_schematic, 0 );
SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
wxString msg; wxString msg;
int err_count = 0; int err_count = 0;

View File

@ -47,6 +47,7 @@
#include <string_utils.h> #include <string_utils.h>
#include <widgets/grid_combobox.h> #include <widgets/grid_combobox.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <project_sch.h>
enum enum
@ -215,8 +216,7 @@ void FIELDS_GRID_TABLE<T>::initGrid( WX_GRID* aGrid )
m_footprintAttr->SetEditor( fpIdEditor ); m_footprintAttr->SetEditor( fpIdEditor );
m_urlAttr = new wxGridCellAttr; m_urlAttr = new wxGridCellAttr;
GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( m_dialog, GRID_CELL_URL_EDITOR* urlEditor = new GRID_CELL_URL_EDITOR( m_dialog, PROJECT_SCH::SchSearchS( &m_frame->Prj() ) );
m_frame->Prj().SchSearchS() );
urlEditor->SetValidator( m_urlValidator ); urlEditor->SetValidator( m_urlValidator );
m_urlAttr->SetEditor( urlEditor ); m_urlAttr->SetEditor( urlEditor );
@ -906,7 +906,8 @@ void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
else if (event.GetId() == MYID_SHOW_DATASHEET ) else if (event.GetId() == MYID_SHOW_DATASHEET )
{ {
wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE ); wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE );
GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(), m_dlg->Prj().SchSearchS() ); GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(),
PROJECT_SCH::SchSearchS( &m_dlg->Prj() ) );
} }
else else
{ {

View File

@ -39,6 +39,7 @@
#include <core/profile.h> #include <core/profile.h>
#include <project/project_file.h> #include <project/project_file.h>
#include <project_rescue.h> #include <project_rescue.h>
#include <project_sch.h>
#include <dialog_HTML_reporter_base.h> #include <dialog_HTML_reporter_base.h>
#include <reporter.h> #include <reporter.h>
#include <richio.h> #include <richio.h>
@ -185,7 +186,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
// And when a schematic file is loaded, we need these libs to initialize // And when a schematic file is loaded, we need these libs to initialize
// some parameters (links to PART LIB, dangling ends ...) // some parameters (links to PART LIB, dangling ends ...)
Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr ); Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
Prj().SchLibs(); PROJECT_SCH::SchLibs( &Prj() );
} }
} }
else else
@ -196,7 +197,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
// Load the symbol library table, this will be used forever more. // Load the symbol library table, this will be used forever more.
Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
Prj().SchSymbolLibTable(); PROJECT_SCH::SchSymbolLibTable( &Prj() );
// Load project settings after schematic has been set up with the project link, since this will // Load project settings after schematic has been set up with the project link, since this will
// update some of the needed schematic settings such as drawing defaults // update some of the needed schematic settings such as drawing defaults
@ -392,7 +393,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
} }
// Ensure there is only one legacy library loaded and that it is the cache library. // Ensure there is only one legacy library loaded and that it is the cache library.
SYMBOL_LIBS* legacyLibs = Schematic().Prj().SchLibs(); SYMBOL_LIBS* legacyLibs = PROJECT_SCH::SchLibs( &Schematic().Prj() );
if( legacyLibs->GetLibraryCount() == 0 ) if( legacyLibs->GetLibraryCount() == 0 )
{ {

View File

@ -35,6 +35,7 @@
#include <wx/wfstream.h> #include <wx/wfstream.h>
#include <xnode.h> // also nests: <wx/xml/xml.h> #include <xnode.h> // also nests: <wx/xml/xml.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <project_sch.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
@ -541,7 +542,7 @@ XNODE* NETLIST_EXPORTER_XML::makeDesignHeader()
XNODE* NETLIST_EXPORTER_XML::makeLibraries() XNODE* NETLIST_EXPORTER_XML::makeLibraries()
{ {
XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr
SYMBOL_LIB_TABLE* symbolLibTable = m_schematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* symbolLibTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
for( std::set<wxString>::iterator it = m_libraries.begin(); it!=m_libraries.end(); ++it ) for( std::set<wxString>::iterator it = m_libraries.begin(); it!=m_libraries.end(); ++it )
{ {

View File

@ -41,6 +41,7 @@
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/ee_actions.h> #include <tools/ee_actions.h>
#include <project_sch.h>
#include <dialog_choose_symbol.h> #include <dialog_choose_symbol.h>
@ -97,7 +98,7 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SYMBOL_LIBRARY_FILTER
bool aAllowFields ) bool aAllowFields )
{ {
std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock ); std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_SYMBOL::g_Mutex, std::defer_lock );
SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &Prj() );
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings(); COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
PROJECT_FILE& project = Prj().GetProjectFile(); PROJECT_FILE& project = Prj().GetProjectFile();

View File

@ -30,6 +30,7 @@
#include <kiway.h> #include <kiway.h>
#include <symbol_viewer_frame.h> #include <symbol_viewer_frame.h>
#include <project_rescue.h> #include <project_rescue.h>
#include <project_sch.h>
#include <sch_symbol.h> #include <sch_symbol.h>
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
@ -37,6 +38,7 @@
#include <string_utils.h> #include <string_utils.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <project_sch.h>
#include <cctype> #include <cctype>
#include <map> #include <map>
@ -159,13 +161,14 @@ void RESCUE_CASE_CANDIDATE::FindRescues( RESCUER& aRescuer,
LIB_ID id( wxEmptyString, symbol_name ); LIB_ID id( wxEmptyString, symbol_name );
case_sensitive_match = aRescuer.GetPrj()->SchLibs()->FindLibSymbol( id ); case_sensitive_match = PROJECT_SCH::SchLibs( aRescuer.GetPrj() )->FindLibSymbol( id );
if( case_sensitive_match ) if( case_sensitive_match )
continue; continue;
// If the case sensitive match failed, try a case insensitive match. // If the case sensitive match failed, try a case insensitive match.
aRescuer.GetPrj()->SchLibs()->FindLibraryNearEntries( case_insensitive_matches, PROJECT_SCH::SchLibs( aRescuer.GetPrj() )
->FindLibraryNearEntries( case_insensitive_matches,
symbol_name ); symbol_name );
// If there are not case insensitive matches either, the symbol cannot be rescued. // If there are not case insensitive matches either, the symbol cannot be rescued.
@ -267,8 +270,8 @@ void RESCUE_CACHE_CANDIDATE::FindRescues( RESCUER& aRescuer,
// A new symbol name is found (a new group starts here). // A new symbol name is found (a new group starts here).
// Search the symbol names candidates only once for this group: // Search the symbol names candidates only once for this group:
old_symbol_name = symbol_name; old_symbol_name = symbol_name;
cache_match = findSymbol( symbol_name, aRescuer.GetPrj()->SchLibs(), true ); cache_match = findSymbol( symbol_name, PROJECT_SCH::SchLibs( aRescuer.GetPrj() ), true );
lib_match = findSymbol( symbol_name, aRescuer.GetPrj()->SchLibs(), false ); lib_match = findSymbol( symbol_name, PROJECT_SCH::SchLibs( aRescuer.GetPrj() ), false );
// At some point during V5 development, the LIB_ID delimiter character ':' was // At some point during V5 development, the LIB_ID delimiter character ':' was
// replaced by '_' when writing the symbol cache library so we have to test for // replaced by '_' when writing the symbol cache library so we have to test for
@ -279,7 +282,7 @@ void RESCUE_CACHE_CANDIDATE::FindRescues( RESCUER& aRescuer,
tmp = eachSymbol->GetLibId().GetLibNickname().wx_str() + wxT( "_" ) + tmp = eachSymbol->GetLibId().GetLibNickname().wx_str() + wxT( "_" ) +
eachSymbol->GetLibId().GetLibItemName().wx_str(); eachSymbol->GetLibId().GetLibItemName().wx_str();
cache_match = findSymbol( tmp, aRescuer.GetPrj()->SchLibs(), true ); cache_match = findSymbol( tmp, PROJECT_SCH::SchLibs( aRescuer.GetPrj() ), true );
} }
// Test whether there is a conflict or if the symbol can only be found in the cache // Test whether there is a conflict or if the symbol can only be found in the cache
@ -410,7 +413,7 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
// Get the library symbol from the cache library. It will be a flattened // Get the library symbol from the cache library. It will be a flattened
// symbol by default (no inheritance). // symbol by default (no inheritance).
cache_match = findSymbol( symbolName, aRescuer.GetPrj()->SchLibs(), true ); cache_match = findSymbol( symbolName, PROJECT_SCH::SchLibs( aRescuer.GetPrj() ), true );
// At some point during V5 development, the LIB_ID delimiter character ':' was // At some point during V5 development, the LIB_ID delimiter character ':' was
// replaced by '_' when writing the symbol cache library so we have to test for // replaced by '_' when writing the symbol cache library so we have to test for
@ -419,11 +422,11 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
{ {
symbolName = symbol_id.GetLibNickname().wx_str() + wxT( "_" ) + symbolName = symbol_id.GetLibNickname().wx_str() + wxT( "_" ) +
symbol_id.GetLibItemName().wx_str(); symbol_id.GetLibItemName().wx_str();
cache_match = findSymbol( symbolName, aRescuer.GetPrj()->SchLibs(), true ); cache_match = findSymbol( symbolName, PROJECT_SCH::SchLibs( aRescuer.GetPrj() ), true );
} }
// Get the library symbol from the symbol library table. // Get the library symbol from the symbol library table.
lib_match = SchGetLibSymbol( symbol_id, aRescuer.GetPrj()->SchSymbolLibTable() ); lib_match = SchGetLibSymbol( symbol_id, PROJECT_SCH::SchSymbolLibTable( aRescuer.GetPrj() ) );
if( !cache_match && !lib_match ) if( !cache_match && !lib_match )
continue; continue;
@ -687,7 +690,7 @@ void LEGACY_RESCUER::OpenRescueLibrary()
// If a rescue library already exists copy the contents of that library so we do not // If a rescue library already exists copy the contents of that library so we do not
// lose any previous rescues. // lose any previous rescues.
SYMBOL_LIB* rescueLib = m_prj->SchLibs()->FindLibrary( fn.GetName() ); SYMBOL_LIB* rescueLib = PROJECT_SCH::SchLibs( m_prj )->FindLibrary( fn.GetName() );
if( rescueLib ) if( rescueLib )
{ {
@ -823,7 +826,7 @@ void SYMBOL_LIB_TABLE_RESCUER::OpenRescueLibrary()
wxFileName fn = GetRescueLibraryFileName( m_schematic ); wxFileName fn = GetRescueLibraryFileName( m_schematic );
SYMBOL_LIB_TABLE_ROW* row = m_prj->SchSymbolLibTable()->FindRow( fn.GetName() ); SYMBOL_LIB_TABLE_ROW* row = PROJECT_SCH::SchSymbolLibTable( m_prj )->FindRow( fn.GetName() );
// If a rescue library already exists copy the contents of that library so we do not // If a rescue library already exists copy the contents of that library so we do not
// lose any previous rescues. // lose any previous rescues.
@ -836,7 +839,7 @@ void SYMBOL_LIB_TABLE_RESCUER::OpenRescueLibrary()
try try
{ {
m_prj->SchSymbolLibTable()->LoadSymbolLib( symbols, fn.GetName() ); PROJECT_SCH::SchSymbolLibTable( m_prj )->LoadSymbolLib( symbols, fn.GetName() );
} }
catch( ... /* IO_ERROR */ ) catch( ... /* IO_ERROR */ )
{ {
@ -853,7 +856,7 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( wxWindow *aParent )
{ {
wxString msg; wxString msg;
wxFileName fn = GetRescueLibraryFileName( m_schematic ); wxFileName fn = GetRescueLibraryFileName( m_schematic );
SYMBOL_LIB_TABLE_ROW* row = m_prj->SchSymbolLibTable()->FindRow( fn.GetName() ); SYMBOL_LIB_TABLE_ROW* row = PROJECT_SCH::SchSymbolLibTable( m_prj )->FindRow( fn.GetName() );
fn.SetExt( KiCadSymbolLibFileExtension ); fn.SetExt( KiCadSymbolLibFileExtension );
@ -881,13 +884,13 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( wxWindow *aParent )
wxString libNickname = fn.GetName(); wxString libNickname = fn.GetName();
row = new SYMBOL_LIB_TABLE_ROW( libNickname, uri, wxT( "KiCad" ) ); row = new SYMBOL_LIB_TABLE_ROW( libNickname, uri, wxT( "KiCad" ) );
m_prj->SchSymbolLibTable()->InsertRow( row, true ); PROJECT_SCH::SchSymbolLibTable( m_prj )->InsertRow( row, true );
fn = wxFileName( m_prj->GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); fn = wxFileName( m_prj->GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
try try
{ {
m_prj->SchSymbolLibTable()->Save( fn.GetFullPath() ); PROJECT_SCH::SchSymbolLibTable( m_prj )->Save( fn.GetFullPath() );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
@ -900,7 +903,7 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( wxWindow *aParent )
m_prj->SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); m_prj->SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
// This can only happen if the symbol library table file was corrupted on write. // This can only happen if the symbol library table file was corrupted on write.
if( !m_prj->SchSymbolLibTable() ) if( !PROJECT_SCH::SchSymbolLibTable( m_prj ) )
return false; return false;
// Update the schematic symbol library links since the library list has changed. // Update the schematic symbol library links since the library list has changed.

View File

@ -24,7 +24,10 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <wx/app.h> #include <wx/app.h>
#include <core/utf8.h> #include <core/utf8.h>
#include <symbol_lib_table.h>
#include <project_sch.h>
static std::mutex s_symbolTableMutex;
// non-member so it can be moved easily, and kept REALLY private. // non-member so it can be moved easily, and kept REALLY private.
// Do NOT Clear() in here. // Do NOT Clear() in here.
@ -35,28 +38,28 @@ static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int
} }
SEARCH_STACK* PROJECT::SchSearchS() SEARCH_STACK* PROJECT_SCH::SchSearchS( PROJECT* aProject )
{ {
SEARCH_STACK* ss = (SEARCH_STACK*) GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ); SEARCH_STACK* ss = (SEARCH_STACK*) aProject->GetElem( PROJECT::ELEM_SCH_SEARCH_STACK );
wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ) ) ); wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( aProject->GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ) ) );
if( !ss ) if( !ss )
{ {
ss = new SEARCH_STACK(); ss = new SEARCH_STACK();
// Make PROJECT the new SEARCH_STACK owner. // Make PROJECT the new SEARCH_STACK owner.
SetElem( PROJECT::ELEM_SCH_SEARCH_STACK, ss ); aProject->SetElem( PROJECT::ELEM_SCH_SEARCH_STACK, ss );
// to the empty SEARCH_STACK for SchSearchS(), add project dir as first // to the empty SEARCH_STACK for SchSearchS(), add project dir as first
ss->AddPaths( m_project_name.GetPath() ); ss->AddPaths( aProject->GetProjectDirectory() );
// next add the paths found in *.pro, variable "LibDir" // next add the paths found in *.pro, variable "LibDir"
wxString libDir; wxString libDir;
try try
{ {
SYMBOL_LIBS::GetLibNamesAndPaths( this, &libDir ); SYMBOL_LIBS::GetLibNamesAndPaths( aProject, &libDir );
} }
catch( const IO_ERROR& ) catch( const IO_ERROR& )
{ {
@ -70,7 +73,7 @@ SEARCH_STACK* PROJECT::SchSearchS()
for( unsigned i =0; i<paths.GetCount(); ++i ) for( unsigned i =0; i<paths.GetCount(); ++i )
{ {
wxString path = AbsolutePath( paths[i] ); wxString path = aProject->AbsolutePath( paths[i] );
ss->AddPaths( path ); // at the end ss->AddPaths( path ); // at the end
} }
@ -84,9 +87,9 @@ SEARCH_STACK* PROJECT::SchSearchS()
} }
SYMBOL_LIBS* PROJECT::SchLibs() SYMBOL_LIBS* PROJECT_SCH::SchLibs( PROJECT* aProject )
{ {
SYMBOL_LIBS* libs = (SYMBOL_LIBS*) GetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS ); SYMBOL_LIBS* libs = (SYMBOL_LIBS*) aProject->GetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS );
wxASSERT( !libs || libs->Type() == SYMBOL_LIBS_T ); wxASSERT( !libs || libs->Type() == SYMBOL_LIBS_T );
@ -95,11 +98,11 @@ SYMBOL_LIBS* PROJECT::SchLibs()
libs = new SYMBOL_LIBS(); libs = new SYMBOL_LIBS();
// Make PROJECT the new SYMBOL_LIBS owner. // Make PROJECT the new SYMBOL_LIBS owner.
SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, libs ); aProject->SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, libs );
try try
{ {
libs->LoadAllLibraries( this ); libs->LoadAllLibraries( aProject );
} }
catch( const PARSE_ERROR& pe ) catch( const PARSE_ERROR& pe )
{ {
@ -125,3 +128,48 @@ SYMBOL_LIBS* PROJECT::SchLibs()
return libs; return libs;
} }
SYMBOL_LIB_TABLE* PROJECT_SCH::SchSymbolLibTable( PROJECT* aProject )
{
std::lock_guard<std::mutex> lock( s_symbolTableMutex );
// This is a lazy loading function, it loads the project specific table when
// that table is asked for, not before.
SYMBOL_LIB_TABLE* tbl = (SYMBOL_LIB_TABLE*) aProject->GetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE );
// its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
if( !tbl )
{
// Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
// ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
// stack this way, all using the same global fallback table.
tbl = new SYMBOL_LIB_TABLE( &SYMBOL_LIB_TABLE::GetGlobalLibTable() );
aProject->SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, tbl );
wxString prjPath;
wxGetEnv( PROJECT_VAR_NAME, &prjPath );
if( !prjPath.IsEmpty() )
{
wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
try
{
tbl->Load( fn.GetFullPath() );
}
catch( const IO_ERROR& ioe )
{
wxString msg;
msg.Printf( _( "Error loading the symbol library table '%s'." ), fn.GetFullPath() );
DisplayErrorMessage( nullptr, msg, ioe.What() );
}
}
}
return tbl;
}

45
eeschema/project_sch.h Normal file
View File

@ -0,0 +1,45 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#pragma once
class SYMBOL_LIB_TABLE;
class PROJECT;
class SEARCH_STACK;
class SYMBOL_LIBS;
class PROJECT_SCH
{
public:
// These are all prefaced with "Sch"
static SYMBOL_LIBS* SchLibs( PROJECT* aProject );
/// Accessor for Eeschema search stack.
static SEARCH_STACK* SchSearchS( PROJECT* aProject );
/// Accessor for project symbol library table.
static SYMBOL_LIB_TABLE* SchSymbolLibTable( PROJECT* aProject );
private:
PROJECT_SCH() {}
};

View File

@ -38,6 +38,7 @@
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <confirm.h> #include <confirm.h>
#include <preview_items/selection_area.h> #include <preview_items/selection_area.h>
#include <project_sch.h>
#include <symbol_library.h> #include <symbol_library.h>
#include <sch_base_frame.h> #include <sch_base_frame.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
@ -203,9 +204,10 @@ void SCH_BASE_FRAME::UpdateStatusBar()
LIB_SYMBOL* SCH_BASE_FRAME::GetLibSymbol( const LIB_ID& aLibId, bool aUseCacheLib, LIB_SYMBOL* SCH_BASE_FRAME::GetLibSymbol( const LIB_ID& aLibId, bool aUseCacheLib,
bool aShowErrorMsg ) bool aShowErrorMsg )
{ {
SYMBOL_LIB* cache = ( aUseCacheLib ) ? Prj().SchLibs()->GetCacheLibrary() : nullptr; SYMBOL_LIB* cache =
( aUseCacheLib ) ? PROJECT_SCH::SchLibs( &Prj() )->GetCacheLibrary() : nullptr;
return SchGetLibSymbol( aLibId, Prj().SchSymbolLibTable(), cache, this, aShowErrorMsg ); return SchGetLibSymbol( aLibId, PROJECT_SCH::SchSymbolLibTable( &Prj() ), cache, this, aShowErrorMsg );
} }
@ -234,7 +236,7 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject )
try try
{ {
Prj().SchSymbolLibTable()->Save( fn.GetFullPath() ); PROJECT_SCH::SchSymbolLibTable( &Prj() )->Save( fn.GetFullPath() );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
@ -287,7 +289,7 @@ SYMBOL_LIB_TABLE* SCH_BASE_FRAME::SelectSymLibTable( bool aOptional )
switch( dlg.GetSelection() ) switch( dlg.GetSelection() )
{ {
case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable(); case 0: return &SYMBOL_LIB_TABLE::GetGlobalLibTable();
case 1: return Prj().SchSymbolLibTable(); case 1: return PROJECT_SCH::SchSymbolLibTable( &Prj() );
default: return nullptr; default: return nullptr;
} }
} }
@ -554,7 +556,7 @@ wxString SCH_BASE_FRAME::SelectLibraryFromList()
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings(); COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
PROJECT& prj = Prj(); PROJECT& prj = Prj();
if( prj.SchSymbolLibTable()->IsEmpty() ) if( PROJECT_SCH::SchSymbolLibTable( &prj )->IsEmpty() )
{ {
ShowInfoBarError( _( "No symbol libraries are loaded." ) ); ShowInfoBarError( _( "No symbol libraries are loaded." ) );
return wxEmptyString; return wxEmptyString;
@ -565,12 +567,12 @@ wxString SCH_BASE_FRAME::SelectLibraryFromList()
headers.Add( _( "Library" ) ); headers.Add( _( "Library" ) );
std::vector< wxArrayString > itemsToDisplay; std::vector< wxArrayString > itemsToDisplay;
std::vector< wxString > libNicknames = prj.SchSymbolLibTable()->GetLogicalLibs(); std::vector< wxString > libNicknames = PROJECT_SCH::SchSymbolLibTable( &prj )->GetLogicalLibs();
for( const wxString& name : libNicknames ) for( const wxString& name : libNicknames )
{ {
// Exclude read only libraries. // Exclude read only libraries.
if( !prj.SchSymbolLibTable()->IsSymbolLibWritable( name ) ) if( !PROJECT_SCH::SchSymbolLibTable( &prj )->IsSymbolLibWritable( name ) )
continue; continue;
if( alg::contains( prj.GetProjectFile().m_PinnedSymbolLibs, name ) if( alg::contains( prj.GetProjectFile().m_PinnedSymbolLibs, name )
@ -586,7 +588,7 @@ wxString SCH_BASE_FRAME::SelectLibraryFromList()
for( const wxString& name : libNicknames ) for( const wxString& name : libNicknames )
{ {
// Exclude read only libraries. // Exclude read only libraries.
if( !prj.SchSymbolLibTable()->IsSymbolLibWritable( name ) ) if( !PROJECT_SCH::SchSymbolLibTable( &prj )->IsSymbolLibWritable( name ) )
continue; continue;
if( !alg::contains( prj.GetProjectFile().m_PinnedSymbolLibs, name ) if( !alg::contains( prj.GetProjectFile().m_PinnedSymbolLibs, name )
@ -611,7 +613,7 @@ wxString SCH_BASE_FRAME::SelectLibraryFromList()
if( !libName.empty() ) if( !libName.empty() )
{ {
if( prj.SchSymbolLibTable()->HasLibrary( libName ) ) if( PROJECT_SCH::SchSymbolLibTable( &prj )->HasLibrary( libName ) )
prj.SetRString( PROJECT::SCH_LIB_SELECT, libName ); prj.SetRString( PROJECT::SCH_LIB_SELECT, libName );
else else
libName = wxEmptyString; libName = wxEmptyString;
@ -634,7 +636,7 @@ void SCH_BASE_FRAME::setSymWatcher( const LIB_ID* aID )
} }
wxString libfullname; wxString libfullname;
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* tbl = PROJECT_SCH::SchSymbolLibTable( &Prj() );
if( !aID || !tbl ) if( !aID || !tbl )
return; return;
@ -683,7 +685,7 @@ void SCH_BASE_FRAME::setSymWatcher( const LIB_ID* aID )
void SCH_BASE_FRAME::OnSymChange( wxFileSystemWatcherEvent& aEvent ) void SCH_BASE_FRAME::OnSymChange( wxFileSystemWatcherEvent& aEvent )
{ {
SYMBOL_LIBS* libs = Prj().SchLibs(); SYMBOL_LIBS* libs = PROJECT_SCH::SchLibs( &Prj() );
wxLogTrace( "KICAD_LIB_WATCH", "OnSymChange: %s, watcher file: %s", wxLogTrace( "KICAD_LIB_WATCH", "OnSymChange: %s, watcher file: %s",
aEvent.GetPath().GetFullPath(), m_watcherFileName.GetFullPath() ); aEvent.GetPath().GetFullPath(), m_watcherFileName.GetFullPath() );

View File

@ -31,6 +31,7 @@
#include <sch_plugins/altium/sch_altium_plugin.h> #include <sch_plugins/altium/sch_altium_plugin.h>
#include <schematic.h> #include <schematic.h>
#include <project_sch.h>
#include <lib_shape.h> #include <lib_shape.h>
#include <lib_id.h> #include <lib_id.h>
@ -328,7 +329,7 @@ SCH_SHEET* SCH_ALTIUM_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHE
const_cast<KIID&>( m_rootSheet->m_Uuid ) = screen->GetUuid(); const_cast<KIID&>( m_rootSheet->m_Uuid ) = screen->GetUuid();
} }
SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
@ -358,7 +359,7 @@ SCH_SHEET* SCH_ALTIUM_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHE
// Reload the symbol library table. // Reload the symbol library table.
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
m_schematic->Prj().SchSymbolLibTable(); PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
} }
m_sheetPath.push_back( m_rootSheet ); m_sheetPath.push_back( m_rootSheet );

View File

@ -29,6 +29,7 @@
#include <lib_symbol.h> #include <lib_symbol.h>
#include <progress_reporter.h> #include <progress_reporter.h>
#include <project_sch.h>
#include <string_utf8_map.h> #include <string_utf8_map.h>
#include <sch_screen.h> #include <sch_screen.h>
#include <sch_sheet.h> #include <sch_sheet.h>
@ -83,7 +84,7 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::LoadSchematicFile( const wxString&
csaLoader.Load( aSchematic, rootSheet ); csaLoader.Load( aSchematic, rootSheet );
// SAVE SYMBOLS TO PROJECT LIBRARY: // SAVE SYMBOLS TO PROJECT LIBRARY:
SYMBOL_LIB_TABLE* libTable = aSchematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
@ -129,7 +130,7 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::LoadSchematicFile( const wxString&
// Relaod the symbol library table. // Relaod the symbol library table.
aSchematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); aSchematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
aSchematic->Prj().SchSymbolLibTable(); PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
} }
// set properties to prevent save file on every symbol save // set properties to prevent save file on every symbol save

View File

@ -45,6 +45,7 @@
#include <lib_pin.h> #include <lib_pin.h>
#include <lib_text.h> #include <lib_text.h>
#include <project.h> #include <project.h>
#include <project_sch.h>
#include <sch_bus_entry.h> #include <sch_bus_entry.h>
#include <sch_symbol.h> #include <sch_symbol.h>
#include <project/net_settings.h> #include <project/net_settings.h>
@ -469,7 +470,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEM
const_cast<KIID&>( m_rootSheet->m_Uuid ) = screen->GetUuid(); const_cast<KIID&>( m_rootSheet->m_Uuid ) = screen->GetUuid();
} }
SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
wxCHECK_MSG( libTable, nullptr, wxT( "Could not load symbol lib table." ) ); wxCHECK_MSG( libTable, nullptr, wxT( "Could not load symbol lib table." ) );
@ -501,7 +502,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEM
// Reload the symbol library table. // Reload the symbol library table.
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
m_schematic->Prj().SchSymbolLibTable(); PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
} }
// Retrieve the root as current node // Retrieve the root as current node
@ -1826,7 +1827,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
symbol->AddHierarchicalReference( m_sheetPath.Path(), reference, unit ); symbol->AddHierarchicalReference( m_sheetPath.Path(), reference, unit );
// Save the pin positions // Save the pin positions
SYMBOL_LIB_TABLE& schLibTable = *m_schematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE& schLibTable = *PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
LIB_SYMBOL* libSymbol = schLibTable.LoadSymbol( symbol->GetLibId() ); LIB_SYMBOL* libSymbol = schLibTable.LoadSymbol( symbol->GetLibId() );
wxCHECK( libSymbol, /*void*/ ); wxCHECK( libSymbol, /*void*/ );

View File

@ -29,6 +29,7 @@
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_screen.h> #include <sch_screen.h>
#include <kiplatform/environment.h> #include <kiplatform/environment.h>
#include <project_sch.h>
#include <wx/log.h> #include <wx/log.h>
#include <wx/stdstream.h> #include <wx/stdstream.h>
@ -573,7 +574,7 @@ SCH_SHEET* SCH_EASYEDA_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCH
rootSheet->SetScreen( screen ); rootSheet->SetScreen( screen );
} }
SYMBOL_LIB_TABLE* libTable = aSchematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) ); wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) );
LoadSchematic( aSchematic, rootSheet, aFileName ); LoadSchematic( aSchematic, rootSheet, aFileName );

View File

@ -44,6 +44,7 @@
#include <sch_plugins/kicad/sch_sexpr_plugin.h> #include <sch_plugins/kicad/sch_sexpr_plugin.h>
#include <plugins/easyedapro/easyedapro_import_utils.h> #include <plugins/easyedapro/easyedapro_import_utils.h>
#include <core/map_helpers.h> #include <core/map_helpers.h>
#include <project_sch.h>
struct SCH_EASYEDAPRO_PLUGIN::PRJ_DATA struct SCH_EASYEDAPRO_PLUGIN::PRJ_DATA
@ -400,7 +401,7 @@ SCH_SHEET* SCH_EASYEDAPRO_PLUGIN::LoadSchematicFile( const wxString& aFileName,
rootSheet->SetScreen( screen ); rootSheet->SetScreen( screen );
} }
SYMBOL_LIB_TABLE* libTable = aSchematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) ); wxCHECK_MSG( libTable, nullptr, wxS( "Could not load symbol lib table." ) );
SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr ); SCH_EASYEDAPRO_PARSER parser( nullptr, nullptr );
@ -546,7 +547,7 @@ SCH_SHEET* SCH_EASYEDAPRO_PLUGIN::LoadSchematicFile( const wxString& aFileName,
// Relaod the symbol library table. // Relaod the symbol library table.
aSchematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); aSchematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL );
aSchematic->Prj().SchSymbolLibTable(); PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
} }
// set properties to prevent save file on every symbol save // set properties to prevent save file on every symbol save

View File

@ -23,6 +23,7 @@
#include <sch_plugins/ltspice/ltspice_sch_plugin.h> #include <sch_plugins/ltspice/ltspice_sch_plugin.h>
#include <sch_plugins/ltspice/ltspice_sch_parser.h> #include <sch_plugins/ltspice/ltspice_sch_parser.h>
#include <project_sch.h>
#include <schematic.h> #include <schematic.h>
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_screen.h> #include <sch_screen.h>
@ -72,10 +73,10 @@ SCH_SHEET* SCH_LTSPICE_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCH
rootSheet->SetScreen( screen ); rootSheet->SetScreen( screen );
} }
SYMBOL_LIB_TABLE* libTable = aSchematic->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
// Windows path: C:\Users\USERNAME\AppData\Local\LTspice\lib // Windows path: C:\Users\USERNAME\AppData\Local\LTspice\lib
wxFileName ltspiceDataDir( KIPLATFORM::ENV::GetUserLocalDataPath(), wxEmptyString ); wxFileName ltspiceDataDir( KIPLATFORM::ENV::GetUserLocalDataPath(), wxEmptyString );
ltspiceDataDir.AppendDir( wxS( "LTspice" ) ); ltspiceDataDir.AppendDir( wxS( "LTspice" ) );

View File

@ -33,6 +33,7 @@
#include <kiway.h> #include <kiway.h>
#include <plotters/plotter.h> #include <plotters/plotter.h>
#include <project.h> #include <project.h>
#include <project_sch.h>
#include <reporter.h> #include <reporter.h>
#include <sch_draw_panel.h> #include <sch_draw_panel.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
@ -885,10 +886,10 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
wxString msg; wxString msg;
std::unique_ptr< LIB_SYMBOL > libSymbol; std::unique_ptr< LIB_SYMBOL > libSymbol;
std::vector<SCH_SYMBOL*> symbols; std::vector<SCH_SYMBOL*> symbols;
SYMBOL_LIB_TABLE* libs = Schematic()->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &Schematic()->Prj() );
// This will be a nullptr if an s-expression schematic is loaded. // This will be a nullptr if an s-expression schematic is loaded.
SYMBOL_LIBS* legacyLibs = Schematic()->Prj().SchLibs(); SYMBOL_LIBS* legacyLibs = PROJECT_SCH::SchLibs( &Schematic()->Prj() );
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) ) for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
symbols.push_back( static_cast<SCH_SYMBOL*>( item ) ); symbols.push_back( static_cast<SCH_SYMBOL*>( item ) );

View File

@ -29,6 +29,7 @@
#include <math/vector2wx.h> #include <math/vector2wx.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <project_sch.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <sch_plugins/legacy/sch_legacy_plugin.h> #include <sch_plugins/legacy/sch_legacy_plugin.h>
#include <sch_sheet.h> #include <sch_sheet.h>
@ -269,7 +270,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
// library links are valid but it's better than nothing. // library links are valid but it's better than nothing.
for( const wxString& name : names ) for( const wxString& name : names )
{ {
if( !Prj().SchSymbolLibTable()->HasLibrary( name ) ) if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( name ) )
newLibNames.Add( name ); newLibNames.Add( name );
} }
@ -300,7 +301,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
for( const wxString& name : names ) for( const wxString& name : names )
{ {
if( !Prj().SchSymbolLibTable()->HasLibrary( name ) ) if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( name ) )
newLibNames.Add( name ); newLibNames.Add( name );
else else
duplicateLibNames.Add( name ); duplicateLibNames.Add( name );
@ -391,8 +392,8 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
const SYMBOL_LIB_TABLE_ROW* thisRow = nullptr; const SYMBOL_LIB_TABLE_ROW* thisRow = nullptr;
const SYMBOL_LIB_TABLE_ROW* otherRow = nullptr; const SYMBOL_LIB_TABLE_ROW* otherRow = nullptr;
if( Prj().SchSymbolLibTable()->HasLibrary( duplicateLibName ) ) if( PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( duplicateLibName ) )
thisRow = Prj().SchSymbolLibTable()->FindRow( duplicateLibName ); thisRow = PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( duplicateLibName );
if( table.HasLibrary( duplicateLibName ) ) if( table.HasLibrary( duplicateLibName ) )
otherRow = table.FindRow( duplicateLibName ); otherRow = table.FindRow( duplicateLibName );
@ -448,7 +449,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
for( const wxString& libName : newLibNames ) for( const wxString& libName : newLibNames )
{ {
if( !table.HasLibrary( libName ) if( !table.HasLibrary( libName )
|| Prj().SchSymbolLibTable()->HasLibrary( libName ) ) || PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( libName ) )
{ {
continue; continue;
} }
@ -482,7 +483,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
row->GetOptions(), row->GetOptions(),
row->GetDescr() ); row->GetDescr() );
Prj().SchSymbolLibTable()->InsertRow( newRow ); PROJECT_SCH::SchSymbolLibTable( &Prj() )->InsertRow( newRow );
libTableChanged = true; libTableChanged = true;
} }
} }
@ -494,7 +495,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
if( libTableChanged ) if( libTableChanged )
{ {
Prj().SchSymbolLibTable()->Save( Prj().GetProjectPath() + PROJECT_SCH::SchSymbolLibTable( &Prj() )->Save( Prj().GetProjectPath() +
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
} }

View File

@ -42,6 +42,7 @@
#include <symbol_editor_settings.h> #include <symbol_editor_settings.h>
#include <paths.h> #include <paths.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <project_sch.h>
#include <sch_painter.h> #include <sch_painter.h>
#include <sch_view.h> #include <sch_view.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
@ -717,7 +718,7 @@ wxString SYMBOL_EDIT_FRAME::GetCurLib() const
if( !libNickname.empty() ) if( !libNickname.empty() )
{ {
if( !Prj().SchSymbolLibTable()->HasLibrary( libNickname ) ) if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( libNickname ) )
{ {
Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString ); Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
libNickname = wxEmptyString; libNickname = wxEmptyString;
@ -732,7 +733,7 @@ wxString SYMBOL_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
{ {
wxString old = GetCurLib(); wxString old = GetCurLib();
if( aLibNickname.empty() || !Prj().SchSymbolLibTable()->HasLibrary( aLibNickname ) ) if( aLibNickname.empty() || !PROJECT_SCH::SchSymbolLibTable( &Prj() )->HasLibrary( aLibNickname ) )
Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString ); Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, wxEmptyString );
else else
Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname ); Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
@ -1374,7 +1375,7 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
wxString libNickname; wxString libNickname;
wxString msg; wxString msg;
SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName ); const LIB_TABLE_ROW* libTableRow = libTable->FindRowByURI( libFileName );
if( !libTableRow ) if( !libTableRow )
@ -1413,7 +1414,7 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
case MAIL_RELOAD_LIB: case MAIL_RELOAD_LIB:
{ {
wxString currentLib = GetCurLib(); wxString currentLib = GetCurLib();
SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
FreezeLibraryTree(); FreezeLibraryTree();
@ -1433,7 +1434,7 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
case MAIL_REFRESH_SYMBOL: case MAIL_REFRESH_SYMBOL:
{ {
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* tbl = PROJECT_SCH::SchSymbolLibTable( &Prj() );
LIB_SYMBOL* symbol = GetCurSymbol(); LIB_SYMBOL* symbol = GetCurSymbol();
wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s", wxLogTrace( "KICAD_LIB_WATCH", "Received refresh symbol request for %s",
@ -1658,7 +1659,7 @@ bool SYMBOL_EDIT_FRAME::addLibTableEntry( const wxString& aLibFile, TABLE_SCOPE
wxFileName libTableFileName( Prj().GetProjectPath(), wxFileName libTableFileName( Prj().GetProjectPath(),
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
wxString libNickname = fn.GetName(); wxString libNickname = fn.GetName();
SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables(); const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
if( libTable->HasLibrary( libNickname ) ) if( libTable->HasLibrary( libNickname ) )
@ -1727,7 +1728,7 @@ bool SYMBOL_EDIT_FRAME::replaceLibTableEntry( const wxString& aLibNickname,
{ {
libTableFileName.SetPath( Prj().GetProjectPath() ); libTableFileName.SetPath( Prj().GetProjectPath() );
libTableFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); libTableFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
libTable = Prj().SchSymbolLibTable(); libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
isGlobalTable = false; isGlobalTable = false;
row = libTable->FindRow( aLibNickname ); row = libTable->FindRow( aLibNickname );
} }

View File

@ -45,6 +45,7 @@
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <wx/log.h> #include <wx/log.h>
#include <project_sch.h>
#include <string_utils.h> #include <string_utils.h>
#include "symbol_saveas_type.h" #include "symbol_saveas_type.h"
@ -153,7 +154,7 @@ bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConver
{ {
try try
{ {
LIB_SYMBOL* readOnlySym = Prj().SchSymbolLibTable()->LoadSymbol( aLibId ); LIB_SYMBOL* readOnlySym = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( aLibId );
if( readOnlySym && readOnlySym->GetSourceLibId().IsValid() ) if( readOnlySym && readOnlySym->GetSourceLibId().IsValid() )
libId = readOnlySym->GetSourceLibId(); libId = readOnlySym->GetSourceLibId();
@ -222,7 +223,7 @@ bool SYMBOL_EDIT_FRAME::LoadSymbolFromCurrentLib( const wxString& aAliasName, in
try try
{ {
alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName ); alias = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( GetCurLib(), aAliasName );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
@ -567,7 +568,7 @@ public:
{ {
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings(); COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
PROJECT_FILE& project = aParent->Prj().GetProjectFile(); PROJECT_FILE& project = aParent->Prj().GetProjectFile();
SYMBOL_LIB_TABLE* tbl = aParent->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* tbl = PROJECT_SCH::SchSymbolLibTable( &Prj() );
std::vector<wxString> libNicknames = tbl->GetLogicalLibs(); std::vector<wxString> libNicknames = tbl->GetLogicalLibs();
wxArrayString headers; wxArrayString headers;
std::vector<wxArrayString> itemsToDisplay; std::vector<wxArrayString> itemsToDisplay;
@ -1059,7 +1060,7 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
m_toolManager->RunAction( ACTIONS::cancelInteractive ); m_toolManager->RunAction( ACTIONS::cancelInteractive );
if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) ) if( !aNewFile && ( aLibrary.empty() || !PROJECT_SCH::SchSymbolLibTable( &prj )->HasLibrary( aLibrary ) ) )
{ {
ShowInfoBarError( _( "No library specified." ) ); ShowInfoBarError( _( "No library specified." ) );
return false; return false;
@ -1067,7 +1068,7 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
if( aNewFile ) if( aNewFile )
{ {
SEARCH_STACK* search = prj.SchSearchS(); SEARCH_STACK* search = PROJECT_SCH::SchSearchS( &prj );
// Get a new name for the library // Get a new name for the library
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH ); wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
@ -1101,7 +1102,7 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
} }
else else
{ {
fn = prj.SchSymbolLibTable()->GetFullURI( aLibrary ); fn = PROJECT_SCH::SchSymbolLibTable( &prj )->GetFullURI( aLibrary );
fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() ); fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
if( fileType == SCH_IO_MGR::SCH_FILE_UNKNOWN ) if( fileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )

View File

@ -33,6 +33,7 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <project/project_file.h> #include <project/project_file.h>
#include <project_rescue.h> #include <project_rescue.h>
#include <project_sch.h>
#include <string_utf8_map.h> #include <string_utf8_map.h>
#include <widgets/app_progress_dialog.h> #include <widgets/app_progress_dialog.h>
@ -500,7 +501,7 @@ void SYMBOL_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress )
{ {
wxString filename; wxString filename;
wxString libs_not_found; wxString libs_not_found;
SEARCH_STACK* lib_search = aProject->SchSearchS(); SEARCH_STACK* lib_search = PROJECT_SCH::SchSearchS( aProject );
#if defined(DEBUG) && 0 #if defined(DEBUG) && 0
lib_search->Show( __func__ ); lib_search->Show( __func__ );

View File

@ -29,6 +29,7 @@
#include <symbol_edit_frame.h> #include <symbol_edit_frame.h>
#include <env_paths.h> #include <env_paths.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <project_sch.h>
#include <kiway.h> #include <kiway.h>
#include <core/profile.h> #include <core/profile.h>
#include <wx_filename.h> #include <wx_filename.h>
@ -767,7 +768,7 @@ bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate
SYMBOL_LIB_TABLE* SYMBOL_LIBRARY_MANAGER::symTable() const SYMBOL_LIB_TABLE* SYMBOL_LIBRARY_MANAGER::symTable() const
{ {
return m_frame.Prj().SchSymbolLibTable(); return PROJECT_SCH::SchSymbolLibTable( &m_frame.Prj() );
} }

View File

@ -29,6 +29,7 @@
#include <lib_symbol_library_manager.h> #include <lib_symbol_library_manager.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <tools/symbol_editor_control.h> #include <tools/symbol_editor_control.h>
#include <project_sch.h>
#include <string_utils.h> #include <string_utils.h>
#include <symbol_preview_widget.h> #include <symbol_preview_widget.h>
#include <widgets/wx_panel.h> #include <widgets/wx_panel.h>
@ -91,9 +92,9 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( const wxString& aForceRefresh,
// modified libraries before the symbol library table which prevents the library from // modified libraries before the symbol library table which prevents the library from
// being removed from the tree control. // being removed from the tree control.
if( !m_libMgr->LibraryExists( name, true ) if( !m_libMgr->LibraryExists( name, true )
|| !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true ) || !PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->HasLibrary( name, true )
|| m_frame->Prj().SchSymbolLibTable()->FindRow( name, true ) != || PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->FindRow( name, true ) !=
m_frame->Prj().SchSymbolLibTable()->FindRow( name, false ) PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->FindRow( name, false )
|| name == aForceRefresh ) || name == aForceRefresh )
{ {
it = deleteLibrary( it ); it = deleteLibrary( it );

View File

@ -46,6 +46,7 @@
#include <symbol_tree_model_adapter.h> #include <symbol_tree_model_adapter.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <project/project_file.h> #include <project/project_file.h>
#include <project_sch.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <symbol_async_loader.h> #include <symbol_async_loader.h>
#include <tool/action_toolbar.h> #include <tool/action_toolbar.h>
@ -296,7 +297,7 @@ SYMBOL_VIEWER_FRAME::~SYMBOL_VIEWER_FRAME()
void SYMBOL_VIEWER_FRAME::loadAllLibraries() void SYMBOL_VIEWER_FRAME::loadAllLibraries()
{ {
// TODO: deduplicate with SYMBOL_TREE_MODEL_ADAPTER::AddLibraries // TODO: deduplicate with SYMBOL_TREE_MODEL_ADAPTER::AddLibraries
std::vector<wxString> libraryNames = Prj().SchSymbolLibTable()->GetLogicalLibs(); std::vector<wxString> libraryNames = PROJECT_SCH::SchSymbolLibTable( &Prj() )->GetLogicalLibs();
std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter = nullptr; std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter = nullptr;
if( m_show_progress ) if( m_show_progress )
@ -311,7 +312,7 @@ void SYMBOL_VIEWER_FRAME::loadAllLibraries()
std::unordered_map<wxString, std::vector<LIB_SYMBOL*>> loadedSymbols; std::unordered_map<wxString, std::vector<LIB_SYMBOL*>> loadedSymbols;
SYMBOL_ASYNC_LOADER loader( libraryNames, Prj().SchSymbolLibTable(), false, nullptr, SYMBOL_ASYNC_LOADER loader( libraryNames, PROJECT_SCH::SchSymbolLibTable( &Prj() ), false, nullptr,
progressReporter.get() ); progressReporter.get() );
LOCALE_IO toggle; LOCALE_IO toggle;
@ -453,7 +454,7 @@ LIB_SYMBOL* SYMBOL_VIEWER_FRAME::GetSelectedSymbol() const
LIB_SYMBOL* symbol = nullptr; LIB_SYMBOL* symbol = nullptr;
if( m_currentSymbol.IsValid() ) if( m_currentSymbol.IsValid() )
symbol = Prj().SchSymbolLibTable()->LoadSymbol( m_currentSymbol ); symbol = PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbol( m_currentSymbol );
return symbol; return symbol;
} }
@ -502,7 +503,7 @@ bool SYMBOL_VIEWER_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
if( aSymbol && !aSymbol->IsEmpty() ) if( aSymbol && !aSymbol->IsEmpty() )
{ {
wxString msg; wxString msg;
LIB_TABLE* libTable = Prj().SchSymbolLibTable(); LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
LIB_ID libid; LIB_ID libid;
libid.Parse( *aSymbol, true ); libid.Parse( *aSymbol, true );
@ -610,7 +611,7 @@ bool SYMBOL_VIEWER_FRAME::ReCreateLibList()
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings(); COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
PROJECT_FILE& project = Kiway().Prj().GetProjectFile(); PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
SYMBOL_LIB_TABLE* libTable = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &Prj() );
std::vector<wxString> libs = libTable->GetLogicalLibs(); std::vector<wxString> libs = libTable->GetLogicalLibs();
std::vector<wxString> pinnedMatches; std::vector<wxString> pinnedMatches;
std::vector<wxString> otherMatches; std::vector<wxString> otherMatches;
@ -644,7 +645,7 @@ bool SYMBOL_VIEWER_FRAME::ReCreateLibList()
{ {
wxArrayString aliasNames; wxArrayString aliasNames;
Prj().SchSymbolLibTable()->EnumerateSymbolLib( aLib, aliasNames, true ); PROJECT_SCH::SchSymbolLibTable( &Prj() )->EnumerateSymbolLib( aLib, aliasNames, true );
if( aliasNames.IsEmpty() ) if( aliasNames.IsEmpty() )
return; return;
@ -747,12 +748,12 @@ bool SYMBOL_VIEWER_FRAME::ReCreateSymbolList()
return false; return false;
std::vector<LIB_SYMBOL*> symbols; std::vector<LIB_SYMBOL*> symbols;
SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( libName ); SYMBOL_LIB_TABLE_ROW* row = PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( libName );
try try
{ {
if( row ) if( row )
Prj().SchSymbolLibTable()->LoadSymbolLib( symbols, libName, m_listPowerOnly ); PROJECT_SCH::SchSymbolLibTable( &Prj() )->LoadSymbolLib( symbols, libName, m_listPowerOnly );
} }
catch( const IO_ERROR& ) {} // ignore, it is handled below catch( const IO_ERROR& ) {} // ignore, it is handled below
@ -834,7 +835,7 @@ void SYMBOL_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
wxString selection = EscapeString( m_libList->GetBaseString( ii ), CTX_LIBID ); wxString selection = EscapeString( m_libList->GetBaseString( ii ), CTX_LIBID );
if( !Prj().SchSymbolLibTable()->FindRow( selection ) if( !PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( selection )
&& selection.Find( '-' ) != wxNOT_FOUND ) && selection.Find( '-' ) != wxNOT_FOUND )
{ {
// Probably a sub-library // Probably a sub-library
@ -1080,7 +1081,7 @@ void SYMBOL_VIEWER_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
return; return;
// Container doing search-as-you-type. // Container doing search-as-you-type.
SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &Prj() );
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> dataPtr wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> dataPtr
= SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ); = SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
SYMBOL_TREE_MODEL_ADAPTER* modelAdapter SYMBOL_TREE_MODEL_ADAPTER* modelAdapter
@ -1263,7 +1264,7 @@ void SYMBOL_VIEWER_FRAME::DisplayLibInfos()
if( m_libList && !m_libList->IsEmpty() && !libName.IsEmpty() ) if( m_libList && !m_libList->IsEmpty() && !libName.IsEmpty() )
{ {
const SYMBOL_LIB_TABLE_ROW* row = const SYMBOL_LIB_TABLE_ROW* row =
Prj().SchSymbolLibTable()->FindRow( libName, true ); PROJECT_SCH::SchSymbolLibTable( &Prj() )->FindRow( libName, true );
wxString title = row ? row->GetFullURI( true ) : _( "[no library selected]" ); wxString title = row ? row->GetFullURI( true ) : _( "[no library selected]" );
@ -1291,7 +1292,7 @@ void SYMBOL_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
} }
case MAIL_REFRESH_SYMBOL: case MAIL_REFRESH_SYMBOL:
{ {
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* tbl = PROJECT_SCH::SchSymbolLibTable( &Prj() );
LIB_SYMBOL* symbol = GetSelectedSymbol(); LIB_SYMBOL* symbol = GetSelectedSymbol();
wxCHECK2( tbl && symbol, break ); wxCHECK2( tbl && symbol, break );

View File

@ -41,6 +41,7 @@
#include <eda_doc.h> #include <eda_doc.h>
#include <sch_marker.h> #include <sch_marker.h>
#include <project.h> #include <project.h>
#include <project_sch.h>
#include <dialogs/html_message_box.h> #include <dialogs/html_message_box.h>
#include <dialogs/dialog_erc.h> #include <dialogs/dialog_erc.h>
#include <dialogs/dialog_book_reporter.h> #include <dialogs/dialog_book_reporter.h>
@ -283,7 +284,7 @@ int EE_INSPECTION_TOOL::DiffSymbol( const TOOL_EVENT& aEvent )
r->Report( "" ); r->Report( "" );
SYMBOL_LIB_TABLE* libTable = m_frame->Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
const LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName ); const LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName );
if( !libTableRow ) if( !libTableRow )
@ -432,7 +433,8 @@ int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent )
} }
else else
{ {
GetAssociatedDocument( m_frame, datasheet, &m_frame->Prj(), m_frame->Prj().SchSearchS() ); GetAssociatedDocument( m_frame, datasheet, &m_frame->Prj(),
PROJECT_SCH::SchSearchS( &m_frame->Prj() ) );
} }
return 0; return 0;

View File

@ -43,6 +43,7 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <project/project_file.h> #include <project/project_file.h>
#include <project/net_settings.h> #include <project/net_settings.h>
#include <project_sch.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <sch_plugins/kicad/sch_sexpr_plugin.h> #include <sch_plugins/kicad/sch_sexpr_plugin.h>
#include <sch_line.h> #include <sch_line.h>
@ -452,7 +453,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
SYMBOL_LIB_TABLE* projectTable = nullptr; SYMBOL_LIB_TABLE* projectTable = nullptr;
if( !m_frame->Prj().IsNullProject() ) if( !m_frame->Prj().IsNullProject() )
projectTable = m_frame->Prj().SchSymbolLibTable(); projectTable = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
if( globalTable->FindRow( targetLib ) ) if( globalTable->FindRow( targetLib ) )
{ {

View File

@ -27,6 +27,7 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <sch_painter.h> #include <sch_painter.h>
#include <eda_draw_frame.h> #include <eda_draw_frame.h>
#include <project_sch.h>
#include <eeschema_settings.h> #include <eeschema_settings.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <wx/log.h> #include <wx/log.h>
@ -190,7 +191,7 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit, i
try try
{ {
LIB_SYMBOL* tmp = m_kiway->Prj().SchSymbolLibTable()->LoadSymbol( aSymbolID ); LIB_SYMBOL* tmp = PROJECT_SCH::SchSymbolLibTable( &m_kiway->Prj() )->LoadSymbol( aSymbolID );
if( tmp ) if( tmp )
symbol = tmp->Flatten(); symbol = tmp->Flatten();

View File

@ -113,6 +113,14 @@ public:
*/ */
virtual const wxString GetProjectPath() const; virtual const wxString GetProjectPath() const;
/**
* Return the full path of the project DIRECTORY
*
* This is the path of the project file and will always be an absolute path, ending with
* a path separator.
*/
virtual const wxString GetProjectDirectory() const;
/** /**
* Return the short name of the project. * Return the short name of the project.
* *
@ -267,30 +275,6 @@ public:
*/ */
virtual FP_LIB_TABLE* PcbFootprintLibs( KIWAY& aKiway ); virtual FP_LIB_TABLE* PcbFootprintLibs( KIWAY& aKiway );
// These are the non-virtual DATA LOAD ON DEMAND members. They load project related
// data on demand, and do so typically into m_elems[] at a particular index using
// SetElem() & GetElem(). That is, they wrap SetElem() and GetElem().
// To get the data to reload on demand, first SetProjectFullName(),
// then call SetElem( ELEM_T, NULL ) from client code.
// non-virtuals resident in PCBNEW link image(s). By being non-virtual, these
// functions can get linked into the KIFACE that needs them, and only there.
// In fact, the other KIFACEs don't even know they exist.
#if defined( EESCHEMA )
// These are all prefaced with "Sch"
SYMBOL_LIBS* SchLibs();
/// Accessor for Eeschema search stack.
SEARCH_STACK* SchSearchS();
/// Accessor for project symbol library table.
SYMBOL_LIB_TABLE* SchSymbolLibTable();
/// Accessor for 3D path resolver
FILENAME_RESOLVER* Get3DFilenameResolver() { return nullptr; }
#endif
private: private:
friend class SETTINGS_MANAGER; // so that SM can set project path friend class SETTINGS_MANAGER; // so that SM can set project path
friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required