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_logPlayer.reset( new PNS_LOG_PLAYER );
358 m_board = nullptr;
359 m_logFile.reset( aLog );
360
361 SetBoard( m_logFile->GetBoard() );
362
363 m_logPlayer->ReplayLog( m_logFile.get(), 0, 0, -1, true );
364
365 auto dbgd = m_logPlayer->GetDebugDecorator();
366 int n_stages = dbgd->GetStageCount();
367 m_rewindSlider->SetMax( n_stages - 1 );
368 m_rewindSlider->SetValue( n_stages - 1 );
369 m_rewindIter = n_stages - 1;
370
371 auto extents = m_board->GetBoundingBox();
372
373
374 BOX2D bbd;
375 bbd.SetOrigin( extents.GetOrigin() );
376 bbd.SetWidth( extents.GetWidth() );
377 bbd.SetHeight( extents.GetHeight() );
378 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
379
380 m_galPanel->GetView()->SetViewport( bbd );
381
385}
386
387
388void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
389{
390 SetBoard( aBoard );
391
392 auto extents = m_board->GetBoundingBox();
393
394 BOX2D bbd;
395 bbd.SetOrigin( extents.GetOrigin() );
396 bbd.SetWidth( extents.GetWidth() );
397 bbd.SetHeight( extents.GetHeight() );
398 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
399
400 m_galPanel->GetView()->SetViewport( bbd );
401}
402
403
404void PNS_LOG_VIEWER_FRAME::onOpen( wxCommandEvent& event )
405{
406 wxFileDialog dlg( this, "Select Log File", m_mruPath, wxEmptyString,
407 "PNS log files" + AddFileExtListToFilter( { "log" } ),
408 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
409
410 if( dlg.ShowModal() != wxID_CANCEL )
411 {
412 wxString logPath = dlg.GetPath();
413 LoadLogFile( logPath );
414 m_mruPath = wxFileName( logPath ).GetPath();
415 }
416}
417
418
419void PNS_LOG_VIEWER_FRAME::onSaveAs( wxCommandEvent& event )
420{
421 if( !m_logFile )
422 {
423 DisplayError( this, wxT( "No log file Loaded!" ) );
424 return;
425 }
426
427 wxFileDialog dlg( this, "New log file", m_mruPath, wxEmptyString,
428 "PNS log files" + AddFileExtListToFilter( { "log" } ),
429 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
430
431 if( dlg.ShowModal() != wxID_CANCEL )
432 {
433 // Enforce the extension, wxFileDialog is inept.
434 wxFileName create_me = EnsureFileExtension( dlg.GetPath(), "log" );
435
436 wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
437
438 m_logFile->SaveLog( create_me, m_reporter.get() );
439 m_mruPath = create_me.GetPath();
440 }
441
442}
443
444
445void PNS_LOG_VIEWER_FRAME::onExit( wxCommandEvent& event )
446{
447 Close();
448}
449
450
451void PNS_LOG_VIEWER_FRAME::onListChecked( wxCommandEvent& event )
452{
453 syncModel();
455}
456
458{
459 m_showThinLines = event.GetInt();
462}
463
464void PNS_LOG_VIEWER_FRAME::onShowRPIsChecked( wxCommandEvent& event )
465{
466 m_showRPIs = event.GetInt();
469}
470
472{
473 m_showVertices = event.GetInt();
476}
477
478
479void PNS_LOG_VIEWER_FRAME::onRewindScroll( wxScrollEvent& event )
480{
481 m_rewindIter = event.GetPosition();
485 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
486 event.Skip();
487}
488
489
490void PNS_LOG_VIEWER_FRAME::onBtnRewindLeft( wxCommandEvent& event )
491{
492 if( m_rewindIter > 0 )
493 {
494 m_rewindIter--;
498 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
499 m_rewindSlider->SetValue( m_rewindIter );
500 }
501}
502
503
504void PNS_LOG_VIEWER_FRAME::onBtnRewindRight( wxCommandEvent& event )
505{
506 auto dbgd = m_logPlayer->GetDebugDecorator();
507 int count = dbgd->GetStageCount();
508
509 if( m_rewindIter < count )
510 {
511 m_rewindIter++;
515 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
516 m_rewindSlider->SetValue( m_rewindIter );
517 }
518}
519
520void PNS_LOG_VIEWER_FRAME::onFilterText( wxCommandEvent& event )
521{
522 m_searchString = m_filterString->GetValue();
524}
525
526
527void PNS_LOG_VIEWER_FRAME::onRewindCountText( wxCommandEvent& event )
528{
529 if( !m_logPlayer )
530 return;
531
532 int val = wxAtoi( m_rewindPos->GetValue() );
533
534 auto dbgd = m_logPlayer->GetDebugDecorator();
535 int count = dbgd->GetStageCount();
536
537 if( val < 0 )
538 val = 0;
539
540 if( val >= count )
541 val = count - 1;
542
543 m_rewindIter = val;
544 m_rewindSlider->SetValue( m_rewindIter );
548
549 event.Skip();
550}
551
552
554{
555 for( wxTreeListItem item = m_itemList->GetFirstItem(); item.IsOk();
556 item = m_itemList->GetNextItem( item ) )
557 {
559 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( m_itemList->GetItemData( item ) );
560
561 if( idata )
562 {
563 bool checked = m_itemList->GetCheckedState( item ) == wxCHK_CHECKED;
564 bool selected = m_itemList->IsSelected( item );
565 idata->m_item->m_visible = checked || selected;
566 idata->m_item->m_selected = selected;
567 }
568 }
569}
570
571
572void runCommand( const wxString& aCommand )
573{
574#ifdef __WXMSW__
575 wxShell( aCommand ); // on windows we need to launch a shell in order to run the command
576#else
577 wxExecute( aCommand );
578#endif /* __WXMSW__ */
579}
580
581
582void PNS_LOG_VIEWER_FRAME::onListRightClick( wxMouseEvent& event )
583{
584 auto sel = m_itemList->GetPopupMenuSelectionFromUser( *m_listPopupMenu );
585
586 switch( sel )
587 {
589 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_UNCHECKED );
590 syncModel();
592 break;
593 case ID_LIST_SHOW_ALL:
594 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_CHECKED );
595 syncModel();
597 break;
598 case ID_LIST_COPY:
599 {
600 wxString s;
601
603
604 if( !st )
605 return;
606
607 auto formatShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
608 {
609 if( ent->m_selected )
610 {
611 for( auto sh : ent->m_shapes )
612 {
613 s += "// " + ent->m_name + "\n " + sh->Format() + "; \n";
614 }
615 }
616
617 return true;
618 };
619
620 st->m_entries->IterateTree( formatShapes );
621
622 if( wxTheClipboard->Open() )
623 {
624 // This data objects are held by the clipboard,
625 // so do not delete them in the app.
626 wxTheClipboard->SetData( new wxTextDataObject( s ) );
627 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
628 wxTheClipboard->Close();
629 }
630
631 return;
632 }
634 {
635 wxVector<wxTreeListItem> selectedItems;
636
637 if( m_itemList->GetSelections( selectedItems ) == 1 )
638 {
639 wxString filename = m_itemList->GetItemText(selectedItems.back(), 2);
640 wxString line = m_itemList->GetItemText(selectedItems.back(), 4);
641
642
643 if( !filename.empty() && !line.empty() )
644 {
645 wxString filepath = m_filenameToPathMap[filename];
646
647 switch( m_ideChoice->GetCurrentSelection() )
648 {
649 case 0: runCommand( wxString::Format( "code --goto %s:%s", filepath, line ) ); return;
650 case 1: runCommand( wxString::Format( "start devenv /edit %s /command \"Gotoln %s\"", filepath, line ) ); return; // fixme
651 case 2: runCommand( wxString::Format( "clion --line %s %s", line, filepath ) ); return;
652 case 3: runCommand( wxString::Format( "emacsclient +%s %s", line, filepath ) ); return;
653 default: return;
654 }
655 }
656 }
657 break;
658 }
659 }
660 return;
661}
662
663
664void PNS_LOG_VIEWER_FRAME::onListSelect( wxCommandEvent& event )
665{
666 syncModel();
668}
669
670
671
672static bool isLine45Degree( const SHAPE_LINE_CHAIN* lc )
673{
674 for( int i = 0; i < lc->SegmentCount(); i++ )
675 {
676 const SEG& s = lc->CSegment( i );
677
678 if( lc->IsArcSegment( i ) )
679 continue;
680
681 if( s.Length() < 10 )
682 continue;
683
684 double angle = 180.0 / M_PI *
685 atan2( (double) s.B.y - (double) s.A.y,
686 (double) s.B.x - (double) s.A.x );
687
688 if( angle < 0 )
689 angle += 360.0;
690
691 double angle_a = fabs( fmod( angle, 45.0 ) );
692
693 if( angle_a > 1.0 && angle_a < 44.0 )
694 return false;
695 }
696
697 return true;
698}
699
700
702{
703
704 std::set<PNS_DEBUG_SHAPE*> processed;
705 std::deque<PNS_DEBUG_SHAPE*> q;
706
707 q.push_back(ent);
708 int total = 0;
709 while ( q.size() > 0 )
710 {
711 PNS_DEBUG_SHAPE* top = q.front();
712
713 q.pop_front();
714
715 for ( auto chld : top->m_children )
716 {
717 bool match = m_searchString.Length() == 0 ? true : false;
718 //printf("CHK %s\n", (const char *) chld->m_name.c_str() );
719 chld->m_filterMatch = false;
720 if ( chld->m_name.Contains( m_searchString ) )
721 match = true;
722 if ( chld->m_msg.Contains( m_searchString ) )
723 match = true;
724
725 if( match )
726 {
727 for ( PNS_DEBUG_SHAPE *cur = chld; cur; cur = cur->m_parent )
728 cur->m_filterMatch = match;
729 }
730
731 if( processed.find(chld) == processed.end() )
732 {
733 q.push_back( chld );
734 processed.insert( chld );
735 }
736 }
737 total++;
738 }
739
740 printf("total: %d\n", total );
741
742 return false;
743}
744
745
746void PNS_LOG_VIEWER_FRAME::buildListTree( wxTreeListItem item,
747 PNS_DEBUG_SHAPE* ent, int depth )
748{
749#ifdef EXTRA_VERBOSE
750 for( int i = 0; i < depth * 2; i++ )
751 printf( " " );
752
753 if( ent->m_msg.length() )
754 printf( "MSG: %s\n", ent->m_msg.c_str() );
755 else
756 printf( "SHAPES: %s [%d]\n", ent->m_name.c_str(), ent->m_children.size() );
757#endif
758
759 wxTreeListItem ritem;
760
761 if( !ent->m_filterMatch )
762 return;
763
764 if( ent->m_msg.length() )
765 {
766 ritem = m_itemList->AppendItem( item, "Child" );
767 m_itemList->SetItemText( ritem, 0, "Message" );
768 m_itemList->SetItemText( ritem, 1, ent->m_msg );
769 }
770 else
771 {
772 ritem = m_itemList->AppendItem( item, "Child" );
773 int n_verts = 0;
774 for(auto sh : ent->m_shapes )
775 {
776 if ( sh->Type() == SH_LINE_CHAIN )
777 {
778 n_verts += static_cast<const SHAPE_LINE_CHAIN*>( sh )->PointCount();
779 }
780 }
781 m_itemList->SetItemText( ritem, 0, wxString::Format( "Shapes [%d verts]", n_verts ) );
782 m_itemList->SetItemText( ritem, 1, ent->m_name );
783 }
784
785 wxString fullfilepath = ent->m_srcLoc.fileName;
786 wxString filename = wxFileNameFromPath( fullfilepath );
787
788 if( !filename.empty() )
789 m_filenameToPathMap.insert( { filename, fullfilepath } );
790
791 m_itemList->SetItemText( ritem, 2, filename );
792 m_itemList->SetItemText( ritem, 3, ent->m_srcLoc.funcName );
793 m_itemList->SetItemText( ritem, 4, wxString::Format("%d", ent->m_srcLoc.line ) );
794
795 int totalVC = 0, totalVCSimplified = 0;
796 bool is45Degree = true;
797
798 for( SHAPE* sh : ent->m_shapes )
799 {
800 if( sh->Type() == SH_LINE_CHAIN )
801 {
802 auto lc = static_cast<SHAPE_LINE_CHAIN*>( sh );
803
804 totalVC += lc->PointCount();
805
806 SHAPE_LINE_CHAIN simp(*lc);
807
808 simp.Simplify();
809
810 totalVCSimplified += simp.PointCount();
811
812 if( !isLine45Degree( lc ) )
813 is45Degree = false;
814 }
815 }
816
817 if( totalVC > 0 )
818 m_itemList->SetItemText( ritem, 5, wxString::Format( "%d [%d]", totalVC, totalVCSimplified ) );
819
820 if( !is45Degree )
821 m_itemList->SetItemText( ritem, 6, wxT("") );
822
823 m_itemList->SetItemData( ritem, new WX_SHAPE_TREE_ITEM_DATA( ent, depth ) );
824
825 if( !ent->m_children.size() )
826 return;
827
828 for( auto child : ent->m_children )
829 {
830 buildListTree( ritem, child, depth + 1 );
831 }
832}
833
834
835static void expandAllChildren( wxTreeListCtrl* tree, int maxLevel = -1 )
836{
837 wxTreeListItem child = tree->GetFirstItem ();
838
839 while( child.IsOk() )
840 {
842 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( tree->GetItemData( child ) );
843
844 if( maxLevel < 0 || idata->m_level <= maxLevel )
845 tree->Expand ( child );
846 else
847 tree->Collapse ( child );
848 child = tree->GetNextItem( child );
849 }
850}
851
852static void collapseAllChildren( wxTreeListCtrl* tree )
853{
854 wxTreeListItem child = tree->GetFirstItem ();
855
856 while( child.IsOk() )
857 {
858 tree->Collapse ( child );
859 child = tree->GetNextItem( child );
860 }
861}
862
863
865{
866 printf("UpdateDUmp %d\n", iter );
867 if( !m_logPlayer )
868 return;
869
870 auto dbgd = m_logPlayer->GetDebugDecorator();
871 int count = dbgd->GetStageCount();
872
873 wxArrayString dumpStrings;
874
875 if( count <= 0 )
876 return;
877
878 if( iter < 0 )
879 iter = 0;
880
881 if( iter >= count )
882 iter = count - 1;
883
884 auto st = dbgd->GetStage( iter );
885
886 if( st->m_status )
887 {
888 m_algoStatus->SetLabel("OK");
889 m_algoStatus->SetForegroundColour( wxColor(*wxGREEN));
890 }
891 else
892 {
893 m_algoStatus->SetLabel("FAIL");
894 m_algoStatus->SetForegroundColour( wxColor(*wxRED));
895 }
896
897 auto rootItem = m_itemList->GetRootItem();
898
899 m_itemList->DeleteAllItems();
900 filterStringMatches( st->m_entries );
901 buildListTree( rootItem, st->m_entries );
902 m_itemList->CheckItemRecursively( rootItem, wxCHK_UNCHECKED );
903
905
906 m_itemList->Refresh();
907}
908
910{
911 auto viewTracker = m_logPlayer->GetViewTracker();
912 PNS_LOG_VIEW_TRACKER::VIEW_ENTRIES& entries = viewTracker->GetEntriesForStage( iter );
913 auto view = m_galPanel->GetView();
914 printf("DBG updatePnsPreviewItems: %zu items\n", entries.size() );
915
916 m_previewItems.reset( new KIGFX::VIEW_GROUP( m_galPanel->GetView() ) );
917 m_galPanel->GetView()->Add( m_previewItems.get() );
919 m_galPanel->GetView()->SetLayerVisible( LAYER_SELECT_OVERLAY );
920
921 if( !m_showRPIs )
922 return;
923
924 for( auto& ent : entries )
925 {
926 if ( ent.m_isHideOp )
927 {
928
929 auto parent = ent.m_item->Parent();
930 if( parent )
931 {
932
933 view->Hide( parent );
934 }
935 }
936 else
937 {
938 ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( ent.m_item, view );
939 pitem->Update( ent.m_item );
940 m_previewItems->Add(pitem);
941 // printf("DBG vadd %p total %d\n", pitem, m_previewItems->GetSize() );
942 }
943 }
944
945 view->SetVisible( m_previewItems.get(), true );
946
947 view->Update( m_previewItems.get() );
948 printf("DBG vgrp %p total %d\n", m_previewItems.get(), m_previewItems->GetSize() );
949
950
951 //view->UpdateAllItems( KIGFX::ALL );
952}
953
955{
956 return m_reporter.get();
957}
958
959
960#if 0
961
962static BOARD* loadBoard( const std::string& filename )
963{
965 BOARD* brd = nullptr;
966
967 try
968 {
969 brd = pi->LoadBoard( wxString( filename.c_str() ), nullptr, nullptr );
970 }
971 catch( const IO_ERROR& )
972 {
973 return nullptr;
974 }
975
976 return brd;
977}
978
979
980
981
982
983int render_perftest_main_func( int argc, char* argv[] )
984{
985 auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
986
987 // drcCreateTestsProviderClearance();
988 // drcCreateTestsProviderEdgeClearance();
989
990 if( argc >= 2 && std::string( argv[1] ) == "-h" )
991 {
992 printf( "PCB render performance test. Just renders a board without UI update overhead.\n" );
993 return 0;
994 }
995
996 if( argc < 2 )
997 {
998 printf( "Expected parameters: board_file\n" );
999 return 0;
1000 }
1001
1002 PROF_TIMER cnt("load-board");
1003 std::shared_ptr<BOARD> brd ( loadBoard( argv[1] ) );
1004 cnt.Stop();
1005
1006 KI_TRACE( traceGalProfile, "%s\n", cnt.to_string() );
1007
1008 frame->SetBoard2( brd );
1009
1010 return 0;
1011}
1012
1013
1014static bool registered3 = UTILITY_REGISTRY::Register( {
1015 "render_perftest",
1016 "Renderer performance test",
1017 render_perftest_main_func,
1018} );
1019
1020
1021VECTOR2I NearestPointFixpt( SEG seg, const VECTOR2I& aP )
1022{
1023 VECTOR2I d = seg.B - seg.A;
1024 SEG::ecoord l_squared = d.Dot( d );
1025
1026 if( l_squared == 0 )
1027 return seg.A;
1028
1029 SEG::ecoord t = d.Dot( aP - seg.A );
1030
1031 if( t < 0 )
1032 return seg.A;
1033 else if( t > l_squared )
1034 return seg.B;
1035
1036 int xp = rescale( t, (SEG::ecoord) d.x, l_squared );
1037 int yp = rescale( t, (SEG::ecoord) d.y, l_squared );
1038
1039 return seg.A + VECTOR2I( xp, yp );
1040}
1041
1042
1043VECTOR2D NearestPointDbl( SEG seg, const VECTOR2I& aP )
1044{
1045 VECTOR2D d = seg.B - seg.A;
1046 double l_squared = d.Dot(d);
1047
1048 if( l_squared == 0 )
1049 return seg.A;
1050
1051 double t = d.Dot(VECTOR2D( aP - seg.A ) );
1052
1053 if( t < 0 )
1054 return seg.A;
1055 else if( t > l_squared )
1056 return seg.B;
1057
1058 double xp = t * d.x / l_squared;
1059 double yp = t * d.y / l_squared;
1060
1061 return VECTOR2D(seg.A) + VECTOR2D( xp, yp );
1062}
1063
1064int ttt_main_func( int argc, char* argv[] )
1065{
1066 int n = 1000000;
1067 std::vector<VECTOR2I> pts;
1068 std::vector<SEG> segs;
1069 std::vector<VECTOR2D> rv;
1070 std::vector<VECTOR2I> rvi;
1071
1072
1073 rv.resize(n);
1074 rvi.resize(n);
1075
1076 for (int i = 0; i < n ;i++)
1077 {
1078 pts.push_back(VECTOR2I(random()%100000000, random()%100000000));
1079 segs.push_back(SEG( VECTOR2I(random()%100000000, random()%100000000), VECTOR2I(random()%100000000, random()%100000000) ) );
1080 }
1081
1082 PROF_TIMER tmrFix("nearest-fixpt");
1083 for(int i = 0; i < n ; i++)
1084 {
1085 rvi[i] = NearestPointFixpt( segs[i], pts[i]);
1086 }
1087 tmrFix.Show();
1088
1089 PROF_TIMER tmrDbl("nearest-double");
1090 for(int i = 0; i < n ; i++)
1091 {
1092 rv[i] = NearestPointDbl( segs[i], pts[i]);
1093 }
1094 tmrDbl.Show();
1095 return 0;
1096}
1097
1098
1099
1100static bool registered4 = UTILITY_REGISTRY::Register( {
1101 "ttt",
1102 "Renderer performance test",
1103 ttt_main_func,
1104} );
1105
1106#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:282
void SetOrigin(const Vec &pos)
Definition: box2.h:227
void SetHeight(size_type val)
Definition: box2.h:275
size_type GetHeight() const
Definition: box2.h:205
void SetWidth(size_type val)
Definition: box2.h:270
size_type GetWidth() const
Definition: box2.h:204
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
@ 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: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 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: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:524
int GetWidth() const
Definition: shape_arc.h:160
double GetRadius() const
Definition: shape_arc.cpp:540
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:495
const VECTOR2I & GetCenter() const
Definition: shape_arc.cpp:509
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.
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:479
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: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: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: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:162
VECTOR2< double > VECTOR2D
Definition: vector2d.h:601
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602
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.