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