From 0d7588bdfb60004fcd1e1f9df72d92f29a489127 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Thu, 28 Nov 2024 17:58:07 -0500 Subject: [PATCH] API: Improve handling of compound shapes --- api/proto/common/commands/base_commands.proto | 12 ++++++++++-- api/proto/common/types/base_types.proto | 14 +------------- common/api/api_handler_common.cpp | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/api/proto/common/commands/base_commands.proto b/api/proto/common/commands/base_commands.proto index 2e243b95cc..ef5976842c 100644 --- a/api/proto/common/commands/base_commands.proto +++ b/api/proto/common/commands/base_commands.proto @@ -44,17 +44,25 @@ message GetTextExtents kiapi.common.types.Text text = 1; } +message TextOrTextBox +{ + oneof inner { + kiapi.common.types.Text text = 1; + kiapi.common.types.TextBox textbox = 2; + } +} + // Render the given text object(s) as shapes. Depending on whether the text is using // the KiCad stroke font or a custom font, the response will be a compound shape containing // a set of polygons or a set of segments. message GetTextAsShapes { - repeated kiapi.common.types.Text text = 1; + repeated TextOrTextBox text = 1; } message TextWithShapes { - kiapi.common.types.Text text = 1; + TextOrTextBox text = 1; kiapi.common.types.CompoundShape shapes = 2; } diff --git a/api/proto/common/types/base_types.proto b/api/proto/common/types/base_types.proto index 7b68cd80b5..ee0a64f814 100644 --- a/api/proto/common/types/base_types.proto +++ b/api/proto/common/types/base_types.proto @@ -404,22 +404,10 @@ message GraphicShape } } -message CompoundShapeEntry -{ - oneof geometry { - GraphicSegmentAttributes segment = 1; - GraphicRectangleAttributes rectangle = 2; - GraphicArcAttributes arc = 3; - GraphicCircleAttributes circle = 4; - PolySet polygon = 5; - GraphicBezierAttributes bezier = 6; - } -} - // A SHAPE_COMPOUND in KiCad message CompoundShape { - repeated CompoundShapeEntry shapes = 1; + repeated GraphicShape shapes = 1; } // The text strings that can be set in a drawing sheet for the title block diff --git a/common/api/api_handler_common.cpp b/common/api/api_handler_common.cpp index dd888c1857..6e039fb048 100644 --- a/common/api/api_handler_common.cpp +++ b/common/api/api_handler_common.cpp @@ -125,11 +125,21 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetTextAsShape { GetTextAsShapesResponse reply; - for( const Text& textMsg : aMsg.text() ) + for( const TextOrTextBox& textMsg : aMsg.text() ) { + Text dummyText; + const Text* textPtr = &textMsg.text(); + + if( textMsg.has_textbox() ) + { + dummyText.set_text( textMsg.textbox().text() ); + dummyText.mutable_attributes()->CopyFrom( textMsg.textbox().attributes() ); + textPtr = &dummyText; + } + EDA_TEXT text( pcbIUScale ); google::protobuf::Any any; - any.PackFrom( textMsg ); + any.PackFrom( *textPtr ); if( !text.Deserialize( any ) ) { @@ -148,7 +158,8 @@ HANDLER_RESULT API_HANDLER_COMMON::handleGetTextAsShape { EDA_SHAPE proxy( *subshape ); proxy.Serialize( any ); - any.UnpackTo( entry->mutable_shapes() ); + GraphicShape* shapeMsg = entry->mutable_shapes()->add_shapes(); + any.UnpackTo( shapeMsg ); } }