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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
26// (unless you want to improve it).
27
28#ifndef __PNS_LOG_FILE_H
29#define __PNS_LOG_FILE_H
30
31#include <memory>
32#include <vector>
33#include <set>
34
35#include <wx/filename.h>
36
37#include <kiid.h>
38#include <math/vector2d.h>
39
40#include <router/pns_logger.h>
41#include <router/pns_router.h>
42#include <router/pns_item.h>
44
45#include <pcbnew/board.h>
47
49
51{
52public:
55
57 {
59 COMMIT_STATE( const COMMIT_STATE& aOther ) :
61 m_heads( aOther.m_heads )
62 {
63 }
64
65 std::set<KIID> m_removedIds;
66 std::vector<PNS::ITEM*> m_addedItems;
67 std::vector<PNS::ITEM*> m_heads;
68
69 bool Compare( const COMMIT_STATE& aOther );
70 };
71
72 // Saves a P&S event log only (e.g. after fixing a bug and wanting a new "golden" commit state)
73 bool SaveLog( const wxFileName& logFileName, REPORTER* aRpt );
74
75 // Loads a P&S event log and the associated board file. These always go together.
76 bool Load( const wxFileName& logFileName, REPORTER* aRpt, const wxString boardFileName = wxT("") );
77 const std::optional<wxString> GetLogBoardHash( const wxString& logFileName );
78
79 std::vector<BOARD_CONNECTED_ITEM*> ItemsById( const PNS::LOGGER::EVENT_ENTRY& evt );
81
82 std::vector<PNS::LOGGER::EVENT_ENTRY>& Events() { return m_events; }
83
84 void SetBoard( std::shared_ptr<BOARD> brd ) { m_board = brd; }
85 std::shared_ptr<BOARD> GetBoard() const { return m_board; }
86
88
89 const COMMIT_STATE& GetExpectedResult() const { return m_commitState; }
90
91 void SetExpectedResult( const COMMIT_STATE& aCommitState,
92 std::vector<std::unique_ptr<PNS::ITEM>> aParsedItems )
93 {
94 m_commitState = aCommitState;
95 m_parsed_items = std::move( aParsedItems );
96 }
97
98 PNS::ROUTER_MODE GetMode() const { return m_mode; }
99
100 void SetMode( PNS::ROUTER_MODE aMode ) { m_mode = aMode; }
102 std::optional<PNS::LOGGER::TEST_CASE_TYPE> GetTestCaseType() const { return m_testCaseType; }
103
104private:
105 bool parseLegacyCommonPnsProps( PNS::ITEM* aItem, const wxString& cmd, wxStringTokenizer& aTokens );
106 std::unique_ptr<PNS::SEGMENT> parseLegacyPnsSegmentFromString( wxStringTokenizer& aTokens );
107 std::unique_ptr<PNS::VIA> parseLegacyPnsViaFromString( wxStringTokenizer& aTokens );
108 std::unique_ptr<PNS::ITEM> parseLegacyItemFromString( wxStringTokenizer& aTokens );
109 std::shared_ptr<SHAPE> parseLegacyShape( SHAPE_TYPE expectedType, wxStringTokenizer& aTokens );
110
111 std::shared_ptr<SHAPE> parseShape( const nlohmann::json& aJSON );
112 bool parseCommonPnsProps( const nlohmann::json& aJSON, PNS::ITEM* aItem );
113 std::unique_ptr<PNS::ITEM> parseItem( const nlohmann::json& aJSON );
114 bool loadJsonLog( const wxString& aFilename, REPORTER* aRpt, bool aHashOnly = false );
115 bool loadLegacyLog( const wxString& aFilename, REPORTER* aRpt );
116
117private:
118 std::optional<wxString> m_boardHash;
119 std::shared_ptr<SETTINGS_MANAGER> m_settingsMgr;
120 std::unique_ptr<PNS::ROUTING_SETTINGS> m_routerSettings;
121 std::vector<PNS::LOGGER::EVENT_ENTRY> m_events;
122 std::shared_ptr<BOARD> m_board;
124 std::vector<std::unique_ptr<PNS::ITEM>> m_parsed_items;
126 std::optional<PNS::LOGGER::TEST_CASE_TYPE> m_testCaseType;
127};
128
129#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:73
ROUTER_MODE
Definition pns_router.h:67
SHAPE_TYPE
Lists all supported shapes.
Definition shape.h:46
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