KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_symbol.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 *
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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef KICAD_API_HANDLER_SYMBOL_H
21#define KICAD_API_HANDLER_SYMBOL_H
22
23#include <google/protobuf/empty.pb.h>
24
26#include <api/common/commands/editor_commands.pb.h>
27#include <api/common/commands/project_commands.pb.h>
29
30using google::protobuf::Empty;
31
32class LIB_SYMBOL;
33class SCH_ITEM;
35
36
38{
39public:
41 API_HANDLER_SYMBOL( std::shared_ptr<SYMBOL_EDITOR_CONTEXT> aContext,
42 SYMBOL_EDIT_FRAME* aFrame = nullptr );
43
44protected:
45 std::unique_ptr<COMMIT> createCommit() override;
46
47 kiapi::common::types::DocumentType thisDocumentType() const override
48 {
49 return kiapi::common::types::DOCTYPE_SYMBOL;
50 }
51
52 const EDA_IU_SCALE& getIuScale() const override { return schIUScale; }
53
54 tl::expected<bool, ApiResponseStatus> validateDocumentInternal( const DocumentSpecifier& aDocument ) const override;
55
56 std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument, const KIID& aId ) override;
57
59 const std::string& aClientName,
60 const types::ItemHeader &aHeader,
61 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
62 std::function<void( commands::ItemStatus, google::protobuf::Any )> aItemHandler )
63 override;
64
65 void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
66 const std::string& aClientName ) override;
67
68 void onModified() override;
69
70 void pushCurrentCommit( const std::string& aClientName, const wxString& aMessage ) override;
71
74
75 SYMBOL_EDITOR_CONTEXT* context() const { return m_context.get(); }
76
77 LIB_SYMBOL* symbol() const { return context()->GetCurSymbol(); }
78
79 SYMBOL_EDIT_FRAME* frame() const;
80
81private:
83
86
88
91
93
96
99
100 std::shared_ptr<SYMBOL_EDITOR_CONTEXT> m_context;
101 static std::set<KICAD_T> s_allowedTypes;
102};
103
104
105#endif //KICAD_API_HANDLER_SYMBOL_H
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition api_handler.h:47
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
API_HANDLER_EDITOR(EDA_BASE_FRAME *aFrame=nullptr)
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems(const HANDLER_CONTEXT< commands::GetItems > &aCtx)
tl::expected< bool, ApiResponseStatus > validateDocumentInternal(const DocumentSpecifier &aDocument) const override
std::unique_ptr< COMMIT > createCommit() override
Override this to create an appropriate COMMIT subclass for the frame in question.
HANDLER_RESULT< Empty > handleSaveDocument(const HANDLER_CONTEXT< commands::SaveDocument > &aCtx)
SYMBOL_EDITOR_CONTEXT * context() const
static std::set< KICAD_T > s_allowedTypes
LIB_SYMBOL * symbol() const
HANDLER_RESULT< Empty > handleRevertDocument(const HANDLER_CONTEXT< commands::RevertDocument > &aCtx)
HANDLER_RESULT< commands::GetDocumentModifiedStateResponse > handleGetDocumentModifiedState(const HANDLER_CONTEXT< commands::GetDocumentModifiedState > &aCtx) override
void deleteItemsInternal(std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const std::string &aClientName) override
const EDA_IU_SCALE & getIuScale() const override
Returns the internal-unit scale that the concrete editor uses.
HANDLER_RESULT< Empty > handleOpenLibraryItem(const HANDLER_CONTEXT< commands::OpenLibraryItem > &aCtx)
HANDLER_RESULT< types::ItemRequestStatus > handleCreateUpdateItemsInternal(bool aCreate, const std::string &aClientName, const types::ItemHeader &aHeader, const google::protobuf::RepeatedPtrField< google::protobuf::Any > &aItems, std::function< void(commands::ItemStatus, google::protobuf::Any)> aItemHandler) override
API_HANDLER_SYMBOL(SYMBOL_EDIT_FRAME *aFrame)
std::shared_ptr< SYMBOL_EDITOR_CONTEXT > m_context
HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments(const HANDLER_CONTEXT< commands::GetOpenDocuments > &aCtx)
HANDLER_RESULT< Empty > handleSaveCopyOfDocument(const HANDLER_CONTEXT< commands::SaveCopyOfDocument > &aCtx)
void pushCurrentCommit(const std::string &aClientName, const wxString &aMessage) override
SYMBOL_EDIT_FRAME * frame() const
kiapi::common::types::DocumentType thisDocumentType() const override
Override this to specify which document type this editor handles.
std::optional< EDA_ITEM * > getItemFromDocument(const DocumentSpecifier &aDocument, const KIID &aId) override
HANDLER_RESULT< commands::GetItemsResponse > handleGetItemsById(const HANDLER_CONTEXT< commands::GetItemsById > &aCtx)
Definition kiid.h:46
Define a library symbol object.
Definition lib_symbol.h:114
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
virtual LIB_SYMBOL * GetCurSymbol() const =0
The symbol library editor main window.