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