KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_logger.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __PNS_LOGGER_H
23#define __PNS_LOGGER_H
24
25#include <cstdio>
26#include <vector>
27#include <string>
28#include <sstream>
29#include <set>
30
31#include <math/vector2d.h>
32#include <kiid.h>
33#include <json_common.h>
34
35#include "pns_sizes_settings.h"
36#include "pns_router.h"
37
39class SHAPE;
40
41void to_json( nlohmann::json& aJson, const VECTOR2I& aPoint );
42void from_json( const nlohmann::json& aJson, VECTOR2I& aPoint );
43
44namespace PNS {
45
46class ITEM;
47
48class LOGGER
49{
50public:
51
59
70
71 struct EVENT_ENTRY {
74 std::vector<KIID> uuids;
76 int layer;
77
80 layer( 0 )
81 {
82 }
83
84 EVENT_ENTRY( const EVENT_ENTRY& aE ) :
85 p( aE.p ),
86 type( aE.type ),
87 uuids( aE.uuids ),
88 sizes( aE.sizes ),
89 layer( aE.layer )
90 {
91 }
92 };
93
94 struct LOG_DATA
95 {
99 std::optional<wxString> m_BoardHash;
100 std::vector<ITEM*> m_AddedItems;
101 std::set<KIID> m_RemovedItems;
102 std::vector<ITEM*> m_Heads;
103 std::vector<EVENT_ENTRY> m_Events;
104 std::optional<TEST_CASE_TYPE> m_TestCaseType;
105 };
106
107 LOGGER();
108 ~LOGGER();
109
110 void Clear();
111
112 void LogM( EVENT_TYPE evt, const VECTOR2I& pos = VECTOR2I(), std::vector<ITEM*> items = {},
113 const SIZES_SETTINGS* sizes = nullptr, int aLayer = 0 );
114
115 void Log( EVENT_TYPE evt, const VECTOR2I& pos = VECTOR2I(), const ITEM* item = nullptr,
116 const SIZES_SETTINGS* sizes = nullptr, int aLayer = 0 );
117
118 const std::vector<EVENT_ENTRY>& GetEvents()
119 {
120 return m_events;
121 }
122
123 static nlohmann::json FormatEventAsJSON( const EVENT_ENTRY& aEvent );
124
125 static EVENT_ENTRY ParseEvent( const wxString& aLine );
126 static EVENT_ENTRY ParseEventFromJSON( const nlohmann::json& aJSON );
127 static wxString FormatLogFileAsJSON( const LOG_DATA& aLogData );
128
129private:
130
131 static nlohmann::json formatSizesAsJSON( const SIZES_SETTINGS& aEvent );
132 static nlohmann::json formatRouterItemAsJSON( const PNS::ITEM* aItem );
133 static nlohmann::json formatShapeAsJSON( const SHAPE* aShape );
134
135 std::vector<EVENT_ENTRY> m_events;
136 std::optional<TEST_CASE_TYPE> m_testCaseType;
137};
138
139}
140
141#endif
Base class for PNS router board items.
Definition pns_item.h:98
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)
std::optional< TEST_CASE_TYPE > m_testCaseType
Definition pns_logger.h:136
const std::vector< EVENT_ENTRY > & GetEvents()
Definition pns_logger.h:118
static EVENT_ENTRY ParseEventFromJSON(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)
@ TCT_STRICT_GEOMETRY
Definition pns_logger.h:54
@ TCT_EXPECTED_FAIL
Definition pns_logger.h:56
@ TCT_CONNECTIVITY_ONLY
Definition pns_logger.h:55
@ EVT_START_MULTIDRAG
Definition pns_logger.h:68
std::vector< EVENT_ENTRY > m_events
Definition pns_logger.h:135
static nlohmann::json formatRouterItemAsJSON(const PNS::ITEM *aItem)
static EVENT_ENTRY ParseEvent(const wxString &aLine)
static nlohmann::json formatSizesAsJSON(const SIZES_SETTINGS &aEvent)
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.
Definition shape.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
ROUTER_MODE
Definition pns_router.h:67
void from_json(const nlohmann::json &aJson, VECTOR2I &aPoint)
void to_json(nlohmann::json &aJson, const VECTOR2I &aPoint)
int layer
Definition pns_logger.h:76
SIZES_SETTINGS sizes
Definition pns_logger.h:75
EVENT_ENTRY(const EVENT_ENTRY &aE)
Definition pns_logger.h:84
EVENT_ENTRY()
Definition pns_logger.h:78
std::vector< KIID > uuids
Definition pns_logger.h:74
EVENT_TYPE type
Definition pns_logger.h:73
VECTOR2I p
Definition pns_logger.h:72
std::optional< wxString > m_BoardHash
Definition pns_logger.h:99
std::optional< TEST_CASE_TYPE > m_TestCaseType
Definition pns_logger.h:104
std::vector< ITEM * > m_AddedItems
Definition pns_logger.h:100
std::vector< EVENT_ENTRY > m_Events
Definition pns_logger.h:103
std::set< KIID > m_RemovedItems
Definition pns_logger.h:101
std::vector< ITEM * > m_Heads
Definition pns_logger.h:102
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687