KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_sch_libraries.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 * @author Jon Evans <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <api/api_utils.h>
23
25#include <pgm_base.h>
26#include <project_sch.h>
28#include <lib_symbol.h>
29
30
35
36
38 const wxString& aNickname ) const
39{
40 return static_cast<SYMBOL_LIBRARY_ADAPTER&>( aAdapter ).GetSymbolNames( aNickname );
41}
42
43
44bool API_HANDLER_SCH_LIBRARIES::packLibraryItem( const LIB_ID& aId, google::protobuf::Any& aOutput ) const
45{
46 SYMBOL_LIBRARY_ADAPTER* adapter =
47 static_cast<SYMBOL_LIBRARY_ADAPTER*>( adapterForProject( Pgm().GetSettingsManager().Prj() ) );
48
49 LIB_SYMBOL* libSymbol = adapter->LoadSymbol( aId );
50
51 if( !libSymbol )
52 return false;
53
54 // Clients get the inherited drawings resolved, so derived symbols are reported flattened.
55 std::unique_ptr<LIB_SYMBOL> flattened;
56
57 if( libSymbol->IsDerived() )
58 {
59 flattened = libSymbol->Flatten();
60
61 if( flattened )
62 flattened->SetParentName( libSymbol->GetParentName() );
63 }
64 else if( !libSymbol->GetParentName().IsEmpty() )
65 {
66 wxLogTrace( traceApi, "Cannot resolve the parent of derived symbol '%s'", aId.Format().wx_str() );
67 }
68
69 ( flattened ? flattened.get() : libSymbol )->Serialize( aOutput );
70
71 return true;
72}
LIBRARY_MANAGER_ADAPTER * adapterForProject(PROJECT &aProject) const override
std::vector< wxString > getItemNames(LIBRARY_MANAGER_ADAPTER &aAdapter, const wxString &aNickname) const override
Returns the names of all entries in the given library, or an empty vector if the library is not loade...
bool packLibraryItem(const LIB_ID &aId, google::protobuf::Any &aOutput) const override
The interface used by the classes that actually can load IO plugins for the different parts of KiCad ...
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
UTF8 Format() const
Definition lib_id.cpp:132
Define a library symbol object.
Definition lib_symbol.h:114
void Serialize(kiapi::schematic::types::SchematicSymbol &aOutput, bool aSkipPins=false) const
bool IsDerived() const
Definition lib_symbol.h:241
const wxString & GetParentName() const
Definition lib_symbol.h:995
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
Definition project.h:63
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
wxString wx_str() const
Definition utf8.cpp:41
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
Definition api_utils.cpp:33
PROJECT & Prj()
Definition kicad.cpp:737
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE