From 3514d130cb07d7c990906366cdc4e99d391060cf Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 1 Mar 2026 22:24:38 -0500 Subject: [PATCH] API: Add support for retrieving user names for all layers --- 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 a24a787fcf..1f726d5de7 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 56e6705a00..841674512b 100644 --- a/pcbnew/api/api_handler_pcb.cpp +++ b/pcbnew/api/api_handler_pcb.cpp @@ -90,6 +90,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 ); @@ -1099,6 +1100,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 7974884a65..20d2a207ed 100644 --- a/pcbnew/api/api_handler_pcb.h +++ b/pcbnew/api/api_handler_pcb.h @@ -103,6 +103,9 @@ private: HANDLER_RESULT handleSetBoardOrigin( const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetBoardLayerName( + const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetBoundingBox( const HANDLER_CONTEXT& aCtx );