21#include <magic_enum.hpp>
24#include <api/schematic/schematic_types.pb.h>
33const wxChar*
const traceApi = wxT(
"KICAD_API" );
42 s.set_status( aCode );
44 if( !aMessage.empty() )
45 s.set_error_message( aMessage );
52 if( aMessage.type_url() ==
"type.googleapis.com/kiapi.schematic.types.BusEntry" )
54 kiapi::schematic::types::BusEntry entry;
56 if( !aMessage.UnpackTo( &entry ) )
59 switch( entry.type() )
61 case kiapi::schematic::types::BET_WIRE_TO_BUS:
64 case kiapi::schematic::types::BET_BUS_TO_BUS:
72 static const std::map<std::string, KICAD_T> s_types = {
73 {
"type.googleapis.com/kiapi.board.types.Track",
PCB_TRACE_T },
74 {
"type.googleapis.com/kiapi.board.types.Arc",
PCB_ARC_T },
75 {
"type.googleapis.com/kiapi.board.types.Via",
PCB_VIA_T },
76 {
"type.googleapis.com/kiapi.board.types.BoardText",
PCB_TEXT_T },
77 {
"type.googleapis.com/kiapi.board.types.BoardTextBox",
PCB_TEXTBOX_T },
78 {
"type.googleapis.com/kiapi.board.types.Table",
PCB_TABLE_T },
82 {
"type.googleapis.com/kiapi.board.types.BoardGraphicShape",
PCB_SHAPE_T },
83 {
"type.googleapis.com/kiapi.board.types.Barcode",
PCB_BARCODE_T },
84 {
"type.googleapis.com/kiapi.board.types.Pad",
PCB_PAD_T },
85 {
"type.googleapis.com/kiapi.board.types.Zone",
PCB_ZONE_T },
88 {
"type.googleapis.com/kiapi.board.types.ReferencePoint",
PCB_POINT_T },
90 {
"type.googleapis.com/kiapi.board.types.Group",
PCB_GROUP_T },
91 {
"type.googleapis.com/kiapi.board.types.TuningPattern",
PCB_GENERATOR_T },
92 {
"type.googleapis.com/kiapi.board.types.ViaStitchArea",
PCB_GENERATOR_T },
95 {
"type.googleapis.com/kiapi.board.types.Field",
PCB_FIELD_T },
96 {
"type.googleapis.com/kiapi.board.types.FootprintInstance",
PCB_FOOTPRINT_T },
97 {
"type.googleapis.com/kiapi.schematic.types.Junction",
SCH_JUNCTION_T },
98 {
"type.googleapis.com/kiapi.schematic.types.NoConnectMarker",
SCH_NO_CONNECT_T },
100 {
"type.googleapis.com/kiapi.schematic.types.SchematicLine",
SCH_LINE_T },
101 {
"type.googleapis.com/kiapi.schematic.types.SchematicGraphicShape",
SCH_SHAPE_T },
102 {
"type.googleapis.com/kiapi.schematic.types.SchematicImage",
SCH_BITMAP_T },
103 {
"type.googleapis.com/kiapi.schematic.types.SchematicTextBox",
SCH_TEXTBOX_T },
104 {
"type.googleapis.com/kiapi.schematic.types.SchematicText",
SCH_TEXT_T },
105 {
"type.googleapis.com/kiapi.schematic.types.SchematicField",
SCH_FIELD_T },
106 {
"type.googleapis.com/kiapi.schematic.types.SchematicTableCell",
SCH_TABLECELL_T },
107 {
"type.googleapis.com/kiapi.schematic.types.SchematicTable",
SCH_TABLE_T },
108 {
"type.googleapis.com/kiapi.schematic.types.LocalLabel",
SCH_LABEL_T },
110 {
"type.googleapis.com/kiapi.schematic.types.HierarchicalLabel",
SCH_HIER_LABEL_T },
112 {
"type.googleapis.com/kiapi.schematic.types.Group",
SCH_GROUP_T },
113 {
"type.googleapis.com/kiapi.schematic.types.SheetSymbol",
SCH_SHEET_T },
114 {
"type.googleapis.com/kiapi.schematic.types.SchematicSymbolInstance",
SCH_SYMBOL_T },
115 {
"type.googleapis.com/kiapi.schematic.types.SchematicPin",
SCH_PIN_T },
116 {
"type.googleapis.com/kiapi.schematic.types.SchematicSymbol",
LIB_SYMBOL_T },
117 {
"type.googleapis.com/kiapi.schematic.types.SchematicRuleArea",
SCH_RULE_AREA_T },
120 auto it = s_types.find( aMessage.type_url() );
122 if( it != s_types.end() )
125 wxLogTrace(
traceApi, wxString::Format( wxS(
"Any message type %s is not known" ),
126 aMessage.type_url() ) );
134 static const std::map<std::string, wxString> s_generatorTypes = {
135 {
"type.googleapis.com/kiapi.board.types.TuningPattern", wxS(
"tuning_pattern" ) },
136 {
"type.googleapis.com/kiapi.board.types.ViaStitchArea", wxS(
"via_stitch" ) },
137 {
"type.googleapis.com/kiapi.board.types.ViaStack", wxS(
"via_stack" ) },
140 auto it = s_generatorTypes.find( aMessage.type_url() );
142 if( it != s_generatorTypes.end() )
151 return LIB_ID( aId.library_nickname(), aId.entry_name() );
164 aOutput.set_x_nm( aScale.
IUToNm( aInput.
x ) );
165 aOutput.set_y_nm( aScale.
IUToNm( aInput.
y ) );
178 aOutput.set_x_nm( aInput.
x );
179 aOutput.set_y_nm( aInput.
y );
180 aOutput.set_z_nm( aInput.
z );
186 return VECTOR3D( aInput.x_nm(), aInput.y_nm(), aInput.z_nm() );
205 aOutput.set_value_nm( aScale.
IUToNm( aInput ) );
217 for(
int vertex = 0; vertex < aSlc.
PointCount(); ++vertex )
221 types::PolyLineNode* node = aOutput.mutable_nodes()->Add();
229 types::PolyLineNode* node = aOutput.mutable_nodes()->Add();
234 aOutput.set_closed( aSlc.
IsClosed() );
242 for(
const types::PolyLineNode& node : aInput.nodes() )
244 if( node.has_point() )
248 else if( node.has_arc() )
272 types::PolygonWithHoles* polyMsg = aOutput.mutable_polygons()->Add();
273 PackPolyLine( *polyMsg->mutable_outline(), poly.front(), aScale );
275 if( poly.size() > 1 )
277 for(
size_t hole = 1; hole < poly.size(); ++hole )
279 types::PolyLine* pl = polyMsg->mutable_holes()->Add();
291 for(
const types::PolygonWithHoles& polygonWithHoles : aInput.polygons() )
295 polygon.emplace_back(
UnpackPolyLine( polygonWithHoles.outline(), aScale ) );
297 for(
const types::PolyLine& holeMsg : polygonWithHoles.holes() )
309 aOutput.set_r( aInput.
r );
310 aOutput.set_g( aInput.
g );
311 aOutput.set_b( aInput.
b );
312 aOutput.set_a( aInput.
a );
318 double r = std::clamp( aInput.r(), 0.0, 1.0 );
319 double g = std::clamp( aInput.g(), 0.0, 1.0 );
320 double b = std::clamp( aInput.b(), 0.0, 1.0 );
321 double a = std::clamp( aInput.a(), 0.0, 1.0 );
328 aOutput.clear_path();
330 for(
const KIID& entry : aInput )
331 aOutput.add_path()->set_value( entry.AsStdString() );
338 for(
const types::KIID& sheet : aInput.path() )
339 output.push_back(
KIID( sheet.value() ) );
362 if( aInput.has_color() )
390 if( aInput.has_length() )
393 if( aInput.has_width() )
396 if( aInput.has_stroke() )
413#if defined( __MINGW32__ )
427 if( !request.mutable_message()->PackFrom( aMessage ) )
430 aBytes = request.SerializeAsString();
440 types::CustomProperty* entry = aOutput->Add();
441 entry->set_key( key.ToUTF8() );
442 entry->set_value( value.ToUTF8() );
450 std::map<wxString, wxString> props;
452 for(
const types::CustomProperty& prop : aInput )
453 props[wxString::FromUTF8( prop.key() )] = wxString::FromUTF8( prop.value() );
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr const Vec & GetOrigin() const
constexpr const SizeVec & GetSize() const
A base class for most all the KiCad significant classes used in schematics and boards.
void SetCustomProperties(const std::map< wxString, wxString > &aProps)
const std::map< wxString, wxString > & GetCustomProperties() const
Custom user-defined string key/value properties attached to this item.
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
int GetLength() const
Along-line size. 0 = auto.
const STROKE_PARAMS & GetStroke() const
int GetWidth() const
Perpendicular size. 0 = auto.
void SetStroke(const STROKE_PARAMS &aStroke)
void SetLength(int aLength)
void SetStyle(LINE_ENDING_STYLE aStyle)
void SetWidth(int aWidth)
LINE_ENDING_STYLE GetStyle() const
int GetStrokeWidth() const
Outline stroke width.
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
const VECTOR2I & GetArcMid() const
const VECTOR2I & GetP1() const
const VECTOR2I & GetP0() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsPtOnArc(size_t aPtIndex) const
const SHAPE_ARC & Arc(size_t aArc) const
bool IsClosed() const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
bool IsArcStart(size_t aIndex) const
Represent a set of closed polygons.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
int AddPolygon(const POLYGON &apolygon)
Adds a polygon to the set.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
int OutlineCount() const
Return the number of outlines in the set.
Simple container to manage line stroke parameters.
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void SetColor(const KIGFX::COLOR4D &aColor)
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
KICOMMON_API void PackLineEnding(types::LineEnding &aOutput, const LINE_ENDING &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackProject(types::ProjectSpecifier &aOutput, const PROJECT &aInput)
KICOMMON_API void PackColor(types::Color &aOutput, const KIGFX::COLOR4D &aInput)
KICOMMON_API void UnpackStroke(STROKE_PARAMS &aOutput, const types::StrokeAttributes &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API KIID_PATH UnpackSheetPath(const types::SheetPath &aInput)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API void PackPolySet(types::PolySet &aOutput, const SHAPE_POLY_SET &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API VECTOR3D UnpackVector3D(const types::Vector3D &aInput)
KICOMMON_API LINE_ENDING UnpackLineEnding(const types::LineEnding &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API KIGFX::COLOR4D UnpackColor(const types::Color &aInput)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API ApiResponseStatus MakeResponseStatus(ApiStatusCode aCode, const std::string &aMessage)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackBox2(types::Box2 &aOutput, const BOX2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API std::optional< wxString > GeneratorTypeFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API BOX2I UnpackBox2(const types::Box2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API SHAPE_LINE_CHAIN UnpackPolyLine(const types::PolyLine &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackStroke(types::StrokeAttributes &aOutput, const STROKE_PARAMS &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
KICOMMON_API void PackLibId(types::LibraryIdentifier *aOutput, const LIB_ID &aId)
KICOMMON_API LIB_ID UnpackLibId(const types::LibraryIdentifier &aId)
KICOMMON_API bool PackKiwayApiMessage(const google::protobuf::Message &aMessage, std::string &aBytes)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
const KICOMMON_API std::string KiwayClientName
KICOMMON_API void PackPolyLine(types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc, const EDA_IU_SCALE &aScale)
KICOMMON_API SHAPE_POLY_SET UnpackPolySet(const types::PolySet &aInput, const EDA_IU_SCALE &aScale)
const KICOMMON_API std::string StandaloneCrossProbeClientName
KICOMMON_API void PackVector3D(types::Vector3D &aOutput, const VECTOR3D &aInput)
constexpr double NmToIUD(int64_t nm) const
constexpr int64_t IUToNm(int iu) const
@ PCB_CONSTRAINT_T
a geometric constraint between board items
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_GRID_ITEM_T
a subgrid placed on a board
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
VECTOR2< int32_t > VECTOR2I
VECTOR3< double > VECTOR3D