KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_libraries.h
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
21#ifndef KICAD_API_HANDLER_LIBRARIES_H
22#define KICAD_API_HANDLER_LIBRARIES_H
23
24#include <functional>
25#include <map>
26#include <vector>
27
28#include <api/api_handler.h>
29#include <api/common/commands/editor_commands.pb.h>
30#include <api/common/commands/library_commands.pb.h>
32
33class LIB_ID;
35class KIWAY;
36struct KIFACE;
37class PROJECT;
38
47{
48public:
50
52
53 void SetKiway( KIWAY* aKiway ) { m_kiway = aKiway; }
54
56 void SetLibraryHandlerRegistrar( std::function<void( KIFACE* )> aRegistrar )
57 {
58 m_handlerRegisterCallback = std::move( aRegistrar );
59 }
60
61
62protected:
65
68
71
74
76 kiapi::common::types::LibraryCommandStatus loadAllLibraries();
77
80
81 virtual bool packLibraryItem( const LIB_ID& aId, google::protobuf::Any& aOutput ) const
82 {
83 return false;
84 }
85
87
88 virtual LIBRARY_MANAGER_ADAPTER* adapterForProject( PROJECT& aProject ) const;
89
94 virtual std::vector<wxString> getItemNames( LIBRARY_MANAGER_ADAPTER& aAdapter, const wxString& aNickname ) const;
95
96private:
98
100 KIWAY* m_kiway = nullptr;
101
103 std::function<void( KIFACE* )> m_handlerRegisterCallback;
104};
105
106#endif //KICAD_API_HANDLER_LIBRARIES_H
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition api_handler.h:45
HANDLER_RESULT< kiapi::common::commands::LibraryItemsResponse > handleGetLibraryItems(const HANDLER_CONTEXT< kiapi::common::commands::GetLibraryItems > &aCtx)
HANDLER_RESULT< kiapi::common::commands::LibraryStatusResponse > handleGetLibraryStatuses(const HANDLER_CONTEXT< kiapi::common::commands::GetLibraryStatuses > &aCtx)
virtual bool packLibraryItem(const LIB_ID &aId, google::protobuf::Any &aOutput) const
~API_HANDLER_LIBRARIES() override
HANDLER_RESULT< kiapi::common::types::LibraryCommandStatus > handleReloadLibrary(const HANDLER_CONTEXT< kiapi::common::commands::ReloadLibrary > &aCtx)
kiapi::common::types::LibraryCommandStatus loadAllLibraries()
Starts a background load of all libraries of this handler's type.
virtual std::vector< wxString > getItemNames(LIBRARY_MANAGER_ADAPTER &aAdapter, const wxString &aNickname) const
Returns the names of all entries in the given library, or an empty vector if the library is not loade...
void SetKiway(KIWAY *aKiway)
virtual LIBRARY_MANAGER_ADAPTER * adapterForProject(PROJECT &aProject) const
API_HANDLER_LIBRARIES(LIBRARY_TABLE_TYPE aType=LIBRARY_TABLE_TYPE::DESIGN_BLOCK)
LIBRARY_TABLE_TYPE libraryType() const
std::function< void(KIFACE *)> m_handlerRegisterCallback
Invoked with a lazily-loaded KIFACE so its handlers can be registered on the server.
KIWAY * m_kiway
Used to lazily load kifaces for LoadAllLibraries in headless; null in GUI mode.
HANDLER_RESULT< kiapi::common::types::LibraryCommandStatus > handleLoadAllLibraries(const HANDLER_CONTEXT< kiapi::common::commands::LoadAllLibraries > &aCtx)
void SetLibraryHandlerRegistrar(std::function< void(KIFACE *)> aRegistrar)
Set a callback to register the handler on the API server in headless mode.
HANDLER_RESULT< kiapi::common::commands::GetItemsResponse > handleGetItemsFromLibrary(const HANDLER_CONTEXT< kiapi::common::commands::GetItemsFromLibrary > &aCtx)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:340
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
Container for project specific data.
Definition project.h:63
LIBRARY_TABLE_TYPE
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153