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