7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-20 00:11:41 +00:00

API: refactor handlers to be slightly less verbose

This commit is contained in:
Jon Evans 2024-12-08 20:13:18 -05:00
parent df872a8af6
commit 96536f380d
9 changed files with 198 additions and 210 deletions

View File

@ -52,8 +52,8 @@ API_HANDLER_COMMON::API_HANDLER_COMMON() :
}
HANDLER_RESULT<GetVersionResponse> API_HANDLER_COMMON::handleGetVersion( commands::GetVersion&,
const HANDLER_CONTEXT& )
HANDLER_RESULT<GetVersionResponse> API_HANDLER_COMMON::handleGetVersion(
const HANDLER_CONTEXT<GetVersion>& )
{
GetVersionResponse reply;
@ -68,8 +68,8 @@ HANDLER_RESULT<GetVersionResponse> API_HANDLER_COMMON::handleGetVersion( command
}
HANDLER_RESULT<NetClassesResponse> API_HANDLER_COMMON::handleGetNetClasses( GetNetClasses& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<NetClassesResponse> API_HANDLER_COMMON::handleGetNetClasses(
const HANDLER_CONTEXT<GetNetClasses>& aCtx )
{
NetClassesResponse reply;
@ -85,18 +85,18 @@ HANDLER_RESULT<NetClassesResponse> API_HANDLER_COMMON::handleGetNetClasses( GetN
}
HANDLER_RESULT<Empty> API_HANDLER_COMMON::handlePing( Ping& aMsg, const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<Empty> API_HANDLER_COMMON::handlePing( const HANDLER_CONTEXT<Ping>& aCtx )
{
return Empty();
}
HANDLER_RESULT<types::Box2> API_HANDLER_COMMON::handleGetTextExtents( GetTextExtents& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<types::Box2> API_HANDLER_COMMON::handleGetTextExtents(
const HANDLER_CONTEXT<GetTextExtents>& aCtx )
{
EDA_TEXT text( pcbIUScale );
google::protobuf::Any any;
any.PackFrom( aMsg.text() );
any.PackFrom( aCtx.Request.text() );
if( !text.Deserialize( any ) )
{
@ -124,11 +124,11 @@ HANDLER_RESULT<types::Box2> API_HANDLER_COMMON::handleGetTextExtents( GetTextExt
HANDLER_RESULT<GetTextAsShapesResponse> API_HANDLER_COMMON::handleGetTextAsShapes(
GetTextAsShapes& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<GetTextAsShapes>& aCtx )
{
GetTextAsShapesResponse reply;
for( const TextOrTextBox& textMsg : aMsg.text() )
for( const TextOrTextBox& textMsg : aCtx.Request.text() )
{
Text dummyText;
const Text* textPtr = &textMsg.text();
@ -202,9 +202,9 @@ HANDLER_RESULT<GetTextAsShapesResponse> API_HANDLER_COMMON::handleGetTextAsShape
HANDLER_RESULT<ExpandTextVariablesResponse> API_HANDLER_COMMON::handleExpandTextVariables(
ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<ExpandTextVariables>& aCtx )
{
if( !aMsg.has_document() || aMsg.document().type() != DocumentType::DOCTYPE_PROJECT )
if( !aCtx.Request.has_document() || aCtx.Request.document().type() != DOCTYPE_PROJECT )
{
ApiResponseStatus e;
e.set_status( ApiStatusCode::AS_UNHANDLED );
@ -215,7 +215,7 @@ HANDLER_RESULT<ExpandTextVariablesResponse> API_HANDLER_COMMON::handleExpandText
ExpandTextVariablesResponse reply;
PROJECT& project = Pgm().GetSettingsManager().Prj();
for( const std::string& textMsg : aMsg.text() )
for( const std::string& textMsg : aCtx.Request.text() )
{
wxString result = ExpandTextVars( wxString::FromUTF8( textMsg ), &project );
reply.add_text( result.ToUTF8() );

View File

@ -40,8 +40,8 @@ API_HANDLER_EDITOR::API_HANDLER_EDITOR( EDA_BASE_FRAME* aFrame ) :
}
HANDLER_RESULT<BeginCommitResponse> API_HANDLER_EDITOR::handleBeginCommit( BeginCommit& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<BeginCommitResponse> API_HANDLER_EDITOR::handleBeginCommit(
const HANDLER_CONTEXT<BeginCommit>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
@ -69,8 +69,8 @@ HANDLER_RESULT<BeginCommitResponse> API_HANDLER_EDITOR::handleBeginCommit( Begin
}
HANDLER_RESULT<EndCommitResponse> API_HANDLER_EDITOR::handleEndCommit( EndCommit& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<EndCommitResponse> API_HANDLER_EDITOR::handleEndCommit(
const HANDLER_CONTEXT<EndCommit>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
@ -93,7 +93,7 @@ HANDLER_RESULT<EndCommitResponse> API_HANDLER_EDITOR::handleEndCommit( EndCommit
EndCommitResponse response;
// Do not check IDs with drop; it is a safety net in case the id was lost on the client side
switch( aMsg.action() )
switch( aCtx.Request.action() )
{
case kiapi::common::commands::CMA_DROP:
{
@ -105,16 +105,16 @@ HANDLER_RESULT<EndCommitResponse> API_HANDLER_EDITOR::handleEndCommit( EndCommit
case kiapi::common::commands::CMA_COMMIT:
{
if( aMsg.id().value().compare( id.AsStdString() ) != 0 )
if( aCtx.Request.id().value().compare( id.AsStdString() ) != 0 )
{
ApiResponseStatus e;
e.set_status( ApiStatusCode::AS_BAD_REQUEST );
e.set_error_message( fmt::format( "the id {} does not match the commit in progress",
aMsg.id().value() ) );
aCtx.Request.id().value() ) );
return tl::unexpected( e );
}
pushCurrentCommit( aCtx, wxString( aMsg.message().c_str(), wxConvUTF8 ) );
pushCurrentCommit( aCtx.ClientName, wxString( aCtx.Request.message().c_str(), wxConvUTF8 ) );
break;
}
@ -126,33 +126,33 @@ HANDLER_RESULT<EndCommitResponse> API_HANDLER_EDITOR::handleEndCommit( EndCommit
}
COMMIT* API_HANDLER_EDITOR::getCurrentCommit( const HANDLER_CONTEXT& aCtx )
COMMIT* API_HANDLER_EDITOR::getCurrentCommit( const std::string& aClientName )
{
if( !m_commits.count( aCtx.ClientName ) )
if( !m_commits.count( aClientName ) )
{
KIID id;
m_commits[aCtx.ClientName] = std::make_pair( id, createCommit() );
m_commits[aClientName] = std::make_pair( id, createCommit() );
}
return m_commits.at( aCtx.ClientName ).second.get();
return m_commits.at( aClientName ).second.get();
}
void API_HANDLER_EDITOR::pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage )
void API_HANDLER_EDITOR::pushCurrentCommit( const std::string& aClientName,
const wxString& aMessage )
{
auto it = m_commits.find( aCtx.ClientName );
auto it = m_commits.find( aClientName );
if( it == m_commits.end() )
return;
it->second.second->Push( aMessage.IsEmpty() ? m_defaultCommitMessage : aMessage );
m_commits.erase( it );
m_activeClients.erase( aCtx.ClientName );
m_activeClients.erase( aClientName );
}
HANDLER_RESULT<bool> API_HANDLER_EDITOR::validateDocument(
const kiapi::common::types::DocumentSpecifier& aDocument )
HANDLER_RESULT<bool> API_HANDLER_EDITOR::validateDocument( const DocumentSpecifier& aDocument )
{
if( !validateDocumentInternal( aDocument ) )
{
@ -168,7 +168,7 @@ HANDLER_RESULT<bool> API_HANDLER_EDITOR::validateDocument(
HANDLER_RESULT<std::optional<KIID>> API_HANDLER_EDITOR::validateItemHeaderDocument(
const kiapi::common::types::ItemHeader& aHeader )
const types::ItemHeader& aHeader )
{
if( !aHeader.has_document() || aHeader.document().type() != thisDocumentType() )
{
@ -216,16 +216,17 @@ std::optional<ApiResponseStatus> API_HANDLER_EDITOR::checkForBusy()
}
HANDLER_RESULT<CreateItemsResponse> API_HANDLER_EDITOR::handleCreateItems( CreateItems& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<CreateItemsResponse> API_HANDLER_EDITOR::handleCreateItems(
const HANDLER_CONTEXT<CreateItems>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
CreateItemsResponse response;
HANDLER_RESULT<ItemRequestStatus> result = handleCreateUpdateItemsInternal( true, aCtx,
aMsg.header(), aMsg.items(),
HANDLER_RESULT<ItemRequestStatus> result = handleCreateUpdateItemsInternal( true,
aCtx.ClientName,
aCtx.Request.header(), aCtx.Request.items(),
[&]( const ItemStatus& aStatus, const google::protobuf::Any& aItem )
{
ItemCreationResult itemResult;
@ -242,16 +243,17 @@ HANDLER_RESULT<CreateItemsResponse> API_HANDLER_EDITOR::handleCreateItems( Creat
}
HANDLER_RESULT<UpdateItemsResponse> API_HANDLER_EDITOR::handleUpdateItems( UpdateItems& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<UpdateItemsResponse> API_HANDLER_EDITOR::handleUpdateItems(
const HANDLER_CONTEXT<UpdateItems>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
UpdateItemsResponse response;
HANDLER_RESULT<ItemRequestStatus> result = handleCreateUpdateItemsInternal( false, aCtx,
aMsg.header(), aMsg.items(),
HANDLER_RESULT<ItemRequestStatus> result = handleCreateUpdateItemsInternal( false,
aCtx.ClientName,
aCtx.Request.header(), aCtx.Request.items(),
[&]( const ItemStatus& aStatus, const google::protobuf::Any& aItem )
{
ItemUpdateResult itemResult;
@ -268,13 +270,13 @@ HANDLER_RESULT<UpdateItemsResponse> API_HANDLER_EDITOR::handleUpdateItems( Updat
}
HANDLER_RESULT<DeleteItemsResponse> API_HANDLER_EDITOR::handleDeleteItems( DeleteItems& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<DeleteItemsResponse> API_HANDLER_EDITOR::handleDeleteItems(
const HANDLER_CONTEXT<DeleteItems>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
if( !validateItemHeaderDocument( aMsg.header() ) )
if( !validateItemHeaderDocument( aCtx.Request.header() ) )
{
ApiResponseStatus e;
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
@ -284,7 +286,7 @@ HANDLER_RESULT<DeleteItemsResponse> API_HANDLER_EDITOR::handleDeleteItems( Delet
std::map<KIID, ItemDeletionStatus> itemsToDelete;
for( const kiapi::common::types::KIID& kiidBuf : aMsg.item_ids() )
for( const kiapi::common::types::KIID& kiidBuf : aCtx.Request.item_ids() )
{
if( !kiidBuf.value().empty() )
{
@ -301,7 +303,7 @@ HANDLER_RESULT<DeleteItemsResponse> API_HANDLER_EDITOR::handleDeleteItems( Delet
return tl::unexpected( e );
}
deleteItemsInternal( itemsToDelete, aCtx );
deleteItemsInternal( itemsToDelete, aCtx.ClientName );
DeleteItemsResponse response;
@ -317,13 +319,13 @@ HANDLER_RESULT<DeleteItemsResponse> API_HANDLER_EDITOR::handleDeleteItems( Delet
}
HANDLER_RESULT<HitTestResponse> API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<HitTestResponse> API_HANDLER_EDITOR::handleHitTest(
const HANDLER_CONTEXT<HitTest>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
if( !validateItemHeaderDocument( aMsg.header() ) )
if( !validateItemHeaderDocument( aCtx.Request.header() ) )
{
ApiResponseStatus e;
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
@ -333,8 +335,8 @@ HANDLER_RESULT<HitTestResponse> API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg
HitTestResponse response;
std::optional<EDA_ITEM*> item = getItemFromDocument( aMsg.header().document(),
KIID( aMsg.id().value() ) );
std::optional<EDA_ITEM*> item = getItemFromDocument( aCtx.Request.header().document(),
KIID( aCtx.Request.id().value() ) );
if( !item )
{
@ -344,7 +346,7 @@ HANDLER_RESULT<HitTestResponse> API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg
return tl::unexpected( e );
}
if( ( *item )->HitTest( kiapi::common::UnpackVector2( aMsg.position() ), aMsg.tolerance() ) )
if( ( *item )->HitTest( UnpackVector2( aCtx.Request.position() ), aCtx.Request.tolerance() ) )
response.set_result( HitTestResult::HTR_HIT );
else
response.set_result( HitTestResult::HTR_NO_HIT );

View File

@ -62,9 +62,9 @@ bool API_HANDLER_SCH::validateDocumentInternal( const DocumentSpecifier& aDocume
HANDLER_RESULT<GetOpenDocumentsResponse> API_HANDLER_SCH::handleGetOpenDocuments(
GetOpenDocuments& aMsg, const HANDLER_CONTEXT& )
const HANDLER_CONTEXT<GetOpenDocuments>& aCtx )
{
if( aMsg.type() != DocumentType::DOCTYPE_SCHEMATIC )
if( aCtx.Request.type() != DocumentType::DOCTYPE_SCHEMATIC )
{
ApiResponseStatus e;
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
@ -129,7 +129,7 @@ HANDLER_RESULT<std::unique_ptr<EDA_ITEM>> API_HANDLER_SCH::createItemForType( KI
HANDLER_RESULT<ItemRequestStatus> API_HANDLER_SCH::handleCreateUpdateItemsInternal( bool aCreate,
const HANDLER_CONTEXT& aCtx,
const std::string& aClientName,
const types::ItemHeader &aHeader,
const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
std::function<void( ItemStatus, google::protobuf::Any )> aItemHandler )
@ -190,7 +190,7 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_SCH::handleCreateUpdateItemsIntern
}
}
COMMIT* commit = getCurrentCommit( aCtx );
COMMIT* commit = getCurrentCommit( aClientName );
for( const google::protobuf::Any& anyItem : aItems )
{
@ -252,8 +252,8 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_SCH::handleCreateUpdateItemsIntern
item->Serialize( newItem );
commit->Add( item.release() );
if( !m_activeClients.count( aCtx.ClientName ) )
pushCurrentCommit( aCtx, _( "Added items via API" ) );
if( !m_activeClients.count( aClientName ) )
pushCurrentCommit( aClientName, _( "Added items via API" ) );
}
else
{
@ -270,8 +270,8 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_SCH::handleCreateUpdateItemsIntern
wxASSERT( false );
}
if( !m_activeClients.count( aCtx.ClientName ) )
pushCurrentCommit( aCtx, _( "Created items via API" ) );
if( !m_activeClients.count( aClientName ) )
pushCurrentCommit( aClientName, _( "Created items via API" ) );
}
aItemHandler( status, newItem );
@ -283,7 +283,7 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_SCH::handleCreateUpdateItemsIntern
void API_HANDLER_SCH::deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
const HANDLER_CONTEXT& aCtx )
const std::string& aClientName )
{
// TODO
}

View File

@ -51,21 +51,21 @@ protected:
EDA_ITEM* aContainer );
HANDLER_RESULT<types::ItemRequestStatus> handleCreateUpdateItemsInternal( bool aCreate,
const HANDLER_CONTEXT& aCtx,
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;
void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
const HANDLER_CONTEXT& aCtx ) override;
const std::string& aClientName ) override;
std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument,
const KIID& aId ) override;
private:
HANDLER_RESULT<commands::GetOpenDocumentsResponse> handleGetOpenDocuments(
commands::GetOpenDocuments& aMsg, const HANDLER_CONTEXT& aCtx );
const HANDLER_CONTEXT<commands::GetOpenDocuments>& aCtx );
SCH_EDIT_FRAME* m_frame;
};

View File

@ -45,9 +45,11 @@ template <typename T>
using HANDLER_RESULT = tl::expected<T, ApiResponseStatus>;
template <typename RequestMessageType>
struct HANDLER_CONTEXT
{
std::string ClientName;
RequestMessageType Request;
};
@ -88,9 +90,8 @@ protected:
* @param aHandler is the handler function for the given request and response types
*/
template <class RequestType, class ResponseType, class HandlerType>
void registerHandler(
HANDLER_RESULT<ResponseType>( HandlerType::* aHandler )( RequestType&,
const HANDLER_CONTEXT& ) )
void registerHandler( HANDLER_RESULT<ResponseType> ( HandlerType::*aHandler )(
const HANDLER_CONTEXT<RequestType>& ) )
{
std::string typeName = RequestType().GetTypeName();
@ -100,17 +101,16 @@ protected:
m_handlers[typeName] =
[this, aHandler]( ApiRequest& aRequest ) -> API_RESULT
{
RequestType cmd;
HANDLER_CONTEXT<RequestType> ctx;
ApiResponse envelope;
if( !tryUnpack( aRequest, envelope, cmd ) )
if( !tryUnpack( aRequest, envelope, ctx.Request ) )
return envelope;
HANDLER_CONTEXT ctx;
ctx.ClientName = aRequest.header().client_name();
HANDLER_RESULT<ResponseType> response =
std::invoke( aHandler, static_cast<HandlerType*>( this ), cmd, ctx );
std::invoke( aHandler, static_cast<HandlerType*>( this ), ctx );
if( response.has_value() )
{

View File

@ -38,22 +38,22 @@ public:
~API_HANDLER_COMMON() override {}
private:
HANDLER_RESULT<commands::GetVersionResponse> handleGetVersion( commands::GetVersion& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::GetVersionResponse> handleGetVersion(
const HANDLER_CONTEXT<commands::GetVersion>& aCtx );
HANDLER_RESULT<commands::NetClassesResponse> handleGetNetClasses( commands::GetNetClasses& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::NetClassesResponse> handleGetNetClasses(
const HANDLER_CONTEXT<commands::GetNetClasses>& aCtx );
HANDLER_RESULT<Empty> handlePing( commands::Ping& aMsg, const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<Empty> handlePing( const HANDLER_CONTEXT<commands::Ping>& aCtx );
HANDLER_RESULT<types::Box2> handleGetTextExtents( commands::GetTextExtents& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<types::Box2> handleGetTextExtents(
const HANDLER_CONTEXT<commands::GetTextExtents>& aCtx );
HANDLER_RESULT<commands::GetTextAsShapesResponse>
handleGetTextAsShapes( commands::GetTextAsShapes& aMsg, const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::GetTextAsShapesResponse> handleGetTextAsShapes(
const HANDLER_CONTEXT<commands::GetTextAsShapes>& aCtx );
HANDLER_RESULT<commands::ExpandTextVariablesResponse>
handleExpandTextVariables( commands::ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::ExpandTextVariablesResponse> handleExpandTextVariables(
const HANDLER_CONTEXT<commands::ExpandTextVariables>& aCtx );
};
#endif //KICAD_API_HANDLER_COMMON_H

View File

@ -54,27 +54,27 @@ protected:
*/
virtual std::optional<ApiResponseStatus> checkForBusy();
HANDLER_RESULT<commands::BeginCommitResponse> handleBeginCommit( commands::BeginCommit& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::BeginCommitResponse> handleBeginCommit(
const HANDLER_CONTEXT<commands::BeginCommit>& aCtx );
HANDLER_RESULT<commands::EndCommitResponse> handleEndCommit( commands::EndCommit& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::EndCommitResponse> handleEndCommit(
const HANDLER_CONTEXT<commands::EndCommit>& aCtx );
COMMIT* getCurrentCommit( const HANDLER_CONTEXT& aCtx );
COMMIT* getCurrentCommit( const std::string& aClientName );
virtual void pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage );
virtual void pushCurrentCommit( const std::string& aClientName, const wxString& aMessage );
HANDLER_RESULT<commands::CreateItemsResponse> handleCreateItems( commands::CreateItems& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::CreateItemsResponse> handleCreateItems(
const HANDLER_CONTEXT<commands::CreateItems>& aCtx );
HANDLER_RESULT<commands::UpdateItemsResponse> handleUpdateItems( commands::UpdateItems& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::UpdateItemsResponse> handleUpdateItems(
const HANDLER_CONTEXT<commands::UpdateItems>& aCtx );
HANDLER_RESULT<commands::DeleteItemsResponse> handleDeleteItems( commands::DeleteItems& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::DeleteItemsResponse> handleDeleteItems(
const HANDLER_CONTEXT<commands::DeleteItems>& aCtx );
HANDLER_RESULT<commands::HitTestResponse> handleHitTest( commands::HitTest& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::HitTestResponse> handleHitTest(
const HANDLER_CONTEXT<commands::HitTest>& aCtx );
/**
* Override this to create an appropriate COMMIT subclass for the frame in question
@ -85,7 +85,7 @@ protected:
/**
* Override this to specify which document type this editor handles
*/
virtual kiapi::common::types::DocumentType thisDocumentType() const = 0;
virtual types::DocumentType thisDocumentType() const = 0;
/**
* @return true if the given document is valid for this editor and is currently open
@ -93,13 +93,13 @@ protected:
virtual bool validateDocumentInternal( const DocumentSpecifier& aDocument ) const = 0;
virtual HANDLER_RESULT<ItemRequestStatus> handleCreateUpdateItemsInternal( bool aCreate,
const HANDLER_CONTEXT& aCtx,
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;
virtual void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
const HANDLER_CONTEXT& aCtx ) = 0;
const std::string& aClientName ) = 0;
virtual std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument,
const KIID& aId ) = 0;

View File

@ -97,15 +97,15 @@ PCB_EDIT_FRAME* API_HANDLER_PCB::frame() const
}
HANDLER_RESULT<RunActionResponse> API_HANDLER_PCB::handleRunAction( RunAction& aRequest,
const HANDLER_CONTEXT& )
HANDLER_RESULT<RunActionResponse> API_HANDLER_PCB::handleRunAction(
const HANDLER_CONTEXT<RunAction>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
RunActionResponse response;
if( frame()->GetToolManager()->RunAction( aRequest.action(), true ) )
if( frame()->GetToolManager()->RunAction( aCtx.Request.action(), true ) )
response.set_status( RunActionStatus::RAS_OK );
else
response.set_status( RunActionStatus::RAS_INVALID );
@ -115,9 +115,9 @@ HANDLER_RESULT<RunActionResponse> API_HANDLER_PCB::handleRunAction( RunAction& a
HANDLER_RESULT<GetOpenDocumentsResponse> API_HANDLER_PCB::handleGetOpenDocuments(
GetOpenDocuments& aMsg, const HANDLER_CONTEXT& )
const HANDLER_CONTEXT<GetOpenDocuments>& aCtx )
{
if( aMsg.type() != DocumentType::DOCTYPE_PCB )
if( aCtx.Request.type() != DocumentType::DOCTYPE_PCB )
{
ApiResponseStatus e;
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
@ -141,9 +141,9 @@ HANDLER_RESULT<GetOpenDocumentsResponse> API_HANDLER_PCB::handleGetOpenDocuments
}
void API_HANDLER_PCB::pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage )
void API_HANDLER_PCB::pushCurrentCommit( const std::string& aClientName, const wxString& aMessage )
{
API_HANDLER_EDITOR::pushCurrentCommit( aCtx, aMessage );
API_HANDLER_EDITOR::pushCurrentCommit( aClientName, aMessage );
frame()->Refresh();
}
@ -219,7 +219,7 @@ HANDLER_RESULT<std::unique_ptr<BOARD_ITEM>> API_HANDLER_PCB::createItemForType(
HANDLER_RESULT<ItemRequestStatus> API_HANDLER_PCB::handleCreateUpdateItemsInternal( bool aCreate,
const HANDLER_CONTEXT& aCtx,
const std::string& aClientName,
const types::ItemHeader &aHeader,
const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems,
std::function<void( ItemStatus, google::protobuf::Any )> aItemHandler )
@ -271,7 +271,7 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_PCB::handleCreateUpdateItemsIntern
}
}
BOARD_COMMIT* commit = static_cast<BOARD_COMMIT*>( getCurrentCommit( aCtx ) );
BOARD_COMMIT* commit = static_cast<BOARD_COMMIT*>( getCurrentCommit( aClientName ) );
for( const google::protobuf::Any& anyItem : aItems )
{
@ -371,10 +371,10 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_PCB::handleCreateUpdateItemsIntern
aItemHandler( status, newItem );
}
if( !m_activeClients.count( aCtx.ClientName ) )
if( !m_activeClients.count( aClientName ) )
{
pushCurrentCommit( aCtx, aCreate ? _( "Created items via API" )
: _( "Added items via API" ) );
pushCurrentCommit( aClientName, aCreate ? _( "Created items via API" )
: _( "Added items via API" ) );
}
@ -382,13 +382,13 @@ HANDLER_RESULT<ItemRequestStatus> API_HANDLER_PCB::handleCreateUpdateItemsIntern
}
HANDLER_RESULT<GetItemsResponse> API_HANDLER_PCB::handleGetItems( GetItems& aMsg,
const HANDLER_CONTEXT& )
HANDLER_RESULT<GetItemsResponse> API_HANDLER_PCB::handleGetItems(
const HANDLER_CONTEXT<GetItems>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
if( !validateItemHeaderDocument( aMsg.header() ) )
if( !validateItemHeaderDocument( aCtx.Request.header() ) )
{
ApiResponseStatus e;
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
@ -403,7 +403,7 @@ HANDLER_RESULT<GetItemsResponse> API_HANDLER_PCB::handleGetItems( GetItems& aMsg
std::set<KICAD_T> typesRequested, typesInserted;
bool handledAnything = false;
for( int typeRaw : aMsg.types() )
for( int typeRaw : aCtx.Request.types() )
{
auto typeMessage = static_cast<common::types::KiCadObjectType>( typeRaw );
KICAD_T type = FromProtoEnum<KICAD_T>( typeMessage );
@ -514,7 +514,7 @@ HANDLER_RESULT<GetItemsResponse> API_HANDLER_PCB::handleGetItems( GetItems& aMsg
void API_HANDLER_PCB::deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
const HANDLER_CONTEXT& aCtx )
const std::string& aClientName )
{
BOARD* board = frame()->GetBoard();
std::vector<BOARD_ITEM*> validatedItems;
@ -531,13 +531,13 @@ void API_HANDLER_PCB::deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& a
// to add it in the future (and return IDS_IMMUTABLE)
}
COMMIT* commit = getCurrentCommit( aCtx );
COMMIT* commit = getCurrentCommit( aClientName );
for( BOARD_ITEM* item : validatedItems )
commit->Remove( item );
if( !m_activeClients.count( aCtx.ClientName ) )
pushCurrentCommit( aCtx, _( "Deleted items via API" ) );
if( !m_activeClients.count( aClientName ) )
pushCurrentCommit( aClientName, _( "Deleted items via API" ) );
}
@ -551,13 +551,13 @@ std::optional<EDA_ITEM*> API_HANDLER_PCB::getItemFromDocument( const DocumentSpe
}
HANDLER_RESULT<BoardStackupResponse> API_HANDLER_PCB::handleGetStackup( GetBoardStackup& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<BoardStackupResponse> API_HANDLER_PCB::handleGetStackup(
const HANDLER_CONTEXT<GetBoardStackup>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -574,13 +574,12 @@ HANDLER_RESULT<BoardStackupResponse> API_HANDLER_PCB::handleGetStackup( GetBoard
HANDLER_RESULT<GraphicsDefaultsResponse> API_HANDLER_PCB::handleGetGraphicsDefaults(
GetGraphicsDefaults& aMsg,
const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<GetGraphicsDefaults>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -617,13 +616,13 @@ HANDLER_RESULT<GraphicsDefaultsResponse> API_HANDLER_PCB::handleGetGraphicsDefau
}
HANDLER_RESULT<GetBoundingBoxResponse> API_HANDLER_PCB::handleGetBoundingBox( GetBoundingBox& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<GetBoundingBoxResponse> API_HANDLER_PCB::handleGetBoundingBox(
const HANDLER_CONTEXT<GetBoundingBox>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
if( !validateItemHeaderDocument( aMsg.header() ) )
if( !validateItemHeaderDocument( aCtx.Request.header() ) )
{
ApiResponseStatus e;
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
@ -632,9 +631,9 @@ HANDLER_RESULT<GetBoundingBoxResponse> API_HANDLER_PCB::handleGetBoundingBox( Ge
}
GetBoundingBoxResponse response;
bool includeText = aMsg.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT;
bool includeText = aCtx.Request.mode() == BoundingBoxMode::BBM_ITEM_AND_CHILD_TEXT;
for( const types::KIID& idMsg : aMsg.items() )
for( const types::KIID& idMsg : aCtx.Request.items() )
{
KIID id( idMsg.value() );
std::optional<BOARD_ITEM*> optItem = getItemById( id );
@ -659,19 +658,18 @@ HANDLER_RESULT<GetBoundingBoxResponse> API_HANDLER_PCB::handleGetBoundingBox( Ge
HANDLER_RESULT<PadShapeAsPolygonResponse> API_HANDLER_PCB::handleGetPadShapeAsPolygon(
GetPadShapeAsPolygon& aMsg,
const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<GetPadShapeAsPolygon>& aCtx )
{
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
SHAPE_POLY_SET poly;
PadShapeAsPolygonResponse response;
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( aMsg.layer() );
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID, board::types::BoardLayer>( aCtx.Request.layer() );
for( const types::KIID& padRequest : aMsg.pads() )
for( const types::KIID& padRequest : aCtx.Request.pads() )
{
KIID id( padRequest.value() );
std::optional<BOARD_ITEM*> optPad = getItemById( id );
@ -694,10 +692,9 @@ HANDLER_RESULT<PadShapeAsPolygonResponse> API_HANDLER_PCB::handleGetPadShapeAsPo
HANDLER_RESULT<types::TitleBlockInfo> API_HANDLER_PCB::handleGetTitleBlockInfo(
GetTitleBlockInfo& aMsg,
const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<GetTitleBlockInfo>& aCtx )
{
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.document() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -726,9 +723,9 @@ HANDLER_RESULT<types::TitleBlockInfo> API_HANDLER_PCB::handleGetTitleBlockInfo(
HANDLER_RESULT<ExpandTextVariablesResponse> API_HANDLER_PCB::handleExpandTextVariables(
ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<ExpandTextVariables>& aCtx )
{
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.document() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -743,7 +740,7 @@ HANDLER_RESULT<ExpandTextVariablesResponse> API_HANDLER_PCB::handleExpandTextVar
return board->ResolveTextVar( token, 0 );
};
for( const std::string& textMsg : aMsg.text() )
for( const std::string& textMsg : aCtx.Request.text() )
{
wxString text = ExpandTextVars( wxString::FromUTF8( textMsg ), &textResolver );
reply.add_text( text.ToUTF8() );
@ -753,13 +750,13 @@ HANDLER_RESULT<ExpandTextVariablesResponse> API_HANDLER_PCB::handleExpandTextVar
}
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMoveItems& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleInteractiveMoveItems(
const HANDLER_CONTEXT<InteractiveMoveItems>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -767,7 +764,7 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMo
TOOL_MANAGER* mgr = frame()->GetToolManager();
std::vector<EDA_ITEM*> toSelect;
for( const kiapi::common::types::KIID& id : aMsg.items() )
for( const kiapi::common::types::KIID& id : aCtx.Request.items() )
{
if( std::optional<BOARD_ITEM*> item = getItemById( KIID( id.value() ) ) )
toSelect.emplace_back( static_cast<EDA_ITEM*>( *item ) );
@ -778,7 +775,7 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMo
ApiResponseStatus e;
e.set_status( ApiStatusCode::AS_BAD_REQUEST );
e.set_error_message( fmt::format( "None of the given items exist on the board",
aMsg.board().board_filename() ) );
aCtx.Request.board().board_filename() ) );
return tl::unexpected( e );
}
@ -788,20 +785,19 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMo
mgr->RunAction( PCB_ACTIONS::selectionClear );
mgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &toSelect );
COMMIT* commit = getCurrentCommit( aCtx );
COMMIT* commit = getCurrentCommit( aCtx.ClientName );
mgr->PostAction( PCB_ACTIONS::move, commit );
return Empty();
}
HANDLER_RESULT<NetsResponse> API_HANDLER_PCB::handleGetNets( GetNets& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<NetsResponse> API_HANDLER_PCB::handleGetNets( const HANDLER_CONTEXT<GetNets>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -811,7 +807,7 @@ HANDLER_RESULT<NetsResponse> API_HANDLER_PCB::handleGetNets( GetNets& aMsg,
std::set<wxString> netclassFilter;
for( const std::string& nc : aMsg.netclass_filter() )
for( const std::string& nc : aCtx.Request.netclass_filter() )
netclassFilter.insert( wxString( nc.c_str(), wxConvUTF8 ) );
for( NETINFO_ITEM* net : board->GetNetInfo() )
@ -830,18 +826,17 @@ HANDLER_RESULT<NetsResponse> API_HANDLER_PCB::handleGetNets( GetNets& aMsg,
}
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleRefillZones( RefillZones& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleRefillZones( const HANDLER_CONTEXT<RefillZones>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
if( aMsg.zones().empty() )
if( aCtx.Request.zones().empty() )
{
TOOL_MANAGER* mgr = frame()->GetToolManager();
frame()->CallAfter( [mgr]()
@ -862,15 +857,15 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleRefillZones( RefillZones& aMsg,
HANDLER_RESULT<SavedDocumentResponse> API_HANDLER_PCB::handleSaveDocumentToString(
SaveDocumentToString& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<SaveDocumentToString>& aCtx )
{
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.document() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
SavedDocumentResponse response;
response.mutable_document()->CopyFrom( aMsg.document() );
response.mutable_document()->CopyFrom( aCtx.Request.document() );
CLIPBOARD_IO io;
io.SetWriter(
@ -886,7 +881,7 @@ HANDLER_RESULT<SavedDocumentResponse> API_HANDLER_PCB::handleSaveDocumentToStrin
HANDLER_RESULT<SavedSelectionResponse> API_HANDLER_PCB::handleSaveSelectionToString(
SaveSelectionToString& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<SaveSelectionToString>& aCtx )
{
SavedSelectionResponse response;
@ -909,12 +904,12 @@ HANDLER_RESULT<SavedSelectionResponse> API_HANDLER_PCB::handleSaveSelectionToStr
HANDLER_RESULT<CreateItemsResponse> API_HANDLER_PCB::handleParseAndCreateItemsFromString(
ParseAndCreateItemsFromString& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<ParseAndCreateItemsFromString>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.document() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.document() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -924,10 +919,10 @@ HANDLER_RESULT<CreateItemsResponse> API_HANDLER_PCB::handleParseAndCreateItemsFr
}
HANDLER_RESULT<BoardLayers> API_HANDLER_PCB::handleGetVisibleLayers( GetVisibleLayers& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<BoardLayers> API_HANDLER_PCB::handleGetVisibleLayers(
const HANDLER_CONTEXT<GetVisibleLayers>& aCtx )
{
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -941,13 +936,13 @@ HANDLER_RESULT<BoardLayers> API_HANDLER_PCB::handleGetVisibleLayers( GetVisibleL
}
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetVisibleLayers( SetVisibleLayers& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetVisibleLayers(
const HANDLER_CONTEXT<SetVisibleLayers>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -955,7 +950,7 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetVisibleLayers( SetVisibleLayers&
LSET visible;
LSET enabled = frame()->GetBoard()->GetEnabledLayers();
for( int layerIdx : aMsg.layers() )
for( int layerIdx : aCtx.Request.layers() )
{
PCB_LAYER_ID layer =
FromProtoEnum<PCB_LAYER_ID>( static_cast<board::types::BoardLayer>( layerIdx ) );
@ -973,9 +968,9 @@ HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetVisibleLayers( SetVisibleLayers&
HANDLER_RESULT<BoardLayerResponse> API_HANDLER_PCB::handleGetActiveLayer(
GetActiveLayer& aMsg, const HANDLER_CONTEXT& aCtx )
const HANDLER_CONTEXT<GetActiveLayer>& aCtx )
{
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
@ -988,18 +983,18 @@ HANDLER_RESULT<BoardLayerResponse> API_HANDLER_PCB::handleGetActiveLayer(
}
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetActiveLayer( SetActiveLayer& aMsg,
const HANDLER_CONTEXT& aCtx )
HANDLER_RESULT<Empty> API_HANDLER_PCB::handleSetActiveLayer(
const HANDLER_CONTEXT<SetActiveLayer>& aCtx )
{
if( std::optional<ApiResponseStatus> busy = checkForBusy() )
return tl::unexpected( *busy );
HANDLER_RESULT<bool> documentValidation = validateDocument( aMsg.board() );
HANDLER_RESULT<bool> documentValidation = validateDocument( aCtx.Request.board() );
if( !documentValidation )
return tl::unexpected( documentValidation.error() );
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( aMsg.layer() );
PCB_LAYER_ID layer = FromProtoEnum<PCB_LAYER_ID>( aCtx.Request.layer() );
if( !frame()->GetBoard()->GetEnabledLayers().Contains( layer ) )
{

View File

@ -58,59 +58,51 @@ private:
static HANDLER_RESULT<std::unique_ptr<BOARD_ITEM>> createItemForType( KICAD_T aType,
BOARD_ITEM_CONTAINER* aContainer );
HANDLER_RESULT<commands::RunActionResponse> handleRunAction( commands::RunAction& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::RunActionResponse> handleRunAction( const HANDLER_CONTEXT<commands::RunAction>& aCtx );
HANDLER_RESULT<commands::GetOpenDocumentsResponse> handleGetOpenDocuments(
commands::GetOpenDocuments& aMsg, const HANDLER_CONTEXT& aCtx );
const HANDLER_CONTEXT<commands::GetOpenDocuments>& aCtx );
HANDLER_RESULT<commands::GetItemsResponse> handleGetItems( commands::GetItems& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::GetItemsResponse> handleGetItems(
const HANDLER_CONTEXT<commands::GetItems>& aCtx );
HANDLER_RESULT<BoardStackupResponse> handleGetStackup( GetBoardStackup& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<BoardStackupResponse> handleGetStackup( const HANDLER_CONTEXT<GetBoardStackup>& aCtx );
HANDLER_RESULT<GraphicsDefaultsResponse> handleGetGraphicsDefaults( GetGraphicsDefaults& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<GraphicsDefaultsResponse> handleGetGraphicsDefaults(
const HANDLER_CONTEXT<GetGraphicsDefaults>& aCtx );
HANDLER_RESULT<commands::GetBoundingBoxResponse> handleGetBoundingBox( commands::GetBoundingBox& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::GetBoundingBoxResponse> handleGetBoundingBox(
const HANDLER_CONTEXT<commands::GetBoundingBox>& aCtx );
HANDLER_RESULT<PadShapeAsPolygonResponse> handleGetPadShapeAsPolygon( GetPadShapeAsPolygon& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<PadShapeAsPolygonResponse> handleGetPadShapeAsPolygon(
const HANDLER_CONTEXT<GetPadShapeAsPolygon>& aCtx );
HANDLER_RESULT<types::TitleBlockInfo> handleGetTitleBlockInfo( commands::GetTitleBlockInfo& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<types::TitleBlockInfo> handleGetTitleBlockInfo(
const HANDLER_CONTEXT<commands::GetTitleBlockInfo>& aCtx );
HANDLER_RESULT<commands::ExpandTextVariablesResponse>
handleExpandTextVariables( commands::ExpandTextVariables& aMsg, const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<commands::ExpandTextVariablesResponse> handleExpandTextVariables(
const HANDLER_CONTEXT<commands::ExpandTextVariables>& aCtx );
HANDLER_RESULT<Empty> handleInteractiveMoveItems( InteractiveMoveItems& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<Empty> handleInteractiveMoveItems( const HANDLER_CONTEXT<InteractiveMoveItems>& aCtx );
HANDLER_RESULT<NetsResponse> handleGetNets( GetNets& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<NetsResponse> handleGetNets( const HANDLER_CONTEXT<GetNets>& aCtx );
HANDLER_RESULT<Empty> handleRefillZones( RefillZones& aMsg, const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<Empty> handleRefillZones( const HANDLER_CONTEXT<RefillZones>& aCtx );
HANDLER_RESULT<commands::SavedDocumentResponse> handleSaveDocumentToString(
commands::SaveDocumentToString& aMsg, const HANDLER_CONTEXT& aCtx );
const HANDLER_CONTEXT<commands::SaveDocumentToString>& aCtx );
HANDLER_RESULT<commands::SavedSelectionResponse> handleSaveSelectionToString(
commands::SaveSelectionToString& aMsg, const HANDLER_CONTEXT& aCtx );
const HANDLER_CONTEXT<commands::SaveSelectionToString>& aCtx );
HANDLER_RESULT<commands::CreateItemsResponse> handleParseAndCreateItemsFromString(
commands::ParseAndCreateItemsFromString& aMsg, const HANDLER_CONTEXT& aCtx );
const HANDLER_CONTEXT<commands::ParseAndCreateItemsFromString>& aCtx );
HANDLER_RESULT<BoardLayers> handleGetVisibleLayers( GetVisibleLayers& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<BoardLayers> handleGetVisibleLayers( const HANDLER_CONTEXT<GetVisibleLayers>& aCtx );
HANDLER_RESULT<Empty> handleSetVisibleLayers( const HANDLER_CONTEXT<SetVisibleLayers>& aCtx );
HANDLER_RESULT<Empty> handleSetVisibleLayers( SetVisibleLayers& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<BoardLayerResponse> handleGetActiveLayer( GetActiveLayer& aMsg,
const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<Empty> handleSetActiveLayer( SetActiveLayer& aMsg, const HANDLER_CONTEXT& aCtx );
HANDLER_RESULT<BoardLayerResponse> handleGetActiveLayer( const HANDLER_CONTEXT<GetActiveLayer>& aCtx );
HANDLER_RESULT<Empty> handleSetActiveLayer( const HANDLER_CONTEXT<SetActiveLayer>& aCtx );
protected:
std::unique_ptr<COMMIT> createCommit() override;
@ -123,20 +115,19 @@ protected:
bool validateDocumentInternal( const DocumentSpecifier& aDocument ) const override;
void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete,
const HANDLER_CONTEXT& aCtx ) override;
const std::string& aClientName ) override;
std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument,
const KIID& aId ) override;
std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument, const KIID& aId ) override;
private:
PCB_EDIT_FRAME* frame() const;
void pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ) override;
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 HANDLER_CONTEXT& aCtx,
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 )