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