From af71ea869e06f7d6db8a6a3bf30256b73be410d3 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 19 Nov 2024 23:44:29 -0500 Subject: [PATCH] API: Expose title block info --- .../common/commands/editor_commands.proto | 6 ++++ api/proto/common/types/base_types.proto | 21 ++++++++++++ pcbnew/api/api_handler_pcb.cpp | 34 +++++++++++++++++++ pcbnew/api/api_handler_pcb.h | 3 ++ 4 files changed, 64 insertions(+) diff --git a/api/proto/common/commands/editor_commands.proto b/api/proto/common/commands/editor_commands.proto index 44b6cbee9f..824201d211 100644 --- a/api/proto/common/commands/editor_commands.proto +++ b/api/proto/common/commands/editor_commands.proto @@ -309,3 +309,9 @@ message HitTestResponse { HitTestResult result = 1; } + +// returns common.types.TitleBlockInfo +message GetTitleBlockInfo +{ + kiapi.common.types.DocumentSpecifier document = 1; +} diff --git a/api/proto/common/types/base_types.proto b/api/proto/common/types/base_types.proto index 5de82fb9f3..20dd44a90b 100644 --- a/api/proto/common/types/base_types.proto +++ b/api/proto/common/types/base_types.proto @@ -338,3 +338,24 @@ message GraphicAttributes StrokeAttributes stroke = 1; GraphicFillAttributes fill = 2; } + +// The text strings that can be set in a drawing sheet for the title block +message TitleBlockInfo +{ + string title = 1; + string date = 2; + string revision = 3; + string company = 4; + + // Note: not a repeated string; there can be gaps and the UI limits the count to 9 + + string comment1 = 5; + string comment2 = 6; + string comment3 = 7; + string comment4 = 8; + string comment5 = 9; + string comment6 = 10; + string comment7 = 11; + string comment8 = 12; + string comment9 = 13; +} diff --git a/pcbnew/api/api_handler_pcb.cpp b/pcbnew/api/api_handler_pcb.cpp index 9411ad7ca9..9e4abb99c0 100644 --- a/pcbnew/api/api_handler_pcb.cpp +++ b/pcbnew/api/api_handler_pcb.cpp @@ -69,6 +69,8 @@ API_HANDLER_PCB::API_HANDLER_PCB( PCB_EDIT_FRAME* aFrame ) : &API_HANDLER_PCB::handleGetTextExtents ); registerHandler( &API_HANDLER_PCB::handleGetPadShapeAsPolygon ); + registerHandler( + &API_HANDLER_PCB::handleGetTitleBlockInfo ); registerHandler( &API_HANDLER_PCB::handleInteractiveMoveItems ); registerHandler( &API_HANDLER_PCB::handleGetNets ); @@ -683,6 +685,38 @@ HANDLER_RESULT API_HANDLER_PCB::handleGetPadShapeAsPo } +HANDLER_RESULT API_HANDLER_PCB::handleGetTitleBlockInfo( + GetTitleBlockInfo& aMsg, + const HANDLER_CONTEXT& aCtx ) +{ + HANDLER_RESULT documentValidation = validateDocument( aMsg.document() ); + + if( !documentValidation ) + return tl::unexpected( documentValidation.error() ); + + BOARD* board = frame()->GetBoard(); + const TITLE_BLOCK& block = board->GetTitleBlock(); + + types::TitleBlockInfo response; + + response.set_title( block.GetTitle().ToUTF8() ); + response.set_date( block.GetDate().ToUTF8() ); + response.set_revision( block.GetRevision().ToUTF8() ); + response.set_company( block.GetCompany().ToUTF8() ); + response.set_comment1( block.GetComment( 0 ).ToUTF8() ); + response.set_comment2( block.GetComment( 1 ).ToUTF8() ); + response.set_comment3( block.GetComment( 2 ).ToUTF8() ); + response.set_comment4( block.GetComment( 3 ).ToUTF8() ); + response.set_comment5( block.GetComment( 4 ).ToUTF8() ); + response.set_comment6( block.GetComment( 5 ).ToUTF8() ); + response.set_comment7( block.GetComment( 6 ).ToUTF8() ); + response.set_comment8( block.GetComment( 7 ).ToUTF8() ); + response.set_comment9( block.GetComment( 8 ).ToUTF8() ); + + return response; +} + + HANDLER_RESULT API_HANDLER_PCB::handleInteractiveMoveItems( InteractiveMoveItems& aMsg, const HANDLER_CONTEXT& aCtx ) { diff --git a/pcbnew/api/api_handler_pcb.h b/pcbnew/api/api_handler_pcb.h index 88fa320fe6..43af6c8ac9 100644 --- a/pcbnew/api/api_handler_pcb.h +++ b/pcbnew/api/api_handler_pcb.h @@ -81,6 +81,9 @@ private: HANDLER_RESULT handleGetPadShapeAsPolygon( GetPadShapeAsPolygon& aMsg, const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleGetTitleBlockInfo( commands::GetTitleBlockInfo& aMsg, + const HANDLER_CONTEXT& aCtx ); + HANDLER_RESULT handleInteractiveMoveItems( InteractiveMoveItems& aMsg, const HANDLER_CONTEXT& aCtx );