28#include <google/protobuf/empty.pb.h>
36using namespace kiapi::common::commands;
37using namespace kiapi::common::types;
38using google::protobuf::Empty;
48 registerHandler<GetTextAsShapes, GetTextAsShapesResponse>(
50 registerHandler<ExpandTextVariables, ExpandTextVariablesResponse>(
58 GetVersionResponse reply;
60 reply.mutable_version()->set_full_version(
GetBuildVersion().ToStdString() );
63 reply.mutable_version()->set_major( std::get<0>( version ) );
64 reply.mutable_version()->set_minor( std::get<1>( version ) );
65 reply.mutable_version()->set_patch( std::get<2>( version ) );
74 NetClassesResponse reply;
76 std::shared_ptr<NET_SETTINGS>& netSettings =
79 for(
const auto& [
name, netClass] : netSettings->GetNetclasses() )
81 reply.add_net_classes()->set_name(
name.ToStdString() );
98 google::protobuf::Any any;
99 any.PackFrom( aCtx.
Request.text() );
101 if( !
text.Deserialize( any ) )
104 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
105 e.set_error_message(
"Could not decode text in GetTextExtents message" );
106 return tl::unexpected( e );
109 types::Box2 response;
117 response.mutable_position()->set_x_nm( bbox.
GetPosition().
x );
118 response.mutable_position()->set_y_nm( bbox.
GetPosition().
y );
119 response.mutable_size()->set_x_nm( bbox.
GetSize().
x );
120 response.mutable_size()->set_y_nm( bbox.
GetSize().
y );
129 GetTextAsShapesResponse reply;
131 for(
const TextOrTextBox& textMsg : aCtx.
Request.text() )
134 const Text* textPtr = &textMsg.text();
136 if( textMsg.has_textbox() )
138 dummyText.set_text( textMsg.textbox().text() );
139 dummyText.mutable_attributes()->CopyFrom( textMsg.textbox().attributes() );
140 textPtr = &dummyText;
144 google::protobuf::Any any;
145 any.PackFrom( *textPtr );
147 if( !
text.Deserialize( any ) )
150 e.set_status( ApiStatusCode::AS_BAD_REQUEST );
151 e.set_error_message(
"Could not decode text in GetTextAsShapes message" );
152 return tl::unexpected( e );
155 std::shared_ptr<SHAPE_COMPOUND> shapes =
text.GetEffectiveTextShape(
false );
157 TextWithShapes* entry = reply.add_text_with_shapes();
158 entry->mutable_text()->CopyFrom( textMsg );
160 for(
SHAPE* subshape : shapes->Shapes() )
164 GraphicShape* shapeMsg = entry->mutable_shapes()->add_shapes();
165 any.UnpackTo( shapeMsg );
168 if( textMsg.has_textbox() )
170 GraphicShape* border = entry->mutable_shapes()->add_shapes();
171 int width = textMsg.textbox().attributes().stroke_width().value_nm();
172 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
177 PackVector2( *border->mutable_segment()->mutable_start(), tl );
181 border = entry->mutable_shapes()->add_shapes();
182 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
184 PackVector2( *border->mutable_segment()->mutable_end(), br );
187 border = entry->mutable_shapes()->add_shapes();
188 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
189 PackVector2( *border->mutable_segment()->mutable_start(), br );
193 border = entry->mutable_shapes()->add_shapes();
194 border->mutable_attributes()->mutable_stroke()->mutable_width()->set_value_nm( width );
196 PackVector2( *border->mutable_segment()->mutable_end(), tl );
207 if( !aCtx.
Request.has_document() || aCtx.
Request.document().type() != DOCTYPE_PROJECT )
210 e.set_status( ApiStatusCode::AS_UNHANDLED );
212 return tl::unexpected( e );
215 ExpandTextVariablesResponse reply;
218 for(
const std::string& textMsg : aCtx.
Request.text() )
221 reply.add_text( result.ToUTF8() );
tl::expected< T, ApiResponseStatus > HANDLER_RESULT
constexpr EDA_IU_SCALE pcbIUScale
const std::tuple< int, int, int > & GetMajorMinorPatchTuple()
Get the build version numbers as a tuple.
wxString GetBuildVersion()
Get the full KiCad version string.
HANDLER_RESULT< Empty > handlePing(const HANDLER_CONTEXT< commands::Ping > &aCtx)
HANDLER_RESULT< types::Box2 > handleGetTextExtents(const HANDLER_CONTEXT< commands::GetTextExtents > &aCtx)
HANDLER_RESULT< commands::GetTextAsShapesResponse > handleGetTextAsShapes(const HANDLER_CONTEXT< commands::GetTextAsShapes > &aCtx)
HANDLER_RESULT< commands::GetVersionResponse > handleGetVersion(const HANDLER_CONTEXT< commands::GetVersion > &aCtx)
HANDLER_RESULT< commands::NetClassesResponse > handleGetNetClasses(const HANDLER_CONTEXT< commands::GetNetClasses > &aCtx)
HANDLER_RESULT< commands::ExpandTextVariablesResponse > handleExpandTextVariables(const HANDLER_CONTEXT< commands::ExpandTextVariables > &aCtx)
constexpr const Vec & GetPosition() const
const BOX2< Vec > GetBoundingBoxRotated(const VECTOR2I &aRotCenter, const EDA_ANGLE &aAngle) const
Useful to calculate bounding box of rotated items, when rotation is not cardinal.
constexpr const SizeVec & GetSize() const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual SETTINGS_MANAGER & GetSettingsManager() const
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Container for project specific data.
virtual PROJECT_FILE & GetProjectFile() const
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
An abstract shape on 2D plane.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
PGM_BASE & Pgm()
The global Program "get" accessor.
RequestMessageType Request