KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_log_viewer_frame.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-2022 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#include <string>
28
29#include <confirm.h>
30#include <wx/clipbrd.h>
31#include <pgm_base.h>
32#include <core/profile.h>
33#include <reporter.h>
34#include <trace_helpers.h>
35#include <view/view_overlay.h>
36#include <view/view_controls.h>
38
39
40#include "label_manager.h"
41
42#include "pns_log_file.h"
43#include "pns_log_player.h"
45
47#include "router/pns_utils.h"
49
51
52class WX_SHAPE_TREE_ITEM_DATA : public wxClientData
53{
54public:
55 WX_SHAPE_TREE_ITEM_DATA( PNS_DEBUG_SHAPE* item, int level = 0 ) : m_item( item ), m_level( level ) {};
56
59};
60
61
63{
64 m_labelMgr.reset( new LABEL_MANAGER( aGal ) );
65}
66
67
69 bool aShowVertexNumbers )
70{
71 Polyline( aL );
72
73 if( name.length() > 0 && aL.PointCount() > 0 )
74 m_labelMgr->Add( aL.CPoint( -1 ), name, GetStrokeColor() );
75
76 if( aShowVertexNumbers )
77 {
78 for( int i = 0; i < aL.PointCount(); i++ )
79 m_labelMgr->Add( aL.CPoint(i), wxString::Format("%d", i ), GetStrokeColor() );
80 }
81}
82
83
84void PNS_LOG_VIEWER_OVERLAY::AnnotatedPoint( const VECTOR2I p, int size, std::string name, bool aShowVertexNumbers )
85{
86 Line( p + VECTOR2D( size, size ), p - VECTOR2D( size, size ) );
87 Line( p + VECTOR2D( -size, size ), p - VECTOR2D( -size, size ) );
88
89 if( name.length() > 0 )
90 m_labelMgr->Add( p, name, GetStrokeColor() );
91}
92
93
95{
96 double radius = arc.GetRadius();
97 EDA_ANGLE start_angle = arc.GetStartAngle();
98 EDA_ANGLE angle = arc.GetCentralAngle();
99
101 KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
102
104 COLOR4D lightStrokeCol = prevStrokeCol.WithAlpha(0.5);
105 KIGFX::VIEW_OVERLAY::SetStrokeColor( lightStrokeCol );
106
108 KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
109
111}
112
114{
115 m_labelMgr->Redraw( this );
116}
117
118
120 PNS_LOG_VIEWER_FRAME_BASE( frame ), m_rewindIter( 0 ), m_reporter( &m_consoleLog )
121{
122 LoadSettings();
124
125 m_viewSizer->Add( m_galPanel.get(), 1, wxEXPAND, 5 );
126
127 Layout();
128
129 Show( true );
130 Maximize();
131 Raise();
132
133 auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
134 m_galPanel->GetView()->GetPainter()->GetSettings() );
135
136
138
139 opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE;
140
141 double opacity = 0.5;
142
143 opts.m_TrackOpacity = opacity;
144 opts.m_ViaOpacity = opacity;
145 opts.m_PadOpacity = opacity;
146 opts.m_ZoneOpacity = opacity;
147
148 settings->LoadDisplayOptions( opts );
149
150
151 m_listPopupMenu = new wxMenu( wxT( "" ) );
152 m_listPopupMenu->Append( ID_LIST_COPY, wxT( "Copy selected geometry" ), wxT( "" ),
153 wxITEM_NORMAL );
154 m_listPopupMenu->Append( ID_LIST_SHOW_ALL, wxT( "Show all" ), wxT( "" ), wxITEM_NORMAL );
155 m_listPopupMenu->Append( ID_LIST_SHOW_NONE, wxT( "Show none" ), wxT( "" ), wxITEM_NORMAL );
156
157 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CONTEXT_MENU,
158 wxMouseEventHandler( PNS_LOG_VIEWER_FRAME::onListRightClick ), nullptr,
159 this );
160 //m_itemList->Connect(m_itemList->GetId(),wxEVT_LISTBOX,wxCommandEventHandler(PNS_LOG_VIEWER_FRAME::onListSelect),nullptr,this);
161 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_SELECTION_CHANGED,
162 wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListSelect ),
163 nullptr, this );
164 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CHECKED,
165 wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListChecked ),
166 nullptr, this );
167
168 m_itemList->AppendColumn( "Type" );
169 m_itemList->AppendColumn( "Value" );
170 m_itemList->AppendColumn( "File" );
171 m_itemList->AppendColumn( "Method" );
172 m_itemList->AppendColumn( "Line" );
173 m_itemList->AppendColumn( "VCount" );
174 m_itemList->AppendColumn( "Non-45" );
175
176 m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
177 m_galPanel->GetView()->Add( m_overlay.get() );
178 m_galPanel->GetViewControls()->EnableCursorWarping(false);
179
180 for( PCB_LAYER_ID layer : LSET::AllNonCuMask().Seq() )
181 m_galPanel->GetView()->SetLayerVisible( layer, false );
182}
183
184
186{
187 m_board = nullptr;
188 m_logPlayer = nullptr;
189 m_logFile = nullptr;
190 m_overlay = nullptr;
191}
192
193
195{
196
197}
198
199
201{
202 PNS_TEST_DEBUG_DECORATOR* dbgd = m_logPlayer->GetDebugDecorator();
203 int count = dbgd->GetStageCount();
204
205 int iter = m_rewindIter;
206
207 if( count <= 0 )
208 return nullptr;
209
210 if( iter < 0 )
211 iter = 0;
212
213 if( iter >= count )
214 iter = count - 1;
215
216 return dbgd->GetStage( iter );
217}
218
219
220void PNS_LOG_VIEWER_FRAME::drawSimpleShape( SHAPE* aShape, bool aIsSelected, const std::string& aName )
221{
222 switch( aShape->Type() )
223 {
224 case SH_CIRCLE:
225 {
226 auto cir = static_cast<SHAPE_CIRCLE*>( aShape );
227 m_overlay->Circle( cir->GetCenter(), cir->GetRadius() );
228
229 break;
230 }
231 case SH_SEGMENT:
232 {
233 auto seg = static_cast<SHAPE_SEGMENT*>( aShape );
234 m_overlay->Line( seg->GetSeg().A, seg->GetSeg().B );
235
236 break;
237 }
238 case SH_RECT:
239 {
240 auto rect = static_cast<SHAPE_RECT*>( aShape );
241 m_overlay->Rectangle( rect->GetPosition(), rect->GetPosition() + rect->GetSize() );
242
243 break;
244 }
245 case SH_LINE_CHAIN:
246 {
247 auto lc = static_cast<SHAPE_LINE_CHAIN*>( aShape );
248 m_overlay->AnnotatedPolyline( *lc, aName, m_showVertices || aIsSelected );
249
250 break;
251 }
252 default: break;
253 }
254}
255
256
258{
259 if( !m_logPlayer )
260 return;
261
263
264 if( !st )
265 return;
266
267 m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
268 m_galPanel->GetView()->Add( m_overlay.get() );
269 //m_galPanel->GetGAL()->EnableDepthTest( false );
270
271 auto drawShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
272 {
273 bool isEnabled = ent->IsVisible();
274 bool isSelected = ent->m_selected;
275
276 if( m_searchString.Length() > 0 )
277 isEnabled = ent->m_filterMatch;
278
279 if( !isEnabled )
280 return true;
281
282 for( auto& sh : ent->m_shapes )
283 {
284 COLOR4D color = ent->m_color;
285 int lineWidth = ent->m_width;
286
287 m_overlay->SetIsStroke( true );
288 m_overlay->SetIsFill( false );
289
290 if( isSelected )
291 {
292 color.Brighten( 0.5 );
293 }
294
295 color.a = 1.0;
296
297 m_overlay->SetStrokeColor( color );
298 m_overlay->SetLineWidth( m_showThinLines ? 10000 : ent->m_width );
299
300 if( sh->Type() == SH_COMPOUND )
301 {
302 auto cmpnd = static_cast<SHAPE_COMPOUND*>( sh );
303
304 for( auto subshape : cmpnd->Shapes() )
305 {
306 drawSimpleShape( subshape, isSelected, ent->m_name.ToStdString() );
307 }
308 }
309 else
310 {
311 drawSimpleShape( sh, isSelected, ent->m_name.ToStdString() );
312 }
313 }
314
315 return true;
316 };
317
319
320 m_overlay->DrawAnnotations();
321
322 m_galPanel->GetView()->MarkDirty();
323 m_galPanel->GetParent()->Refresh();
324}
325
326
327void PNS_LOG_VIEWER_FRAME::LoadLogFile( const wxString& aFile )
328{
329 std::unique_ptr<PNS_LOG_FILE> logFile( new PNS_LOG_FILE );
330
331 if( logFile->Load( wxFileName( aFile ), &m_reporter ) )
332 SetLogFile( logFile.release() );
333}
334
335
337{
338 m_logPlayer.reset( new PNS_LOG_PLAYER );
339 m_board = nullptr;
340 m_logFile.reset( aLog );
341
342 SetBoard( m_logFile->GetBoard() );
343
344 m_logPlayer->ReplayLog( m_logFile.get(), 0, 0, -1);
345
346 auto dbgd = m_logPlayer->GetDebugDecorator();
347 int n_stages = dbgd->GetStageCount();
348 m_rewindSlider->SetMax( n_stages - 1 );
349 m_rewindSlider->SetValue( n_stages - 1 );
350 m_rewindIter = n_stages - 1;
351
352 auto extents = m_board->GetBoundingBox();
353
354
355 BOX2D bbd;
356 bbd.SetOrigin( extents.GetOrigin() );
357 bbd.SetWidth( extents.GetWidth() );
358 bbd.SetHeight( extents.GetHeight() );
359 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
360
361 m_galPanel->GetView()->SetViewport( bbd );
362
366}
367
368
369void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
370{
371 SetBoard( aBoard );
372
373 auto extents = m_board->GetBoundingBox();
374
375 BOX2D bbd;
376 bbd.SetOrigin( extents.GetOrigin() );
377 bbd.SetWidth( extents.GetWidth() );
378 bbd.SetHeight( extents.GetHeight() );
379 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
380
381 m_galPanel->GetView()->SetViewport( bbd );
382}
383
384
385void PNS_LOG_VIEWER_FRAME::onOpen( wxCommandEvent& event )
386{
387 wxFileDialog dlg( this, "Select Log File", m_mruPath, wxEmptyString,
388 "PNS log files" + AddFileExtListToFilter( { "log" } ),
389 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
390
391 if( dlg.ShowModal() != wxID_CANCEL )
392 {
393 wxString logPath = dlg.GetPath();
394 LoadLogFile( logPath );
395 m_mruPath = wxFileName( logPath ).GetPath();
396 }
397}
398
399
400void PNS_LOG_VIEWER_FRAME::onSaveAs( wxCommandEvent& event )
401{
402 if( !m_logFile )
403 {
404 DisplayError( this, wxT( "No log file Loaded!" ) );
405 return;
406 }
407
408 wxFileDialog dlg( this, "New log file", m_mruPath, wxEmptyString,
409 "PNS log files" + AddFileExtListToFilter( { "log" } ),
410 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
411
412 if( dlg.ShowModal() != wxID_CANCEL )
413 {
414 // Enforce the extension, wxFileDialog is inept.
415 wxFileName create_me = EnsureFileExtension( dlg.GetPath(), "log" );
416
417 wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
418
419 m_logFile->SaveLog( create_me, &m_reporter );
420 m_mruPath = create_me.GetPath();
421 }
422
423}
424
425
426void PNS_LOG_VIEWER_FRAME::onExit( wxCommandEvent& event )
427{
428 Close();
429}
430
431
432void PNS_LOG_VIEWER_FRAME::onListChecked( wxCommandEvent& event )
433{
434 syncModel();
436}
437
439{
440 m_showThinLines = event.GetInt();
443}
444
445void PNS_LOG_VIEWER_FRAME::onShowRPIsChecked( wxCommandEvent& event )
446{
447 m_showRPIs = event.GetInt();
450}
451
453{
454 m_showVertices = event.GetInt();
457}
458
459
460void PNS_LOG_VIEWER_FRAME::onRewindScroll( wxScrollEvent& event )
461{
462 m_rewindIter = event.GetPosition();
466 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
467 event.Skip();
468}
469
470
471void PNS_LOG_VIEWER_FRAME::onBtnRewindLeft( wxCommandEvent& event )
472{
473 if( m_rewindIter > 0 )
474 {
475 m_rewindIter--;
479 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
480 m_rewindSlider->SetValue( m_rewindIter );
481 }
482}
483
484
485void PNS_LOG_VIEWER_FRAME::onBtnRewindRight( wxCommandEvent& event )
486{
487 auto dbgd = m_logPlayer->GetDebugDecorator();
488 int count = dbgd->GetStageCount();
489
490 if( m_rewindIter < count )
491 {
492 m_rewindIter++;
496 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
497 m_rewindSlider->SetValue( m_rewindIter );
498 }
499}
500
501void PNS_LOG_VIEWER_FRAME::onFilterText( wxCommandEvent& event )
502{
503 m_searchString = m_filterString->GetValue();
505}
506
507
508void PNS_LOG_VIEWER_FRAME::onRewindCountText( wxCommandEvent& event )
509{
510 if( !m_logPlayer )
511 return;
512
513 int val = wxAtoi( m_rewindPos->GetValue() );
514
515 auto dbgd = m_logPlayer->GetDebugDecorator();
516 int count = dbgd->GetStageCount();
517
518 if( val < 0 )
519 val = 0;
520
521 if( val >= count )
522 val = count - 1;
523
524 m_rewindIter = val;
525 m_rewindSlider->SetValue( m_rewindIter );
529
530 event.Skip();
531}
532
533
535{
536 for( wxTreeListItem item = m_itemList->GetFirstItem(); item.IsOk();
537 item = m_itemList->GetNextItem( item ) )
538 {
540 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( m_itemList->GetItemData( item ) );
541
542 if( idata )
543 {
544 bool checked = m_itemList->GetCheckedState( item ) == wxCHK_CHECKED;
545 bool selected = m_itemList->IsSelected( item );
546 idata->m_item->m_visible = checked || selected;
547 idata->m_item->m_selected = selected;
548 }
549 }
550}
551
552
553void PNS_LOG_VIEWER_FRAME::onListRightClick( wxMouseEvent& event )
554{
555 auto sel = m_itemList->GetPopupMenuSelectionFromUser( *m_listPopupMenu );
556
557 switch( sel )
558 {
560 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_UNCHECKED );
561 syncModel();
563 break;
564 case ID_LIST_SHOW_ALL:
565 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_CHECKED );
566 syncModel();
568 break;
569 case ID_LIST_COPY:
570 {
571 wxString s;
572
574
575 if( !st )
576 return;
577
578 auto formatShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
579 {
580 if( ent->m_selected )
581 {
582 for( auto sh : ent->m_shapes )
583 {
584 s += "// " + ent->m_name + "\n " + sh->Format() + "; \n";
585 }
586 }
587
588 return true;
589 };
590
591 st->m_entries->IterateTree( formatShapes );
592
593 if( wxTheClipboard->Open() )
594 {
595 // This data objects are held by the clipboard,
596 // so do not delete them in the app.
597 wxTheClipboard->SetData( new wxTextDataObject( s ) );
598 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
599 wxTheClipboard->Close();
600 }
601
602 return;
603 }
604 }
605}
606
607
608void PNS_LOG_VIEWER_FRAME::onListSelect( wxCommandEvent& event )
609{
610 syncModel();
612}
613
614
615
616static bool isLine45Degree( const SHAPE_LINE_CHAIN* lc )
617{
618 for( int i = 0; i < lc->SegmentCount(); i++ )
619 {
620 const SEG& s = lc->CSegment( i );
621
622 if( lc->IsArcSegment( i ) )
623 continue;
624
625 if( s.Length() < 10 )
626 continue;
627
628 double angle = 180.0 / M_PI *
629 atan2( (double) s.B.y - (double) s.A.y,
630 (double) s.B.x - (double) s.A.x );
631
632 if( angle < 0 )
633 angle += 360.0;
634
635 double angle_a = fabs( fmod( angle, 45.0 ) );
636
637 if( angle_a > 1.0 && angle_a < 44.0 )
638 return false;
639 }
640
641 return true;
642}
643
644
646{
647
648 std::set<PNS_DEBUG_SHAPE*> processed;
649 std::deque<PNS_DEBUG_SHAPE*> q;
650
651 q.push_back(ent);
652 int total = 0;
653 while ( q.size() > 0 )
654 {
655 PNS_DEBUG_SHAPE* top = q.front();
656
657 q.pop_front();
658
659 for ( auto chld : top->m_children )
660 {
661 bool match = m_searchString.Length() == 0 ? true : false;
662 //printf("CHK %s\n", (const char *) chld->m_name.c_str() );
663 chld->m_filterMatch = false;
664 if ( chld->m_name.Contains( m_searchString ) )
665 match = true;
666 if ( chld->m_msg.Contains( m_searchString ) )
667 match = true;
668
669 if( match )
670 {
671 for ( PNS_DEBUG_SHAPE *cur = chld; cur; cur = cur->m_parent )
672 cur->m_filterMatch = match;
673 }
674
675 if( processed.find(chld) == processed.end() )
676 {
677 q.push_back( chld );
678 processed.insert( chld );
679 }
680 }
681 total++;
682 }
683
684 printf("total: %d\n", total );
685
686 return false;
687}
688
689
690void PNS_LOG_VIEWER_FRAME::buildListTree( wxTreeListItem item,
691 PNS_DEBUG_SHAPE* ent, int depth )
692{
693#ifdef EXTRA_VERBOSE
694 for( int i = 0; i < depth * 2; i++ )
695 printf( " " );
696
697 if( ent->m_msg.length() )
698 printf( "MSG: %s\n", ent->m_msg.c_str() );
699 else
700 printf( "SHAPES: %s [%d]\n", ent->m_name.c_str(), ent->m_children.size() );
701#endif
702
703 wxTreeListItem ritem;
704
705 if( !ent->m_filterMatch )
706 return;
707
708 if( ent->m_msg.length() )
709 {
710 ritem = m_itemList->AppendItem( item, "Child" );
711 m_itemList->SetItemText( ritem, 0, "Message" );
712 m_itemList->SetItemText( ritem, 1, ent->m_msg );
713 }
714 else
715 {
716 ritem = m_itemList->AppendItem( item, "Child" );
717 int n_verts = 0;
718 for(auto sh : ent->m_shapes )
719 {
720 if ( sh->Type() == SH_LINE_CHAIN )
721 {
722 n_verts += static_cast<const SHAPE_LINE_CHAIN*>( sh )->PointCount();
723 }
724 }
725 m_itemList->SetItemText( ritem, 0, wxString::Format( "Shapes [%d verts]", n_verts ) );
726 m_itemList->SetItemText( ritem, 1, ent->m_name );
727 }
728
729 m_itemList->SetItemText( ritem, 2, wxFileNameFromPath( ent->m_srcLoc.fileName ) );
730 m_itemList->SetItemText( ritem, 3, ent->m_srcLoc.funcName );
731 m_itemList->SetItemText( ritem, 4, wxString::Format("%d", ent->m_srcLoc.line ) );
732
733 int totalVC = 0, totalVCSimplified = 0;
734 bool is45Degree = true;
735
736 for( SHAPE* sh : ent->m_shapes )
737 {
738 if( sh->Type() == SH_LINE_CHAIN )
739 {
740 auto lc = static_cast<SHAPE_LINE_CHAIN*>( sh );
741
742 totalVC += lc->PointCount();
743
744 SHAPE_LINE_CHAIN simp(*lc);
745
746 simp.Simplify();
747
748 totalVCSimplified += simp.PointCount();
749
750 if( !isLine45Degree( lc ) )
751 is45Degree = false;
752 }
753 }
754
755 if( totalVC > 0 )
756 m_itemList->SetItemText( ritem, 5, wxString::Format( "%d [%d]", totalVC, totalVCSimplified ) );
757
758 if( !is45Degree )
759 m_itemList->SetItemText( ritem, 6, wxT("") );
760
761 m_itemList->SetItemData( ritem, new WX_SHAPE_TREE_ITEM_DATA( ent, depth ) );
762
763 if( !ent->m_children.size() )
764 return;
765
766 for( auto child : ent->m_children )
767 {
768 buildListTree( ritem, child, depth + 1 );
769 }
770}
771
772
773static void expandAllChildren( wxTreeListCtrl* tree, int maxLevel = -1 )
774{
775 wxTreeListItem child = tree->GetFirstItem ();
776
777 while( child.IsOk() )
778 {
780 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( tree->GetItemData( child ) );
781
782 if( maxLevel < 0 || idata->m_level <= maxLevel )
783 tree->Expand ( child );
784 else
785 tree->Collapse ( child );
786 child = tree->GetNextItem( child );
787 }
788}
789
790static void collapseAllChildren( wxTreeListCtrl* tree )
791{
792 wxTreeListItem child = tree->GetFirstItem ();
793
794 while( child.IsOk() )
795 {
796 tree->Collapse ( child );
797 child = tree->GetNextItem( child );
798 }
799}
800
801
803{
804 printf("UpdateDUmp %d\n", iter );
805 if( !m_logPlayer )
806 return;
807
808 auto dbgd = m_logPlayer->GetDebugDecorator();
809 int count = dbgd->GetStageCount();
810
811 wxArrayString dumpStrings;
812
813 if( count <= 0 )
814 return;
815
816 if( iter < 0 )
817 iter = 0;
818
819 if( iter >= count )
820 iter = count - 1;
821
822 auto st = dbgd->GetStage( iter );
823
824 if( st->m_status )
825 {
826 m_algoStatus->SetLabel("OK");
827 m_algoStatus->SetForegroundColour( wxColor(*wxGREEN));
828 }
829 else
830 {
831 m_algoStatus->SetLabel("FAIL");
832 m_algoStatus->SetForegroundColour( wxColor(*wxRED));
833 }
834
835 auto rootItem = m_itemList->GetRootItem();
836
837 m_itemList->DeleteAllItems();
838 filterStringMatches( st->m_entries );
839 buildListTree( rootItem, st->m_entries );
840 m_itemList->CheckItemRecursively( rootItem, wxCHK_UNCHECKED );
841
843
844 m_itemList->Refresh();
845}
846
848{
849 auto viewTracker = m_logPlayer->GetViewTracker();
850 PNS_LOG_VIEW_TRACKER::VIEW_ENTRIES& entries = viewTracker->GetEntriesForStage( iter );
851 auto view = m_galPanel->GetView();
852 printf("DBG updatePnsPreviewItems: %zu items\n", entries.size() );
853
854 m_previewItems.reset( new KIGFX::VIEW_GROUP( m_galPanel->GetView() ) );
855 m_galPanel->GetView()->Add( m_previewItems.get() );
857 m_galPanel->GetView()->SetLayerVisible( LAYER_SELECT_OVERLAY );
858
859 if( !m_showRPIs )
860 return;
861
862 for( auto& ent : entries )
863 {
864 if ( ent.isHideOp )
865 {
866
867 auto parent = ent.item->Parent();
868 if( parent )
869 {
870
871 view->Hide( parent );
872 }
873 }
874 else
875 {
876 ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( ent.item, view );
877 pitem->Update( ent.item );
878 m_previewItems->Add(pitem);
879 // printf("DBG vadd %p total %d\n", pitem, m_previewItems->GetSize() );
880 }
881 }
882
883 view->SetVisible( m_previewItems.get(), true );
884
885 view->Update( m_previewItems.get() );
886 printf("DBG vgrp %p total %d\n", m_previewItems.get(), m_previewItems->GetSize() );
887
888
889 //view->UpdateAllItems( KIGFX::ALL );
890}
891
892#if 0
893
894static BOARD* loadBoard( const std::string& filename )
895{
897 BOARD* brd = nullptr;
898
899 try
900 {
901 brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
902 }
903 catch( const IO_ERROR& )
904 {
905 return nullptr;
906 }
907
908 return brd;
909}
910
911
912
913
914
915int render_perftest_main_func( int argc, char* argv[] )
916{
917 auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
918
919 // drcCreateTestsProviderClearance();
920 // drcCreateTestsProviderEdgeClearance();
921
922 if( argc >= 2 && std::string( argv[1] ) == "-h" )
923 {
924 printf( "PCB render performance test. Just renders a board without UI update overhead.\n" );
925 return 0;
926 }
927
928 if( argc < 2 )
929 {
930 printf( "Expected parameters: board_file\n" );
931 return 0;
932 }
933
934 PROF_TIMER cnt("load-board");
935 std::shared_ptr<BOARD> brd ( loadBoard( argv[1] ) );
936 cnt.Stop();
937
938 KI_TRACE( traceGalProfile, "%s\n", cnt.to_string() );
939
940 frame->SetBoard2( brd );
941
942 return 0;
943}
944
945
946static bool registered3 = UTILITY_REGISTRY::Register( {
947 "render_perftest",
948 "Renderer performance test",
949 render_perftest_main_func,
950} );
951
952
953VECTOR2I NearestPointFixpt( SEG seg, const VECTOR2I& aP )
954{
955 VECTOR2I d = seg.B - seg.A;
956 SEG::ecoord l_squared = d.Dot( d );
957
958 if( l_squared == 0 )
959 return seg.A;
960
961 SEG::ecoord t = d.Dot( aP - seg.A );
962
963 if( t < 0 )
964 return seg.A;
965 else if( t > l_squared )
966 return seg.B;
967
968 int xp = rescale( t, (SEG::ecoord) d.x, l_squared );
969 int yp = rescale( t, (SEG::ecoord) d.y, l_squared );
970
971 return seg.A + VECTOR2I( xp, yp );
972}
973
974
975VECTOR2D NearestPointDbl( SEG seg, const VECTOR2I& aP )
976{
977 VECTOR2D d = seg.B - seg.A;
978 double l_squared = d.Dot(d);
979
980 if( l_squared == 0 )
981 return seg.A;
982
983 double t = d.Dot(VECTOR2D( aP - seg.A ) );
984
985 if( t < 0 )
986 return seg.A;
987 else if( t > l_squared )
988 return seg.B;
989
990 double xp = t * d.x / l_squared;
991 double yp = t * d.y / l_squared;
992
993 return VECTOR2D(seg.A) + VECTOR2D( xp, yp );
994}
995
996int ttt_main_func( int argc, char* argv[] )
997{
998 int n = 1000000;
999 std::vector<VECTOR2I> pts;
1000 std::vector<SEG> segs;
1001 std::vector<VECTOR2D> rv;
1002 std::vector<VECTOR2I> rvi;
1003
1004
1005 rv.resize(n);
1006 rvi.resize(n);
1007
1008 for (int i = 0; i < n ;i++)
1009 {
1010 pts.push_back(VECTOR2I(random()%100000000, random()%100000000));
1011 segs.push_back(SEG( VECTOR2I(random()%100000000, random()%100000000), VECTOR2I(random()%100000000, random()%100000000) ) );
1012 }
1013
1014 PROF_TIMER tmrFix("nearest-fixpt");
1015 for(int i = 0; i < n ; i++)
1016 {
1017 rvi[i] = NearestPointFixpt( segs[i], pts[i]);
1018 }
1019 tmrFix.Show();
1020
1021 PROF_TIMER tmrDbl("nearest-double");
1022 for(int i = 0; i < n ; i++)
1023 {
1024 rv[i] = NearestPointDbl( segs[i], pts[i]);
1025 }
1026 tmrDbl.Show();
1027 return 0;
1028}
1029
1030
1031
1032static bool registered4 = UTILITY_REGISTRY::Register( {
1033 "ttt",
1034 "Renderer performance test",
1035 ttt_main_func,
1036} );
1037
1038#endif
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
void SetOrigin(const Vec &pos)
Definition: box2.h:203
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetWidth() const
Definition: box2.h:188
void SetWidth(coord_type val)
Definition: box2.h:246
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:507
void SetHeight(coord_type val)
Definition: box2.h:251
@ GAL_TYPE_OPENGL
OpenGL implementation.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:311
Abstract interface for drawing on a 2D-surface.
PCB specific render settings.
Definition: pcb_painter.h:76
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition: view_group.h:48
void SetLineWidth(double aLineWidth)
void Polyline(const SHAPE_LINE_CHAIN &aPolyLine)
const COLOR4D & GetStrokeColor() const
Definition: view_overlay.h:104
void Line(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
void Arc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle)
void SetStrokeColor(const COLOR4D &aColor)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:803
double m_TrackOpacity
Opacity override for all tracks.
double m_ZoneOpacity
Opacity override for filled zone areas.
double m_PadOpacity
Opacity override for SMD pads and PTHs.
double m_ViaOpacity
Opacity override for all types of via.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
Definition: pcb_plugin.h:275
std::shared_ptr< BOARD > m_board
std::shared_ptr< PCB_DRAW_PANEL_GAL > m_galPanel
void createView(wxWindow *aParent, PCB_DRAW_PANEL_GAL::GAL_TYPE aGalType=PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL)
virtual void SetBoard(std::shared_ptr< BOARD > b)
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:614
std::vector< SHAPE * > m_shapes
void IterateTree(std::function< bool(PNS_DEBUG_SHAPE *)> visitor, int depth=0)
PNS_DEBUG_SHAPE * m_parent
PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO m_srcLoc
std::vector< PNS_DEBUG_SHAPE * > m_children
Class PNS_LOG_VIEWER_FRAME_BASE.
std::shared_ptr< PNS_LOG_FILE > m_logFile
virtual void onListRightClick(wxMouseEvent &event)
std::shared_ptr< PNS_LOG_PLAYER > m_logPlayer
void drawSimpleShape(SHAPE *aShape, bool aIsSelected, const std::string &aName)
virtual void onRewindCountText(wxCommandEvent &event) override
std::shared_ptr< KIGFX::VIEW_GROUP > m_previewItems
PNS_DEBUG_STAGE * getCurrentStage()
bool filterStringMatches(PNS_DEBUG_SHAPE *ent)
void SetBoard2(std::shared_ptr< BOARD > aBoard)
virtual void createUserTools() override
void buildListTree(wxTreeListItem item, PNS_DEBUG_SHAPE *ent, int depth=0)
virtual void onShowVerticesChecked(wxCommandEvent &event) override
void SetLogFile(PNS_LOG_FILE *aLog)
virtual void onShowThinLinesChecked(wxCommandEvent &event) override
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > m_overlay
void LoadLogFile(const wxString &aFile)
virtual void onListChecked(wxCommandEvent &event)
virtual void onListSelect(wxCommandEvent &event)
KI_TEST::CONSOLE_MSG_REPORTER m_reporter
virtual void onSaveAs(wxCommandEvent &event) override
virtual void onRewindScroll(wxScrollEvent &event) override
virtual void onShowRPIsChecked(wxCommandEvent &event) override
void updatePnsPreviewItems(int iter)
virtual void onBtnRewindRight(wxCommandEvent &event) override
virtual void onFilterText(wxCommandEvent &event) override
PNS_LOG_VIEWER_FRAME(wxFrame *frame)
virtual void onOpen(wxCommandEvent &event) override
virtual void onBtnRewindLeft(wxCommandEvent &event) override
virtual void onExit(wxCommandEvent &event) override
void AnnotatedPoint(const VECTOR2I p, int size, std::string name="", bool aShowVertexNumbers=false)
void AnnotatedPolyline(const SHAPE_LINE_CHAIN &aL, std::string name, bool aShowVertexNumbers=false)
PNS_LOG_VIEWER_OVERLAY(KIGFX::GAL *aGal)
std::unique_ptr< LABEL_MANAGER > m_labelMgr
void Arc(const SHAPE_ARC &arc)
std::vector< ENTRY > VIEW_ENTRIES
PNS_DEBUG_STAGE * GetStage(int index)
A small class to help profiling.
Definition: profile.h:47
void Update(const PNS::ITEM *aItem)
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I::extended_type ecoord
Definition: seg.h:44
VECTOR2I B
Definition: seg.h:50
int Length() const
Return the length (this).
Definition: seg.h:326
EDA_ANGLE GetCentralAngle() const
Definition: shape_arc.cpp:449
int GetWidth() const
Definition: shape_arc.h:157
double GetRadius() const
Definition: shape_arc.cpp:465
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:420
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:434
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:98
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
SHAPE_LINE_CHAIN & Simplify(bool aRemoveColinear=true)
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
bool IsArcSegment(size_t aSegment) const
An abstract shape on 2D plane.
Definition: shape.h:126
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:465
WX_SHAPE_TREE_ITEM_DATA(PNS_DEBUG_SHAPE *item, int level=0)
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
Definition: common.cpp:398
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
This file is part of the common library.
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:220
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
see class PGM_BASE
int drawShapes(int argc, char *argv[])
Definition: playground.cpp:231
static bool isLine45Degree(const SHAPE_LINE_CHAIN *lc)
static void collapseAllChildren(wxTreeListCtrl *tree)
static void expandAllChildren(wxTreeListCtrl *tree, int maxLevel=-1)
#define ID_LIST_COPY
#define ID_LIST_SHOW_ALL
#define ID_LIST_SHOW_NONE
@ SH_RECT
axis-aligned rectangle
Definition: shape.h:47
@ SH_CIRCLE
circle
Definition: shape.h:50
@ SH_SEGMENT
line segment
Definition: shape.h:48
@ SH_LINE_CHAIN
line chain (polyline)
Definition: shape.h:49
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
Definition: shape.h:53
PNS_DEBUG_SHAPE * m_entries
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
Definition: util.h:118
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
Definition of file extensions used in Kicad.