KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_board.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 (C) 2023 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
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 along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_API_HANDLER_BOARD_H
22#define KICAD_API_HANDLER_BOARD_H
23
24#include <memory>
25
26#include <google/protobuf/empty.pb.h>
27
29#include <api/board_context.h>
30#include <api/board/board_commands.pb.h>
31#include <api/board/board_types.pb.h>
32#include <api/common/commands/editor_commands.pb.h>
33#include <api/common/commands/project_commands.pb.h>
34#include <kiid.h>
35
36using namespace kiapi;
37using namespace kiapi::common;
38using namespace kiapi::board::commands;
39
40using google::protobuf::Empty;
41
42
43class BOARD_COMMIT;
44class BOARD_ITEM;
46class EDA_ITEM;
47
48
54{
55public:
56 API_HANDLER_BOARD( std::shared_ptr<BOARD_CONTEXT> aContext, EDA_BASE_FRAME* aFrame = nullptr );
57
58protected:
59 std::unique_ptr<COMMIT> createCommit() override;
60
61 void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
62 const std::string& aClientName ) override;
63
64 std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument,
65 const KIID& aId ) override;
66
67 void pushCurrentCommit( const std::string& aClientName, const wxString& aMessage ) override;
68
70 const std::string& aClientName,
71 const types::ItemHeader &aHeader,
72 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
73 std::function<void(commands::ItemStatus, google::protobuf::Any)> aItemHandler )
74 override;
75
76 BOARD_CONTEXT* context() const { return m_context.get(); }
77
78 BOARD* board() const { return context()->GetBoard(); }
79
80 PROJECT& project() const { return context()->Prj(); }
81
83
84 std::optional<BOARD_ITEM*> getItemById( const KIID& aId ) const;
85
87 BOARD_ITEM_CONTAINER* aContainer );
88
90
91 std::optional<ApiResponseStatus> checkForHeadless( const std::string& aCommandName ) const;
92
93 std::vector<KICAD_T> parseRequestedItemTypes(
94 const google::protobuf::RepeatedField<int>& aTypes );
95
96private:
99
102
105
108
111
114
117
120
123
126
129
132
135
138
141
144
147
150
153
156
159
160 std::shared_ptr<BOARD_CONTEXT> m_context;
161};
162
163#endif //KICAD_API_HANDLER_BOARD_H
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition api_handler.h:45
API_HANDLER_BOARD(std::shared_ptr< BOARD_CONTEXT > aContext, EDA_BASE_FRAME *aFrame=nullptr)
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables(const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
HANDLER_RESULT< BoardEnabledLayersResponse > handleGetBoardEnabledLayers(const HANDLER_CONTEXT< GetBoardEnabledLayers > &aCtx)
std::unique_ptr< COMMIT > createCommit() override
Override this to create an appropriate COMMIT subclass for the frame in question.
HANDLER_RESULT< commands::SelectionResponse > handleGetSelection(const HANDLER_CONTEXT< commands::GetSelection > &aCtx)
HANDLER_RESULT< commands::SavedSelectionResponse > handleSaveSelectionToString(const HANDLER_CONTEXT< commands::SaveSelectionToString > &aCtx)
HANDLER_RESULT< Empty > handleSetActiveLayer(const HANDLER_CONTEXT< SetActiveLayer > &aCtx)
HANDLER_RESULT< BoardLayers > handleGetVisibleLayers(const HANDLER_CONTEXT< GetVisibleLayers > &aCtx)
TOOL_MANAGER * toolManager() const
HANDLER_RESULT< commands::SelectionResponse > handleAddToSelection(const HANDLER_CONTEXT< commands::AddToSelection > &aCtx)
HANDLER_RESULT< commands::CreateItemsResponse > handleParseAndCreateItemsFromString(const HANDLER_CONTEXT< commands::ParseAndCreateItemsFromString > &aCtx)
HANDLER_RESULT< Empty > handleClearSelection(const HANDLER_CONTEXT< commands::ClearSelection > &aCtx)
std::vector< KICAD_T > parseRequestedItemTypes(const google::protobuf::RepeatedField< int > &aTypes)
HANDLER_RESULT< Empty > handleInteractiveMoveItems(const HANDLER_CONTEXT< InteractiveMoveItems > &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
HANDLER_RESULT< BoardStackupResponse > handleGetStackup(const HANDLER_CONTEXT< GetBoardStackup > &aCtx)
PROJECT & project() const
void pushCurrentCommit(const std::string &aClientName, const wxString &aMessage) override
HANDLER_RESULT< commands::GetItemsResponse > handleGetItemsById(const HANDLER_CONTEXT< commands::GetItemsById > &aCtx)
BOARD * board() const
std::optional< EDA_ITEM * > getItemFromDocument(const DocumentSpecifier &aDocument, const KIID &aId) override
BOARD_CONTEXT * context() const
void deleteItemsInternal(std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const std::string &aClientName) override
HANDLER_RESULT< commands::SelectionResponse > handleRemoveFromSelection(const HANDLER_CONTEXT< commands::RemoveFromSelection > &aCtx)
HANDLER_RESULT< GraphicsDefaultsResponse > handleGetGraphicsDefaults(const HANDLER_CONTEXT< GetGraphicsDefaults > &aCtx)
HANDLER_RESULT< BoardLayerResponse > handleGetActiveLayer(const HANDLER_CONTEXT< GetActiveLayer > &aCtx)
HANDLER_RESULT< commands::GetBoundingBoxResponse > handleGetBoundingBox(const HANDLER_CONTEXT< commands::GetBoundingBox > &aCtx)
static HANDLER_RESULT< std::unique_ptr< BOARD_ITEM > > createItemForType(KICAD_T aType, BOARD_ITEM_CONTAINER *aContainer)
HANDLER_RESULT< commands::RunActionResponse > handleRunAction(const HANDLER_CONTEXT< commands::RunAction > &aCtx)
std::optional< ApiResponseStatus > checkForHeadless(const std::string &aCommandName) const
HANDLER_RESULT< commands::SavedDocumentResponse > handleSaveDocumentToString(const HANDLER_CONTEXT< commands::SaveDocumentToString > &aCtx)
HANDLER_RESULT< PadShapeAsPolygonResponse > handleGetPadShapeAsPolygon(const HANDLER_CONTEXT< GetPadShapeAsPolygon > &aCtx)
std::shared_ptr< BOARD_CONTEXT > m_context
HANDLER_RESULT< PadstackPresenceResponse > handleCheckPadstackPresenceOnLayers(const HANDLER_CONTEXT< CheckPadstackPresenceOnLayers > &aCtx)
virtual BOARD_ITEM_CONTAINER * getDefaultContainer()
HANDLER_RESULT< Empty > handleSetVisibleLayers(const HANDLER_CONTEXT< SetVisibleLayers > &aCtx)
std::optional< BOARD_ITEM * > getItemById(const KIID &aId) const
API_HANDLER_EDITOR(EDA_BASE_FRAME *aFrame=nullptr)
Base interface for board-level API contexts; shared by PCB editor and footprint editor.
virtual TOOL_MANAGER * GetToolManager() const =0
virtual BOARD * GetBoard() const =0
virtual PROJECT & Prj() const =0
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
The base frame for deriving all KiCad main window classes.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:100
Definition kiid.h:48
Container for project specific data.
Definition project.h:66
Master controller class:
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:75