KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_log_file.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20
21// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
22// (unless you want to improve it).
23
24#ifndef __PNS_LOG_FILE_H
25#define __PNS_LOG_FILE_H
26
27#include <memory>
28#include <vector>
29#include <set>
30
31#include <wx/filename.h>
32
33#include <kiid.h>
34#include <math/vector2d.h>
35
36#include <router/pns_logger.h>
37#include <router/pns_router.h>
38#include <router/pns_item.h>
40
41#include <pcbnew/board.h>
43
45
47{
48public:
51
53 {
55 COMMIT_STATE( const COMMIT_STATE& aOther ) :
57 m_heads( aOther.m_heads )
58 {
59 }
60
61 std::set<KIID> m_removedIds;
62 std::vector<PNS::ITEM*> m_addedItems;
63 std::vector<PNS::ITEM*> m_heads;
64
65 bool Compare( const COMMIT_STATE& aOther );
66 };
67
68 // Saves a P&S event log only (e.g. after fixing a bug and wanting a new "golden" commit state)
69 bool SaveLog( const wxFileName& logFileName, REPORTER* aRpt );
70
71 // Loads a P&S event log and the associated board file. These always go together.
72 bool Load( const wxFileName& logFileName, REPORTER* aRpt, const wxString boardFileName = wxT("") );
73 const std::optional<wxString> GetLogBoardHash( const wxString& logFileName );
74
75 std::vector<BOARD_CONNECTED_ITEM*> ItemsById( const PNS::LOGGER::EVENT_ENTRY& evt );
77
78 std::vector<PNS::LOGGER::EVENT_ENTRY>& Events() { return m_events; }
79
80 void SetBoard( std::shared_ptr<BOARD> brd ) { m_board = brd; }
81 std::shared_ptr<BOARD> GetBoard() const { return m_board; }
82
84
85 const COMMIT_STATE& GetExpectedResult() const { return m_commitState; }
86
87 void SetExpectedResult( const COMMIT_STATE& aCommitState,
88 std::vector<std::unique_ptr<PNS::ITEM>> aParsedItems )
89 {
90 m_commitState = aCommitState;
91 m_parsed_items = std::move( aParsedItems );
92 }
93
94 PNS::ROUTER_MODE GetMode() const { return m_mode; }
95
96 void SetMode( PNS::ROUTER_MODE aMode ) { m_mode = aMode; }
98 std::optional<PNS::LOGGER::TEST_CASE_TYPE> GetTestCaseType() const { return m_testCaseType; }
99
100private:
101 bool parseLegacyCommonPnsProps( PNS::ITEM* aItem, const wxString& cmd, wxStringTokenizer& aTokens );
102 std::unique_ptr<PNS::SEGMENT> parseLegacyPnsSegmentFromString( wxStringTokenizer& aTokens );
103 std::unique_ptr<PNS::VIA> parseLegacyPnsViaFromString( wxStringTokenizer& aTokens );
104 std::unique_ptr<PNS::ITEM> parseLegacyItemFromString( wxStringTokenizer& aTokens );
105 std::shared_ptr<SHAPE> parseLegacyShape( SHAPE_TYPE expectedType, wxStringTokenizer& aTokens );
106
107 std::shared_ptr<SHAPE> parseShape( const nlohmann::json& aJSON );
108 bool parseCommonPnsProps( const nlohmann::json& aJSON, PNS::ITEM* aItem );
109 std::unique_ptr<PNS::ITEM> parseItem( const nlohmann::json& aJSON );
110 bool loadJsonLog( const wxString& aFilename, REPORTER* aRpt, bool aHashOnly = false );
111 bool loadLegacyLog( const wxString& aFilename, REPORTER* aRpt );
112
113private:
114 std::optional<wxString> m_boardHash;
115 std::shared_ptr<SETTINGS_MANAGER> m_settingsMgr;
116 std::unique_ptr<PNS::ROUTING_SETTINGS> m_routerSettings;
117 std::vector<PNS::LOGGER::EVENT_ENTRY> m_events;
118 std::shared_ptr<BOARD> m_board;
120 std::vector<std::unique_ptr<PNS::ITEM>> m_parsed_items;
122 std::optional<PNS::LOGGER::TEST_CASE_TYPE> m_testCaseType;
123};
124
125#endif
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Base class for PNS router board items.
Definition pns_item.h:98
Contain all persistent settings of the router, such as the mode, optimization effort,...
bool parseCommonPnsProps(const nlohmann::json &aJSON, PNS::ITEM *aItem)
BOARD_CONNECTED_ITEM * ItemById(const PNS::LOGGER::EVENT_ENTRY &evt)
void SetExpectedResult(const COMMIT_STATE &aCommitState, std::vector< std::unique_ptr< PNS::ITEM > > aParsedItems)
void SetBoard(std::shared_ptr< BOARD > brd)
std::optional< PNS::LOGGER::TEST_CASE_TYPE > GetTestCaseType() const
void SetTestCaseType(PNS::LOGGER::TEST_CASE_TYPE aType)
std::unique_ptr< PNS::VIA > parseLegacyPnsViaFromString(wxStringTokenizer &aTokens)
const std::optional< wxString > GetLogBoardHash(const wxString &logFileName)
const COMMIT_STATE & GetExpectedResult() const
bool SaveLog(const wxFileName &logFileName, REPORTER *aRpt)
bool loadLegacyLog(const wxString &aFilename, REPORTER *aRpt)
PNS::ROUTER_MODE m_mode
std::shared_ptr< BOARD > m_board
bool parseLegacyCommonPnsProps(PNS::ITEM *aItem, const wxString &cmd, wxStringTokenizer &aTokens)
std::shared_ptr< SETTINGS_MANAGER > m_settingsMgr
std::shared_ptr< SHAPE > parseShape(const nlohmann::json &aJSON)
std::unique_ptr< PNS::ITEM > parseItem(const nlohmann::json &aJSON)
std::shared_ptr< SHAPE > parseLegacyShape(SHAPE_TYPE expectedType, wxStringTokenizer &aTokens)
std::vector< std::unique_ptr< PNS::ITEM > > m_parsed_items
PNS::ROUTING_SETTINGS * GetRoutingSettings() const
std::optional< wxString > m_boardHash
void SetMode(PNS::ROUTER_MODE aMode)
COMMIT_STATE m_commitState
PNS::ROUTER_MODE GetMode() const
std::vector< PNS::LOGGER::EVENT_ENTRY > & Events()
bool loadJsonLog(const wxString &aFilename, REPORTER *aRpt, bool aHashOnly=false)
std::shared_ptr< BOARD > GetBoard() const
std::vector< PNS::LOGGER::EVENT_ENTRY > m_events
std::vector< BOARD_CONNECTED_ITEM * > ItemsById(const PNS::LOGGER::EVENT_ENTRY &evt)
std::unique_ptr< PNS::SEGMENT > parseLegacyPnsSegmentFromString(wxStringTokenizer &aTokens)
std::optional< PNS::LOGGER::TEST_CASE_TYPE > m_testCaseType
std::unique_ptr< PNS::ROUTING_SETTINGS > m_routerSettings
bool Load(const wxFileName &logFileName, REPORTER *aRpt, const wxString boardFileName=wxT(""))
std::unique_ptr< PNS::ITEM > parseLegacyItemFromString(wxStringTokenizer &aTokens)
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
ROUTER_MODE
Definition pns_router.h:67
SHAPE_TYPE
Lists all supported shapes.
Definition shape.h:42
Definition pns_logger.h:71
std::set< KIID > m_removedIds
COMMIT_STATE(const COMMIT_STATE &aOther)
bool Compare(const COMMIT_STATE &aOther)
std::vector< PNS::ITEM * > m_addedItems
std::vector< PNS::ITEM * > m_heads