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