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