21#include <magic_enum.hpp> 
   27const wxChar* 
const traceApi = wxT( 
"KICAD_API" );
 
   35    static const std::map<std::string, KICAD_T> s_types = {
 
   36        { 
"type.googleapis.com/kiapi.board.types.Track", 
PCB_TRACE_T },
 
   37        { 
"type.googleapis.com/kiapi.board.types.Arc", 
PCB_ARC_T },
 
   38        { 
"type.googleapis.com/kiapi.board.types.Via", 
PCB_VIA_T },
 
   39        { 
"type.googleapis.com/kiapi.board.types.BoardText", 
PCB_TEXT_T },
 
   40        { 
"type.googleapis.com/kiapi.board.types.BoardTextBox", 
PCB_TEXTBOX_T },
 
   41        { 
"type.googleapis.com/kiapi.board.types.BoardGraphicShape", 
PCB_SHAPE_T },
 
   42        { 
"type.googleapis.com/kiapi.board.types.Barcode", 
PCB_BARCODE_T },
 
   43        { 
"type.googleapis.com/kiapi.board.types.Pad", 
PCB_PAD_T },
 
   44        { 
"type.googleapis.com/kiapi.board.types.Zone", 
PCB_ZONE_T },
 
   47        { 
"type.googleapis.com/kiapi.board.types.Group", 
PCB_GROUP_T },
 
   48        { 
"type.googleapis.com/kiapi.board.types.Field", 
PCB_FIELD_T },
 
   49        { 
"type.googleapis.com/kiapi.board.types.FootprintInstance", 
PCB_FOOTPRINT_T },
 
   52    auto it = s_types.find( aMessage.type_url() );
 
   54    if( it != s_types.end() )
 
   57    wxLogTrace( 
traceApi, wxString::Format( wxS( 
"Any message type %s is not known" ),
 
   58                                            aMessage.type_url() ) );
 
 
   66    return LIB_ID( aId.library_nickname(), aId.entry_name() );
 
 
   72    types::LibraryIdentifier msg;
 
 
   81    aOutput.set_x_nm( aInput.
x );
 
   82    aOutput.set_y_nm( aInput.
y );
 
 
   88    return VECTOR2I( aInput.x_nm(), aInput.y_nm() );
 
 
   94    aOutput.set_x_nm( aInput.
x );
 
   95    aOutput.set_y_nm( aInput.
y );
 
   96    aOutput.set_z_nm( aInput.
z );
 
 
  102    return VECTOR3D( aInput.x_nm(), aInput.y_nm(), aInput.z_nm() );
 
 
  126        types::PolyLineNode* node = aOutput.mutable_nodes()->Add();
 
  131            node->mutable_arc()->mutable_start()->set_x_nm( arc.
GetP0().
x );
 
  132            node->mutable_arc()->mutable_start()->set_y_nm( arc.
GetP0().
y );
 
  133            node->mutable_arc()->mutable_mid()->set_x_nm( arc.
GetArcMid().
x );
 
  134            node->mutable_arc()->mutable_mid()->set_y_nm( arc.
GetArcMid().
y );
 
  135            node->mutable_arc()->mutable_end()->set_x_nm( arc.
GetP1().
x );
 
  136            node->mutable_arc()->mutable_end()->set_y_nm( arc.
GetP1().
y );
 
  140            node->mutable_point()->set_x_nm( aSlc.
CPoint( vertex ).
x );
 
  141            node->mutable_point()->set_y_nm( aSlc.
CPoint( vertex ).
y );
 
  145    aOutput.set_closed( aSlc.
IsClosed() );
 
 
  153    for( 
const types::PolyLineNode& node : aInput.nodes() )
 
  155        if( node.has_point() )
 
  157            slc.
Append( 
VECTOR2I( node.point().x_nm(), node.point().y_nm() ) );
 
  159        else if( node.has_arc() )
 
  162                                   VECTOR2I( node.arc().mid().x_nm(), node.arc().mid().y_nm() ),
 
  163                                   VECTOR2I( node.arc().end().x_nm(), node.arc().end().y_nm() ),
 
 
  183        types::PolygonWithHoles* polyMsg = aOutput.mutable_polygons()->Add();
 
  184        PackPolyLine( *polyMsg->mutable_outline(), poly.front() );
 
  186        if( poly.size() > 1 )
 
  188            for( 
size_t hole = 1; hole < poly.size(); ++hole )
 
  190                types::PolyLine* pl = polyMsg->mutable_holes()->Add();
 
 
  202    for( 
const types::PolygonWithHoles& polygonWithHoles : aInput.polygons() )
 
  206        polygon.emplace_back( 
UnpackPolyLine( polygonWithHoles.outline() ) );
 
  208        for( 
const types::PolyLine& holeMsg : polygonWithHoles.holes() )
 
 
  220    aOutput.set_r( aInput.
r );
 
  221    aOutput.set_g( aInput.
g );
 
  222    aOutput.set_b( aInput.
b );
 
  223    aOutput.set_a( aInput.
a );
 
 
  229    double r = std::clamp( aInput.r(), 0.0, 1.0 );
 
  230    double g = std::clamp( aInput.g(), 0.0, 1.0 );
 
  231    double b = std::clamp( aInput.b(), 0.0, 1.0 );
 
  232    double a = std::clamp( aInput.a(), 0.0, 1.0 );
 
 
  239    aOutput.clear_path();
 
  241    for( 
const KIID& entry : aInput )
 
  242        aOutput.add_path()->set_value( entry.AsStdString() );
 
 
 
constexpr const Vec & GetOrigin() const
 
constexpr const SizeVec & GetSize() const
 
A color representation with 4 components: red, green, blue, alpha.
 
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.
 
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.
 
int NextShape(int aPointIndex) const
Return the vertex index of the next shape in the chain, or -1 if aPointIndex is the last shape.
 
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.
 
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.
 
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
 
KICOMMON_API SHAPE_LINE_CHAIN UnpackPolyLine(const types::PolyLine &aInput)
 
KICOMMON_API void PackColor(types::Color &aOutput, const KIGFX::COLOR4D &aInput)
 
KICOMMON_API BOX2I UnpackBox2(const types::Box2 &aInput)
 
KICOMMON_API void PackBox2(types::Box2 &aOutput, const BOX2I &aInput)
 
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
 
KICOMMON_API VECTOR3D UnpackVector3D(const types::Vector3D &aInput)
 
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput)
 
KICOMMON_API SHAPE_POLY_SET UnpackPolySet(const types::PolySet &aInput)
 
KICOMMON_API KIGFX::COLOR4D UnpackColor(const types::Color &aInput)
 
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput)
 
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
 
KICOMMON_API LIB_ID LibIdFromProto(const types::LibraryIdentifier &aId)
 
KICOMMON_API types::LibraryIdentifier LibIdToProto(const LIB_ID &aId)
 
KICOMMON_API void PackPolyLine(types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc)
 
KICOMMON_API void PackVector3D(types::Vector3D &aOutput, const VECTOR3D &aInput)
 
KICOMMON_API void PackPolySet(types::PolySet &aOutput, const SHAPE_POLY_SET &aInput)
 
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
 
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
 
@ 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_FOOTPRINT_T
class FOOTPRINT, a footprint
 
@ 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_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
 
VECTOR2< int32_t > VECTOR2I
 
VECTOR3< double > VECTOR3D