KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_kicad_diff.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, see AUTHORS.txt for contributors.
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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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#include "dialog_kicad_diff.h"
25
28
29#include <bitmaps.h>
30#include <eda_draw_frame.h>
31#include <layer_ids.h>
32#include <lseq.h>
33#include <property_holder.h>
34#include <set>
35#include <wx/bmpbuttn.h>
36#include <wx/button.h>
37#include <wx/checkbox.h>
38#include <wx/choice.h>
39#include <wx/menu.h>
40#include <wx/settings.h>
41#include <wx/srchctrl.h>
42#include <wx/sizer.h>
43#include <wx/splitter.h>
44#include <wx/stattext.h>
45#include <wx/wrapsizer.h>
46#include <wx/wupdlock.h>
47
48
49DIALOG_KICAD_DIFF::DIALOG_KICAD_DIFF( wxWindow* aParent, const wxString& aReferencePath,
50 const wxString& aComparisonPath, const KICAD_DIFF::DOCUMENT_DIFF& aDiff,
51 KICAD_DIFF::DOCUMENT_GEOMETRY aReferenceGeometry,
52 KICAD_DIFF::DOCUMENT_GEOMETRY aComparisonGeometry, SHEET_SWITCHER aSheetSwitcher,
53 KIID_PATH aInitialSheet ) :
54 DIALOG_KICAD_DIFF_BASE( aParent ),
55 m_diff( aDiff ),
56 m_sheetSwitcher( std::move( aSheetSwitcher ) ),
57 m_currentCanvasSheet( std::move( aInitialSheet ) )
58{
59 SetEscapeId( wxID_OK );
60
61 // The base class resets the sash on the first idle event, after the saved one is restored
62 m_splitter->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_KICAD_DIFF_BASE::m_splitterOnIdle ), nullptr, this );
63 m_splitter->SetSashPosition( FromDIP( 280 ) );
64
65 m_treeChanges->Bind( wxEVT_TREE_ITEM_MENU, &DIALOG_KICAD_DIFF::OnTreeItemMenu, this );
66
67 m_pathReference->SetLabel( aReferencePath );
68 m_pathComparison->SetLabel( aComparisonPath );
69
70 // Two property columns: name | before -> after
71 m_listProperties->AppendColumn( _( "Property" ), wxLIST_FORMAT_LEFT, 180 );
72 m_listProperties->AppendColumn( _( "Before" ), wxLIST_FORMAT_LEFT, 160 );
73 m_listProperties->AppendColumn( _( "After" ), wxLIST_FORMAT_LEFT, 160 );
74
75 // Splice a search box above the change tree. Empty filter = show all.
76 if( wxSizer* treeSizer = m_panelTree->GetSizer() )
77 {
78 wxSearchCtrl* search = new wxSearchCtrl( m_panelTree, wxID_ANY );
79 OptOut( search );
80 search->SetDescriptiveText( _( "Filter changes…" ) );
81 search->ShowCancelButton( true );
82
83 auto onSearch = [this, search]( wxCommandEvent& aEvent )
84 {
85 // BuildChangeTreeGroups lowercases internally; keep the
86 // raw input here so a future surface displaying the
87 // active filter (e.g. tooltip) preserves capitalization.
88 m_searchFilter = search->GetValue();
89 buildTree();
90 aEvent.Skip();
91 };
92
93 // wxSearchCtrl's cancel button fires its own event on some ports
94 // (notably macOS); binding both keeps the filter cleared whichever
95 // path the user takes to empty the box.
96 search->Bind( wxEVT_TEXT, onSearch );
97 search->Bind( wxEVT_SEARCHCTRL_CANCEL_BTN, onSearch );
98
99 treeSizer->Insert( 0, search, wxSizerFlags().Expand().Border( wxLEFT | wxRIGHT | wxTOP, 4 ) );
100 m_panelTree->Layout();
101 }
102
103 // Splice the thumbnail into the detail sizer between the summary label
104 // and the property list. Only construct when we can attach.
105 if( wxSizer* detailSizer = m_panelDetail->GetSizer() )
106 {
107 // Board on top, property list below, with a draggable sash. Gravity 1
108 // gives extra height to the board when the dialog grows.
109 wxSplitterWindow* detailSplitter =
110 new wxSplitterWindow( m_panelDetail, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE );
111 detailSplitter->SetSashGravity( 1.0 );
112 detailSplitter->SetMinimumPaneSize( 40 );
113
115
116 if( EDA_DRAW_FRAME* frame = dynamic_cast<EDA_DRAW_FRAME*>( aParent ) )
117 {
118 if( frame->GetCanvas() )
119 backend = frame->GetCanvas()->GetBackend();
120 }
121
122 m_canvas = new WIDGET_DIFF_CANVAS( detailSplitter, backend );
123
124 if( m_sheetSwitcher )
126
129
130 scene.referenceGeometry = std::move( aReferenceGeometry );
131 scene.comparisonGeometry = std::move( aComparisonGeometry );
133
134 // A board can have dozens of layers, so the checkboxes wrap rather than widen the dialog. The wrap
135 // sizer sits directly in the vertical detail sizer, the only parent that tells it its width
136 m_filterSizer = new wxWrapSizer( wxHORIZONTAL );
137
138 const std::array<std::pair<KICAD_DIFF::CATEGORY, wxString>, 4> categories{ {
139 { KICAD_DIFF::CATEGORY::ADDED, _( "Added" ) },
140 { KICAD_DIFF::CATEGORY::REMOVED, _( "Removed" ) },
141 { KICAD_DIFF::CATEGORY::MODIFIED, _( "Modified" ) },
142 { KICAD_DIFF::CATEGORY::CONFLICT, _( "Conflict" ) },
143 } };
144
145 for( const auto& [cat, label] : categories )
146 {
147 wxCheckBox* cb = new wxCheckBox( m_panelDetail, wxID_ANY, label );
148
149 // A restored value never reaches the canvas, and position-based keys shift between documents
150 OptOut( cb );
151 cb->SetValue( true );
152 cb->Bind( wxEVT_CHECKBOX,
153 [this, cat]( wxCommandEvent& aEvent )
154 {
155 m_canvas->SetCategoryVisible( cat, aEvent.IsChecked() );
156 buildTree();
157 } );
158 m_filterSizer->Add( cb, wxSizerFlags().Border( wxRIGHT, 8 ).Centre() );
159 }
160
161 m_layerControlsIndex = m_filterSizer->GetItemCount();
162 buildLayerControls( scene );
163
164 // Toggle the property list so the board can use the full detail panel.
165
166 wxCheckBox* propsToggle = new wxCheckBox( m_panelDetail, wxID_ANY, _( "Properties" ) );
167 OptOut( propsToggle );
168 propsToggle->SetValue( true );
169 propsToggle->Bind( wxEVT_CHECKBOX,
170 [this, detailSplitter]( wxCommandEvent& aEvent )
171 {
172 if( aEvent.IsChecked() && !detailSplitter->IsSplit() )
173 detailSplitter->SplitHorizontally( m_canvas, m_listProperties );
174 else if( !aEvent.IsChecked() && detailSplitter->IsSplit() )
175 detailSplitter->Unsplit( m_listProperties );
176 } );
177 m_filterSizer->Add( propsToggle, wxSizerFlags().Border( wxRIGHT, 8 ).Centre() );
178
179 // Move the property list out of the detail sizer and under the splitter
180 // so the sash can resize it. A small min height lets it shrink freely.
181 detailSizer->Detach( m_listProperties );
182 m_listProperties->Reparent( detailSplitter );
183 m_listProperties->SetMinSize( wxSize( -1, 40 ) );
184 detailSplitter->SplitHorizontally( m_canvas, m_listProperties, -200 );
185
186 propsToggle->SetValue( detailSplitter->IsSplit() );
187
188 size_t insertAt = std::min<size_t>( 1, detailSizer->GetItemCount() );
189 detailSizer->Insert( insertAt++, m_filterSizer, wxSizerFlags().Expand().Border( wxLEFT | wxRIGHT | wxTOP, 4 ) );
190 detailSizer->Insert( insertAt, detailSplitter, wxSizerFlags( 1 ).Expand().Border( wxALL, 4 ) );
191 m_panelDetail->Layout();
192
193 m_canvas->SetScene( std::move( scene ) );
194
195 m_canvas->SetPickHandler(
196 [this]( const std::optional<KIID_PATH>& aChangeId )
197 {
198 if( aChangeId )
199 {
200 m_suppressCenter = true;
201 selectChangeById( *aChangeId );
202 m_suppressCenter = false;
203 }
204 else if( m_treeChanges )
205 {
206 m_treeChanges->UnselectAll();
207 showChange( nullptr );
208 }
209 } );
210 }
211
212 buildTree();
213 Layout();
214}
215
216
218{
219 if( m_diff.Empty() )
220 m_labelSummary->SetLabel( _( "No differences detected." ) );
221 else
222 m_labelSummary->SetLabel( wxString::Format(
223 wxPLURAL( "%zu change detected.", "%zu changes detected.", m_diff.Size() ), m_diff.Size() ) );
224}
225
226
227void DIALOG_KICAD_DIFF::OnClose( wxCloseEvent& aEvent )
228{
229 EndModal( wxID_OK );
230}
231
232
233void DIALOG_KICAD_DIFF::OnOK( wxCommandEvent& aEvent )
234{
235 EndModal( wxID_OK );
236}
237
238
240{
241 wxTreeItemId sel = aEvent.GetItem();
242
243 if( !sel.IsOk() )
244 {
245 showChange( nullptr );
246 return;
247 }
248
249 auto it = m_changeByTreeId.find( reinterpret_cast<wxUIntPtr>( sel.GetID() ) );
250
251 if( it == m_changeByTreeId.end() )
252 {
253 showChange( nullptr ); // group node — no per-item details
254 return;
255 }
256
257 showChange( it->second );
258}
259
260
261std::optional<KIID_PATH> DIALOG_KICAD_DIFF::selectedChangeId() const
262{
263 if( wxTreeItemId sel = m_treeChanges->GetSelection(); sel.IsOk() )
264 {
265 auto it = m_changeByTreeId.find( reinterpret_cast<wxUIntPtr>( sel.GetID() ) );
266
267 if( it != m_changeByTreeId.end() && it->second )
268 return it->second->id;
269 }
270
271 return std::nullopt;
272}
273
274
275void DIALOG_KICAD_DIFF::buildTree( const std::optional<KIID_PATH>& aSelect )
276{
277 wxWindowUpdateLocker updateLock( m_treeChanges );
278
279 m_treeChanges->DeleteAllItems();
280 m_changeByTreeId.clear();
281
282 wxTreeItemId root = m_treeChanges->AddRoot( wxS( "root" ) );
283
284 // Per-category visibility comes from the canvas's checkbox row when
285 // present (the dialog hosts both a thumbnail canvas and the tree).
286 // With no canvas (degenerate test path) treat every category as visible.
287 std::array<bool, KICAD_DIFF::CATEGORY_COUNT> visibleCats{};
288 visibleCats.fill( true );
289
290 if( m_canvas )
291 {
292 for( std::size_t i = 0; i < KICAD_DIFF::CATEGORY_COUNT; ++i )
293 {
294 visibleCats[i] = m_canvas->IsCategoryVisible( static_cast<KICAD_DIFF::CATEGORY>( i ) );
295 }
296 }
297
300 {
301 wxTreeItemId groupNode = m_treeChanges->AppendItem( root, group.groupLabel );
302
303 for( const KICAD_DIFF::CHANGE_TREE_ENTRY& entry : group.entries )
304 {
305 wxTreeItemId itemNode = m_treeChanges->AppendItem( groupNode, entry.itemLabel );
306 m_changeByTreeId[reinterpret_cast<wxUIntPtr>( itemNode.GetID() )] = entry.change;
307 }
308
309 m_treeChanges->Expand( groupNode );
310 }
311
312 if( !aSelect || !selectChangeById( *aSelect ) )
313 showChange( nullptr );
314
316}
317
318
319void DIALOG_KICAD_DIFF::OnTreeItemMenu( wxTreeEvent& aEvent )
320{
321 wxTreeItemId item = aEvent.GetItem();
322
323 if( !item.IsOk() )
324 return;
325
326 auto it = m_changeByTreeId.find( reinterpret_cast<wxUIntPtr>( item.GetID() ) );
327
328 if( it == m_changeByTreeId.end() || !it->second )
329 return; // group node, nothing to hide
330
331 const std::vector<KIID_PATH> ids = changeRowIds( *it->second );
332 const bool hidden = m_hiddenChanges.count( it->second->id ) > 0;
333
334 enum
335 {
336 ID_HIDE = wxID_HIGHEST + 1,
337 ID_SHOW,
338 ID_SHOW_ALL
339 };
340
341 wxMenu menu;
342
343 if( hidden )
344 menu.Append( ID_SHOW, _( "Show Change" ) );
345 else
346 menu.Append( ID_HIDE, _( "Hide Change" ) );
347
348 menu.Append( ID_SHOW_ALL, _( "Show All Hidden" ) );
349 menu.Enable( ID_SHOW_ALL, !m_hiddenChanges.empty() );
350
351 switch( m_treeChanges->GetPopupMenuSelectionFromUser( menu ) )
352 {
353 case ID_HIDE: m_hiddenChanges.insert( ids.begin(), ids.end() ); break;
354 case ID_SHOW:
355 for( const KIID_PATH& id : ids )
356 m_hiddenChanges.erase( id );
357 break;
358 case ID_SHOW_ALL: m_hiddenChanges.clear(); break;
359 default: return;
360 }
361
362 if( m_canvas )
363 m_canvas->SetHiddenChanges( m_hiddenChanges );
364
366}
367
368
369std::vector<KIID_PATH> DIALOG_KICAD_DIFF::changeRowIds( const KICAD_DIFF::ITEM_CHANGE& aChange ) const
370{
371 if( !KICAD_DIFF::IsRoutingNetChange( aChange ) )
372 return { aChange.id };
373
374 std::vector<KIID_PATH> ids;
375
376 std::function<void( const std::vector<KICAD_DIFF::ITEM_CHANGE>& )> walk =
377 [&]( const std::vector<KICAD_DIFF::ITEM_CHANGE>& aChanges )
378 {
379 for( const KICAD_DIFF::ITEM_CHANGE& c : aChanges )
380 {
381 if( KICAD_DIFF::IsRoutingNetChange( c ) && c.kind == aChange.kind && c.refdes == aChange.refdes )
382 {
383 ids.push_back( c.id );
384 }
385
386 walk( c.children );
387 }
388 };
389
390 walk( m_diff.changes );
391 return ids;
392}
393
394
396{
397 const wxColour grey = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
398 const wxColour normal = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
399
400 for( const auto& [key, change] : m_changeByTreeId )
401 {
402 if( !change )
403 continue;
404
405 wxTreeItemId node( reinterpret_cast<void*>( key ) );
406 const bool hidden = m_hiddenChanges.count( change->id ) > 0;
407
408 m_treeChanges->SetItemTextColour( node, hidden ? grey : normal );
409 }
410}
411
412
413void DIALOG_KICAD_DIFF::SetRevisionChooser( const std::vector<wxString>& aLabels, int aSelected,
414 REVISION_HANDLER aOnChange )
415{
416 wxSizer* top = GetSizer();
417
418 if( !top || aLabels.empty() )
419 return;
420
421 m_revisionHandler = std::move( aOnChange );
422
423 wxBoxSizer* row = new wxBoxSizer( wxHORIZONTAL );
424 row->Add( new wxStaticText( this, wxID_ANY, _( "Revision:" ) ), wxSizerFlags().Border( wxRIGHT, 4 ).Centre() );
425
426 wxArrayString choices;
427
428 for( const wxString& label : aLabels )
429 choices.Add( label );
430
431 m_revisionChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices );
432 m_revisionChoice->SetSelection( aSelected );
433
434 // The caller loads the revision it selects, so a restored choice would disagree with the diff
436 row->Add( m_revisionChoice, wxSizerFlags( 1 ).Centre() );
437
438 wxButton* olderBtn = new wxButton( this, wxID_ANY, _( "Older" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
439 wxButton* newerBtn = new wxButton( this, wxID_ANY, _( "Newer" ), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
440 row->Add( olderBtn, wxSizerFlags().Border( wxLEFT, 4 ).Centre() );
441 row->Add( newerBtn, wxSizerFlags().Border( wxLEFT, 2 ).Centre() );
442
443 auto fire = [this]( int aIndex )
444 {
445 if( aIndex < 0 || aIndex >= static_cast<int>( m_revisionChoice->GetCount() ) )
446 return;
447
448 m_revisionChoice->SetSelection( aIndex );
449
451 m_revisionHandler( aIndex );
452 };
453
454 m_revisionChoice->Bind( wxEVT_CHOICE,
455 [fire]( wxCommandEvent& aEvent )
456 {
457 fire( aEvent.GetSelection() );
458 } );
459
460 // Snapshots are newest-first, so older steps up the index and newer down.
461 olderBtn->Bind( wxEVT_BUTTON,
462 [this, fire]( wxCommandEvent& )
463 {
464 fire( m_revisionChoice->GetSelection() + 1 );
465 } );
466 newerBtn->Bind( wxEVT_BUTTON,
467 [this, fire]( wxCommandEvent& )
468 {
469 fire( m_revisionChoice->GetSelection() - 1 );
470 } );
471
472 top->Insert( 0, row, wxSizerFlags().Expand().Border( wxALL, 4 ) );
473 Layout();
474}
475
476
478{
479 m_upHandler = std::move( aHandler );
480
481 if( !m_filterSizer || m_btnUp )
482 return;
483
484 m_btnUp = new wxBitmapButton( m_panelDetail, wxID_ANY, KiBitmapBundle( BITMAPS::up ) );
485 m_btnUp->SetToolTip( _( "Navigate up one sheet in the hierarchy" ) );
486 m_btnUp->Enable( false );
487
488 m_btnUp->Bind( wxEVT_BUTTON,
489 [this]( wxCommandEvent& )
490 {
491 if( m_upHandler )
492 m_upHandler();
493 } );
494
495 m_filterSizer->Insert( 0, m_btnUp, wxSizerFlags().Border( wxRIGHT, 8 ).Centre() );
496 m_panelDetail->Layout();
497}
498
499
500void DIALOG_KICAD_DIFF::EnableUp( bool aEnable )
501{
502 if( m_btnUp )
503 m_btnUp->Enable( aEnable );
504}
505
506
507void DIALOG_KICAD_DIFF::Reload( const wxString& aReferencePath, const wxString& aComparisonPath,
509 KICAD_DIFF::DOCUMENT_GEOMETRY aComparisonGeometry, SHEET_SWITCHER aSheetSwitcher,
510 KIID_PATH aInitialSheet )
511{
512 m_pathReference->SetLabel( aReferencePath );
513 m_pathComparison->SetLabel( aComparisonPath );
514
515 // The tree rows point into the diff being replaced
516 const std::optional<KIID_PATH> selected = selectedChangeId();
517 m_changeByTreeId.clear();
518 m_diff = std::move( aDiff );
519
520 // Outlives the canvas reconfigure below: it owns cloned items the view still references.
521 SHEET_SWITCHER previousSwitcher = std::move( m_sheetSwitcher );
522 m_sheetSwitcher = std::move( aSheetSwitcher );
523 m_currentCanvasSheet = std::move( aInitialSheet );
524
525 if( m_canvas )
526 {
527 // Hold rendering so reconfiguring the context and setting the new scene
528 // produce a single repaint instead of flashing an intermediate frame.
529 // EndUpdate must run even on a throw, or rendering stays frozen.
530 m_canvas->BeginUpdate();
531
532 try
533 {
534 m_canvas->HighlightChange( std::nullopt );
535
536 if( m_sheetSwitcher )
538
541
542 scene.referenceGeometry = std::move( aReferenceGeometry );
543 scene.comparisonGeometry = std::move( aComparisonGeometry );
545
546 // Another revision can have other layers
547 buildLayerControls( scene );
548 m_canvas->SetScene( std::move( scene ) );
549 }
550 catch( ... )
551 {
552 m_canvas->EndUpdate();
553 throw;
554 }
555
556 m_canvas->EndUpdate();
557 }
558
559 buildTree( selected );
560
561 Layout();
562
563 // The detail panel sits in a splitter, so the dialog Layout() skips it at an unchanged size
564 m_panelDetail->Layout();
565}
566
567
569{
570 m_listProperties->DeleteAllItems();
571
572 // Library differs name each change after its item
574 {
575 // Every library item sits at the origin, so only the one on show may be picked
577 shown.docType = m_diff.docType;
578
579 if( aChange )
580 shown.changes.push_back( *aChange );
581
583 m_drawLibraryItem( *m_canvas, aChange && aChange->refdes ? *aChange->refdes : wxString() );
584 }
585
586 if( !aChange )
587 {
589
590 if( m_canvas )
591 m_canvas->HighlightChange( std::nullopt );
592
593 return;
594 }
595
596 m_labelSummary->SetLabel( wxString::Format( wxS( "%s — %s" ), KICAD_DIFF::ChangeKindLabel( aChange->kind ),
597 aChange->DisplayType() ) );
598
599 if( m_canvas )
600 {
601 // Only auto-switch when the change carries a sheet prefix. Scoped
602 // diffs emit single-element ids with no sheet path.
603 if( aChange->id.size() > 1 )
604 {
605 KIID_PATH sheetPath = aChange->id;
606 sheetPath.pop_back();
607
608 if( sheetPath != m_currentCanvasSheet && m_sheetSwitcher )
609 {
610 m_currentCanvasSheet = sheetPath;
611 m_sheetSwitcher( *m_canvas, sheetPath );
612 }
613 }
614
615 m_canvas->HighlightChange( aChange->id );
616
617 if( !m_suppressCenter )
618 m_canvas->CenterOnHighlight();
619 }
620
621 long row = 0;
622 std::set<wxString> seen;
623 const EDA_UNITS units = GetUserUnits();
625
626 auto emitDelta = [&]( const wxString& aPrefix, const KICAD_DIFF::PROPERTY_DELTA& d )
627 {
628 const wxString label = aPrefix.IsEmpty() ? d.name : aPrefix + wxS( " / " ) + d.name;
629 const wxString beforeStr = d.before.ToDisplayString( units, iuScale );
630 const wxString afterStr = d.after.ToDisplayString( units, iuScale );
631 const wxString key = label + wxS( "|" ) + beforeStr + wxS( "|" ) + afterStr;
632
633 if( !seen.insert( key ).second )
634 return;
635
636 long idx = m_listProperties->InsertItem( row++, label );
637 m_listProperties->SetItem( idx, 1, beforeStr );
638 m_listProperties->SetItem( idx, 2, afterStr );
639 };
640
641 for( const KICAD_DIFF::PROPERTY_DELTA& d : aChange->properties )
642 emitDelta( wxEmptyString, d );
643
644 // When the clicked item carries its real diffs in children (e.g. a
645 // FOOTPRINT whose pad or field changed), surface those here so the panel
646 // is not empty for the parent.
647 std::function<void( const wxString&, const KICAD_DIFF::ITEM_CHANGE& )> walkChildren =
648 [&]( const wxString& aPrefix, const KICAD_DIFF::ITEM_CHANGE& aC )
649 {
650 for( const KICAD_DIFF::ITEM_CHANGE& child : aC.children )
651 {
652 wxString prefix = child.DisplayType();
653
654 if( child.refdes && !child.refdes->IsEmpty() )
655 prefix += wxS( " " ) + *child.refdes;
656
657 if( !aPrefix.IsEmpty() )
658 prefix = aPrefix + wxS( " / " ) + prefix;
659
660 for( const KICAD_DIFF::PROPERTY_DELTA& d : child.properties )
661 emitDelta( prefix, d );
662
663 walkChildren( prefix, child );
664 }
665 };
666
667 walkChildren( wxEmptyString, *aChange );
668}
669
670
672{
673 m_drawLibraryItem = std::move( aDraw );
674
675 // The whole-library geometry only seeds the layer checkboxes, drawn together it piles up
676 if( m_canvas )
677 {
678 m_canvas->SetChangeOutlinesShown( false );
680 }
681
682 // A canvas configured before it is shown keeps a black background, so select once it is
683 CallAfter(
684 [this]()
685 {
686 wxTreeItemIdValue groupCookie;
687 wxTreeItemId root = m_treeChanges->GetRootItem();
688
689 for( wxTreeItemId group = m_treeChanges->GetFirstChild( root, groupCookie ); group.IsOk();
690 group = m_treeChanges->GetNextChild( root, groupCookie ) )
691 {
692 wxTreeItemIdValue itemCookie;
693 wxTreeItemId item = m_treeChanges->GetFirstChild( group, itemCookie );
694
695 if( item.IsOk() )
696 {
697 m_treeChanges->SelectItem( item );
698 return;
699 }
700 }
701 } );
702}
703
704
706{
707 for( wxWindow* control : m_layerControls )
708 {
709 // The dialog frees opt-out markers only on its own close
710 delete PROPERTY_HOLDER::SafeCast( control->GetClientData() );
711 control->Destroy();
712 }
713
714 m_layerControls.clear();
715
718
719 if( layers.none() )
720 return;
721
722 std::map<PCB_LAYER_ID, wxString> layerNames = aScene.referenceGeometry.layerNames;
723
724 for( const auto& [layer, name] : aScene.comparisonGeometry.layerNames )
725 layerNames[layer] = name;
726
728
729 auto add = [&]( wxWindow* aControl, const wxSizerFlags& aFlags )
730 {
731 OptOut( aControl );
732 m_filterSizer->Insert( index++, aControl, aFlags );
733 m_layerControls.push_back( aControl );
734 };
735
736 add( new wxStaticText( m_panelDetail, wxID_ANY, _( "Layers:" ) ),
737 wxSizerFlags().Border( wxLEFT | wxRIGHT, 4 ).Centre() );
738
739 for( PCB_LAYER_ID layer : layers.UIOrder() )
740 {
741 auto nameIt = layerNames.find( layer );
742 const wxString label = nameIt != layerNames.end() ? nameIt->second : LayerName( layer );
743 wxCheckBox* cb = new wxCheckBox( m_panelDetail, wxID_ANY, label );
744
745 cb->SetValue( m_canvas->IsLayerVisible( layer ) );
746 cb->Bind( wxEVT_CHECKBOX,
747 [this, layer]( wxCommandEvent& aEvent )
748 {
749 m_canvas->SetLayerVisible( layer, aEvent.IsChecked() );
750 } );
751 add( cb, wxSizerFlags().Border( wxRIGHT, 8 ).Centre() );
752 }
753}
754
755
757{
758 for( const auto& [treeIdNum, change] : m_changeByTreeId )
759 {
760 if( change && change->id == aChangeId )
761 {
762 wxTreeItemId treeId( reinterpret_cast<void*>( treeIdNum ) );
763
764 m_treeChanges->EnsureVisible( treeId );
765 m_treeChanges->SelectItem( treeId );
766 return true;
767 }
768 }
769
770 return false;
771}
int index
const char * name
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
void m_splitterOnIdle(wxIdleEvent &)
DIALOG_KICAD_DIFF_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Compare Files"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(900, 650), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
std::vector< KIID_PATH > changeRowIds(const KICAD_DIFF::ITEM_CHANGE &aChange) const
Change ids a tree row stands for.
SHEET_SWITCHER m_sheetSwitcher
std::optional< KIID_PATH > selectedChangeId() const
The selected row's change id. Valid only while m_diff still owns the listed changes.
size_t m_layerControlsIndex
Index in m_filterSizer of the first layer control, which follow the category filters.
void OnTreeSelectionChanged(wxTreeEvent &aEvent) override
std::function< void(WIDGET_DIFF_CANVAS &, const wxString &aName)> LIBRARY_ITEM_DRAWER
std::set< KIID_PATH > m_hiddenChanges
Changes the user has muted via the tree's right-click menu.
void showChange(const KICAD_DIFF::ITEM_CHANGE *aChange)
Populate the property list for the change associated with the selected tree node, or clear the list i...
wxWrapSizer * m_filterSizer
std::function< void(int aIndex)> REVISION_HANDLER
WIDGET_DIFF_CANVAS * m_canvas
GAL-backed canvas showing the DIFF_SCENE shape rectangles.
void DrawChosenLibraryItem(LIBRARY_ITEM_DRAWER aDraw)
Draw only the library item named by the chosen change, since the outlines of a whole library pile up ...
std::function< void()> UP_HANDLER
std::map< wxUIntPtr, const KICAD_DIFF::ITEM_CHANGE * > m_changeByTreeId
Maps tree item IDs to the underlying change record so selection can find the data without walking the...
std::vector< wxWindow * > m_layerControls
void OnOK(wxCommandEvent &aEvent) override
void buildTree()
Populate the tree from m_diff, keeping the selected change. Groups by CHANGE_KIND.
void SetUpHandler(UP_HANDLER aHandler)
std::function< void(WIDGET_DIFF_CANVAS &, const KIID_PATH &)> SHEET_SWITCHER
wxString m_searchFilter
Lowercased free-text filter applied to typeName / refdes.
void applyHiddenToTree()
Grey out tree rows whose change is in m_hiddenChanges, restore the rest.
DIALOG_KICAD_DIFF(wxWindow *aParent, const wxString &aReferencePath, const wxString &aComparisonPath, const KICAD_DIFF::DOCUMENT_DIFF &aDiff, KICAD_DIFF::DOCUMENT_GEOMETRY aReferenceGeometry={}, KICAD_DIFF::DOCUMENT_GEOMETRY aComparisonGeometry={}, SHEET_SWITCHER aSheetSwitcher={}, KIID_PATH aInitialSheet={})
bool selectChangeById(const KIID_PATH &aChangeId)
Select the tree row whose change has the given KIID_PATH.
KICAD_DIFF::DOCUMENT_DIFF m_diff
void OnClose(wxCloseEvent &aEvent) override
REVISION_HANDLER m_revisionHandler
void OnTreeItemMenu(wxTreeEvent &aEvent)
LIBRARY_ITEM_DRAWER m_drawLibraryItem
void showDiffSummary()
Report the number of changes in the summary label.
void buildLayerControls(const KICAD_DIFF::DIFF_SCENE &aScene)
Replace the layer checkboxes with one per layer of aScene's geometry, after the category filters.
void EnableUp(bool aEnable)
bool m_suppressCenter
True while a canvas click is propagating into the tree, so the tree- selection handler skips re-cente...
void SetRevisionChooser(const std::vector< wxString > &aLabels, int aSelected, REVISION_HANDLER aOnChange)
Add a revision dropdown (with prev/next) at the top.
void Reload(const wxString &aReferencePath, const wxString &aComparisonPath, KICAD_DIFF::DOCUMENT_DIFF aDiff, KICAD_DIFF::DOCUMENT_GEOMETRY aReferenceGeometry, KICAD_DIFF::DOCUMENT_GEOMETRY aComparisonGeometry, SHEET_SWITCHER aSheetSwitcher, KIID_PATH aInitialSheet)
Swap in a fresh diff with new schematics.
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
EDA_UNITS GetUserUnits() const
The base class for create windows for drawing purpose.
static constexpr GAL_TYPE GAL_FALLBACK
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
static PROPERTY_HOLDER * SafeCast(void *aPtr) noexcept
Safely cast a void pointer to PROPERTY_HOLDER*.
GAL-backed canvas for visualizing a KICAD_DIFF::DIFF_SCENE.
#define _(s)
EDA_UNITS
Definition eda_units.h:45
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition layer_id.cpp:31
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
constexpr std::size_t CATEGORY_COUNT
Definition diff_scene.h:75
DIFF_SCENE BuildScene(const DOCUMENT_DIFF &aDiff, const DIFF_COLOR_THEME &aTheme)
Build a DIFF_SCENE from a DOCUMENT_DIFF, populating the shape lists and computing the union bbox.
LSET GeometryLayerSet(const DOCUMENT_GEOMETRY &aGeometry)
Return the union of every non-empty layer set carried by the geometry.
const EDA_IU_SCALE & IuScaleForDocKind(DOC_KIND aKind)
Internal-unit scale a document kind's coordinates are expressed in.
Definition diff_scene.h:256
std::vector< CHANGE_TREE_GROUP > BuildChangeTreeGroups(const DOCUMENT_DIFF &aDiff, const wxString &aSearchFilter, const std::array< bool, CATEGORY_COUNT > &aVisibleCategories)
Group the changes in a DOCUMENT_DIFF by kind, apply category and search filters, and return the resul...
wxString ChangeKindLabel(CHANGE_KIND aKind)
Human-readable label for a CHANGE_KIND (e.g.
void ExpandBBoxToGeometry(DIFF_SCENE &aScene)
Grow the scene's documentBBox to also include the extent of any background geometry.
bool IsRoutingNetChange(const ITEM_CHANGE &aChange)
Presentation predicate for PCB routing changes that should be displayed as one net-level entry/shape.
CATEGORY
Visual category each ITEM_CHANGE belongs to in the scene.
Definition diff_scene.h:52
DOC_KIND DocKindFromDocType(const wxString &aDocType)
Map a DOCUMENT_DIFF::docType tag written by the differs ("kicad_pcb", "kicad_sch",...
STL namespace.
One row in a grouped change tree — an ITEM_CHANGE plus its display label (typeName + optional refdes ...
const ITEM_CHANGE * change
wxString itemLabel
One bucket in a grouped change tree — a CHANGE_KIND, a human- readable group label,...
Diff colors with defaults for light backgrounds.
Definition diff_scene.h:278
DOCUMENT_GEOMETRY referenceGeometry
Background geometry from the two source documents.
Definition diff_scene.h:242
DOCUMENT_GEOMETRY comparisonGeometry
Definition diff_scene.h:243
The full set of changes between two parsed documents of one type.
std::vector< ITEM_CHANGE > changes
Aggregate of background geometry extracted from one source document.
Definition diff_scene.h:163
std::map< PCB_LAYER_ID, wxString > layerNames
Board layer names, including user-assigned ones. Empty for documents without a board.
Definition diff_scene.h:169
One change record on a single item.
const wxString & DisplayType() const
std::vector< PROPERTY_DELTA > properties
std::optional< wxString > refdes
std::vector< ITEM_CHANGE > children
Single (name, before, after) triple for one mutated property on an item.
KIBIS top(path, &reporter)