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