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, 2024 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
68void PNS_LOG_VIEWER_OVERLAY::AnnotatedPolyset( const SHAPE_POLY_SET& aPolyset, std::string aName,
69 bool aShowVertexNumbers )
70{
71 for( int i = 0; i < aPolyset.OutlineCount(); i++ )
72 {
73 if( i == 0 && !aName.empty() )
74 AnnotatedPolyline( aPolyset.COutline( i ), aName );
75 else
76 AnnotatedPolyline( aPolyset.COutline( i ), "" );
77
78 for( int j = 0; j < aPolyset.HoleCount( i ); j++ )
79 AnnotatedPolyline( aPolyset.CHole( i, j ), "" );
80 }
81}
82
83
85 bool aShowVertexNumbers )
86{
87 Polyline( aL );
88
89 if( name.length() > 0 && aL.PointCount() > 0 )
90 m_labelMgr->Add( aL.CPoint( -1 ), name, GetStrokeColor() );
91
92 if( aShowVertexNumbers )
93 {
94 for( int i = 0; i < aL.PointCount(); i++ )
95 m_labelMgr->Add( aL.CPoint(i), wxString::Format("%d", i ), GetStrokeColor() );
96 }
97}
98
99
100void PNS_LOG_VIEWER_OVERLAY::AnnotatedPoint( const VECTOR2I p, int size, std::string name, bool aShowVertexNumbers )
101{
102 Line( p + VECTOR2D( size, size ), p - VECTOR2D( size, size ) );
103 Line( p + VECTOR2D( -size, size ), p - VECTOR2D( -size, size ) );
104
105 if( name.length() > 0 )
106 m_labelMgr->Add( p, name, GetStrokeColor() );
107}
108
109
111{
112 double radius = arc.GetRadius();
113 EDA_ANGLE start_angle = arc.GetStartAngle();
114 EDA_ANGLE angle = arc.GetCentralAngle();
115
117 KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
118
120 COLOR4D lightStrokeCol = prevStrokeCol.WithAlpha(0.5);
121 KIGFX::VIEW_OVERLAY::SetStrokeColor( lightStrokeCol );
122
124 KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
125
127}
128
130{
131 m_labelMgr->Redraw( this );
132}
133
134
136 PNS_LOG_VIEWER_FRAME_BASE( frame ), m_rewindIter( 0 )
137{
138 LoadSettings();
140
142 m_galPanel->SetParent( m_mainSplitter );
143 m_mainSplitter->SplitHorizontally( m_galPanel.get(), m_panelProps );
144
145 Layout();
146
147 Show( true );
148 Maximize();
149 Raise();
150
151 auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
152 m_galPanel->GetView()->GetPainter()->GetSettings() );
153
154
156
157 opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE;
158
159 double opacity = 0.5;
160
161 opts.m_TrackOpacity = opacity;
162 opts.m_ViaOpacity = opacity;
163 opts.m_PadOpacity = opacity;
164 opts.m_ZoneOpacity = opacity;
165
166 settings->LoadDisplayOptions( opts );
167
168
169 m_listPopupMenu = new wxMenu( wxT( "" ) );
170 m_listPopupMenu->Append( ID_LIST_COPY, wxT( "Copy selected geometry" ), wxT( "" ),
171 wxITEM_NORMAL );
172 m_listPopupMenu->Append( ID_LIST_SHOW_ALL, wxT( "Show all" ), wxT( "" ), wxITEM_NORMAL );
173 m_listPopupMenu->Append( ID_LIST_SHOW_NONE, wxT( "Show none" ), wxT( "" ), wxITEM_NORMAL );
174 m_listPopupMenu->Append( ID_LIST_DISPLAY_LINE, wxT( "Go to line in IDE" ), wxT( "" ), wxITEM_NORMAL );
175
176 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CONTEXT_MENU,
177 wxMouseEventHandler( PNS_LOG_VIEWER_FRAME::onListRightClick ), nullptr,
178 this );
179 //m_itemList->Connect(m_itemList->GetId(),wxEVT_LISTBOX,wxCommandEventHandler(PNS_LOG_VIEWER_FRAME::onListSelect),nullptr,this);
180 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_SELECTION_CHANGED,
181 wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListSelect ),
182 nullptr, this );
183 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CHECKED,
184 wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListChecked ),
185 nullptr, this );
186
187 m_itemList->AppendColumn( "Type" );
188 m_itemList->AppendColumn( "Value" );
189 m_itemList->AppendColumn( "File" );
190 m_itemList->AppendColumn( "Method" );
191 m_itemList->AppendColumn( "Line" );
192 m_itemList->AppendColumn( "VCount" );
193 m_itemList->AppendColumn( "Non-45" );
194
195 m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
196 m_galPanel->GetView()->Add( m_overlay.get() );
197 m_galPanel->GetViewControls()->EnableCursorWarping(false);
198
199 for( PCB_LAYER_ID layer : LSET::AllNonCuMask().Seq() )
200 m_galPanel->GetView()->SetLayerVisible( layer, false );
201}
202
203
205{
206 m_board = nullptr;
207 m_logPlayer = nullptr;
208 m_logFile = nullptr;
209 m_overlay = nullptr;
210}
211
212
214{
215
216}
217
218
220{
221 PNS_TEST_DEBUG_DECORATOR* dbgd = m_logPlayer->GetDebugDecorator();
222 int count = dbgd->GetStageCount();
223
224 int iter = m_rewindIter;
225
226 if( count <= 0 )
227 return nullptr;
228
229 if( iter < 0 )
230 iter = 0;
231
232 if( iter >= count )
233 iter = count - 1;
234
235 return dbgd->GetStage( iter );
236}
237
238
239void PNS_LOG_VIEWER_FRAME::drawSimpleShape( SHAPE* aShape, bool aIsSelected, const std::string& aName )
240{
241 switch( aShape->Type() )
242 {
243 case SH_CIRCLE:
244 {
245 auto cir = static_cast<SHAPE_CIRCLE*>( aShape );
246 m_overlay->Circle( cir->GetCenter(), cir->GetRadius() );
247
248 break;
249 }
250 case SH_SEGMENT:
251 {
252 auto seg = static_cast<SHAPE_SEGMENT*>( aShape );
253 m_overlay->Line( seg->GetSeg().A, seg->GetSeg().B );
254
255 break;
256 }
257 case SH_RECT:
258 {
259 auto rect = static_cast<SHAPE_RECT*>( aShape );
260 m_overlay->Rectangle( rect->GetPosition(), rect->GetPosition() + rect->GetSize() );
261
262 break;
263 }
264 case SH_LINE_CHAIN:
265 {
266 auto lc = static_cast<SHAPE_LINE_CHAIN*>( aShape );
267 m_overlay->AnnotatedPolyline( *lc, aName, m_showVertices || aIsSelected );
268
269 break;
270 }
271 default: break;
272 }
273}
274
275
277{
278 if( !m_logPlayer )
279 return;
280
282
283 if( !st )
284 return;
285
286 m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
287 m_galPanel->GetView()->Add( m_overlay.get() );
288 //m_galPanel->GetGAL()->EnableDepthTest( false );
289
290 auto drawShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
291 {
292 bool isEnabled = ent->IsVisible();
293 bool isSelected = ent->m_selected;
294
295 if( m_searchString.Length() > 0 )
296 isEnabled = ent->m_filterMatch;
297
298 if( !isEnabled )
299 return true;
300
301 for( auto& sh : ent->m_shapes )
302 {
303 COLOR4D color = ent->m_color;
304 int lineWidth = ent->m_width;
305
306 m_overlay->SetIsStroke( true );
307 m_overlay->SetIsFill( false );
308
309 if( isSelected )
310 {
311 color.Brighten( 0.5 );
312 }
313
314 color.a = 1.0;
315
316 m_overlay->SetStrokeColor( color );
317 m_overlay->SetLineWidth( m_showThinLines ? 10000 : ent->m_width );
318
319 if( sh->Type() == SH_COMPOUND )
320 {
321 auto cmpnd = static_cast<SHAPE_COMPOUND*>( sh );
322
323 for( auto subshape : cmpnd->Shapes() )
324 {
325 drawSimpleShape( subshape, isSelected, ent->m_name.ToStdString() );
326 }
327 }
328 else
329 {
330 drawSimpleShape( sh, isSelected, ent->m_name.ToStdString() );
331 }
332 }
333
334 return true;
335 };
336
338
339 m_overlay->DrawAnnotations();
340
341 m_galPanel->GetView()->MarkDirty();
342 m_galPanel->GetParent()->Refresh();
343}
344
345
346void PNS_LOG_VIEWER_FRAME::LoadLogFile( const wxString& aFile )
347{
348 std::unique_ptr<PNS_LOG_FILE> logFile( new PNS_LOG_FILE );
349
350 if( logFile->Load( wxFileName( aFile ), m_reporter.get() ) )
351 SetLogFile( logFile.release() );
352}
353
354
356{
357 m_viewerIface = std::make_shared<PNS_VIEWER_IFACE>( m_board );
358}
359
360
362{
363 m_logPlayer.reset( new PNS_LOG_PLAYER );
364 m_board = nullptr;
365 m_logFile.reset( aLog );
366
367 SetBoard( m_logFile->GetBoard() );
369 m_logPlayer->ReplayLog( m_logFile.get(), 0, 0, -1, true );
370
371 auto dbgd = m_logPlayer->GetDebugDecorator();
372 int n_stages = dbgd->GetStageCount();
373 m_rewindSlider->SetMax( n_stages - 1 );
374 m_rewindSlider->SetValue( n_stages - 1 );
375 m_rewindIter = n_stages - 1;
376
377 auto extents = m_board->GetBoundingBox();
378
379
380 BOX2D bbd;
381 bbd.SetOrigin( extents.GetOrigin() );
382 bbd.SetWidth( extents.GetWidth() );
383 bbd.SetHeight( extents.GetHeight() );
384 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
385
386 m_galPanel->GetView()->SetViewport( bbd );
387
391
392}
393
394
395void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
396{
397 SetBoard( aBoard );
399 auto extents = m_board->GetBoundingBox();
400
401 BOX2D bbd;
402 bbd.SetOrigin( extents.GetOrigin() );
403 bbd.SetWidth( extents.GetWidth() );
404 bbd.SetHeight( extents.GetHeight() );
405 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
406
407 m_galPanel->GetView()->SetViewport( bbd );
408}
409
410
411void PNS_LOG_VIEWER_FRAME::onOpen( wxCommandEvent& event )
412{
413 wxFileDialog dlg( this, "Select Log File", m_mruPath, wxEmptyString,
414 "PNS log files" + AddFileExtListToFilter( { "log" } ),
415 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
416
417 if( dlg.ShowModal() != wxID_CANCEL )
418 {
419 wxString logPath = dlg.GetPath();
420 LoadLogFile( logPath );
421 m_mruPath = wxFileName( logPath ).GetPath();
422 }
423}
424
425
426void PNS_LOG_VIEWER_FRAME::onSaveAs( wxCommandEvent& event )
427{
428 if( !m_logFile )
429 {
430 DisplayError( this, wxT( "No log file Loaded!" ) );
431 return;
432 }
433
434 wxFileDialog dlg( this, "New log file", m_mruPath, wxEmptyString,
435 "PNS log files" + AddFileExtListToFilter( { "log" } ),
436 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
437
438 if( dlg.ShowModal() != wxID_CANCEL )
439 {
440 // Enforce the extension, wxFileDialog is inept.
441 wxFileName create_me = EnsureFileExtension( dlg.GetPath(), "log" );
442
443 wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
444
445 m_logFile->SaveLog( create_me, m_reporter.get() );
446 m_mruPath = create_me.GetPath();
447 }
448
449}
450
451
452void PNS_LOG_VIEWER_FRAME::onExit( wxCommandEvent& event )
453{
454 Close();
455}
456
457
458void PNS_LOG_VIEWER_FRAME::onListChecked( wxCommandEvent& event )
459{
460 syncModel();
462}
463
465{
466 m_showThinLines = event.GetInt();
469}
470
471void PNS_LOG_VIEWER_FRAME::onShowRPIsChecked( wxCommandEvent& event )
472{
473 m_showRPIs = event.GetInt();
476}
477
479{
480 m_showVertices = event.GetInt();
483}
484
485
486void PNS_LOG_VIEWER_FRAME::onRewindScroll( wxScrollEvent& event )
487{
488 m_rewindIter = event.GetPosition();
492 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
493 event.Skip();
494}
495
496
497void PNS_LOG_VIEWER_FRAME::onBtnRewindLeft( wxCommandEvent& event )
498{
499 if( m_rewindIter > 0 )
500 {
501 m_rewindIter--;
505 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
506 m_rewindSlider->SetValue( m_rewindIter );
507 }
508}
509
510
511void PNS_LOG_VIEWER_FRAME::onBtnRewindRight( wxCommandEvent& event )
512{
513 auto dbgd = m_logPlayer->GetDebugDecorator();
514 int count = dbgd->GetStageCount();
515
516 if( m_rewindIter < count )
517 {
518 m_rewindIter++;
522 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
523 m_rewindSlider->SetValue( m_rewindIter );
524 }
525}
526
527void PNS_LOG_VIEWER_FRAME::onFilterText( wxCommandEvent& event )
528{
529 m_searchString = m_filterString->GetValue();
531}
532
533
534void PNS_LOG_VIEWER_FRAME::onRewindCountText( wxCommandEvent& event )
535{
536 if( !m_logPlayer )
537 return;
538
539 int val = wxAtoi( m_rewindPos->GetValue() );
540
541 auto dbgd = m_logPlayer->GetDebugDecorator();
542 int count = dbgd->GetStageCount();
543
544 if( val < 0 )
545 val = 0;
546
547 if( val >= count )
548 val = count - 1;
549
550 m_rewindIter = val;
551 m_rewindSlider->SetValue( m_rewindIter );
555
556 event.Skip();
557}
558
559
561{
562 for( wxTreeListItem item = m_itemList->GetFirstItem(); item.IsOk();
563 item = m_itemList->GetNextItem( item ) )
564 {
566 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( m_itemList->GetItemData( item ) );
567
568 if( idata )
569 {
570 bool checked = m_itemList->GetCheckedState( item ) == wxCHK_CHECKED;
571 bool selected = m_itemList->IsSelected( item );
572 idata->m_item->m_visible = checked || selected;
573 idata->m_item->m_selected = selected;
574 }
575 }
576}
577
578
579void runCommand( const wxString& aCommand )
580{
581#ifdef __WXMSW__
582 wxShell( aCommand ); // on windows we need to launch a shell in order to run the command
583#else
584 wxExecute( aCommand );
585#endif /* __WXMSW__ */
586}
587
588
589void PNS_LOG_VIEWER_FRAME::onListRightClick( wxMouseEvent& event )
590{
591 auto sel = m_itemList->GetPopupMenuSelectionFromUser( *m_listPopupMenu );
592
593 switch( sel )
594 {
596 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_UNCHECKED );
597 syncModel();
599 break;
600 case ID_LIST_SHOW_ALL:
601 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_CHECKED );
602 syncModel();
604 break;
605 case ID_LIST_COPY:
606 {
607 wxString s;
608
610
611 if( !st )
612 return;
613
614 auto formatShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
615 {
616 if( ent->m_selected )
617 {
618 for( auto sh : ent->m_shapes )
619 {
620 s += "// " + ent->m_name + "\n " + sh->Format() + "; \n";
621 }
622 }
623
624 return true;
625 };
626
627 st->m_entries->IterateTree( formatShapes );
628
629 if( wxTheClipboard->Open() )
630 {
631 // This data objects are held by the clipboard,
632 // so do not delete them in the app.
633 wxTheClipboard->SetData( new wxTextDataObject( s ) );
634 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
635 wxTheClipboard->Close();
636 }
637
638 return;
639 }
641 {
642 wxVector<wxTreeListItem> selectedItems;
643
644 if( m_itemList->GetSelections( selectedItems ) == 1 )
645 {
646 wxString filename = m_itemList->GetItemText(selectedItems.back(), 2);
647 wxString line = m_itemList->GetItemText(selectedItems.back(), 4);
648
649
650 if( !filename.empty() && !line.empty() )
651 {
652 wxString filepath = m_filenameToPathMap[filename];
653
654 switch( m_ideChoice->GetCurrentSelection() )
655 {
656 case 0: runCommand( wxString::Format( "code --goto %s:%s", filepath, line ) ); return;
657 case 1: runCommand( wxString::Format( "start devenv /edit %s /command \"Gotoln %s\"", filepath, line ) ); return; // fixme
658 case 2: runCommand( wxString::Format( "clion --line %s %s", line, filepath ) ); return;
659 case 3: runCommand( wxString::Format( "emacsclient +%s %s", line, filepath ) ); return;
660 default: return;
661 }
662 }
663 }
664 break;
665 }
666 }
667 return;
668}
669
670
671void PNS_LOG_VIEWER_FRAME::onListSelect( wxCommandEvent& event )
672{
673 syncModel();
675}
676
677
678
679static bool isLine45Degree( const SHAPE_LINE_CHAIN* lc )
680{
681 for( int i = 0; i < lc->SegmentCount(); i++ )
682 {
683 const SEG& s = lc->CSegment( i );
684
685 if( lc->IsArcSegment( i ) )
686 continue;
687
688 if( s.Length() < 10 )
689 continue;
690
691 double angle = 180.0 / M_PI *
692 atan2( (double) s.B.y - (double) s.A.y,
693 (double) s.B.x - (double) s.A.x );
694
695 if( angle < 0 )
696 angle += 360.0;
697
698 double angle_a = fabs( fmod( angle, 45.0 ) );
699
700 if( angle_a > 1.0 && angle_a < 44.0 )
701 return false;
702 }
703
704 return true;
705}
706
707
709{
710
711 std::set<PNS_DEBUG_SHAPE*> processed;
712 std::deque<PNS_DEBUG_SHAPE*> q;
713
714 q.push_back(ent);
715 int total = 0;
716 while ( q.size() > 0 )
717 {
718 PNS_DEBUG_SHAPE* top = q.front();
719
720 q.pop_front();
721
722 for ( auto chld : top->m_children )
723 {
724 bool match = m_searchString.Length() == 0 ? true : false;
725 //printf("CHK %s\n", (const char *) chld->m_name.c_str() );
726 chld->m_filterMatch = false;
727 if ( chld->m_name.Contains( m_searchString ) )
728 match = true;
729 if ( chld->m_msg.Contains( m_searchString ) )
730 match = true;
731
732 if( match )
733 {
734 for ( PNS_DEBUG_SHAPE *cur = chld; cur; cur = cur->m_parent )
735 cur->m_filterMatch = match;
736 }
737
738 if( processed.find(chld) == processed.end() )
739 {
740 q.push_back( chld );
741 processed.insert( chld );
742 }
743 }
744 total++;
745 }
746
747 printf("total: %d\n", total );
748
749 return false;
750}
751
752
753void PNS_LOG_VIEWER_FRAME::buildListTree( wxTreeListItem item,
754 PNS_DEBUG_SHAPE* ent, int depth )
755{
756#ifdef EXTRA_VERBOSE
757 for( int i = 0; i < depth * 2; i++ )
758 printf( " " );
759
760 if( ent->m_msg.length() )
761 printf( "MSG: %s\n", ent->m_msg.c_str() );
762 else
763 printf( "SHAPES: %s [%d]\n", ent->m_name.c_str(), ent->m_children.size() );
764#endif
765
766 wxTreeListItem ritem;
767
768 if( !ent->m_filterMatch )
769 return;
770
771 if( ent->m_msg.length() )
772 {
773 ritem = m_itemList->AppendItem( item, "Child" );
774 m_itemList->SetItemText( ritem, 0, "Message" );
775 m_itemList->SetItemText( ritem, 1, ent->m_msg );
776 }
777 else
778 {
779 ritem = m_itemList->AppendItem( item, "Child" );
780 int n_verts = 0;
781 for(auto sh : ent->m_shapes )
782 {
783 if ( sh->Type() == SH_LINE_CHAIN )
784 {
785 n_verts += static_cast<const SHAPE_LINE_CHAIN*>( sh )->PointCount();
786 }
787 }
788 m_itemList->SetItemText( ritem, 0, wxString::Format( "Shapes [%d verts]", n_verts ) );
789 m_itemList->SetItemText( ritem, 1, ent->m_name );
790 }
791
792 wxString fullfilepath = ent->m_srcLoc.fileName;
793 wxString filename = wxFileNameFromPath( fullfilepath );
794
795 if( !filename.empty() )
796 m_filenameToPathMap.insert( { filename, fullfilepath } );
797
798 m_itemList->SetItemText( ritem, 2, filename );
799 m_itemList->SetItemText( ritem, 3, ent->m_srcLoc.funcName );
800 m_itemList->SetItemText( ritem, 4, wxString::Format("%d", ent->m_srcLoc.line ) );
801
802 int totalVC = 0, totalVCSimplified = 0;
803 bool is45Degree = true;
804
805 for( SHAPE* sh : ent->m_shapes )
806 {
807 if( sh->Type() == SH_LINE_CHAIN )
808 {
809 auto lc = static_cast<SHAPE_LINE_CHAIN*>( sh );
810
811 totalVC += lc->PointCount();
812
813 SHAPE_LINE_CHAIN simp(*lc);
814
815 simp.Simplify();
816
817 totalVCSimplified += simp.PointCount();
818
819 if( !isLine45Degree( lc ) )
820 is45Degree = false;
821 }
822 }
823
824 if( totalVC > 0 )
825 m_itemList->SetItemText( ritem, 5, wxString::Format( "%d [%d]", totalVC, totalVCSimplified ) );
826
827 if( !is45Degree )
828 m_itemList->SetItemText( ritem, 6, wxT("") );
829
830 m_itemList->SetItemData( ritem, new WX_SHAPE_TREE_ITEM_DATA( ent, depth ) );
831
832 if( !ent->m_children.size() )
833 return;
834
835 for( auto child : ent->m_children )
836 {
837 buildListTree( ritem, child, depth + 1 );
838 }
839}
840
841
842static void expandAllChildren( wxTreeListCtrl* tree, int maxLevel = -1 )
843{
844 wxTreeListItem child = tree->GetFirstItem ();
845
846 while( child.IsOk() )
847 {
849 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( tree->GetItemData( child ) );
850
851 if( maxLevel < 0 || idata->m_level <= maxLevel )
852 tree->Expand ( child );
853 else
854 tree->Collapse ( child );
855 child = tree->GetNextItem( child );
856 }
857}
858
859static void collapseAllChildren( wxTreeListCtrl* tree )
860{
861 wxTreeListItem child = tree->GetFirstItem ();
862
863 while( child.IsOk() )
864 {
865 tree->Collapse ( child );
866 child = tree->GetNextItem( child );
867 }
868}
869
870
872{
873 printf("UpdateDUmp %d\n", iter );
874 if( !m_logPlayer )
875 return;
876
877 auto dbgd = m_logPlayer->GetDebugDecorator();
878 int count = dbgd->GetStageCount();
879
880 wxArrayString dumpStrings;
881
882 if( count <= 0 )
883 return;
884
885 if( iter < 0 )
886 iter = 0;
887
888 if( iter >= count )
889 iter = count - 1;
890
891 auto st = dbgd->GetStage( iter );
892
893 if( st->m_status )
894 {
895 m_algoStatus->SetLabel("OK");
896 m_algoStatus->SetForegroundColour( wxColor(*wxGREEN));
897 }
898 else
899 {
900 m_algoStatus->SetLabel("FAIL");
901 m_algoStatus->SetForegroundColour( wxColor(*wxRED));
902 }
903
904 auto rootItem = m_itemList->GetRootItem();
905
906 m_itemList->DeleteAllItems();
907 filterStringMatches( st->m_entries );
908 buildListTree( rootItem, st->m_entries );
909 m_itemList->CheckItemRecursively( rootItem, wxCHK_UNCHECKED );
910
912
913 m_itemList->Refresh();
914}
915
917{
918 auto viewTracker = m_logPlayer->GetViewTracker();
919 PNS_LOG_VIEW_TRACKER::VIEW_ENTRIES& entries = viewTracker->GetEntriesForStage( iter );
920 auto view = m_galPanel->GetView();
921 printf("DBG updatePnsPreviewItems: %zu items\n", entries.size() );
922
923 m_previewItems.reset( new KIGFX::VIEW_GROUP( m_galPanel->GetView() ) );
924 m_galPanel->GetView()->Add( m_previewItems.get() );
926 m_galPanel->GetView()->SetLayerVisible( LAYER_SELECT_OVERLAY );
927
928 if( !m_showRPIs )
929 return;
930
931 for( auto& ent : entries )
932 {
933 if ( ent.m_isHideOp )
934 {
935
936 auto parent = ent.m_item->Parent();
937 if( parent )
938 {
939
940 view->Hide( parent );
941 }
942 }
943 else
944 {
945 ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( ent.m_item, m_viewerIface.get(), view );
946 pitem->Update( ent.m_item );
947 m_previewItems->Add(pitem);
948 // printf("DBG vadd %p total %d\n", pitem, m_previewItems->GetSize() );
949 }
950 }
951
952 view->SetVisible( m_previewItems.get(), true );
953
954 view->Update( m_previewItems.get() );
955 printf("DBG vgrp %p total %d\n", m_previewItems.get(), m_previewItems->GetSize() );
956
957
958 //view->UpdateAllItems( KIGFX::ALL );
959}
960
962{
963 return m_reporter.get();
964}
965
966
967#if 0
968
969static BOARD* loadBoard( const std::string& filename )
970{
972 BOARD* brd = nullptr;
973
974 try
975 {
976 brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
977 }
978 catch( const IO_ERROR& )
979 {
980 return nullptr;
981 }
982
983 return brd;
984}
985
986
987
988
989
990int render_perftest_main_func( int argc, char* argv[] )
991{
992 auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
993
994 // drcCreateTestsProviderClearance();
995 // drcCreateTestsProviderEdgeClearance();
996
997 if( argc >= 2 && std::string( argv[1] ) == "-h" )
998 {
999 printf( "PCB render performance test. Just renders a board without UI update overhead.\n" );
1000 return 0;
1001 }
1002
1003 if( argc < 2 )
1004 {
1005 printf( "Expected parameters: board_file\n" );
1006 return 0;
1007 }
1008
1009 PROF_TIMER cnt("load-board");
1010 std::shared_ptr<BOARD> brd ( loadBoard( argv[1] ) );
1011 cnt.Stop();
1012
1013 KI_TRACE( traceGalProfile, "%s\n", cnt.to_string() );
1014
1015 frame->SetBoard2( brd );
1016
1017 return 0;
1018}
1019
1020
1021static bool registered3 = UTILITY_REGISTRY::Register( {
1022 "render_perftest",
1023 "Renderer performance test",
1024 render_perftest_main_func,
1025} );
1026
1027
1028VECTOR2I NearestPointFixpt( SEG seg, const VECTOR2I& aP )
1029{
1030 VECTOR2I d = seg.B - seg.A;
1031 SEG::ecoord l_squared = d.Dot( d );
1032
1033 if( l_squared == 0 )
1034 return seg.A;
1035
1036 SEG::ecoord t = d.Dot( aP - seg.A );
1037
1038 if( t < 0 )
1039 return seg.A;
1040 else if( t > l_squared )
1041 return seg.B;
1042
1043 int xp = rescale( t, (SEG::ecoord) d.x, l_squared );
1044 int yp = rescale( t, (SEG::ecoord) d.y, l_squared );
1045
1046 return seg.A + VECTOR2I( xp, yp );
1047}
1048
1049
1050VECTOR2D NearestPointDbl( SEG seg, const VECTOR2I& aP )
1051{
1052 VECTOR2D d = seg.B - seg.A;
1053 double l_squared = d.Dot(d);
1054
1055 if( l_squared == 0 )
1056 return seg.A;
1057
1058 double t = d.Dot(VECTOR2D( aP - seg.A ) );
1059
1060 if( t < 0 )
1061 return seg.A;
1062 else if( t > l_squared )
1063 return seg.B;
1064
1065 double xp = t * d.x / l_squared;
1066 double yp = t * d.y / l_squared;
1067
1068 return VECTOR2D(seg.A) + VECTOR2D( xp, yp );
1069}
1070
1071int ttt_main_func( int argc, char* argv[] )
1072{
1073 int n = 1000000;
1074 std::vector<VECTOR2I> pts;
1075 std::vector<SEG> segs;
1076 std::vector<VECTOR2D> rv;
1077 std::vector<VECTOR2I> rvi;
1078
1079
1080 rv.resize(n);
1081 rvi.resize(n);
1082
1083 for (int i = 0; i < n ;i++)
1084 {
1085 pts.push_back(VECTOR2I(random()%100000000, random()%100000000));
1086 segs.push_back(SEG( VECTOR2I(random()%100000000, random()%100000000), VECTOR2I(random()%100000000, random()%100000000) ) );
1087 }
1088
1089 PROF_TIMER tmrFix("nearest-fixpt");
1090 for(int i = 0; i < n ; i++)
1091 {
1092 rvi[i] = NearestPointFixpt( segs[i], pts[i]);
1093 }
1094 tmrFix.Show();
1095
1096 PROF_TIMER tmrDbl("nearest-double");
1097 for(int i = 0; i < n ; i++)
1098 {
1099 rv[i] = NearestPointDbl( segs[i], pts[i]);
1100 }
1101 tmrDbl.Show();
1102 return 0;
1103}
1104
1105
1106
1107static bool registered4 = UTILITY_REGISTRY::Register( {
1108 "ttt",
1109 "Renderer performance test",
1110 ttt_main_func,
1111} );
1112
1113#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:290
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:558
constexpr void SetHeight(size_type val)
Definition: box2.h:292
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr void SetWidth(size_type val)
Definition: box2.h:287
@ 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:78
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:687
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.
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)
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< WX_TEXT_CTRL_REPORTER > m_reporter
std::shared_ptr< PNS_LOG_FILE > m_logFile
virtual void onListRightClick(wxMouseEvent &event)
std::shared_ptr< PNS_LOG_PLAYER > m_logPlayer
std::map< wxString, wxString > m_filenameToPathMap
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)
std::shared_ptr< PNS_VIEWER_IFACE > m_viewerIface
virtual void onListSelect(wxCommandEvent &event)
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 AnnotatedPolyset(const SHAPE_POLY_SET &aL, 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:49
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
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:333
EDA_ANGLE GetCentralAngle() const
Definition: shape_arc.cpp:538
int GetWidth() const
Definition: shape_arc.h:168
double GetRadius() const
Definition: shape_arc.cpp:554
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:507
const VECTOR2I & GetCenter() const
Definition: shape_arc.cpp:523
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...
void Simplify(int aMaxError=0)
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
Represent a set of closed polygons.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) 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.
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:550
WX_SHAPE_TREE_ITEM_DATA(PNS_DEBUG_SHAPE *item, int level=0)
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:145
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:422
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
@ 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:400
static bool isLine45Degree(const SHAPE_LINE_CHAIN *lc)
static void collapseAllChildren(wxTreeListCtrl *tree)
static void expandAllChildren(wxTreeListCtrl *tree, int maxLevel=-1)
void runCommand(const wxString &aCommand)
#define ID_LIST_COPY
#define ID_LIST_DISPLAY_LINE
#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:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
Definition of file extensions used in Kicad.