28#include <wx/tokenzr.h>
42 aJson = nlohmann::json
52 aPoint.
x = aJson.at(
"x" ).get<
int>();
53 aPoint.
y = aJson.at(
"y" ).get<
int>();
89 for(
auto& item : items )
91 if( item && item->Parent() )
92 ent.
uuids.push_back( item->Parent()->m_Uuid );
102 std::vector<ITEM*> items;
103 items.push_back(
const_cast<ITEM*
>( item ) );
104 LogM( evt, pos, items, sizes, aLayer );
124 nlohmann::json events = nlohmann::json::array();
127 json[
"events"] = events;
129 nlohmann::json removed = nlohmann::json::array();
131 removed.push_back( uuid );
132 json[
"removedItems"] = removed;
134 nlohmann::json added = nlohmann::json::array();
137 json[
"addedItems"] = added;
139 nlohmann::json headItems = nlohmann::json::array();
142 json[
"headItems"] = headItems;
146 std::stringstream buffer;
147 buffer << std::setw( 2 ) <<
json << std::endl;
157 ret[
"position"] = aEvent.
p;
158 ret[
"type"] = aEvent.
type;
159 ret[
"layer"] = aEvent.
layer;
164 nlohmann::json uuids = nlohmann::json::array();
166 for(
int i = 0; i < (int) aEvent.
uuids.size(); i++ )
167 uuids.push_back( aEvent.
uuids[i].AsString() );
169 ret[
"uuids"] = uuids;
183 ret [
"kind"] = aItem->
KindStr();
192 switch( aItem->
Kind() )
201 auto line =
static_cast<const LINE*
>( aItem );
202 ret[
"width"] = line->Width();
204 if( line->EndsWithVia() )
211 auto via =
static_cast<const VIA*
>( aItem );
213 ret[
"drill"] =
via->Drill();
218 auto hole =
static_cast<const HOLE*
>( aItem );
232 return nlohmann::json( {
240 {
"viaType", aSizes.
ViaType() },
250 switch( aShape->
Type() )
255 return nlohmann::json( {
256 {
"type",
"segment" },
257 {
"width", seg->GetWidth() },
258 {
"start", seg->GetStart() },
259 {
"end", seg->GetEnd() }
264 auto arc =
static_cast<const SHAPE_ARC*
>( aShape );
265 return nlohmann::json( {
267 {
"width", arc->GetWidth() },
268 {
"start", arc->GetStart() },
269 {
"end", arc->GetEnd() },
270 {
"mid", arc->GetArcMid() }
276 return nlohmann::json( {
277 {
"type",
"circle" },
278 {
"radius",
circle->GetRadius() },
279 {
"center",
circle->GetCenter() },
285 auto points = nlohmann::json::array();
286 for(
int i = 0; i < schain->PointCount(); i++ )
287 points.push_back( schain->CPoint( i ) );
289 return nlohmann::json( { {
"type",
"line_chain" }, {
"points", points } } );
296 return nlohmann::json();
302 wxStringTokenizer tokens( aLine );
303 wxString cmd = tokens.GetNextToken();
307 wxCHECK_MSG( cmd == wxT(
"event" ),
EVENT_ENTRY(),
"Line doesn't contain an event!" );
310 evt.
p.
x = wxAtoi( tokens.GetNextToken() );
311 evt.
p.
y = wxAtoi( tokens.GetNextToken() );
313 evt.
layer = wxAtoi( tokens.GetNextToken() );
314 n_uuids = wxAtoi( tokens.GetNextToken() );
316 for(
int i = 0; i < n_uuids; i++)
317 evt.
uuids.push_back(
KIID( tokens.GetNextToken() ) );
327 auto useConnProp = aJSON.at(
"useConnectedTrackWidth");
329 if( !useConnProp.empty() )
333 evt.
p = aJSON.at(
"position").get<
VECTOR2I>();
334 evt.
type =
static_cast<EVENT_TYPE>( aJSON.at(
"type").get<int>() );
335 evt.
layer = aJSON.at(
"layer").get<
int>();
337 for(
auto &uuid : aJSON.at(
"uuids") )
351 sizes.
SetViaDrill( aJSON.at(
"viaDrill").get<
int>() );
357 catch ( nlohmann::json::exception& )
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Base class for PNS router board items.
virtual const SHAPE * Shape(int aLayer) const
Return the geometrical shape of the item.
const PNS_LAYER_RANGE & Layers() const
virtual NET_HANDLE Net() const
PnsKind Kind() const
Return the type (kind) of the item.
virtual int Layer() const
std::string KindStr() const
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
static wxString FormatLogFileAsJSON(const LOG_DATA &aLogData)
void Log(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), const ITEM *item=nullptr, const SIZES_SETTINGS *sizes=nullptr, int aLayer=0)
static nlohmann::json formatShapeAsJSON(const SHAPE *aShape)
static EVENT_ENTRY ParseEventFromJSON(const nlohmann::json &aJSON)
static SIZES_SETTINGS parseSizesFromJSON(const nlohmann::json &aJSON)
static nlohmann::json FormatEventAsJSON(const EVENT_ENTRY &aEvent)
void LogM(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), std::vector< ITEM * > items={}, const SIZES_SETTINGS *sizes=nullptr, int aLayer=0)
std::vector< EVENT_ENTRY > m_events
static nlohmann::json formatRouterItemAsJSON(const PNS::ITEM *aItem)
static EVENT_ENTRY ParseEvent(const wxString &aLine)
static nlohmann::json formatSizesAsJSON(const SIZES_SETTINGS &aEvent)
virtual wxString GetNetName(PNS::NET_HANDLE aNet) const =0
ROUTER_IFACE * GetInterface() const
static ROUTER * GetInstance()
void SetTrackWidth(int aWidth)
int DiffPairWidth() const
void SetDiffPairWidth(int aWidth)
void SetDiffPairGap(int aGap)
void SetViaDrill(int aDrill)
void SetDiffPairViaGap(int aGap)
int GetLayerBottom() const
bool TrackWidthIsExplicit() const
void SetViaDiameter(int aDiameter)
int DiffPairViaGap() const
void SetTrackWidthIsExplicit(bool aIsExplicit)
SHAPE_TYPE Type() const
Return the type of the shape.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
An abstract shape on 2D plane.
Push and Shove diff pair dimensions (gap) settings dialog.
void from_json(const nlohmann::json &aJson, VECTOR2I &aPoint)
void to_json(nlohmann::json &aJson, const VECTOR2I &aPoint)
@ SH_LINE_CHAIN
line chain (polyline)
std::vector< FAB_LAYER_COLOR > dummy
std::vector< KIID > uuids
bool useConnectedTrackWidth
std::optional< wxString > m_BoardHash
std::optional< TEST_CASE_TYPE > m_TestCaseType
std::vector< ITEM * > m_AddedItems
std::vector< EVENT_ENTRY > m_Events
std::set< KIID > m_RemovedItems
std::vector< ITEM * > m_Heads
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
VECTOR2< int32_t > VECTOR2I