KiCad PCB EDA Suite
Loading...
Searching...
No Matches
API_HANDLER_PCB Class Reference

#include <api_handler_pcb.h>

Inheritance diagram for API_HANDLER_PCB:
API_HANDLER_EDITOR API_HANDLER

Public Member Functions

 API_HANDLER_PCB (PCB_EDIT_FRAME *aFrame)
 
API_RESULT Handle (ApiRequest &aMsg)
 Attempt to handle the given API request, if a handler exists in this class for the message.
 

Protected Types

typedef std::function< HANDLER_RESULT< ApiResponse >(ApiRequest &)> REQUEST_HANDLER
 A handler for outer messages (envelopes) that will unpack to inner messages and call a specific handler function.
 

Protected Member Functions

std::unique_ptr< COMMITcreateCommit () override
 Override this to create an appropriate COMMIT subclass for the frame in question.
 
kiapi::common::types::DocumentType thisDocumentType () const override
 Override this to specify which document type this editor handles.
 
bool validateDocumentInternal (const DocumentSpecifier &aDocument) const override
 
void deleteItemsInternal (std::map< KIID, ItemDeletionStatus > &aItemsToDelete, const std::string &aClientName) override
 
std::optional< EDA_ITEM * > getItemFromDocument (const DocumentSpecifier &aDocument, const KIID &aId) override
 
HANDLER_RESULT< std::optional< KIID > > validateItemHeaderDocument (const kiapi::common::types::ItemHeader &aHeader)
 If the header is valid, returns the item container.
 
HANDLER_RESULT< bool > validateDocument (const DocumentSpecifier &aDocument)
 
virtual std::optional< ApiResponseStatus > checkForBusy ()
 Checks if the editor can accept commands.
 
HANDLER_RESULT< commands::BeginCommitResponse > handleBeginCommit (const HANDLER_CONTEXT< commands::BeginCommit > &aCtx)
 
HANDLER_RESULT< commands::EndCommitResponse > handleEndCommit (const HANDLER_CONTEXT< commands::EndCommit > &aCtx)
 
COMMITgetCurrentCommit (const std::string &aClientName)
 
HANDLER_RESULT< commands::CreateItemsResponse > handleCreateItems (const HANDLER_CONTEXT< commands::CreateItems > &aCtx)
 
HANDLER_RESULT< commands::UpdateItemsResponse > handleUpdateItems (const HANDLER_CONTEXT< commands::UpdateItems > &aCtx)
 
HANDLER_RESULT< commands::DeleteItemsResponse > handleDeleteItems (const HANDLER_CONTEXT< commands::DeleteItems > &aCtx)
 
HANDLER_RESULT< commands::HitTestResponse > handleHitTest (const HANDLER_CONTEXT< commands::HitTest > &aCtx)
 
template<class RequestType , class ResponseType , class HandlerType >
void registerHandler (HANDLER_RESULT< ResponseType >(HandlerType::*aHandler)(const HANDLER_CONTEXT< RequestType > &))
 Registers an API command handler for the given message types.
 

Protected Attributes

std::map< std::string, std::pair< KIID, std::unique_ptr< COMMIT > > > m_commits
 
std::set< std::string > m_activeClients
 
EDA_BASE_FRAMEm_frame
 
std::map< std::string, REQUEST_HANDLERm_handlers
 Maps type name (without the URL prefix) to a handler method.
 

Static Protected Attributes

static const wxString m_defaultCommitMessage = _( "Modification from API" )
 

Private Types

typedef std::map< std::string, PROPERTY_BASE * > PROTO_PROPERTY_MAP
 

Private Member Functions

HANDLER_RESULT< commands::RunActionResponse > handleRunAction (const HANDLER_CONTEXT< commands::RunAction > &aCtx)
 
HANDLER_RESULT< commands::GetOpenDocumentsResponse > handleGetOpenDocuments (const HANDLER_CONTEXT< commands::GetOpenDocuments > &aCtx)
 
HANDLER_RESULT< commands::GetItemsResponse > handleGetItems (const HANDLER_CONTEXT< commands::GetItems > &aCtx)
 
HANDLER_RESULT< BoardStackupResponse > handleGetStackup (const HANDLER_CONTEXT< GetBoardStackup > &aCtx)
 
HANDLER_RESULT< GraphicsDefaultsResponse > handleGetGraphicsDefaults (const HANDLER_CONTEXT< GetGraphicsDefaults > &aCtx)
 
HANDLER_RESULT< commands::GetBoundingBoxResponse > handleGetBoundingBox (const HANDLER_CONTEXT< commands::GetBoundingBox > &aCtx)
 
HANDLER_RESULT< PadShapeAsPolygonResponse > handleGetPadShapeAsPolygon (const HANDLER_CONTEXT< GetPadShapeAsPolygon > &aCtx)
 
HANDLER_RESULT< types::TitleBlockInfo > handleGetTitleBlockInfo (const HANDLER_CONTEXT< commands::GetTitleBlockInfo > &aCtx)
 
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables (const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
 
HANDLER_RESULT< Empty > handleInteractiveMoveItems (const HANDLER_CONTEXT< InteractiveMoveItems > &aCtx)
 
HANDLER_RESULT< NetsResponse > handleGetNets (const HANDLER_CONTEXT< GetNets > &aCtx)
 
HANDLER_RESULT< Empty > handleRefillZones (const HANDLER_CONTEXT< RefillZones > &aCtx)
 
HANDLER_RESULT< commands::SavedDocumentResponse > handleSaveDocumentToString (const HANDLER_CONTEXT< commands::SaveDocumentToString > &aCtx)
 
HANDLER_RESULT< commands::SavedSelectionResponse > handleSaveSelectionToString (const HANDLER_CONTEXT< commands::SaveSelectionToString > &aCtx)
 
HANDLER_RESULT< commands::CreateItemsResponse > handleParseAndCreateItemsFromString (const HANDLER_CONTEXT< commands::ParseAndCreateItemsFromString > &aCtx)
 
HANDLER_RESULT< BoardLayers > handleGetVisibleLayers (const HANDLER_CONTEXT< GetVisibleLayers > &aCtx)
 
HANDLER_RESULT< Empty > handleSetVisibleLayers (const HANDLER_CONTEXT< SetVisibleLayers > &aCtx)
 
HANDLER_RESULT< BoardLayerResponse > handleGetActiveLayer (const HANDLER_CONTEXT< GetActiveLayer > &aCtx)
 
HANDLER_RESULT< Empty > handleSetActiveLayer (const HANDLER_CONTEXT< SetActiveLayer > &aCtx)
 
PCB_EDIT_FRAMEframe () const
 
void pushCurrentCommit (const std::string &aClientName, const wxString &aMessage) override
 
std::optional< BOARD_ITEM * > getItemById (const KIID &aId) const
 
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
 
template<typename MessageType >
bool tryUnpack (ApiRequest &aRequest, ApiResponse &aReply, MessageType &aDest)
 

Static Private Member Functions

static HANDLER_RESULT< std::unique_ptr< BOARD_ITEM > > createItemForType (KICAD_T aType, BOARD_ITEM_CONTAINER *aContainer)
 

Detailed Description

Definition at line 50 of file api_handler_pcb.h.

Member Typedef Documentation

◆ PROTO_PROPERTY_MAP

typedef std::map<std::string, PROPERTY_BASE*> API_HANDLER_PCB::PROTO_PROPERTY_MAP
private

Definition at line 56 of file api_handler_pcb.h.

◆ REQUEST_HANDLER

typedef std::function<HANDLER_RESULT<ApiResponse>( ApiRequest& )> API_HANDLER::REQUEST_HANDLER
protectedinherited

A handler for outer messages (envelopes) that will unpack to inner messages and call a specific handler function.

See also
registerHandler.

Definition at line 76 of file api_handler.h.

Constructor & Destructor Documentation

◆ API_HANDLER_PCB()

Member Function Documentation

◆ checkForBusy()

◆ createCommit()

std::unique_ptr< COMMIT > API_HANDLER_PCB::createCommit ( )
overrideprotectedvirtual

Override this to create an appropriate COMMIT subclass for the frame in question.

Returns
a new COMMIT, bound to the editor frame

Implements API_HANDLER_EDITOR.

Definition at line 151 of file api_handler_pcb.cpp.

References frame().

◆ createItemForType()

HANDLER_RESULT< std::unique_ptr< BOARD_ITEM > > API_HANDLER_PCB::createItemForType ( KICAD_T  aType,
BOARD_ITEM_CONTAINER aContainer 
)
staticprivate

◆ deleteItemsInternal()

void API_HANDLER_PCB::deleteItemsInternal ( std::map< KIID, ItemDeletionStatus > &  aItemsToDelete,
const std::string &  aClientName 
)
overrideprotectedvirtual

◆ frame()

◆ getCurrentCommit()

COMMIT * API_HANDLER_EDITOR::getCurrentCommit ( const std::string &  aClientName)
protectedinherited

◆ getItemById()

◆ getItemFromDocument()

std::optional< EDA_ITEM * > API_HANDLER_PCB::getItemFromDocument ( const DocumentSpecifier &  aDocument,
const KIID aId 
)
overrideprotectedvirtual

Implements API_HANDLER_EDITOR.

Definition at line 544 of file api_handler_pcb.cpp.

References getItemById(), and API_HANDLER_EDITOR::validateDocument().

◆ Handle()

API_RESULT API_HANDLER::Handle ( ApiRequest &  aMsg)
inherited

Attempt to handle the given API request, if a handler exists in this class for the message.

Parameters
aMsgis a request to attempt to handle
Returns
a response to send to the client, or an appropriate error

Definition at line 30 of file api_handler.cpp.

References API_HANDLER::m_handlers.

◆ handleBeginCommit()

HANDLER_RESULT< BeginCommitResponse > API_HANDLER_EDITOR::handleBeginCommit ( const HANDLER_CONTEXT< commands::BeginCommit > &  aCtx)
protectedinherited

◆ handleCreateItems()

HANDLER_RESULT< CreateItemsResponse > API_HANDLER_EDITOR::handleCreateItems ( const HANDLER_CONTEXT< commands::CreateItems > &  aCtx)
protectedinherited

◆ handleCreateUpdateItemsInternal()

HANDLER_RESULT< ItemRequestStatus > API_HANDLER_PCB::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 
)
overrideprivatevirtual

◆ handleDeleteItems()

◆ handleEndCommit()

◆ handleExpandTextVariables()

HANDLER_RESULT< ExpandTextVariablesResponse > API_HANDLER_PCB::handleExpandTextVariables ( const HANDLER_CONTEXT< commands::ExpandTextVariables > &  aCtx)
private

◆ handleGetActiveLayer()

HANDLER_RESULT< BoardLayerResponse > API_HANDLER_PCB::handleGetActiveLayer ( const HANDLER_CONTEXT< GetActiveLayer > &  aCtx)
private

◆ handleGetBoundingBox()

HANDLER_RESULT< GetBoundingBoxResponse > API_HANDLER_PCB::handleGetBoundingBox ( const HANDLER_CONTEXT< commands::GetBoundingBox > &  aCtx)
private

◆ handleGetGraphicsDefaults()

◆ handleGetItems()

◆ handleGetNets()

◆ handleGetOpenDocuments()

HANDLER_RESULT< GetOpenDocumentsResponse > API_HANDLER_PCB::handleGetOpenDocuments ( const HANDLER_CONTEXT< commands::GetOpenDocuments > &  aCtx)
private

Definition at line 117 of file api_handler_pcb.cpp.

References frame(), Prj(), and HANDLER_CONTEXT< RequestMessageType >::Request.

Referenced by API_HANDLER_PCB().

◆ handleGetPadShapeAsPolygon()

HANDLER_RESULT< PadShapeAsPolygonResponse > API_HANDLER_PCB::handleGetPadShapeAsPolygon ( const HANDLER_CONTEXT< GetPadShapeAsPolygon > &  aCtx)
private

◆ handleGetStackup()

◆ handleGetTitleBlockInfo()

◆ handleGetVisibleLayers()

HANDLER_RESULT< BoardLayers > API_HANDLER_PCB::handleGetVisibleLayers ( const HANDLER_CONTEXT< GetVisibleLayers > &  aCtx)
private

◆ handleHitTest()

◆ handleInteractiveMoveItems()

◆ handleParseAndCreateItemsFromString()

HANDLER_RESULT< CreateItemsResponse > API_HANDLER_PCB::handleParseAndCreateItemsFromString ( const HANDLER_CONTEXT< commands::ParseAndCreateItemsFromString > &  aCtx)
private

◆ handleRefillZones()

◆ handleRunAction()

HANDLER_RESULT< RunActionResponse > API_HANDLER_PCB::handleRunAction ( const HANDLER_CONTEXT< commands::RunAction > &  aCtx)
private

◆ handleSaveDocumentToString()

HANDLER_RESULT< SavedDocumentResponse > API_HANDLER_PCB::handleSaveDocumentToString ( const HANDLER_CONTEXT< commands::SaveDocumentToString > &  aCtx)
private

◆ handleSaveSelectionToString()

HANDLER_RESULT< SavedSelectionResponse > API_HANDLER_PCB::handleSaveSelectionToString ( const HANDLER_CONTEXT< commands::SaveSelectionToString > &  aCtx)
private

◆ handleSetActiveLayer()

HANDLER_RESULT< Empty > API_HANDLER_PCB::handleSetActiveLayer ( const HANDLER_CONTEXT< SetActiveLayer > &  aCtx)
private

◆ handleSetVisibleLayers()

◆ handleUpdateItems()

HANDLER_RESULT< UpdateItemsResponse > API_HANDLER_EDITOR::handleUpdateItems ( const HANDLER_CONTEXT< commands::UpdateItems > &  aCtx)
protectedinherited

◆ pushCurrentCommit()

void API_HANDLER_PCB::pushCurrentCommit ( const std::string &  aClientName,
const wxString &  aMessage 
)
overrideprivatevirtual

◆ registerHandler()

template<class RequestType , class ResponseType , class HandlerType >
void API_HANDLER::registerHandler ( HANDLER_RESULT< ResponseType >(HandlerType::*)(const HANDLER_CONTEXT< RequestType > &)  aHandler)
inlineprotectedinherited

Registers an API command handler for the given message types.

When an API request matching the given type comes in, the handler will be called and its response will be packed into an envelope for sending back to the API client.

If the given message does not unpack into the request type, an envelope is returned with status AS_BAD_REQUEST, which probably indicates corruption in the message.

Template Parameters
RequestTypeis a protobuf message type containing a command
ResponseTypeis a protobuf message type containing a command response
HandlerTypeis the implied type of the API_HANDLER subclass
Parameters
aHandleris the handler function for the given request and response types

Definition at line 93 of file api_handler.h.

References HANDLER_CONTEXT< RequestMessageType >::ClientName, and HANDLER_CONTEXT< RequestMessageType >::Request.

◆ thisDocumentType()

kiapi::common::types::DocumentType API_HANDLER_PCB::thisDocumentType ( ) const
inlineoverrideprotectedvirtual

Override this to specify which document type this editor handles.

Implements API_HANDLER_EDITOR.

Definition at line 110 of file api_handler_pcb.h.

◆ tryUnpack()

template<typename MessageType >
bool API_HANDLER::tryUnpack ( ApiRequest &  aRequest,
ApiResponse &  aReply,
MessageType &  aDest 
)
inlineprivateinherited

Definition at line 136 of file api_handler.h.

◆ validateDocument()

◆ validateDocumentInternal()

bool API_HANDLER_PCB::validateDocumentInternal ( const DocumentSpecifier &  aDocument) const
overrideprotectedvirtual
Returns
true if the given document is valid for this editor and is currently open

Implements API_HANDLER_EDITOR.

Definition at line 168 of file api_handler_pcb.cpp.

References frame().

◆ validateItemHeaderDocument()

HANDLER_RESULT< std::optional< KIID > > API_HANDLER_EDITOR::validateItemHeaderDocument ( const kiapi::common::types::ItemHeader &  aHeader)
protectedinherited

Member Data Documentation

◆ m_activeClients

◆ m_commits

std::map<std::string, std::pair<KIID, std::unique_ptr<COMMIT> > > API_HANDLER_EDITOR::m_commits
protectedinherited

◆ m_defaultCommitMessage

const wxString API_HANDLER::m_defaultCommitMessage = _( "Modification from API" )
staticprotectedinherited

Definition at line 131 of file api_handler.h.

Referenced by API_HANDLER_EDITOR::pushCurrentCommit().

◆ m_frame

EDA_BASE_FRAME* API_HANDLER_EDITOR::m_frame
protectedinherited

Definition at line 112 of file api_handler_editor.h.

Referenced by API_HANDLER_EDITOR::checkForBusy(), and frame().

◆ m_handlers

std::map<std::string, REQUEST_HANDLER> API_HANDLER::m_handlers
protectedinherited

Maps type name (without the URL prefix) to a handler method.

Definition at line 129 of file api_handler.h.

Referenced by API_HANDLER::Handle().


The documentation for this class was generated from the following files: