KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_logger.cpp
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 (C) 2016-2023 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#include "pns_logger.h"
23#include "pns_item.h"
24#include "pns_via.h"
25
26#include <wx/log.h>
27
28namespace PNS {
29
31{
32}
33
34
36{
37}
38
39
41{
42 m_events.clear();
43}
44
45
46void LOGGER::LogM( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, std::vector<ITEM*> items,
47 const SIZES_SETTINGS* sizes, int aLayer )
48{
50
51 ent.type = evt;
52 ent.p = pos;
53 ent.layer = aLayer;
54
55 if( sizes )
56 {
57 ent.sizes = *sizes;
58 }
59
60 for( auto& item : items )
61 {
62 if( item && item->Parent() )
63 ent.uuids.push_back( item->Parent()->m_Uuid );
64 }
65
66 m_events.push_back( ent );
67}
68
69
70void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item,
71 const SIZES_SETTINGS* sizes, int aLayer )
72{
73 std::vector<ITEM*> items;
74 items.push_back( const_cast<ITEM*>( item ) );
75 LogM( evt, pos, items, sizes, aLayer );
76}
77
78
80 const std::vector<ITEM*>& aAddedItems,
81 const std::set<KIID>& aRemovedItems,
82 const std::vector<ITEM*>& aHeads,
83 const std::vector<LOGGER::EVENT_ENTRY>& aEvents )
84{
85 wxString result = wxString::Format( "mode %d\n", aMode );
86
87 for( const EVENT_ENTRY& evt : aEvents )
88 result += PNS::LOGGER::FormatEvent( evt );
89
90 for( const KIID& uuid : aRemovedItems )
91 result += wxString::Format( "removed %s\n", uuid.AsString().c_str() );
92
93 for( ITEM* item : aAddedItems )
94 result += wxString::Format( "added %s\n", item->Format().c_str() );
95
96 for( ITEM* item : aHeads )
97 result += wxString::Format( "head %s\n", item->Format().c_str() );
98
99 return result;
100}
101
102
104{
105 wxString str = wxString::Format( "event %d %d %d %d %d ", aEvent.p.x, aEvent.p.y, aEvent.type, aEvent.layer, (int)aEvent.uuids.size() );
106
107 for( int i = 0; i < aEvent.uuids.size(); i++ )
108 {
109 str.Append( aEvent.uuids[i].AsString() );
110 str.Append( wxT(" ") );
111 }
112
113 str.Append( wxString::Format( "%d %d %d %d %d %d %d",
114 aEvent.sizes.TrackWidth(),
115 aEvent.sizes.ViaDiameter(),
116 aEvent.sizes.ViaDrill(),
117 aEvent.sizes.TrackWidthIsExplicit() ? 1 : 0,
118 aEvent.sizes.GetLayerBottom(),
119 aEvent.sizes.GetLayerTop(),
120 static_cast<int>( aEvent.sizes.ViaType() ) ) );
121
122 str.Append( wxT("\n") );
123
124 return str;
125}
126
127
129{
130 wxStringTokenizer tokens( aLine );
131 wxString cmd = tokens.GetNextToken();
132
133 int n_uuids = 0;
134
135 wxCHECK_MSG( cmd == wxT( "event" ), EVENT_ENTRY(), "Line doesn't contain an event!" );
136
137 EVENT_ENTRY evt;
138 evt.p.x = wxAtoi( tokens.GetNextToken() );
139 evt.p.y = wxAtoi( tokens.GetNextToken() );
140 evt.type = (PNS::LOGGER::EVENT_TYPE) wxAtoi( tokens.GetNextToken() );
141 evt.layer = wxAtoi( tokens.GetNextToken() );
142 n_uuids = wxAtoi( tokens.GetNextToken() );
143
144 for( int i = 0; i < n_uuids; i++)
145 evt.uuids.push_back( KIID( tokens.GetNextToken() ) );
146
147 return evt;
148}
149
150}
Definition: kiid.h:49
Base class for PNS router board items.
Definition: pns_item.h:97
void Log(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), const ITEM *item=nullptr, const SIZES_SETTINGS *sizes=nullptr, int aLayer=0)
Definition: pns_logger.cpp:70
static wxString FormatLogFileAsString(int aMode, const std::vector< ITEM * > &aAddedItems, const std::set< KIID > &aRemovedItems, const std::vector< ITEM * > &aHeads, const std::vector< EVENT_ENTRY > &aEvents)
Definition: pns_logger.cpp:79
void LogM(EVENT_TYPE evt, const VECTOR2I &pos=VECTOR2I(), std::vector< ITEM * > items={}, const SIZES_SETTINGS *sizes=nullptr, int aLayer=0)
Definition: pns_logger.cpp:46
void Clear()
Definition: pns_logger.cpp:40
static wxString FormatEvent(const EVENT_ENTRY &aEvent)
Definition: pns_logger.cpp:103
std::vector< EVENT_ENTRY > m_events
Definition: pns_logger.h:99
static EVENT_ENTRY ParseEvent(const wxString &aLine)
Definition: pns_logger.cpp:128
VIATYPE ViaType() const
bool TrackWidthIsExplicit() const
Push and Shove diff pair dimensions (gap) settings dialog.
Definition: pns_logger.h:57
int layer
Definition: pns_logger.h:62
SIZES_SETTINGS sizes
Definition: pns_logger.h:61
std::vector< KIID > uuids
Definition: pns_logger.h:60
EVENT_TYPE type
Definition: pns_logger.h:59
VECTOR2I p
Definition: pns_logger.h:58