KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_log_player.cpp
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 (C) 2020-2021 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
25#include "pns_log_file.h"
26#include "pns_log_player.h"
27
29
30#define PNSLOGINFO PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ )
31
32using namespace PNS;
33
35{
37}
38
39
41{
43 delete m_debugDecorator;
44}
45
47{
50 m_router.reset( new ROUTER );
51 m_iface->SetBoard( m_board.get() );
52 m_router->SetInterface( m_iface.get() );
53 m_router->ClearWorld();
54 m_router->SyncWorld();
55 m_router->LoadSettings( new PNS::ROUTING_SETTINGS( nullptr, "" ) );
56 m_router->Settings().SetMode( PNS::RM_Walkaround );
57 m_router->Sizes().SetTrackWidth( 250000 );
58
61 m_iface->SetDebugDecorator( m_debugDecorator );
62}
63
64
66{
68 std::vector<PNS::ITEM*> added, removed, heads;
69 m_router->GetUpdatedItems( removed, added, heads );
70
71 //printf("a %d r %d\n", added.size(), removed.size() );
72 for( auto item : removed )
73 {
74 if( item->Parent() )
75 {
76 state.m_removedIds.insert( item->Parent()->m_Uuid );
77 }
78 }
79
80 for( auto item : added )
81 {
82 state.m_addedItems.push_back( item );
83 }
84
85 // fixme: update the state with the head trace (not supported in current testsuite)
86
87 return state;
88}
89
90void PNS_LOG_PLAYER::ReplayLog( PNS_LOG_FILE* aLog, int aStartEventIndex, int aFrom, int aTo )
91{
92 m_board = aLog->GetBoard();
93
95
96 m_router->LoadSettings( aLog->GetRoutingSettings() );
97
98 int eventIdx = 0;
99 int totalEvents = aLog->Events().size();
100
101 for( auto evt : aLog->Events() )
102 {
103 if( eventIdx < aFrom || ( aTo >= 0 && eventIdx > aTo ) )
104 continue;
105
106 auto item = aLog->ItemById( evt );
107 ITEM* ritem = item ? m_router->GetWorld()->FindItemByParent( item ) : nullptr;
108 int routingLayer = ritem ? ritem->Layers().Start() : F_Cu;
109
110 eventIdx++;
111
112 switch( evt.type )
113 {
115 {
116 PNS::SIZES_SETTINGS sizes( m_router->Sizes() );
117 m_iface->SetStartLayer( routingLayer );
118 m_iface->ImportSizes( sizes, ritem, nullptr );
119 m_router->UpdateSizes( sizes );
120
121 m_debugDecorator->NewStage( "route-start", 0, PNSLOGINFO );
122 m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
123
124 auto msg = wxString::Format( "event [%d/%d]: route-start (%d, %d)", eventIdx,
125 totalEvents, evt.p.x, evt.p.y );
126
128 m_reporter->Report( msg );
129
130 m_router->StartRouting( evt.p, ritem, routingLayer );
131 break;
132 }
133
135 {
136 PNS::SIZES_SETTINGS sizes( m_router->Sizes() );
137 m_iface->SetStartLayer( routingLayer );
138 m_iface->ImportSizes( sizes, ritem, nullptr );
139 m_router->UpdateSizes( sizes );
140
141 m_debugDecorator->NewStage( "drag-start", 0, PNSLOGINFO );
142 m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
143
144 auto msg = wxString::Format( "event [%d/%d]: drag-start (%d, %d)", eventIdx,
145 totalEvents, evt.p.x, evt.p.y );
146
148 m_reporter->Report( msg );
149
150 bool rv = m_router->StartDragging( evt.p, ritem, 0 );
151 break;
152 }
153
154 case LOGGER::EVT_FIX:
155 {
157 m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
158 m_debugDecorator->Message( wxString::Format( "fix (%d, %d)", evt.p.x, evt.p.y ) );
159 bool rv = m_router->FixRoute( evt.p, ritem );
160 printf( " fix -> (%d, %d) ret %d\n", evt.p.x, evt.p.y, rv ? 1 : 0 );
161 break;
162 }
163
165 {
166 m_debugDecorator->NewStage( "unfix", 0, PNSLOGINFO );
167 m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
168 m_debugDecorator->Message( wxString::Format( "unfix (%d, %d)", evt.p.x, evt.p.y ) );
169 printf( " unfix\n" );
170 m_router->UndoLastSegment();
171 break;
172 }
173
174 case LOGGER::EVT_MOVE:
175 {
176 m_debugDecorator->NewStage( "move", 0, PNSLOGINFO );
177 m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
178
179 auto msg = wxString::Format( "event [%d/%d]: move (%d, %d)", eventIdx, totalEvents, evt.p.x, evt.p.y );
180
182 m_reporter->Report( msg );
183
184 bool ret = m_router->Move( evt.p, ritem );
186 break;
187 }
188
190 {
191 m_debugDecorator->NewStage( "toggle-via", 0, PNSLOGINFO );
192
193 auto msg = wxString::Format( "event [%d/%d]: toggle-via", eventIdx, totalEvents );
194
196 m_reporter->Report( msg );
197
198 m_viewTracker->SetStage( m_debugDecorator->GetStageCount() - 1 );
199 m_router->ToggleViaPlacement();
200 break;
201 }
202
203 default: break;
204 }
205
206 PNS::NODE* node = nullptr;
207
208#if 0
209 if( m_router->GetState() == PNS::ROUTER::ROUTE_TRACK )
210 {
211 m_debugDecorator->BeginGroup( "current route", 0 );
212
213 auto traces = m_router->Placer()->Traces();
214
215 for( const auto& t : traces.CItems() )
216 {
217 const LINE *l = static_cast<LINE*>(t.item);
218 const auto& sh = l->CLine();
219
220 m_debugDecorator->AddItem( l, YELLOW, 0, wxT( "line seg" ) );
221 }
222
224
225 node = m_router->Placer()->CurrentNode( true );
226 }
227 else if( m_router->GetState() == PNS::ROUTER::DRAG_SEGMENT )
228 {
229 node = m_router->GetDragger()->CurrentNode();
230 }
231 if( !node )
232 return;
233
234 NODE::ITEM_VECTOR removed, added;
235
236 node->GetUpdatedItems( removed, added );
237
238 if( ! added.empty() )
239 {
240 bool first = true;
241 m_debugDecorator->BeginGroup( wxT( "node-added-items" ), 0 );
242
243 for( auto t : added )
244 {
245 m_debugDecorator->AddItem( t, MAGENTA, 0, wxT( "seg" ) );
246 }
247
249 }
250#endif
251 }
252
253
254}
255
256
258{
259 auto cstate = GetRouterUpdatedItems();
260
261 printf("Comparing %zu added/%zu removed items\n", cstate.m_addedItems.size(), cstate.m_removedIds.size() );
262 return cstate.Compare( aLog->GetExpectedResult() );
263}
264
265
267 m_viewTracker( aViewTracker )
268{
269}
270
272{
273}
274
276{
277 //printf("DBG hide %p\n", aItem);
278 m_viewTracker->HideItem( aItem );
279}
280
281void PNS_LOG_PLAYER_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit, bool aIsHeadTrace )
282{
283 //printf("DBG disp %p\n", aItem);
284 m_viewTracker->DisplayItem( aItem );
285}
286
287
289{
290 if( aNet )
291 return static_cast<NETINFO_ITEM*>( aNet )->GetNetCode();
292 else
293 return -1;
294}
295
296
298{
299 if( aNet )
300 return static_cast<NETINFO_ITEM*>( aNet )->GetNetname();
301 else
302 return wxEmptyString;
303}
304
305
307{
308}
309
311{
312}
313
315{
316 m_currentStage = aStage;
318}
319
321{
322 ENTRY ent;
323 ent.isHideOp = true;
324 ent.item = aItem;
325 m_vitems[m_currentStage].push_back( ent );
326}
327
329{
330 ENTRY ent;
331 ent.isHideOp = false;
332 ent.item = aItem->Clone();
333 m_vitems[m_currentStage].push_back( ent );
334 //printf("DBG disp cur %d cnt %d\n", m_currentStage, m_vitems[m_currentStage].size() );
335}
336
int Start() const
Definition: pns_layerset.h:82
Handle the data for a net.
Definition: netinfo.h:67
static REPORTER & GetInstance()
Definition: reporter.cpp:119
Base class for PNS router board items.
Definition: pns_item.h:97
virtual ITEM * Clone() const =0
Return a deep copy of the item.
const LAYER_RANGE & Layers() const
Definition: pns_item.h:195
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
const SHAPE_LINE_CHAIN & CLine() const
Definition: pns_line.h:136
@ EVT_START_ROUTE
Definition: pns_logger.h:47
@ EVT_START_DRAG
Definition: pns_logger.h:48
@ EVT_TOGGLE_VIA
Definition: pns_logger.h:52
Keep the router "world" - i.e.
Definition: pns_node.h:198
std::vector< ITEM * > ITEM_VECTOR
Definition: pns_node.h:209
void GetUpdatedItems(ITEM_VECTOR &aRemoved, ITEM_VECTOR &aAdded)
Return the list of items removed and added in this branch with respect to the root branch.
Definition: pns_node.cpp:1393
Contain all persistent settings of the router, such as the mode, optimization effort,...
BOARD_CONNECTED_ITEM * ItemById(const PNS::LOGGER::EVENT_ENTRY &evt)
const COMMIT_STATE & GetExpectedResult() const
Definition: pns_log_file.h:87
PNS::ROUTING_SETTINGS * GetRoutingSettings() const
Definition: pns_log_file.h:85
std::vector< PNS::LOGGER::EVENT_ENTRY > & Events()
Definition: pns_log_file.h:80
std::shared_ptr< BOARD > GetBoard() const
Definition: pns_log_file.h:83
void DisplayItem(const PNS::ITEM *aItem, int aClearance, bool aEdit=false, bool aIsHeadTrace=false) override
int GetNetCode(PNS::NET_HANDLE aNet) const override
PNS_LOG_PLAYER_KICAD_IFACE(PNS_LOG_VIEW_TRACKER *aViewTracker)
PNS_LOG_VIEW_TRACKER * m_viewTracker
void HideItem(PNS::ITEM *aItem) override
wxString GetNetName(PNS::NET_HANDLE aNet) const override
PNS_TEST_DEBUG_DECORATOR * m_debugDecorator
std::shared_ptr< BOARD > m_board
const PNS_LOG_FILE::COMMIT_STATE GetRouterUpdatedItems()
REPORTER * m_reporter
bool CompareResults(PNS_LOG_FILE *aLog)
std::unique_ptr< PNS::ROUTER > m_router
std::shared_ptr< PNS_LOG_VIEW_TRACKER > m_viewTracker
std::unique_ptr< PNS_LOG_PLAYER_KICAD_IFACE > m_iface
void ReplayLog(PNS_LOG_FILE *aLog, int aStartEventIndex=0, int aFrom=0, int aTo=-1)
void SetReporter(REPORTER *aReporter)
std::map< int, VIEW_ENTRIES > m_vitems
void DisplayItem(const PNS::ITEM *aItem)
void HideItem(PNS::ITEM *aItem)
std::vector< ENTRY > VIEW_ENTRIES
void SetStage(int aStage)
virtual void AddItem(const PNS::ITEM *aItem, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void Message(const wxString &msg, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void BeginGroup(const wxString &name, int aLevel=0, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void EndGroup(const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void NewStage(const wxString &name, int iter, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void Clear() override
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
@ MAGENTA
Definition: color4d.h:60
@ YELLOW
Definition: color4d.h:67
@ F_Cu
Definition: layer_ids.h:65
Push and Shove diff pair dimensions (gap) settings dialog.
@ RM_Walkaround
Only walk around.
void * NET_HANDLE
Definition: pns_item.h:54
#define PNSLOGINFO
std::set< KIID > m_removedIds
Definition: pns_log_file.h:66
std::vector< PNS::ITEM * > m_addedItems
Definition: pns_log_file.h:67