KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_sch.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <confirm.h>
22#include <kiface_base.h>
23#include <pgm_base.h>
24#include <wx/app.h>
25#include <core/utf8.h>
26#include <project_sch.h>
29
30static std::mutex s_symbolTableMutex;
32
33// non-member so it can be moved easily, and kept REALLY private.
34// Do NOT Clear() in here.
35static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int aIndex )
36{
37 for( unsigned i=0; i<aSrc.GetCount(); ++i )
38 aDst->AddPaths( aSrc[i], aIndex );
39}
40
41
43{
45
46 wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( ss ) );
47
48 if( !ss )
49 {
50 ss = new SEARCH_STACK();
51
52 // Make PROJECT the new SEARCH_STACK owner.
54
55 // to the empty SEARCH_STACK for SchSearchS(), add project dir as first
56 ss->AddPaths( aProject->GetProjectDirectory() );
57
58 // next add the paths found in *.pro, variable "LibDir"
59 wxString libDir;
60
61 try
62 {
63 LEGACY_SYMBOL_LIBS::GetLibNamesAndPaths( aProject, &libDir );
64 }
65 catch( const IO_ERROR& )
66 {
67 }
68
69 if( !!libDir )
70 {
71 wxArrayString paths;
72
73 SEARCH_STACK::Split( &paths, libDir );
74
75 for( unsigned i =0; i<paths.GetCount(); ++i )
76 {
77 wxString path = aProject->AbsolutePath( paths[i] );
78
79 ss->AddPaths( path ); // at the end
80 }
81 }
82
83 // append all paths from aSList
84 add_search_paths( ss, Kiface().KifaceSearch(), -1 );
85 }
86
87 return ss;
88}
89
90
92{
93 auto libs = static_cast<LEGACY_SYMBOL_LIBS*>( aProject->GetElem( PROJECT::ELEM::LEGACY_SYMBOL_LIBS ) );
94
95 wxASSERT( !libs || libs->ProjectElementType() == PROJECT::ELEM::LEGACY_SYMBOL_LIBS );
96
97 if( !libs )
98 {
99 libs = new LEGACY_SYMBOL_LIBS();
100
101 // Make PROJECT the new SYMBOL_LIBS owner.
103
104 try
105 {
106 libs->LoadAllLibraries( aProject );
107 }
108 catch( const PARSE_ERROR& pe )
109 {
110 wxString lib_list = UTF8( pe.inputLine );
111 wxWindow* parent = Pgm().App().GetTopWindow();
112
113 // parent of this dialog cannot be NULL since that breaks the Kiway() chain.
114 HTML_MESSAGE_BOX dlg( parent, _( "Not Found" ) );
115
116 dlg.MessageSet( _( "The following libraries were not found:" ) );
117 dlg.ListSet( lib_list );
118 dlg.Layout();
119
120 dlg.ShowModal();
121 }
122 catch( const IO_ERROR& ioe )
123 {
124 wxWindow* parent = Pgm().App().GetTopWindow();
125
126 DisplayError( parent, ioe.What() );
127 }
128 }
129
130 return libs;
131}
132
133
135{
136 std::scoped_lock lock( s_libAdapterMutex );
137
139 std::optional<LIBRARY_MANAGER_ADAPTER*> adapter = mgr.Adapter( LIBRARY_TABLE_TYPE::SYMBOL );
140
141 if( !adapter )
142 {
144 std::make_unique<SYMBOL_LIBRARY_ADAPTER>( mgr ) );
145
146 std::optional<LIBRARY_MANAGER_ADAPTER*> created = mgr.Adapter( LIBRARY_TABLE_TYPE::SYMBOL );
147 wxCHECK( created && ( *created )->Type() == LIBRARY_TABLE_TYPE::SYMBOL, nullptr );
148 return static_cast<SYMBOL_LIBRARY_ADAPTER*>( *created );
149 }
150
151 wxCHECK( ( *adapter )->Type() == LIBRARY_TABLE_TYPE::SYMBOL, nullptr );
152 return static_cast<SYMBOL_LIBRARY_ADAPTER*>( *adapter );
153}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
int ShowModal() override
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
void ListSet(const wxString &aList)
Add a list of items.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A collection of #SYMBOL_LIB objects.
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
std::optional< LIBRARY_MANAGER_ADAPTER * > Adapter(LIBRARY_TABLE_TYPE aType) const
void RegisterAdapter(LIBRARY_TABLE_TYPE aType, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > &&aAdapter)
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition pgm_base.cpp:192
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:130
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static LEGACY_SYMBOL_LIBS * LegacySchLibs(PROJECT *aProject)
Returns the list of symbol libraries from a legacy (pre-5.x) design This is only used from the remapp...
static SEARCH_STACK * SchSearchS(PROJECT *aProject)
Accessor for Eeschema search stack.
static std::mutex s_libAdapterMutex
Used to synchronise access to SymbolLibAdapter.
Definition project_sch.h:52
Container for project specific data.
Definition project.h:66
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
Definition project.cpp:378
virtual _ELEM * GetElem(PROJECT::ELEM aIndex)
Get and set the elements for this project.
Definition project.cpp:367
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition project.cpp:389
virtual const wxString GetProjectDirectory() const
Return the full path of the project DIRECTORY.
Definition project.cpp:171
@ SCH_SEARCH_STACK
Definition project.h:76
@ LEGACY_SYMBOL_LIBS
Definition project.h:75
Look for files in a number of paths.
static int Split(wxArrayString *aResult, const wxString &aPathString)
Separate aPathString into individual paths.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
An interface to the global shared library manager that is schematic-specific and linked to one projec...
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition utf8.h:72
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
This file is part of the common library.
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
see class PGM_BASE
static void add_search_paths(SEARCH_STACK *aDst, const SEARCH_STACK &aSrc, int aIndex)
static std::mutex s_symbolTableMutex
A filename or source description, a problem input line, a line number, a byte offset,...
std::string inputLine
problem line of input [say, from a LINE_READER].