KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_handler_editor.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) 2024 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_EDITOR_H
22#define KICAD_API_HANDLER_EDITOR_H
23
24#include <api/api_handler.h>
25#include <api/common/commands/editor_commands.pb.h>
26#include <base_units.h>
27#include <commit.h>
28#include <google/protobuf/empty.pb.h>
29#include <kiid.h>
30#include <page_info.h>
31
32using namespace kiapi::common;
33using kiapi::common::types::DocumentSpecifier;
34using kiapi::common::types::ItemRequestStatus;
35using kiapi::common::commands::ItemDeletionStatus;
36
37class EDA_BASE_FRAME;
38class TITLE_BLOCK;
39
44{
45public:
46 API_HANDLER_EDITOR( EDA_BASE_FRAME* aFrame = nullptr );
47
48protected:
51 const kiapi::common::types::ItemHeader& aHeader );
52
53 HANDLER_RESULT<bool> validateDocument( const DocumentSpecifier& aDocument );
54
59 virtual std::optional<ApiResponseStatus> checkForBusy();
60
63
66
67 COMMIT* getCurrentCommit( const std::string& aClientName );
68
69 virtual void pushCurrentCommit( const std::string& aClientName, const wxString& aMessage );
70
73
76
79
82
85
88
91
94
99 virtual std::unique_ptr<COMMIT> createCommit() = 0;
100
104 virtual types::DocumentType thisDocumentType() const = 0;
105
109 virtual tl::expected<bool, ApiResponseStatus> validateDocumentInternal( const DocumentSpecifier& aDocument ) const = 0;
110
116 virtual const EDA_IU_SCALE& getIuScale() const { return pcbIUScale; }
117
119 const std::string& aClientName,
120 const types::ItemHeader &aHeader,
121 const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
122 std::function<void( commands::ItemStatus, google::protobuf::Any )> aItemHandler ) = 0;
123
124 virtual void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
125 const std::string& aClientName ) = 0;
126
127 virtual std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument,
128 const KIID& aId ) = 0;
129
130 static std::vector<KICAD_T> parseRequestedItemTypes( const google::protobuf::RepeatedField<int>& aTypes );
131
132 virtual std::optional<TITLE_BLOCK*> getTitleBlock() { return std::nullopt; }
133
134 virtual std::optional<PAGE_INFO> getPageSettings() { return std::nullopt; }
135
136 virtual bool setPageSettings( const PAGE_INFO& aPageInfo ) { return false; }
137
138 virtual wxString getDrawingSheetFileName() { return wxEmptyString; }
139
140 virtual void setDrawingSheetFileName( const wxString& aFileName ) {}
141
142 virtual void onModified() {}
143
144protected:
145 std::map<std::string, std::pair<KIID, std::unique_ptr<COMMIT>>> m_commits;
146
147 std::set<std::string> m_activeClients;
148
150};
151
152#endif //KICAD_API_HANDLER_EDITOR_H
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
Definition api_handler.h:45
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:125
virtual std::optional< PAGE_INFO > getPageSettings()
virtual std::unique_ptr< COMMIT > createCommit()=0
Override this to create an appropriate COMMIT subclass for the frame in question.
HANDLER_RESULT< bool > validateDocument(const DocumentSpecifier &aDocument)
HANDLER_RESULT< commands::DeleteItemsResponse > handleDeleteItems(const HANDLER_CONTEXT< commands::DeleteItems > &aCtx)
HANDLER_RESULT< types::PageSettings > handleSetPageSettings(const HANDLER_CONTEXT< commands::SetPageSettings > &aCtx)
virtual const EDA_IU_SCALE & getIuScale() const
Returns the internal-unit scale that the concrete editor uses.
virtual std::optional< EDA_ITEM * > getItemFromDocument(const DocumentSpecifier &aDocument, const KIID &aId)=0
HANDLER_RESULT< std::optional< KIID > > validateItemHeaderDocument(const kiapi::common::types::ItemHeader &aHeader)
If the header is valid, returns the item container.
virtual void setDrawingSheetFileName(const wxString &aFileName)
HANDLER_RESULT< types::PageSettings > handleGetPageSettings(const HANDLER_CONTEXT< commands::GetPageSettings > &aCtx)
virtual std::optional< TITLE_BLOCK * > getTitleBlock()
HANDLER_RESULT< commands::EndCommitResponse > handleEndCommit(const HANDLER_CONTEXT< commands::EndCommit > &aCtx)
virtual tl::expected< bool, ApiResponseStatus > validateDocumentInternal(const DocumentSpecifier &aDocument) const =0
API_HANDLER_EDITOR(EDA_BASE_FRAME *aFrame=nullptr)
static std::vector< KICAD_T > parseRequestedItemTypes(const google::protobuf::RepeatedField< int > &aTypes)
HANDLER_RESULT< commands::CreateItemsResponse > handleCreateItems(const HANDLER_CONTEXT< commands::CreateItems > &aCtx)
COMMIT * getCurrentCommit(const std::string &aClientName)
virtual void pushCurrentCommit(const std::string &aClientName, const wxString &aMessage)
virtual HANDLER_RESULT< 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)=0
std::set< std::string > m_activeClients
std::map< std::string, std::pair< KIID, std::unique_ptr< COMMIT > > > m_commits
virtual bool setPageSettings(const PAGE_INFO &aPageInfo)
HANDLER_RESULT< commands::UpdateItemsResponse > handleUpdateItems(const HANDLER_CONTEXT< commands::UpdateItems > &aCtx)
virtual void deleteItemsInternal(std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const std::string &aClientName)=0
virtual wxString getDrawingSheetFileName()
virtual std::optional< ApiResponseStatus > checkForBusy()
Checks if the editor can accept commands.
HANDLER_RESULT< types::TitleBlockInfo > handleGetTitleBlockInfo(const HANDLER_CONTEXT< commands::GetTitleBlockInfo > &aCtx)
virtual types::DocumentType thisDocumentType() const =0
Override this to specify which document type this editor handles.
HANDLER_RESULT< google::protobuf::Empty > handleSetTitleBlockInfo(const HANDLER_CONTEXT< commands::SetTitleBlockInfo > &aCtx)
HANDLER_RESULT< commands::BeginCommitResponse > handleBeginCommit(const HANDLER_CONTEXT< commands::BeginCommit > &aCtx)
virtual void onModified()
HANDLER_RESULT< commands::HitTestResponse > handleHitTest(const HANDLER_CONTEXT< commands::HitTest > &aCtx)
EDA_BASE_FRAME * m_frame
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:72
The base frame for deriving all KiCad main window classes.
Definition kiid.h:48
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:79
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:41