KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_log_viewer_frame.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020-2022 KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25// WARNING - this Tom's crappy PNS hack tool code. Please don't complain about its quality
26// (unless you want to improve it).
27#include <string>
28
29#include <wx/clipbrd.h>
30#include <pgm_base.h>
31#include <profile.h>
32#include <trace_helpers.h>
33#include <view/view_overlay.h>
34#include <view/view_controls.h>
35
36
37#include "label_manager.h"
38
39#include "pns_log_file.h"
40#include "pns_log_player.h"
42
44#include "router/pns_utils.h"
46
48
49class WX_SHAPE_TREE_ITEM_DATA : public wxClientData
50{
51public:
52 WX_SHAPE_TREE_ITEM_DATA( PNS_DEBUG_SHAPE* item, int level = 0 ) : m_item( item ), m_level( level ) {};
53
56};
57
58
60{
61 m_labelMgr.reset( new LABEL_MANAGER( aGal ) );
62}
63
64
66 bool aShowVertexNumbers )
67{
68 Polyline( aL );
69
70 if( name.length() > 0 && aL.PointCount() > 0 )
71 m_labelMgr->Add( aL.CPoint( -1 ), name, GetStrokeColor() );
72
73 if( aShowVertexNumbers )
74 {
75 for( int i = 0; i < aL.PointCount(); i++ )
76 m_labelMgr->Add( aL.CPoint(i), wxString::Format("%d", i ), GetStrokeColor() );
77 }
78}
79
80
81void PNS_LOG_VIEWER_OVERLAY::AnnotatedPoint( const VECTOR2I p, int size, std::string name, bool aShowVertexNumbers )
82{
83 Line( p + VECTOR2D( size, size ), p - VECTOR2D( size, size ) );
84 Line( p + VECTOR2D( -size, size ), p - VECTOR2D( -size, size ) );
85
86 if( name.length() > 0 )
87 m_labelMgr->Add( p, name, GetStrokeColor() );
88}
89
90
92{
93 double radius = arc.GetRadius();
94 EDA_ANGLE start_angle = arc.GetStartAngle();
95 EDA_ANGLE angle = arc.GetCentralAngle();
96
98 KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
99
101 COLOR4D lightStrokeCol = prevStrokeCol.WithAlpha(0.5);
102 KIGFX::VIEW_OVERLAY::SetStrokeColor( lightStrokeCol );
103
105 KIGFX::VIEW_OVERLAY::Arc( arc.GetCenter(), radius, start_angle, start_angle + angle );
106
108}
109
111{
112 m_labelMgr->Redraw( this );
113}
114
115
117{
118 LoadSettings();
120
121 m_viewSizer->Add( m_galPanel.get(), 1, wxEXPAND, 5 );
122
123 Layout();
124
125 Show( true );
126 Maximize();
127 Raise();
128
129 auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
130 m_galPanel->GetView()->GetPainter()->GetSettings() );
131
132
134
135 opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE;
136
137 double opacity = 0.5;
138
139 opts.m_TrackOpacity = opacity;
140 opts.m_ViaOpacity = opacity;
141 opts.m_PadOpacity = opacity;
142 opts.m_ZoneOpacity = opacity;
143
144 settings->LoadDisplayOptions( opts );
145
146
147 m_listPopupMenu = new wxMenu( wxT( "" ) );
148 m_listPopupMenu->Append( ID_LIST_COPY, wxT( "Copy selected geometry" ), wxT( "" ),
149 wxITEM_NORMAL );
150 m_listPopupMenu->Append( ID_LIST_SHOW_ALL, wxT( "Show all" ), wxT( "" ), wxITEM_NORMAL );
151 m_listPopupMenu->Append( ID_LIST_SHOW_NONE, wxT( "Show none" ), wxT( "" ), wxITEM_NORMAL );
152
153 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CONTEXT_MENU,
154 wxMouseEventHandler( PNS_LOG_VIEWER_FRAME::onListRightClick ), nullptr,
155 this );
156 //m_itemList->Connect(m_itemList->GetId(),wxEVT_LISTBOX,wxCommandEventHandler(PNS_LOG_VIEWER_FRAME::onListSelect),nullptr,this);
157 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_SELECTION_CHANGED,
158 wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListSelect ),
159 nullptr, this );
160 m_itemList->Connect( m_itemList->GetId(), wxEVT_TREELIST_ITEM_CHECKED,
161 wxCommandEventHandler( PNS_LOG_VIEWER_FRAME::onListChecked ),
162 nullptr, this );
163
164 m_itemList->AppendColumn( "Type" );
165 m_itemList->AppendColumn( "Value" );
166 m_itemList->AppendColumn( "File" );
167 m_itemList->AppendColumn( "Method" );
168 m_itemList->AppendColumn( "Line" );
169 m_itemList->AppendColumn( "VCount" );
170 m_itemList->AppendColumn( "Non-45" );
171
172 m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
173 m_galPanel->GetView()->Add( m_overlay.get() );
174 m_galPanel->GetViewControls()->EnableCursorWarping(false);
175}
176
177
179{
180 m_overlay = nullptr;
181}
182
183
185{
186
187}
188
189
191{
192 PNS_TEST_DEBUG_DECORATOR* dbgd = m_logPlayer->GetDebugDecorator();
193 int count = dbgd->GetStageCount();
194
195 int iter = m_rewindIter;
196
197 if( count <= 0 )
198 return nullptr;
199
200 if( iter < 0 )
201 iter = 0;
202
203 if( iter >= count )
204 iter = count - 1;
205
206 return dbgd->GetStage( iter );
207}
208
209
210void PNS_LOG_VIEWER_FRAME::drawSimpleShape( SHAPE* aShape, bool aIsSelected, const std::string& aName )
211{
212 switch( aShape->Type() )
213 {
214 case SH_CIRCLE:
215 {
216 auto cir = static_cast<SHAPE_CIRCLE*>( aShape );
217 m_overlay->Circle( cir->GetCenter(), cir->GetRadius() );
218
219 break;
220 }
221 case SH_SEGMENT:
222 {
223 auto seg = static_cast<SHAPE_SEGMENT*>( aShape );
224 m_overlay->Line( seg->GetSeg().A, seg->GetSeg().B );
225
226 break;
227 }
228 case SH_RECT:
229 {
230 auto rect = static_cast<SHAPE_RECT*>( aShape );
231 m_overlay->Rectangle( rect->GetPosition(), rect->GetPosition() + rect->GetSize() );
232
233 break;
234 }
235 case SH_LINE_CHAIN:
236 {
237 auto lc = static_cast<SHAPE_LINE_CHAIN*>( aShape );
238 m_overlay->AnnotatedPolyline( *lc, aName, m_showVertices || aIsSelected );
239
240 break;
241 }
242 default: break;
243 }
244}
245
247{
248 if( !m_logPlayer )
249 return;
250
252
253 if( !st )
254 return;
255
256 m_overlay.reset( new PNS_LOG_VIEWER_OVERLAY ( m_galPanel->GetGAL() ) );
257 m_galPanel->GetView()->Add( m_overlay.get() );
258 //m_galPanel->GetGAL()->EnableDepthTest( false );
259
260 auto drawShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
261 {
262 bool isEnabled = ent->IsVisible();
263 bool isSelected = ent->m_selected;
264
265 if( m_searchString.Length() > 0 )
266 isEnabled = ent->m_filterMatch;
267
268 if( !isEnabled )
269 return true;
270
271 for( auto& sh : ent->m_shapes )
272 {
273 COLOR4D color = ent->m_color;
274 int lineWidth = ent->m_width;
275
276 m_overlay->SetIsStroke( true );
277 m_overlay->SetIsFill( false );
278
279 if( isSelected )
280 {
281 color.Brighten( 0.5 );
282 }
283
284 color.a = 1.0;
285
286 m_overlay->SetStrokeColor( color );
287 m_overlay->SetLineWidth( m_showThinLines ? 10000 : ent->m_width );
288
289 if( sh->Type() == SH_COMPOUND )
290 {
291 auto cmpnd = static_cast<SHAPE_COMPOUND*>( sh );
292
293 for( auto subshape : cmpnd->Shapes() )
294 {
295 drawSimpleShape( subshape, isSelected, ent->m_name.ToStdString() );
296 }
297 }
298 else
299 {
300 drawSimpleShape( sh, isSelected, ent->m_name.ToStdString() );
301 }
302 }
303
304 return true;
305 };
306
308
309 m_overlay->DrawAnnotations();
310
311 m_galPanel->GetView()->MarkDirty();
312 m_galPanel->GetParent()->Refresh();
313}
314
315
317{
318 m_logFile.reset( aLog );
319
320 SetBoard( m_logFile->GetBoard() );
321
322 m_logPlayer.reset( new PNS_LOG_PLAYER );
323 m_logPlayer->ReplayLog( m_logFile.get(), 0, 0, -1);
324
325 auto dbgd = m_logPlayer->GetDebugDecorator();
326 int n_stages = dbgd->GetStageCount();
327 m_rewindSlider->SetMax( n_stages - 1 );
328 m_rewindSlider->SetValue( n_stages - 1 );
329 m_rewindIter = n_stages - 1;
330
331 auto extents = m_board->GetBoundingBox();
332
333
334 BOX2D bbd;
335 bbd.SetOrigin( extents.GetOrigin() );
336 bbd.SetWidth( extents.GetWidth() );
337 bbd.SetHeight( extents.GetHeight() );
338 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
339
340 m_galPanel->GetView()->SetViewport( bbd );
341
345}
346
347
348
349void PNS_LOG_VIEWER_FRAME::SetBoard2( std::shared_ptr<BOARD> aBoard )
350{
351 SetBoard( aBoard );
352
353 auto extents = m_board->GetBoundingBox();
354
355 BOX2D bbd;
356 bbd.SetOrigin( extents.GetOrigin() );
357 bbd.SetWidth( extents.GetWidth() );
358 bbd.SetHeight( extents.GetHeight() );
359 bbd.Inflate( std::min( bbd.GetWidth(), bbd.GetHeight() ) / 5 );
360
361 m_galPanel->GetView()->SetViewport( bbd );
362}
363
364void PNS_LOG_VIEWER_FRAME::onReload( wxCommandEvent& event )
365{
366 event.Skip();
367}
368
369void PNS_LOG_VIEWER_FRAME::onExit( wxCommandEvent& event )
370{
371 event.Skip();
372}
373
374
375void PNS_LOG_VIEWER_FRAME::onListChecked( wxCommandEvent& event )
376{
377 syncModel();
379}
380
382{
383 m_showThinLines = event.GetInt();
386}
387
388void PNS_LOG_VIEWER_FRAME::onShowRPIsChecked( wxCommandEvent& event )
389{
390 m_showRPIs = event.GetInt();
393}
394
396{
397 m_showVertices = event.GetInt();
400}
401
402
403void PNS_LOG_VIEWER_FRAME::onRewindScroll( wxScrollEvent& event )
404{
405 m_rewindIter = event.GetPosition();
409 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
410 event.Skip();
411}
412
413
414void PNS_LOG_VIEWER_FRAME::onBtnRewindLeft( wxCommandEvent& event )
415{
416 if( m_rewindIter > 0 )
417 {
418 m_rewindIter--;
422 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
423 }
424}
425
426
427void PNS_LOG_VIEWER_FRAME::onBtnRewindRight( wxCommandEvent& event )
428{
429 auto dbgd = m_logPlayer->GetDebugDecorator();
430 int count = dbgd->GetStageCount();
431
432 if( m_rewindIter < count )
433 {
434 m_rewindIter++;
438 m_rewindPos->SetValue( std::to_string( m_rewindIter ) );
439 }
440}
441
442void PNS_LOG_VIEWER_FRAME::onFilterText( wxCommandEvent& event )
443{
444 m_searchString = m_filterString->GetValue();
446}
447
448
449void PNS_LOG_VIEWER_FRAME::onRewindCountText( wxCommandEvent& event )
450{
451 if( !m_logPlayer )
452 return;
453
454 int val = wxAtoi( m_rewindPos->GetValue() );
455
456 auto dbgd = m_logPlayer->GetDebugDecorator();
457 int count = dbgd->GetStageCount();
458
459 if( val < 0 )
460 val = 0;
461
462 if( val >= count )
463 val = count - 1;
464
465 m_rewindIter = val;
466 m_rewindSlider->SetValue( m_rewindIter );
470
471 event.Skip();
472}
473
474
476{
477 for( wxTreeListItem item = m_itemList->GetFirstItem(); item.IsOk();
478 item = m_itemList->GetNextItem( item ) )
479 {
481 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( m_itemList->GetItemData( item ) );
482
483 if( idata )
484 {
485 bool checked = m_itemList->GetCheckedState( item ) == wxCHK_CHECKED;
486 bool selected = m_itemList->IsSelected( item );
487 idata->m_item->m_visible = checked || selected;
488 idata->m_item->m_selected = selected;
489 }
490 }
491}
492
493
494void PNS_LOG_VIEWER_FRAME::onListRightClick( wxMouseEvent& event )
495{
496 auto sel = m_itemList->GetPopupMenuSelectionFromUser( *m_listPopupMenu );
497
498 switch( sel )
499 {
501 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_UNCHECKED );
502 syncModel();
504 break;
505 case ID_LIST_SHOW_ALL:
506 m_itemList->CheckItemRecursively( m_itemList->GetRootItem(), wxCHK_CHECKED );
507 syncModel();
509 break;
510 case ID_LIST_COPY:
511 {
512 wxString s;
513
515
516 if( !st )
517 return;
518
519 auto formatShapes = [&]( PNS_DEBUG_SHAPE* ent ) -> bool
520 {
521 if( ent->m_selected )
522 {
523 for( auto sh : ent->m_shapes )
524 {
525 s += "// " + ent->m_name + "\n " + sh->Format() + "; \n";
526 }
527 }
528
529 return true;
530 };
531
532 st->m_entries->IterateTree( formatShapes );
533
534 if( wxTheClipboard->Open() )
535 {
536 // This data objects are held by the clipboard,
537 // so do not delete them in the app.
538 wxTheClipboard->SetData( new wxTextDataObject( s ) );
539 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
540 wxTheClipboard->Close();
541 }
542
543 return;
544 }
545 }
546}
547
548
549void PNS_LOG_VIEWER_FRAME::onListSelect( wxCommandEvent& event )
550{
551 syncModel();
553}
554
555
556
557static bool isLine45Degree( const SHAPE_LINE_CHAIN* lc )
558{
559 for( int i = 0; i < lc->SegmentCount(); i++ )
560 {
561 const SEG& s = lc->CSegment( i );
562
563 if( lc->IsArcSegment( i ) )
564 continue;
565
566 if( s.Length() < 10 )
567 continue;
568
569 double angle = 180.0 / M_PI *
570 atan2( (double) s.B.y - (double) s.A.y,
571 (double) s.B.x - (double) s.A.x );
572
573 if( angle < 0 )
574 angle += 360.0;
575
576 double angle_a = fabs( fmod( angle, 45.0 ) );
577
578 if( angle_a > 1.0 && angle_a < 44.0 )
579 return false;
580 }
581
582 return true;
583}
584
585
587{
588
589 std::set<PNS_DEBUG_SHAPE*> processed;
590 std::deque<PNS_DEBUG_SHAPE*> q;
591
592 q.push_back(ent);
593 int total = 0;
594 while ( q.size() > 0 )
595 {
596 PNS_DEBUG_SHAPE* top = q.front();
597
598 q.pop_front();
599
600 for ( auto chld : top->m_children )
601 {
602 bool match = m_searchString.Length() == 0 ? true : false;
603 //printf("CHK %s\n", (const char *) chld->m_name.c_str() );
604 chld->m_filterMatch = false;
605 if ( chld->m_name.Contains( m_searchString ) )
606 match = true;
607 if ( chld->m_msg.Contains( m_searchString ) )
608 match = true;
609
610 if( match )
611 {
612 for ( PNS_DEBUG_SHAPE *cur = chld; cur; cur = cur->m_parent )
613 cur->m_filterMatch = match;
614 }
615
616 if( processed.find(chld) == processed.end() )
617 {
618 q.push_back( chld );
619 processed.insert( chld );
620 }
621 }
622 total++;
623 }
624
625 printf("total: %d\n", total );
626
627 return false;
628}
629
630
631void PNS_LOG_VIEWER_FRAME::buildListTree( wxTreeListItem item,
632 PNS_DEBUG_SHAPE* ent, int depth )
633{
634#ifdef EXTRA_VERBOSE
635 for( int i = 0; i < depth * 2; i++ )
636 printf( " " );
637
638 if( ent->m_msg.length() )
639 printf( "MSG: %s\n", ent->m_msg.c_str() );
640 else
641 printf( "SHAPES: %s [%d]\n", ent->m_name.c_str(), ent->m_children.size() );
642#endif
643
644 wxTreeListItem ritem;
645
646 if( !ent->m_filterMatch )
647 return;
648
649 if( ent->m_msg.length() )
650 {
651 ritem = m_itemList->AppendItem( item, "Child" );
652 m_itemList->SetItemText( ritem, 0, "Message" );
653 m_itemList->SetItemText( ritem, 1, ent->m_msg );
654 }
655 else
656 {
657 ritem = m_itemList->AppendItem( item, "Child" );
658 int n_verts = 0;
659 for(auto sh : ent->m_shapes )
660 {
661 if ( sh->Type() == SH_LINE_CHAIN )
662 {
663 n_verts += static_cast<const SHAPE_LINE_CHAIN*>( sh )->PointCount();
664 }
665 }
666 m_itemList->SetItemText( ritem, 0, wxString::Format( "Shapes [%d verts]", n_verts ) );
667 m_itemList->SetItemText( ritem, 1, ent->m_name );
668 }
669
670 m_itemList->SetItemText( ritem, 2, wxFileNameFromPath( ent->m_srcLoc.fileName ) );
671 m_itemList->SetItemText( ritem, 3, ent->m_srcLoc.funcName );
672 m_itemList->SetItemText( ritem, 4, wxString::Format("%d", ent->m_srcLoc.line ) );
673
674 int totalVC = 0, totalVCSimplified = 0;
675 bool is45Degree = true;
676
677 for( SHAPE* sh : ent->m_shapes )
678 {
679 if( sh->Type() == SH_LINE_CHAIN )
680 {
681 auto lc = static_cast<SHAPE_LINE_CHAIN*>( sh );
682
683 totalVC += lc->PointCount();
684
685 SHAPE_LINE_CHAIN simp(*lc);
686
687 simp.Simplify();
688
689 totalVCSimplified += simp.PointCount();
690
691 if( !isLine45Degree( lc ) )
692 is45Degree = false;
693 }
694 }
695
696 if( totalVC > 0 )
697 m_itemList->SetItemText( ritem, 5, wxString::Format( "%d [%d]", totalVC, totalVCSimplified ) );
698
699 if( !is45Degree )
700 m_itemList->SetItemText( ritem, 6, wxT("") );
701
702 m_itemList->SetItemData( ritem, new WX_SHAPE_TREE_ITEM_DATA( ent, depth ) );
703
704 if( !ent->m_children.size() )
705 return;
706
707 for( auto child : ent->m_children )
708 {
709 buildListTree( ritem, child, depth + 1 );
710 }
711}
712
713
714static void expandAllChildren( wxTreeListCtrl* tree, int maxLevel = -1 )
715{
716 wxTreeListItem child = tree->GetFirstItem ();
717
718 while( child.IsOk() )
719 {
721 static_cast<WX_SHAPE_TREE_ITEM_DATA*>( tree->GetItemData( child ) );
722
723 if( maxLevel < 0 || idata->m_level <= maxLevel )
724 tree->Expand ( child );
725 else
726 tree->Collapse ( child );
727 child = tree->GetNextItem( child );
728 }
729}
730
731static void collapseAllChildren( wxTreeListCtrl* tree )
732{
733 wxTreeListItem child = tree->GetFirstItem ();
734
735 while( child.IsOk() )
736 {
737 tree->Collapse ( child );
738 child = tree->GetNextItem( child );
739 }
740}
741
742
744{
745 printf("UpdateDUmp %d\n", iter );
746 if( !m_logPlayer )
747 return;
748
749 auto dbgd = m_logPlayer->GetDebugDecorator();
750 int count = dbgd->GetStageCount();
751
752 wxArrayString dumpStrings;
753
754 if( count <= 0 )
755 return;
756
757 if( iter < 0 )
758 iter = 0;
759
760 if( iter >= count )
761 iter = count - 1;
762
763 auto st = dbgd->GetStage( iter );
764
765 if( st->m_status )
766 {
767 m_algoStatus->SetLabel("OK");
768 m_algoStatus->SetForegroundColour( wxColor(*wxGREEN));
769 }
770 else
771 {
772 m_algoStatus->SetLabel("FAIL");
773 m_algoStatus->SetForegroundColour( wxColor(*wxRED));
774 }
775
776 auto rootItem = m_itemList->GetRootItem();
777
778 m_itemList->DeleteAllItems();
779 filterStringMatches( st->m_entries );
780 buildListTree( rootItem, st->m_entries );
781 m_itemList->CheckItemRecursively( rootItem, wxCHK_UNCHECKED );
782
784
785 m_itemList->Refresh();
786}
787
789{
790 auto viewTracker = m_logPlayer->GetViewTracker();
791 PNS_LOG_VIEW_TRACKER::VIEW_ENTRIES& entries = viewTracker->GetEntriesForStage( iter );
792 auto view = m_galPanel->GetView();
793 printf("DBG updatePnsPreviewItems: %zu items\n", entries.size() );
794
795 m_previewItems.reset( new KIGFX::VIEW_GROUP( m_galPanel->GetView() ) );
796 m_galPanel->GetView()->Add( m_previewItems.get() );
798 m_galPanel->GetView()->SetLayerVisible( LAYER_SELECT_OVERLAY );
799
800 if( !m_showRPIs )
801 return;
802
803 for( auto& ent : entries )
804 {
805 if ( ent.isHideOp )
806 {
807
808 auto parent = ent.item->Parent();
809 if( parent )
810 {
811
812 view->Hide( parent );
813 }
814 }
815 else
816 {
817 ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( ent.item, view );
818 pitem->Update( ent.item );
819 m_previewItems->Add(pitem);
820 // printf("DBG vadd %p total %d\n", pitem, m_previewItems->GetSize() );
821 }
822 }
823
824 view->SetVisible( m_previewItems.get(), true );
825
826 view->Update( m_previewItems.get() );
827 printf("DBG vgrp %p total %d\n", m_previewItems.get(), m_previewItems->GetSize() );
828
829
830 //view->UpdateAllItems( KIGFX::ALL );
831}
832
833#if 0
834
835static BOARD* loadBoard( const std::string& filename )
836{
838 BOARD* brd = nullptr;
839
840 try
841 {
842 brd = pi->Load( wxString( filename.c_str() ), nullptr, nullptr );
843 }
844 catch( const IO_ERROR& )
845 {
846 return nullptr;
847 }
848
849 return brd;
850}
851
852
853
854
855
856int render_perftest_main_func( int argc, char* argv[] )
857{
858 auto frame = new PNS_LOG_VIEWER_FRAME( nullptr );
859
860 // drcCreateTestsProviderClearance();
861 // drcCreateTestsProviderEdgeClearance();
862
863 if( argc >= 2 && std::string( argv[1] ) == "-h" )
864 {
865 printf( "PCB render performance test. Just renders a board without UI update overhead.\n" );
866 return 0;
867 }
868
869 if( argc < 2 )
870 {
871 printf( "Expected parameters: board_file\n" );
872 return 0;
873 }
874
875 PROF_TIMER cnt("load-board");
876 std::shared_ptr<BOARD> brd ( loadBoard( argv[1] ) );
877 cnt.Stop();
878
879 KI_TRACE( traceGalProfile, "%s\n", cnt.to_string() );
880
881 frame->SetBoard2( brd );
882
883 return 0;
884}
885
886
887static bool registered3 = UTILITY_REGISTRY::Register( {
888 "render_perftest",
889 "Renderer performance test",
890 render_perftest_main_func,
891} );
892
893
894VECTOR2I NearestPointFixpt( SEG seg, const VECTOR2I& aP )
895{
896 VECTOR2I d = seg.B - seg.A;
897 SEG::ecoord l_squared = d.Dot( d );
898
899 if( l_squared == 0 )
900 return seg.A;
901
902 SEG::ecoord t = d.Dot( aP - seg.A );
903
904 if( t < 0 )
905 return seg.A;
906 else if( t > l_squared )
907 return seg.B;
908
909 int xp = rescale( t, (SEG::ecoord) d.x, l_squared );
910 int yp = rescale( t, (SEG::ecoord) d.y, l_squared );
911
912 return seg.A + VECTOR2I( xp, yp );
913}
914
915
916VECTOR2D NearestPointDbl( SEG seg, const VECTOR2I& aP )
917{
918 VECTOR2D d = seg.B - seg.A;
919 double l_squared = d.Dot(d);
920
921 if( l_squared == 0 )
922 return seg.A;
923
924 double t = d.Dot(VECTOR2D( aP - seg.A ) );
925
926 if( t < 0 )
927 return seg.A;
928 else if( t > l_squared )
929 return seg.B;
930
931 double xp = t * d.x / l_squared;
932 double yp = t * d.y / l_squared;
933
934 return VECTOR2D(seg.A) + VECTOR2D( xp, yp );
935}
936
937int ttt_main_func( int argc, char* argv[] )
938{
939 int n = 1000000;
940 std::vector<VECTOR2I> pts;
941 std::vector<SEG> segs;
942 std::vector<VECTOR2D> rv;
943 std::vector<VECTOR2I> rvi;
944
945
946 rv.resize(n);
947 rvi.resize(n);
948
949 for (int i = 0; i < n ;i++)
950 {
951 pts.push_back(VECTOR2I(random()%100000000, random()%100000000));
952 segs.push_back(SEG( VECTOR2I(random()%100000000, random()%100000000), VECTOR2I(random()%100000000, random()%100000000) ) );
953 }
954
955 PROF_TIMER tmrFix("nearest-fixpt");
956 for(int i = 0; i < n ; i++)
957 {
958 rvi[i] = NearestPointFixpt( segs[i], pts[i]);
959 }
960 tmrFix.Show();
961
962 PROF_TIMER tmrDbl("nearest-double");
963 for(int i = 0; i < n ; i++)
964 {
965 rv[i] = NearestPointDbl( segs[i], pts[i]);
966 }
967 tmrDbl.Show();
968 return 0;
969}
970
971
972
973static bool registered4 = UTILITY_REGISTRY::Register( {
974 "ttt",
975 "Renderer performance test",
976 ttt_main_func,
977} );
978
979#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:270
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:103
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:310
Abstract interface for drawing on a 2D-surface.
PCB specific render settings.
Definition: pcb_painter.h:70
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:562
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:96
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:124
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:465
WX_SHAPE_TREE_ITEM_DATA(PNS_DEBUG_SHAPE *item, int level=0)
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
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
@ SH_RECT
axis-aligned rectangle
Definition: shape.h:45
@ SH_CIRCLE
circle
Definition: shape.h:48
@ SH_SEGMENT
line segment
Definition: shape.h:46
@ SH_LINE_CHAIN
line chain (polyline)
Definition: shape.h:47
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
Definition: shape.h:51
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:587
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588