From f07f1083ac843904cdabc7514458e14b39d3d22d Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 1 Mar 2026 22:25:39 -0500 Subject: [PATCH] API: Add support for retrieving user names for all layers (cherry picked from commit 3514d130cb07d7c990906366cdc4e99d391060cf) Co-authored-by: Jon Evans --- api/proto/board/board_commands.proto | 14 ++++++++++++++ pcbnew/api/api_handler_pcb.cpp | 20 ++++++++++++++++++++ pcbnew/api/api_handler_pcb.h | 3 +++ 3 files changed, 37 insertions(+) diff --git a/api/proto/board/board_commands.proto b/api/proto/board/board_commands.proto index 1eae3aef6a..c46208d621 100644 --- a/api/proto/board/board_commands.proto +++ b/api/proto/board/board_commands.proto @@ -115,6 +115,20 @@ message SetBoardOrigin kiapi.common.types.Vector2 origin = 3; } +message GetBoardLayerName +{ + kiapi.common.types.DocumentSpecifier board = 1; + + kiapi.board.types.BoardLayer layer = 2; +} + +message BoardLayerNameResponse +{ + // The name of the layer shown in the KiCad GUI, which may be a default value like "F.Cu" or may + // have been customized by the user. + string name = 1; +} + /* * Net management */ diff --git a/pcbnew/api/api_handler_pcb.cpp b/pcbnew/api/api_handler_pcb.cpp index 71026b07c4..2b3060593f 100644 --- a/pcbnew/api/api_handler_pcb.cpp +++ b/pcbnew/api/api_handler_pcb.cpp @@ -97,6 +97,7 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) : &API_HANDLER_PCB::handleExpandTextVariables ); registerHandler( &API_HANDLER_PCB::handleGetBoardOrigin ); registerHandler( &API_HANDLER_PCB::handleSetBoardOrigin ); + registerHandler( &API_HANDLER_PCB::handleGetBoardLayerName ); registerHandler( &API_HANDLER_PCB::handleInteractiveMoveItems ); registerHandler( &API_HANDLER_PCB::handleGetNets ); @@ -1172,6 +1173,25 @@ HANDLER_RESULT API_HANDLER_PCB::handleSetBoardOrigin( } +HANDLER_RESULT API_HANDLER_PCB::handleGetBoardLayerName( + const HANDLER_CONTEXT& aCtx ) +{ + if( HANDLER_RESULT documentValidation = validateDocument( aCtx.Request.board() ); + !documentValidation ) + { + return tl::unexpected( documentValidation.error() ); + } + + BoardLayerNameResponse response; + + PCB_LAYER_ID id = FromProtoEnum( aCtx.Request.layer() ); + + response.set_name( frame()->GetBoard()->GetLayerName( id ) ); + + return response; +} + + HANDLER_RESULT API_HANDLER_PCB::handleGetBoundingBox( const HANDLER_CONTEXT& aCtx ) { diff --git a/pcbnew/api/api_handler_pcb.h b/pcbnew/api/api_handler_pcb.h index 7f568ca566..f57544bb1a 100644 --- a/pcbnew/api/api_handler_pcb.h +++ b/pcbnew/api/api_handler_pcb.h @@ -106,6 +106,9 @@ private: HANDLER_RESULT handleSetBoardOrigin( const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetBoardLayerName( + const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetBoundingBox( const HANDLER_CONTEXT& aCtx );