KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_drc.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2009-2016 Dick Hollenbeck, [email protected]
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "dialog_drc.h"
23
24#include <wx/app.h>
25#include <wx/filedlg.h>
26#include <wx/msgdlg.h>
27#include <wx/statusbr.h>
28#include <wx/wupdlock.h>
29
30#include <bitmaps.h>
31#include <confirm.h>
32#include <core/throttle.h>
34#include <kiface_base.h>
35#include <macros.h>
36#include <pad.h>
37#include <drc/drc_engine.h>
38#include <drc/drc_item.h>
39#include <drc/drc_report.h>
40#include <drc/drc_rule.h>
44#include <pcb_edit_frame.h>
45#include <tool/tool_manager.h>
46#include <tools/pcb_actions.h>
48#include <pcb_marker.h>
49#include <pcb_track.h>
50#include <pgm_base.h>
52#include <widgets/ui_common.h>
57#include <view/view_controls.h>
60#include <tools/drc_tool.h>
63#include <kiplatform/ui.h>
64
65// wxWidgets spends *far* too long calcuating column widths (most of it, believe it or
66// not, in repeatedly creating/destroying a wxDC to do the measurement in).
67// Use default column widths instead.
68static int DEFAULT_SINGLE_COL_WIDTH = 660;
69
70static BOARD* g_lastDRCBoard = nullptr;
71static bool g_lastDRCRun = false;
72static bool g_lastFootprintTestsRun = false;
73
74static std::vector<std::pair<wxString, int>> g_lastIgnored;
75
76
77static PCB_MARKER* findMarker( BOARD* aBoard, const std::shared_ptr<RC_ITEM>& aItem )
78{
79 for( PCB_MARKER* marker : aBoard->Markers() )
80 {
81 if( marker->GetRCItem() == aItem )
82 return marker;
83 }
84
85 return nullptr;
86}
87
88
89DIALOG_DRC::DIALOG_DRC( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent ) :
90 DIALOG_DRC_BASE( aParent ),
92 m_running( false ),
93 m_drcRun( false ),
94 m_footprintTestsRun( false ),
96 m_crossprobe( true ),
98 m_markersTreeModel( nullptr ),
99 m_unconnectedTreeModel( nullptr ),
100 m_fpWarningsTreeModel( nullptr ),
101 m_updateThrottle( std::chrono::milliseconds( 100 ) ),
102 m_yieldThrottle( std::chrono::milliseconds( 2000 ) ),
103 m_drcStatusBar( nullptr ),
105{
106 SetName( DIALOG_DRC_WINDOW_NAME ); // Set a window name to be able to find it
108
109 m_frame = aEditorFrame;
110 m_currentBoard = m_frame->GetBoard();
111
112 m_bMenu->SetBitmap( KiBitmapBundle( BITMAPS::config ) );
113
114 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
115 {
116 m_report_all_track_errors = cfg->m_DRCDialog.report_all_track_errors;
117 m_crossprobe = cfg->m_DRCDialog.crossprobe;
118 m_scroll_on_crossprobe = cfg->m_DRCDialog.scroll_on_crossprobe;
119 }
120
121 m_messages->SetImmediateMode();
122
123 m_markersProvider = std::make_shared<DRC_ITEMS_PROVIDER>( m_currentBoard,
126
127 m_ratsnestProvider = std::make_shared<DRC_ITEMS_PROVIDER>( m_currentBoard,
129
130 m_fpWarningsProvider = std::make_shared<DRC_ITEMS_PROVIDER>( m_currentBoard,
132
133 auto installModel = [this]( RC_TREE_MODEL*& aModel, wxDataViewCtrl* aCtrl )
134 {
135 aModel = new RC_TREE_MODEL( m_frame, aCtrl );
136 aModel->EnableHyperlinks( true );
137 aCtrl->AssociateModel( aModel );
138 installLinkHandlers( aCtrl );
139 };
140
141 installModel( m_markersTreeModel, m_markerDataView );
144
145 // Prevent RTL locales from mirroring the text in the data views
146 m_markerDataView->SetLayoutDirection( wxLayout_LeftToRight );
147 m_unconnectedDataView->SetLayoutDirection( wxLayout_LeftToRight );
148 m_footprintsDataView->SetLayoutDirection( wxLayout_LeftToRight );
149 m_ignoredList->SetLayoutDirection( wxLayout_LeftToRight );
150
151 m_ignoredList->InsertColumn( 0, wxEmptyString, wxLIST_FORMAT_LEFT, DEFAULT_SINGLE_COL_WIDTH );
152
154 {
157
158 for( const auto& [ str, code ] : g_lastIgnored )
159 {
160 wxListItem listItem;
161 listItem.SetId( m_ignoredList->GetItemCount() );
162 listItem.SetText( str );
163 listItem.SetData( code );
164
165 m_ignoredList->InsertItem( listItem );
166 }
167 }
168
169 m_Notebook->SetSelection( 0 );
170
171 if( Kiface().IsSingle() )
172 m_cbTestFootprints->Hide();
173
174 SetupStandardButtons( { { wxID_OK, _( "Run DRC" ) },
175 { wxID_CANCEL, _( "Close" ) } } );
176
177 m_markersTitleTemplate = m_Notebook->GetPageText( 0 );
178 m_unconnectedTitleTemplate = m_Notebook->GetPageText( 1 );
179 m_footprintsTitleTemplate = m_Notebook->GetPageText( 2 );
180 m_ignoredTitleTemplate = m_Notebook->GetPageText( 3 );
181
182 // DPI fix
183 bSizerViolationsBox->SetMinSize( FromDIP( bSizerViolationsBox->GetMinSize() ) );
184
185 m_drcStatusBar = new wxStatusBar( this, wxID_ANY, wxSTB_DEFAULT_STYLE );
186 m_drcStatusBar->SetFieldsCount( 2 );
187
188 int statusBarWidths[2] = { FromDIP( 12 ), -1 };
189 m_drcStatusBar->SetStatusWidths( 2, statusBarWidths );
190
191 if( wxSizer* mainSizer = GetSizer() )
192 mainSizer->Add( m_drcStatusBar, 0, wxEXPAND );
193
194 Layout(); // adding the units above expanded Clearance text, now resize.
195
196 SetFocus();
197
199}
200
201
203{
204 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
205 {
206 cfg->m_DRCDialog.report_all_track_errors = m_report_all_track_errors;
207 cfg->m_DRCDialog.crossprobe = m_crossprobe;
208 cfg->m_DRCDialog.scroll_on_crossprobe = m_scroll_on_crossprobe;
209 }
210
211 m_frame->ClearFocus();
212
216
217 g_lastIgnored.clear();
218
219 for( int ii = 0; ii < m_ignoredList->GetItemCount(); ++ii )
220 g_lastIgnored.push_back( { m_ignoredList->GetItemText( ii ), m_ignoredList->GetItemData( ii ) } );
221
222 m_markersTreeModel->DecRef();
223 m_unconnectedTreeModel->DecRef();
224 m_fpWarningsTreeModel->DecRef();
225}
226
227
228void DIALOG_DRC::installLinkHandlers( wxDataViewCtrl* aCtrl )
229{
230 aCtrl->Bind( wxEVT_MOTION, &DIALOG_DRC::onDataViewMotion, this );
231 aCtrl->Bind( wxEVT_LEFT_UP, &DIALOG_DRC::onDataViewLeftUp, this );
232}
233
234
235void DIALOG_DRC::onDataViewMotion( wxMouseEvent& aEvent )
236{
237 aEvent.Skip();
238
239 wxDataViewCtrl* ctrl = dynamic_cast<wxDataViewCtrl*>( aEvent.GetEventObject() );
240
241 if( !ctrl )
242 return;
243
244 bool overLink = hitTestLink( ctrl, aEvent.GetPosition(), nullptr );
245 ctrl->SetCursor( overLink ? wxCursor( wxCURSOR_HAND ) : wxNullCursor );
246}
247
248
249void DIALOG_DRC::onDataViewLeftUp( wxMouseEvent& aEvent )
250{
251 aEvent.Skip();
252
253 wxDataViewCtrl* ctrl = dynamic_cast<wxDataViewCtrl*>( aEvent.GetEventObject() );
254 wxString href;
255
256 if( ctrl && hitTestLink( ctrl, aEvent.GetPosition(), &href ) )
257 wxLaunchDefaultBrowser( href );
258}
259
260
261bool DIALOG_DRC::hitTestLink( wxDataViewCtrl* aCtrl, const wxPoint& aPoint, wxString* aHref )
262{
263 wxDataViewModel* model = aCtrl->GetModel();
264
265 if( !model )
266 return false;
267
268 wxDataViewItem item;
269 wxDataViewColumn* col = nullptr;
270 aCtrl->HitTest( aPoint, item, col );
271
272 if( !item.IsOk() || !col )
273 return false;
274
275 HYPERLINK_DV_RENDERER* hl = dynamic_cast<HYPERLINK_DV_RENDERER*>( col->GetRenderer() );
276
277 if( !hl )
278 return false;
279
280 wxVariant value;
281 wxDataViewItemAttr attr;
282
283 model->GetValue( value, item, col->GetModelColumn() );
284 model->GetAttr( item, col->GetModelColumn(), attr );
285
286 wxRect cellRect = aCtrl->GetItemRect( item, col );
287
288 return hl->HitTestRunsForCell( value.GetString(), attr, cellRect, aPoint, aHref );
289}
290
291
293{
294 UpdateData();
295 return true;
296}
297
298
299void DIALOG_DRC::OnActivateDlg( wxActivateEvent& aEvent )
300{
301 if( m_currentBoard != m_frame->GetBoard() )
302 {
303 // If m_currentBoard is not the current board, (for instance because a new board was loaded),
304 // close the dialog, because many pointers are now invalid in lists
305 SetReturnCode( wxID_CANCEL );
306 Close();
307
308 DRC_TOOL* drcTool = m_frame->GetToolManager()->GetTool<DRC_TOOL>();
309 drcTool->DestroyDRCDialog();
310
311 return;
312 }
313
314 // Let DIALOG_SHIM re-establish keyboard focus so ESC keeps closing the dialog.
315 aEvent.Skip();
316}
317
318
319// PROGRESS_REPORTER calls
320
322{
323 if( m_maxProgress != 0 )
324 {
325 double cur = std::clamp( (double) m_progress.load() / m_maxProgress, 0.0, 1.0 );
326
327 int newValue = KiROUND( cur * 1000.0 );
328 m_gauge->SetValue( newValue );
329 }
330
332 {
333 int elapsed = static_cast<int>(
334 std::chrono::duration_cast<std::chrono::seconds>( std::chrono::steady_clock::now() - m_drcStartTime )
335 .count() );
336
337 if( elapsed != m_lastTickSeconds )
338 {
339 m_lastTickSeconds = elapsed;
340
341 wxString tick;
342
343 if( elapsed >= 60 )
344 tick = wxString::Format( wxT( "%1$d min %2$d s" ), elapsed / 60, elapsed % 60 );
345 else
346 tick = wxString::Format( wxT( "%d s" ), elapsed );
347
348 m_drcStatusBar->SetStatusText( wxString::Format( _( "Elapsed: %s" ), tick ), 1 );
349 }
350 }
351
352 // Repaint the dialog at ~10Hz using Update() which processes only pending expose/
353 // draw events without entering the full platform event loop.
354 if( m_updateThrottle.Ready() )
355 Update();
356
357 // Yield to the event loop infrequently so the cancel button remains functional.
358 // On some Linux systems with glycin-enabled gdk-pixbuf (2.44+), entering the GTK event
359 // loop triggers heavyweight sandbox process spawning that can add hundreds of milliseconds
360 // per call, so we keep this interval long.
361 if( m_yieldThrottle.Ready() )
362 Pgm().App().SafeYieldFor( this, wxEVT_CATEGORY_NATIVE_EVENTS );
363
364 return !m_cancelled;
365}
366
367
368void DIALOG_DRC::AdvancePhase( const wxString& aMessage )
369{
371 SetCurrentProgress( 0.0 );
372
373 m_messages->Report( aMessage );
374}
375
376
378{
379 int severities = 0;
380
381 if( m_showErrors->GetValue() )
382 severities |= RPT_SEVERITY_ERROR;
383
384 if( m_showWarnings->GetValue() )
385 severities |= RPT_SEVERITY_WARNING;
386
387 if( m_showExclusions->GetValue() )
388 severities |= RPT_SEVERITY_EXCLUSION;
389
390 return severities;
391}
392
393
394void DIALOG_DRC::OnMenu( wxCommandEvent& event )
395{
396 // Build a pop menu:
397 wxMenu menu;
398
399 menu.Append( 4205, _( "Report All Errors for Each Track" ),
400 _( "If unchecked, only the first error will be reported for each track" ),
401 wxITEM_CHECK );
402 menu.Check( 4205, m_report_all_track_errors );
403
404 menu.AppendSeparator();
405
406 menu.Append( 4206, _( "Cross-probe Selected Items" ),
407 _( "Highlight corresponding items on canvas when selected in the DRC list" ),
408 wxITEM_CHECK );
409 menu.Check( 4206, m_crossprobe );
410
411 menu.Append( 4207, _( "Center on Cross-probe" ),
412 _( "When cross-probing, scroll the canvas so that the item is visible" ),
413 wxITEM_CHECK );
414 menu.Check( 4207, m_scroll_on_crossprobe );
415
416 // menu_id is the selected submenu id from the popup menu or wxID_NONE
417 int menu_id = m_bMenu->GetPopupMenuSelectionFromUser( menu );
418
419 if( menu_id == 0 || menu_id == 4205 )
420 {
422 }
423 else if( menu_id == 2 || menu_id == 4206 )
424 {
426 }
427 else if( menu_id == 3 || menu_id == 4207 )
428 {
430 }
431}
432
433
434void DIALOG_DRC::OnErrorLinkClicked( wxHtmlLinkEvent& event )
435{
436 m_frame->ShowBoardSetupDialog( _( "Custom Rules" ), this );
437}
438
439
440void DIALOG_DRC::OnCharHook( wxKeyEvent& aEvt )
441{
442 if( int hotkey = aEvt.GetKeyCode() )
443 {
444 if( aEvt.ControlDown() )
445 hotkey |= MD_CTRL;
446 if( aEvt.ShiftDown() )
447 hotkey |= MD_SHIFT;
448 if( aEvt.AltDown() )
449 hotkey |= MD_ALT;
450
451 if( hotkey == ACTIONS::excludeMarker.GetHotKey() )
452 {
454 return;
455 }
456 }
457
459}
460
461
462void DIALOG_DRC::OnRunDRCClick( wxCommandEvent& aEvent )
463{
464 TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
465 DRC_TOOL* drcTool = toolMgr->GetTool<DRC_TOOL>();
466 ZONE_FILLER_TOOL* zoneFillerTool = toolMgr->GetTool<ZONE_FILLER_TOOL>();
467 bool refillZones = m_cbRefillZones->GetValue();
468 bool testFootprints = m_cbTestFootprints->GetValue();
469
470 if( zoneFillerTool->IsBusy() )
471 {
472 wxBell();
473 return;
474 }
475
476 m_footprintTestsRun = false;
477 m_cancelled = false;
478
479 m_frame->GetBoard()->RecordDRCExclusions();
480 deleteAllMarkers( true );
481
482 // This is not the time to have stale or buggy rules. Ensure they're up-to-date
483 // and that they at least parse.
484 try
485 {
486 drcTool->GetDRCEngine()->InitEngine( m_frame->GetBoard()->GetDesignRulesPath() );
487 }
488 catch( PARSE_ERROR& )
489 {
490 m_runningResultsBook->ChangeSelection( 0 ); // Display the "Tests Running..." tab
491 m_DeleteCurrentMarkerButton->Enable( false );
492 m_DeleteAllMarkersButton->Enable( false );
493 m_saveReport->Enable( false );
494
495 m_messages->Clear();
496 m_messages->Report( _( "DRC incomplete: could not compile custom design rules." )
497 + wxS( "&nbsp;&nbsp;" )
498 + wxS( "<a href='$CUSTOM_RULES'>" ) + _( "Show design rules." ) + wxT( "</a>" ) );
499 m_messages->Flush();
500
501 Raise();
502
503 // set float level again, it can be lost due to window events during test run
505 return;
506 }
507
508 std::vector<std::reference_wrapper<RC_ITEM>> violations = DRC_ITEM::GetItemsWithSeverities();
509 m_ignoredList->DeleteAllItems();
510
511 for( std::reference_wrapper<RC_ITEM>& item : violations )
512 {
513 const int code = item.get().GetErrorCode();
514
515 // Group headings carry code 0 and have no severity of their own.
516 if( code <= 0 )
517 continue;
518
519 if( bds().GetSeverity( code ) == RPT_SEVERITY_IGNORE )
520 {
521 wxListItem listItem;
522 listItem.SetId( m_ignoredList->GetItemCount() );
523 listItem.SetText( wxT( " • " ) + item.get().GetErrorText( true ) );
524 listItem.SetData( code );
525
526 m_ignoredList->InsertItem( listItem );
527 }
528 }
529
530 m_ignoredList->SetColumnWidth( 0, m_ignoredList->GetParent()->GetClientSize().x - 20 );
531
532 Raise();
533
534 m_runningResultsBook->ChangeSelection( 0 ); // Display the "Tests Running..." tab
535 m_messages->Clear();
536 Update(); // Repaint only, don't enter the full event loop
537
538 m_running = true;
539 m_sdbSizerCancel->SetLabel( _( "Cancel" ) );
540 m_sdbSizerOK->Enable( false );
541 m_DeleteCurrentMarkerButton->Enable( false );
542 m_DeleteAllMarkersButton->Enable( false );
543 m_saveReport->Enable( false );
544
545 m_drcStartTime = std::chrono::steady_clock::now();
547
548 if( m_drcStatusBar )
549 m_drcStatusBar->SetStatusText( _( "Elapsed: 0 s" ), 1 );
550
551 {
552 wxBusyCursor dummy;
553 drcTool->RunTests( this, refillZones, m_report_all_track_errors, testFootprints );
554 }
555
556 double elapsedMs =
557 std::chrono::duration<double, std::milli>( std::chrono::steady_clock::now() - m_drcStartTime ).count();
558
559 auto formatElapsed =
560 [&]() -> wxString
561 {
562 int totalSeconds = KiROUND( elapsedMs / 1000.0 );
563
564 if( totalSeconds >= 60 )
565 return wxString::Format( _( "%1$d min %2$d s" ), totalSeconds / 60, totalSeconds % 60 );
566
567 return wxString::Format( _( "%.2f s" ), elapsedMs / 1000.0 );
568 };
569
570 if( m_cancelled )
571 {
572 m_messages->Report( _( "-------- DRC canceled by user.<br><br>" ) );
573
574 if( m_drcStatusBar )
575 m_drcStatusBar->SetStatusText( wxString::Format( _( "Canceled after %s" ), formatElapsed() ), 1 );
576 }
577 else
578 {
579 m_messages->Report( _( "Done.<br><br>" ) );
580
581 if( m_drcStatusBar )
582 m_drcStatusBar->SetStatusText( wxString::Format( _( "Completed in %s" ), formatElapsed() ), 1 );
583 }
584
585 Raise();
586 Update(); // Repaint only, don't enter the full event loop
587
588 m_running = false;
589 m_sdbSizerCancel->SetLabel( _( "Close" ) );
590 m_sdbSizerOK->Enable( true );
591 m_DeleteCurrentMarkerButton->Enable( true );
592 m_DeleteAllMarkersButton->Enable( true );
593 m_saveReport->Enable( true );
594
595 if( !m_cancelled )
596 {
597 m_sdbSizerCancel->SetDefault();
598 // wxWidgets has a tendency to keep both buttons highlighted without the following:
599 m_sdbSizerOK->Enable( false );
600
601 wxMilliSleep( 500 );
602 m_runningResultsBook->ChangeSelection( 1 );
604
605 // now re-enable m_sdbSizerOK button
606 m_sdbSizerOK->Enable( true );
607 }
608
609 // set float level again, it can be lost due to window events during test run
612}
613
614
616{
617 int severities = getSeverities();
618
619 m_markersTreeModel->Update( m_markersProvider, severities );
620 m_unconnectedTreeModel->Update( m_ratsnestProvider, severities );
621 m_fpWarningsTreeModel->Update( m_fpWarningsProvider, severities );
622
624}
625
626
627void DIALOG_DRC::OnDRCItemSelected( wxDataViewEvent& aEvent )
628{
629 if( !m_crossprobe )
630 {
631 aEvent.Skip();
632 return;
633 }
634
635 BOARD* board = m_frame->GetBoard();
636 RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( aEvent.GetItem() );
637
638 if( !node )
639 {
640 // list is being freed; don't do anything with null ptrs
641
642 aEvent.Skip();
643 return;
644 }
645
646 std::shared_ptr<RC_ITEM> rc_item = node->m_RcItem;
647
648 // The tree keeps its RC_ITEMs alive independently of the board, so rc_item->GetParent()
649 // can dangle once the owning marker is deleted (board edited, DRC re-run, undo) while this
650 // modeless dialog stays open. Recover the still-live marker by matching the shared RC_ITEM
651 // against the board's current markers instead of trusting the raw back-pointer.
652 PCB_MARKER* parentMarker = findMarker( board, rc_item );
653
654 if( rc_item->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE && parentMarker
656 {
657 m_frame->FocusOnLocation( parentMarker->GetPos(), m_scroll_on_crossprobe );
658
659 aEvent.Skip();
660 return;
661 }
662
663 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
664 BOARD_ITEM* item = board->ResolveItem( itemID, true );
665
666 if( !item )
667 {
668 aEvent.Skip();
669 return;
670 }
671
672 PCB_LAYER_ID principalLayer = UNDEFINED_LAYER;
673 LSET violationLayers;
674 const BOARD_ITEM* a = board->ResolveItem( rc_item->GetMainItemID(), true );
675 const BOARD_ITEM* b = board->ResolveItem( rc_item->GetAuxItemID(), true );
676
677 auto focus = [&]( BOARD_ITEM* aItem )
678 {
679 std::vector<BOARD_ITEM*> items = { aItem };
680
681 if( parentMarker && parentMarker != aItem )
682 items.push_back( parentMarker );
683
684 m_frame->FocusOnItems( items, principalLayer, m_scroll_on_crossprobe );
685 };
686
687 DRC_ITEM::GetViolationLayers( board, rc_item, parentMarker, principalLayer, violationLayers );
688
689 WINDOW_THAWER thawer( m_frame );
690
691 if( principalLayer > UNDEFINED_LAYER && ( violationLayers & board->GetVisibleLayers() ).none() )
692 m_frame->GetAppearancePanel()->SetLayerVisible( principalLayer, true );
693
694 if( principalLayer > UNDEFINED_LAYER && board->GetVisibleLayers().test( principalLayer ) )
695 m_frame->SetActiveLayer( principalLayer );
696
697 if( rc_item->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
698 {
699 if( !m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest )
700 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::showRatsnest );
701
702 if( item->Type() == PCB_ZONE_T )
703 {
704 focus( item );
705
706 m_frame->GetBoard()->GetConnectivity()->RunOnUnconnectedEdges(
707 [&]( CN_EDGE& edge )
708 {
709 // Connectivity was valid when DRC was run, but this is a modeless dialog
710 // so it might not be now.
711 if( !edge.GetSourceNode() || edge.GetSourceNode()->Dirty() )
712 return true;
713
714 if( !edge.GetTargetNode() || edge.GetTargetNode()->Dirty() )
715 return true;
716
717 if( edge.GetSourceNode()->Parent() == a
718 && edge.GetTargetNode()->Parent() == b )
719 {
720 VECTOR2I focusPos;
721
722 if( item == a && item == b )
723 {
724 focusPos = ( node->m_Type == RC_TREE_NODE::MAIN_ITEM ) ? edge.GetSourcePos()
725 : edge.GetTargetPos();
726 }
727 else
728 {
729 focusPos = ( item == edge.GetSourceNode()->Parent() ) ? edge.GetSourcePos()
730 : edge.GetTargetPos();
731 }
732
733 m_frame->FocusOnLocation( focusPos, m_scroll_on_crossprobe );
734 m_frame->RefreshCanvas();
735
736 return false;
737 }
738
739 return true;
740 } );
741 }
742 else
743 {
744 focus( item );
745 }
746 }
747 else if( rc_item->GetErrorCode() == DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG )
748 {
749 BOARD_CONNECTED_ITEM* track = dynamic_cast<PCB_TRACK*>( item );
750 std::vector<BOARD_ITEM*> items;
751
752 if( track )
753 {
754 int net = track->GetNetCode();
755
756 wxASSERT( net > 0 ); // Without a net how can it be a diff-pair?
757
758 for( const KIID& id : rc_item->GetIDs() )
759 {
760 auto* candidate = dynamic_cast<BOARD_CONNECTED_ITEM*>( board->ResolveItem( id, true ) );
761
762 if( candidate && candidate->GetNetCode() == net )
763 items.push_back( candidate );
764 }
765 }
766 else
767 {
768 items.push_back( item );
769 }
770
771 if( parentMarker && std::find( items.begin(), items.end(), parentMarker ) == items.end() )
772 {
773 items.push_back( parentMarker );
774 }
775
776 m_frame->FocusOnItems( items, principalLayer, m_scroll_on_crossprobe );
777 }
778 else
779 {
780 focus( item );
781 }
782
783 aEvent.Skip();
784}
785
786
787void DIALOG_DRC::OnDRCItemDClick( wxDataViewEvent& aEvent )
788{
789 if( aEvent.GetItem().IsOk() )
790 {
791 // turn control over to m_frame, hide this DIALOG_DRC window,
792 // no destruction so we can preserve listbox cursor
793 if( !IsModal() )
794 Show( false );
795 }
796
797 // Do not skip aEvent here: this is not useful, and Pcbnew crashes if skipped (at least on MSW)
798}
799
800
801void DIALOG_DRC::OnDRCItemRClick( wxDataViewEvent& aEvent )
802{
803 TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
804 BOARD_INSPECTION_TOOL* inspectionTool = toolMgr->GetTool<BOARD_INSPECTION_TOOL>();
805 DRC_TOOL* drcTool = toolMgr->GetTool<DRC_TOOL>();
806 RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( aEvent.GetItem() );
807
808 if( !node )
809 return;
810
811 std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
812 DRC_ITEM* drcItem = static_cast<DRC_ITEM*>( rcItem.get() );
813 std::shared_ptr<CONNECTIVITY_DATA> conn = m_currentBoard->GetConnectivity();
814 PCB_MARKER* currentMarker = findMarker( m_currentBoard, rcItem );
815 wxString listName;
816 wxMenu menu;
817
818 if( !currentMarker )
819 return;
820
821 switch( bds().m_DRCSeverities[ rcItem->GetErrorCode() ] )
822 {
823 case RPT_SEVERITY_ERROR: listName = _( "errors" ); break;
824 case RPT_SEVERITY_WARNING: listName = _( "warnings" ); break;
825 default: listName = _( "appropriate" ); break;
826 }
827
828 enum MENU_IDS
829 {
830 ID_EDIT_EXCLUSION_COMMENT = 4467,
831 ID_REMOVE_EXCLUSION,
832 ID_REMOVE_EXCLUSION_ALL,
833 ID_ADD_EXCLUSION,
834 ID_ADD_EXCLUSION_WITH_COMMENT,
835 ID_ADD_EXCLUSION_ALL,
836 ID_INSPECT_VIOLATION,
837 ID_FIX_VIOLATION,
838 ID_SET_SEVERITY_TO_ERROR,
839 ID_SET_SEVERITY_TO_WARNING,
840 ID_SET_SEVERITY_TO_IGNORE,
841 ID_EDIT_SEVERITIES
842 };
843
844 if( currentMarker->IsExcluded() )
845 {
846 menu.Append( ID_REMOVE_EXCLUSION,
847 _( "Remove exclusion for this violation" ),
848 wxString::Format( _( "It will be placed back in the %s list" ), listName ) );
849
850 menu.Append( ID_EDIT_EXCLUSION_COMMENT,
851 _( "Edit exclusion comment..." ) );
852
853 if( drcItem->GetViolatingRule() && !drcItem->GetViolatingRule()->IsImplicit() )
854 {
855 menu.Append( ID_REMOVE_EXCLUSION_ALL,
856 wxString::Format( _( "Remove all exclusions for violations of rule '%s'" ),
857 drcItem->GetViolatingRule()->m_Name ),
858 wxString::Format( _( "They will be placed back in the %s list" ), listName ) );
859 }
860 }
861 else
862 {
863 menu.Append( ID_ADD_EXCLUSION,
864 _( "Exclude this violation" ),
865 wxString::Format( _( "It will be excluded from the %s list" ), listName ) );
866
867 menu.Append( ID_ADD_EXCLUSION_WITH_COMMENT,
868 _( "Exclude with comment..." ),
869 wxString::Format( _( "It will be excluded from the %s list" ), listName ) );
870
871 if( drcItem->GetViolatingRule() && !drcItem->GetViolatingRule()->IsImplicit() )
872 {
873 menu.Append( ID_ADD_EXCLUSION_ALL,
874 wxString::Format( _( "Exclude all violations of rule '%s'..." ),
875 drcItem->GetViolatingRule()->m_Name ),
876 wxString::Format( _( "They will be excluded from the %s list" ), listName ) );
877 }
878 }
879
880 menu.AppendSeparator();
881
882 wxString inspectDRCErrorMenuText = inspectionTool->InspectDRCErrorMenuText( rcItem );
883 wxString fixDRCErrorMenuText = drcTool->FixDRCErrorMenuText( rcItem );
884
885 if( !inspectDRCErrorMenuText.IsEmpty() || !fixDRCErrorMenuText.IsEmpty() )
886 {
887 if( !inspectDRCErrorMenuText.IsEmpty() )
888 menu.Append( ID_INSPECT_VIOLATION, inspectDRCErrorMenuText );
889
890 if( !fixDRCErrorMenuText.IsEmpty() )
891 menu.Append( ID_FIX_VIOLATION, fixDRCErrorMenuText );
892
893 menu.AppendSeparator();
894 }
895
896 if( bds().m_DRCSeverities[ rcItem->GetErrorCode() ] == RPT_SEVERITY_WARNING )
897 {
898 menu.Append( ID_SET_SEVERITY_TO_ERROR,
899 wxString::Format( _( "Change severity to Error for all '%s' violations" ),
900 rcItem->GetErrorText( true ) ),
901 _( "Violation severities can also be edited in Board Setup" ) );
902 }
903 else
904 {
905 menu.Append( ID_SET_SEVERITY_TO_WARNING,
906 wxString::Format( _( "Change severity to Warning for all '%s' violations" ),
907 rcItem->GetErrorText( true ) ),
908 _( "Violation severities can also be edited in Board Setup" ) );
909 }
910
911 menu.Append( ID_SET_SEVERITY_TO_IGNORE,
912 wxString::Format( _( "Ignore all '%s' violations" ), rcItem->GetErrorText( true ) ),
913 _( "Violations will not be checked or reported" ) );
914
915 menu.AppendSeparator();
916
917 menu.Append( ID_EDIT_SEVERITIES,
918 _( "Edit violation severities..." ),
919 _( "Open the Board Setup dialog" ) );
920
921 bool modified = false;
922 int command = GetPopupMenuSelectionFromUser( menu );
923
924 // A popup runs a nested event loop, so the marker may have been removed while it was open.
925 currentMarker = findMarker( m_currentBoard, rcItem );
926 node = RC_TREE_MODEL::ToNode( aEvent.GetItem() );
927
928 if( !currentMarker || !node )
929 return;
930
931 switch( command )
932 {
933 case ID_EDIT_EXCLUSION_COMMENT:
934 if( PCB_MARKER* marker = currentMarker )
935 {
936 WX_TEXT_ENTRY_DIALOG dlg( this, wxEmptyString, _( "Exclusion Comment" ), marker->GetComment(), true );
937
938 if( dlg.ShowModal() == wxID_CANCEL )
939 break;
940
941 marker = findMarker( m_currentBoard, rcItem );
942 node = RC_TREE_MODEL::ToNode( aEvent.GetItem() );
943
944 if( !marker || !node )
945 break;
946
947 marker->SetExcluded( true, dlg.GetValue() );
948
949 DRC_EXCLUSION exclusion = DRC_EXCLUSION::FromMarker( *marker );
950 exclusion.SetComment( dlg.GetValue() );
951 bds().m_DrcExclusions.erase( exclusion );
952 bds().m_DrcExclusions.insert( exclusion );
953
954 // Update view
955 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->ValueChanged( node );
956 modified = true;
957 }
958
959 break;
960
961 case ID_REMOVE_EXCLUSION:
962 if( PCB_MARKER* marker = currentMarker )
963 {
964 marker->SetExcluded( false );
965 bds().m_DrcExclusions.erase( DRC_EXCLUSION::FromMarker( *marker ) );
966
967 if( rcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
968 {
969 m_frame->GetBoard()->UpdateRatsnestExclusions();
970 m_frame->GetCanvas()->RedrawRatsnest();
971 }
972 else
973 {
974 m_frame->GetCanvas()->GetView()->Update( marker );
975 }
976
977 // Update view
978 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->ValueChanged( node );
979 modified = true;
980 }
981
982 break;
983
984 case ID_ADD_EXCLUSION:
985 case ID_ADD_EXCLUSION_WITH_COMMENT:
986 if( PCB_MARKER* marker = currentMarker )
987 {
988 wxString comment;
989
990 if( command == ID_ADD_EXCLUSION_WITH_COMMENT )
991 {
992 WX_TEXT_ENTRY_DIALOG dlg( this, wxEmptyString, _( "Exclusion Comment" ), wxEmptyString, true );
993
994 if( dlg.ShowModal() == wxID_CANCEL )
995 break;
996
997 marker = findMarker( m_currentBoard, rcItem );
998 node = RC_TREE_MODEL::ToNode( aEvent.GetItem() );
999
1000 if( !marker || !node )
1001 break;
1002
1003 comment = dlg.GetValue();
1004 }
1005
1006 marker->SetExcluded( true, comment );
1007
1008 DRC_EXCLUSION exclusion = DRC_EXCLUSION::FromMarker( *marker );
1009 exclusion.SetComment( comment );
1010 bds().m_DrcExclusions.insert( exclusion );
1011
1012 if( rcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
1013 {
1014 m_frame->GetBoard()->UpdateRatsnestExclusions();
1015 m_frame->GetCanvas()->RedrawRatsnest();
1016 }
1017 else
1018 {
1019 m_frame->GetCanvas()->GetView()->Update( marker );
1020 }
1021
1022 // Update view
1023 if( m_showExclusions->GetValue() )
1024 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->ValueChanged( node );
1025 else
1026 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->DeleteCurrentItem( false );
1027
1028 modified = true;
1029 }
1030
1031 break;
1032
1033 case ID_REMOVE_EXCLUSION_ALL:
1034 for( PCB_MARKER* marker : m_frame->GetBoard()->Markers() )
1035 {
1036 DRC_ITEM* candidateDrcItem = static_cast<DRC_ITEM*>( marker->GetRCItem().get() );
1037
1038 if( candidateDrcItem->GetViolatingRule() == drcItem->GetViolatingRule() )
1039 {
1040 marker->SetExcluded( false );
1041 bds().m_DrcExclusions.erase( DRC_EXCLUSION::FromMarker( *marker ) );
1042 }
1043 }
1044
1045 // Rebuild model and view
1046 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->Update( m_markersProvider, getSeverities() );
1047 modified = true;
1048 break;
1049
1050 case ID_ADD_EXCLUSION_ALL:
1051 for( PCB_MARKER* marker : m_frame->GetBoard()->Markers() )
1052 {
1053 DRC_ITEM* candidateDrcItem = static_cast<DRC_ITEM*>( marker->GetRCItem().get() );
1054
1055 if( candidateDrcItem->GetViolatingRule() == drcItem->GetViolatingRule() )
1056 {
1057 marker->SetExcluded( true );
1058 bds().m_DrcExclusions.insert( DRC_EXCLUSION::FromMarker( *marker ) );
1059 }
1060 }
1061
1062 // Rebuild model and view
1063 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->Update( m_markersProvider, getSeverities() );
1064 modified = true;
1065 break;
1066
1067 case ID_INSPECT_VIOLATION:
1068 inspectionTool->InspectDRCError( rcItem );
1069 break;
1070
1071 case ID_FIX_VIOLATION:
1072 drcTool->FixDRCError( rcItem );
1073 break;
1074
1075 case ID_SET_SEVERITY_TO_ERROR:
1076 bds().m_DRCSeverities[ rcItem->GetErrorCode() ] = RPT_SEVERITY_ERROR;
1077
1078 for( PCB_MARKER* marker : m_frame->GetBoard()->Markers() )
1079 {
1080 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
1081 m_frame->GetCanvas()->GetView()->Update( marker );
1082 }
1083
1084 // Rebuild model and view
1085 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->Update( m_markersProvider, getSeverities() );
1086 modified = true;
1087 break;
1088
1089 case ID_SET_SEVERITY_TO_WARNING:
1090 bds().m_DRCSeverities[ rcItem->GetErrorCode() ] = RPT_SEVERITY_WARNING;
1091
1092 for( PCB_MARKER* marker : m_frame->GetBoard()->Markers() )
1093 {
1094 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
1095 m_frame->GetCanvas()->GetView()->Update( marker );
1096 }
1097
1098 // Rebuild model and view
1099 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->Update( m_markersProvider, getSeverities() );
1100 modified = true;
1101 break;
1102
1103 case ID_SET_SEVERITY_TO_IGNORE:
1104 {
1105 bds().m_DRCSeverities[ rcItem->GetErrorCode() ] = RPT_SEVERITY_IGNORE;
1106
1107 wxListItem listItem;
1108 listItem.SetId( m_ignoredList->GetItemCount() );
1109 listItem.SetText( wxT( " • " ) + rcItem->GetErrorText( true ) );
1110 listItem.SetData( rcItem->GetErrorCode() );
1111
1112 m_ignoredList->InsertItem( listItem );
1113
1114 BOARD* board = m_frame->GetBoard();
1115
1116 std::vector<BOARD_ITEM*> toRemove;
1117
1118 for( PCB_MARKER* marker : board->Markers() )
1119 {
1120 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
1121 {
1122 m_frame->GetCanvas()->GetView()->Remove( marker );
1123 toRemove.emplace_back( marker );
1124 }
1125 }
1126
1127 for( BOARD_ITEM* marker : toRemove )
1128 board->Remove( marker, REMOVE_MODE::BULK );
1129
1130 board->FinalizeBulkRemove( toRemove );
1131
1132 if( rcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
1133 m_frame->GetCanvas()->RedrawRatsnest();
1134
1135 // Rebuild model and view
1136 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->Update( m_markersProvider, getSeverities() );
1137 modified = true;
1138 break;
1139 }
1140
1141 case ID_EDIT_SEVERITIES:
1142 m_frame->ShowBoardSetupDialog( _( "Violation Severity" ), this );
1143
1144 // Rebuild model and view
1145 static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->Update( m_markersProvider, getSeverities() );
1147 break;
1148 }
1149
1150 if( modified )
1151 {
1153 refreshEditor();
1154 m_frame->OnModify();
1155 }
1156}
1157
1158
1159void DIALOG_DRC::OnIgnoredItemRClick( wxListEvent& event )
1160{
1161 int errorCode = (int) event.m_item.GetData();
1162 wxMenu menu;
1163
1164 menu.Append( RPT_SEVERITY_ERROR, _( "Error" ), wxEmptyString, wxITEM_RADIO );
1165 menu.Append( RPT_SEVERITY_WARNING, _( "Warning" ), wxEmptyString, wxITEM_RADIO );
1166 menu.Append( RPT_SEVERITY_IGNORE, _( "Ignore" ), wxEmptyString, wxITEM_RADIO );
1167
1168 menu.Check( bds().GetSeverity( errorCode ), true );
1169
1170 int severity = GetPopupMenuSelectionFromUser( menu );
1171
1172 if( severity > 0 )
1173 {
1174 if( bds().m_DRCSeverities[ errorCode ] != severity )
1175 {
1176 bds().m_DRCSeverities[ errorCode ] = (SEVERITY) severity;
1177 m_ignoredList->DeleteItem( event.m_itemIndex );
1178
1180 refreshEditor();
1181 m_frame->OnModify();
1182 }
1183 }
1184}
1185
1186
1187void DIALOG_DRC::OnEditViolationSeverities( wxHyperlinkEvent& aEvent )
1188{
1189 m_frame->ShowBoardSetupDialog( _( "Violation Severity" ), this );
1190}
1191
1192
1193void DIALOG_DRC::OnSeverity( wxCommandEvent& aEvent )
1194{
1195 if( aEvent.GetEventObject() == m_showAll )
1196 {
1197 m_showErrors->SetValue( true );
1198 m_showWarnings->SetValue( aEvent.IsChecked() );
1199 m_showExclusions->SetValue( aEvent.IsChecked() );
1200 }
1201
1202 UpdateData();
1203}
1204
1205
1206void DIALOG_DRC::OnSaveReport( wxCommandEvent& aEvent )
1207{
1208 wxFileName fn( "DRC." + FILEEXT::ReportFileExtension );
1209
1210 wxFileDialog dlg( this, _( "Save Report File" ), Prj().GetProjectPath(), fn.GetFullName(),
1212 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1213
1215
1216 if( dlg.ShowModal() != wxID_OK )
1217 return;
1218
1219 fn = dlg.GetPath();
1220
1221 if( fn.GetExt().IsEmpty() )
1222 fn.SetExt( FILEEXT::ReportFileExtension );
1223
1224 if( !fn.IsAbsolute() )
1225 {
1226 wxString prj_path = Prj().GetProjectPath();
1227 fn.MakeAbsolute( prj_path );
1228 }
1229
1230 DRC_REPORT reportWriter( m_frame->GetBoard(), GetUserUnits(), m_markersProvider,
1232
1233 bool success = false;
1234
1235 if( fn.GetExt().Lower() == FILEEXT::JsonFileExtension )
1236 success = reportWriter.WriteJsonReport( fn.GetFullPath() );
1237 else
1238 success = reportWriter.WriteTextReport( fn.GetFullPath() );
1239
1240 if( success )
1241 m_messages->Report( wxString::Format( _( "Report file '%s' created<br>" ), fn.GetFullPath() ) );
1242 else
1243 DisplayError( this, wxString::Format( _( "Failed to create file '%s'." ), fn.GetFullPath() ) );
1244}
1245
1246
1247void DIALOG_DRC::OnClose( wxCloseEvent& aEvent )
1248{
1249 wxCommandEvent dummy;
1251}
1252
1253
1254void DIALOG_DRC::OnCancelClick( wxCommandEvent& aEvent )
1255{
1256 if( m_running )
1257 {
1258 m_cancelled = true;
1259 return;
1260 }
1261
1262 m_frame->ClearFocus();
1263
1264 SetReturnCode( wxID_CANCEL );
1265
1266 // The dialog can be modal or not modal.
1267 // Leave the DRC caller destroy (or not) the dialog
1268 DRC_TOOL* drcTool = m_frame->GetToolManager()->GetTool<DRC_TOOL>();
1269 drcTool->DestroyDRCDialog();
1270}
1271
1272
1273void DIALOG_DRC::OnChangingNotebookPage( wxNotebookEvent& aEvent )
1274{
1275 m_markerDataView->UnselectAll();
1276 m_unconnectedDataView->UnselectAll();
1277 m_footprintsDataView->UnselectAll();
1278
1279 aEvent.Skip();
1280}
1281
1282
1284{
1285 WINDOW_THAWER thawer( m_frame );
1286
1287 m_frame->GetCanvas()->Refresh();
1288}
1289
1290
1292{
1293 if( m_Notebook->IsShown() )
1294 {
1295 switch( m_Notebook->GetSelection() )
1296 {
1297 case 0: m_markersTreeModel->PrevMarker(); break;
1298 case 1: m_unconnectedTreeModel->PrevMarker(); break;
1299 case 2: m_fpWarningsTreeModel->PrevMarker(); break;
1300 case 3: break;
1301 }
1302 }
1303}
1304
1305
1307{
1308 if( m_Notebook->IsShown() )
1309 {
1310 switch( m_Notebook->GetSelection() )
1311 {
1312 case 0: m_markersTreeModel->NextMarker(); break;
1313 case 1: m_unconnectedTreeModel->NextMarker(); break;
1314 case 2: m_fpWarningsTreeModel->NextMarker(); break;
1315 case 3: break;
1316 }
1317 }
1318}
1319
1320
1322{
1323 if( m_Notebook->IsShown() )
1324 {
1325 enum MARKER_BASE::MARKER_T markerType = aMarker->GetMarkerType();
1326
1327 if( markerType == MARKER_BASE::MARKER_DRC )
1328 m_Notebook->SetSelection( 0 );
1329 else if( markerType == MARKER_BASE::MARKER_PARITY )
1330 m_Notebook->SetSelection( 2 );
1331
1332 m_markersTreeModel->SelectMarker( aMarker );
1333
1334 CallAfter(
1335 [this, aMarker]
1336 {
1337 m_markersTreeModel->CenterMarker( aMarker );
1338 } );
1339 }
1340}
1341
1342
1344{
1345 if( !m_Notebook->IsShown() || m_Notebook->GetSelection() != 0 )
1346 return;
1347
1348 RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( m_markerDataView->GetCurrentItem() );
1349
1350 if( node && node->m_RcItem )
1351 {
1352 PCB_MARKER* marker = findMarker( m_currentBoard, node->m_RcItem );
1353
1354 if( marker && marker->GetSeverity() != RPT_SEVERITY_EXCLUSION )
1355 {
1356 marker->SetExcluded( true );
1357 bds().m_DrcExclusions.insert( DRC_EXCLUSION::FromMarker( *marker ) );
1358 m_frame->GetCanvas()->GetView()->Update( marker );
1359
1360 // Update view
1361 if( m_showExclusions->GetValue() )
1362 m_markersTreeModel->ValueChanged( node );
1363 else
1364 m_markersTreeModel->DeleteCurrentItem( false );
1365
1367 refreshEditor();
1368 m_frame->OnModify();
1369 }
1370 }
1371}
1372
1373
1374void DIALOG_DRC::deleteAllMarkers( bool aIncludeExclusions )
1375{
1376 // Clear current selection list to avoid selection of deleted items
1377 Freeze();
1378 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
1379
1380 m_markersTreeModel->DeleteItems( false, aIncludeExclusions, false );
1381 m_unconnectedTreeModel->DeleteItems( false, aIncludeExclusions, false );
1382 m_fpWarningsTreeModel->DeleteItems( false, aIncludeExclusions, false );
1383
1384 m_frame->GetBoard()->DeleteMARKERs( true, aIncludeExclusions );
1385 Thaw();
1386}
1387
1388
1389void DIALOG_DRC::OnDeleteOneClick( wxCommandEvent& aEvent )
1390{
1391 if( m_Notebook->GetSelection() == 0 )
1392 {
1393 // Clear the selection. It may be the selected DRC marker.
1394 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
1395
1396 m_markersTreeModel->DeleteCurrentItem( true );
1397
1398 // redraw the pcb
1399 refreshEditor();
1400 }
1401 else if( m_Notebook->GetSelection() == 1 )
1402 {
1403 m_unconnectedTreeModel->DeleteCurrentItem( true );
1404 }
1405 else if( m_Notebook->GetSelection() == 2 )
1406 {
1407 m_fpWarningsTreeModel->DeleteCurrentItem( true );
1408 }
1409
1411}
1412
1413
1414void DIALOG_DRC::OnDeleteAllClick( wxCommandEvent& aEvent )
1415{
1416 static bool s_includeExclusions = false;
1417
1418 int numExcluded = 0;
1419
1420 if( m_markersProvider )
1421 numExcluded += m_markersProvider->GetCount( RPT_SEVERITY_EXCLUSION );
1422
1423 if( m_ratsnestProvider )
1424 numExcluded += m_ratsnestProvider->GetCount( RPT_SEVERITY_EXCLUSION );
1425
1427 numExcluded += m_fpWarningsProvider->GetCount( RPT_SEVERITY_EXCLUSION );
1428
1429 if( numExcluded > 0 )
1430 {
1431 wxMessageDialog dlg( this, _( "Delete exclusions too?" ), _( "Delete All Markers" ),
1432 wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
1433 dlg.SetYesNoLabels( _( "Errors and Warnings Only" ),
1434 _( "Errors, Warnings and Exclusions" ) );
1435
1436 int ret = dlg.ShowModal();
1437
1438 if( ret == wxID_CANCEL )
1439 return;
1440 else if( ret == wxID_NO )
1441 s_includeExclusions = true;
1442 }
1443
1444 deleteAllMarkers( s_includeExclusions );
1445 m_drcRun = false;
1446
1447 refreshEditor();
1449}
1450
1451
1453{
1454 DRC_TOOL* drcTool = m_frame->GetToolManager()->GetTool<DRC_TOOL>();
1455 DRC_ENGINE* drcEngine = drcTool->GetDRCEngine().get();
1456
1457 // Collect counts:
1458
1459 int numMarkers = 0;
1460 int numUnconnected = 0;
1461 int numFootprints = 0;
1462
1463 int numErrors = 0;
1464 int numWarnings = 0;
1465 int numExcluded = 0;
1466
1467 if( m_markersProvider )
1468 {
1469 numMarkers += m_markersProvider->GetCount();
1470 numErrors += m_markersProvider->GetCount( RPT_SEVERITY_ERROR );
1471 numWarnings += m_markersProvider->GetCount( RPT_SEVERITY_WARNING );
1472 numExcluded += m_markersProvider->GetCount( RPT_SEVERITY_EXCLUSION );
1473 }
1474
1475 if( m_ratsnestProvider )
1476 {
1477 numUnconnected += m_ratsnestProvider->GetCount();
1478 numErrors += m_ratsnestProvider->GetCount( RPT_SEVERITY_ERROR );
1479 numWarnings += m_ratsnestProvider->GetCount( RPT_SEVERITY_WARNING );
1480 numExcluded += m_ratsnestProvider->GetCount( RPT_SEVERITY_EXCLUSION );
1481 }
1482
1484 {
1485 numFootprints += m_fpWarningsProvider->GetCount();
1486 numErrors += m_fpWarningsProvider->GetCount( RPT_SEVERITY_ERROR );
1487 numWarnings += m_fpWarningsProvider->GetCount( RPT_SEVERITY_WARNING );
1488 numExcluded += m_fpWarningsProvider->GetCount( RPT_SEVERITY_EXCLUSION );
1489 }
1490
1491 bool errorsOverflowed = false;
1492 bool warningsOverflowed = false;
1493 bool markersOverflowed = false;
1494 bool unconnectedOverflowed = false;
1495 bool footprintsOverflowed = false;
1496
1497 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
1498 {
1499 const SEVERITY severity = bds().GetSeverity( ii );
1500
1501 if( drcEngine->IsErrorLimitExceeded( ii ) )
1502 {
1503 if( severity == RPT_SEVERITY_ERROR )
1504 errorsOverflowed = true;
1505 else if( severity == RPT_SEVERITY_WARNING )
1506 warningsOverflowed = true;
1507
1508 if( ii == DRCE_UNCONNECTED_ITEMS )
1509 {
1510 if( m_showWarnings->GetValue() && severity == RPT_SEVERITY_WARNING )
1511 unconnectedOverflowed = true;
1512 else if( m_showErrors->GetValue() && severity == RPT_SEVERITY_ERROR )
1513 unconnectedOverflowed = true;
1514 }
1515 else if( ii == DRCE_MISSING_FOOTPRINT
1517 || ii == DRCE_EXTRA_FOOTPRINT
1518 || ii == DRCE_NET_CONFLICT
1519 || ii == DRCE_SCHEMATIC_PARITY
1520 || ii == DRCE_FOOTPRINT_FILTERS
1522 {
1523 if( m_showWarnings->GetValue() && severity == RPT_SEVERITY_WARNING )
1524 footprintsOverflowed = true;
1525 else if( m_showErrors->GetValue() && severity == RPT_SEVERITY_ERROR )
1526 footprintsOverflowed = true;
1527 }
1528 else
1529 {
1530 if( m_showWarnings->GetValue() && severity == RPT_SEVERITY_WARNING )
1531 markersOverflowed = true;
1532 else if( m_showErrors->GetValue() && severity == RPT_SEVERITY_ERROR )
1533 markersOverflowed = true;
1534 }
1535 }
1536 }
1537
1538 wxString msg;
1539 wxString num;
1540
1541 // Update tab headers:
1542
1543 if( m_drcRun )
1544 {
1545 num.Printf( markersOverflowed ? wxT( "%d+" ) : wxT( "%d" ), numMarkers );
1546 msg.Printf( m_markersTitleTemplate, num );
1547 }
1548 else
1549 {
1551 msg.Replace( wxT( "(%s)" ), wxEmptyString );
1552 }
1553
1554 m_Notebook->SetPageText( 0, msg );
1555
1556 if( m_drcRun )
1557 {
1558 num.Printf( unconnectedOverflowed ? wxT( "%d+" ) : wxT( "%d" ), numUnconnected );
1559 msg.sprintf( m_unconnectedTitleTemplate, num );
1560 }
1561 else
1562 {
1564 msg.Replace( wxT( "(%s)" ), wxEmptyString );
1565 }
1566
1567 m_Notebook->SetPageText( 1, msg );
1568
1570 {
1571 num.Printf( footprintsOverflowed ? wxT( "%d+" ) : wxT( "%d" ), numFootprints );
1572 msg.sprintf( m_footprintsTitleTemplate, num );
1573 }
1574 else if( m_drcRun )
1575 {
1577 msg.Replace( wxT( "%s" ), _( "not run" ) );
1578 }
1579 else
1580 {
1582 msg.Replace( wxT( "(%s)" ), wxEmptyString );
1583 }
1584
1585 m_Notebook->SetPageText( 2, msg );
1586
1587 if( m_drcRun )
1588 {
1589 num.Printf( wxT( "%d" ), m_ignoredList->GetItemCount() );
1590 msg.sprintf( m_ignoredTitleTemplate, num );
1591 }
1592 else
1593 {
1595 msg.Replace( wxT( "(%s)" ), wxEmptyString );
1596 }
1597
1598 m_Notebook->SetPageText( 3, msg );
1599
1600 // Update badges:
1601
1602 if( !m_drcRun && numErrors == 0 )
1603 numErrors = -1;
1604
1605 if( !m_drcRun && numWarnings == 0 )
1606 numWarnings = -1;
1607
1608 m_errorsBadge->SetMaximumNumber( numErrors );
1609 m_errorsBadge->UpdateNumber( errorsOverflowed ? numErrors + 1 : numErrors, RPT_SEVERITY_ERROR );
1610
1611 m_warningsBadge->SetMaximumNumber( numWarnings );
1612 m_warningsBadge->UpdateNumber( warningsOverflowed ? numWarnings + 1 : numWarnings, RPT_SEVERITY_WARNING );
1613
1614 m_exclusionsBadge->SetMaximumNumber( numExcluded );
1615 m_exclusionsBadge->UpdateNumber( numExcluded, RPT_SEVERITY_EXCLUSION );
1616}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
static TOOL_ACTION excludeMarker
Definition actions.h:126
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::map< int, SEVERITY > m_DRCSeverities
SEVERITY GetSeverity(int aDRCErrorCode) const
Return the severity of a given DRC error code.
std::set< DRC_EXCLUSION, DRC_EXCLUSION_COMPARE > m_DrcExclusions
Tool for pcb inspection.
void InspectDRCError(const std::shared_ptr< RC_ITEM > &aDRCItem)
wxString InspectDRCErrorMenuText(const std::shared_ptr< RC_ITEM > &aDRCItem)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1216
const MARKERS & Markers() const
Definition board.h:497
void FinalizeBulkRemove(std::vector< BOARD_ITEM * > &aRemovedItems)
Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event for listeners.
Definition board.cpp:1695
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition board.cpp:1723
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2176
bool Dirty() const
BOARD_CONNECTED_ITEM * Parent() const
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
std::shared_ptr< const CN_ANCHOR > GetSourceNode() const
std::shared_ptr< const CN_ANCHOR > GetTargetNode() const
const VECTOR2I GetTargetPos() const
const VECTOR2I GetSourcePos() const
wxCheckBox * m_cbRefillZones
wxBoxSizer * bSizerViolationsBox
wxCheckBox * m_showAll
wxButton * m_DeleteAllMarkersButton
wxCheckBox * m_showExclusions
wxNotebook * m_Notebook
wxCheckBox * m_showErrors
wxDataViewCtrl * m_unconnectedDataView
wxDataViewCtrl * m_footprintsDataView
NUMBER_BADGE * m_warningsBadge
NUMBER_BADGE * m_exclusionsBadge
wxSimplebook * m_runningResultsBook
wxButton * m_DeleteCurrentMarkerButton
STD_BITMAP_BUTTON * m_bMenu
wxButton * m_sdbSizerCancel
wxButton * m_saveReport
wxCheckBox * m_cbTestFootprints
DIALOG_DRC_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Design Rules Checker"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxCheckBox * m_showWarnings
wxButton * m_sdbSizerOK
wxListCtrl * m_ignoredList
NUMBER_BADGE * m_errorsBadge
WX_HTML_REPORT_BOX * m_messages
wxDataViewCtrl * m_markerDataView
bool updateUI() override
void OnDRCItemSelected(wxDataViewEvent &aEvent) override
wxString m_footprintsTitleTemplate
Definition dialog_drc.h:133
void UpdateData()
Rebuild the contents of the violation tabs based on the current markers and severties.
std::shared_ptr< RC_ITEMS_PROVIDER > m_ratsnestProvider
Definition dialog_drc.h:137
wxString m_markersTitleTemplate
Definition dialog_drc.h:131
bool m_footprintTestsRun
Definition dialog_drc.h:125
DIALOG_DRC(PCB_EDIT_FRAME *aEditorFrame, wxWindow *aParent)
Constructors.
void OnEditViolationSeverities(wxHyperlinkEvent &aEvent) override
wxStatusBar * m_drcStatusBar
Definition dialog_drc.h:147
void OnDeleteOneClick(wxCommandEvent &aEvent) override
RC_TREE_MODEL * m_fpWarningsTreeModel
Definition dialog_drc.h:142
static bool hitTestLink(wxDataViewCtrl *aCtrl, const wxPoint &aPoint, wxString *aHref)
bool m_running
Definition dialog_drc.h:123
void onDataViewMotion(wxMouseEvent &aEvent)
void OnDeleteAllClick(wxCommandEvent &aEvent) override
bool m_crossprobe
Definition dialog_drc.h:128
void OnMenu(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void OnErrorLinkClicked(wxHtmlLinkEvent &event) override
int m_lastTickSeconds
Definition dialog_drc.h:149
BOARD_DESIGN_SETTINGS & bds()
Definition dialog_drc.h:118
bool m_report_all_track_errors
Definition dialog_drc.h:127
void SelectMarker(const PCB_MARKER *aMarker)
void OnClose(wxCloseEvent &event) override
void installLinkHandlers(wxDataViewCtrl *aCtrl)
void OnCharHook(wxKeyEvent &aEvt) override
std::chrono::steady_clock::time_point m_drcStartTime
Definition dialog_drc.h:148
int getSeverities()
BOARD * m_currentBoard
Definition dialog_drc.h:121
void OnDRCItemRClick(wxDataViewEvent &aEvent) override
void PrevMarker()
void OnRunDRCClick(wxCommandEvent &aEvent) override
wxString m_ignoredTitleTemplate
Definition dialog_drc.h:134
THROTTLE m_yieldThrottle
Definition dialog_drc.h:145
void OnDRCItemDClick(wxDataViewEvent &aEvent) override
THROTTLE m_updateThrottle
Definition dialog_drc.h:144
void deleteAllMarkers(bool aIncludeExclusions)
void updateDisplayedCounts()
RC_TREE_MODEL * m_unconnectedTreeModel
Definition dialog_drc.h:141
bool m_scroll_on_crossprobe
Definition dialog_drc.h:129
void onDataViewLeftUp(wxMouseEvent &aEvent)
void refreshEditor()
wxString m_unconnectedTitleTemplate
Definition dialog_drc.h:132
std::shared_ptr< RC_ITEMS_PROVIDER > m_fpWarningsProvider
Definition dialog_drc.h:138
std::shared_ptr< RC_ITEMS_PROVIDER > m_markersProvider
Definition dialog_drc.h:136
void OnSeverity(wxCommandEvent &aEvent) override
PCB_EDIT_FRAME * m_frame
Definition dialog_drc.h:122
bool m_drcRun
Definition dialog_drc.h:124
void OnIgnoredItemRClick(wxListEvent &event) override
void OnCancelClick(wxCommandEvent &aEvent) override
void NextMarker()
void OnActivateDlg(wxActivateEvent &aEvent) override
void OnChangingNotebookPage(wxNotebookEvent &aEvent) override
void OnSaveReport(wxCommandEvent &aEvent) override
void ExcludeMarker()
RC_TREE_MODEL * m_markersTreeModel
Definition dialog_drc.h:140
bool Show(bool show) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual void OnCharHook(wxKeyEvent &aEvt)
EDA_UNITS GetUserUnits() const
int ShowModal() override
Design Rule Checker object that performs all the DRC tests.
Definition drc_engine.h:129
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
Container for an DRC exclusion, which is a PCB_MARKER plus an optional comment.
void SetComment(const wxString &aComment)
static DRC_EXCLUSION FromMarker(const PCB_MARKER &aMarker)
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition drc_item.h:173
static void GetViolationLayers(BOARD *aBoard, const std::shared_ptr< RC_ITEM > &aItem, PCB_MARKER *aMarker, PCB_LAYER_ID &aPrincipalLayer, LSET &aViolationLayers)
Work out which layer to focus on and which layers a violation involves.
Definition drc_item.cpp:642
DRC_RULE * GetViolatingRule() const
Definition drc_item.h:192
bool WriteJsonReport(const wxString &aFullFileName)
bool WriteTextReport(const wxString &aFullFileName)
bool IsImplicit() const
Definition drc_rule.h:70
wxString m_Name
Definition drc_rule.h:80
void DestroyDRCDialog()
Close and free the DRC dialog.
Definition drc_tool.cpp:123
std::shared_ptr< DRC_ENGINE > GetDRCEngine()
Definition drc_tool.h:79
void RunTests(PROGRESS_REPORTER *aProgressReporter, bool aRefillZones, bool aReportAllTrackErrors, bool aTestFootprints)
Run the DRC tests.
Definition drc_tool.cpp:133
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
Definition kiid.h:46
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
bool IsExcluded() const
Definition marker_base.h:88
const VECTOR2I & GetPos() const
Definition marker_base.h:78
@ MARKER_DRAWING_SHEET
Definition marker_base.h:51
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
Definition marker_base.h:89
enum MARKER_T GetMarkerType() const
Definition marker_base.h:86
static TOOL_ACTION showRatsnest
The main frame for Pcbnew.
SEVERITY GetSeverity() const override
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition pgm_base.cpp:236
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:277
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition rc_item.h:323
void ValueChanged(RC_TREE_NODE *aNode)
Definition rc_item.cpp:602
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition rc_item.cpp:404
void DeleteCurrentItem(bool aDeep)
Definition rc_item.cpp:653
void EnableHyperlinks(bool aEnable)
Render [label](url) markup as clickable links.
Definition rc_item.cpp:410
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:202
std::shared_ptr< RC_ITEM > m_RcItem
Definition rc_item.h:307
NODE_TYPE m_Type
Definition rc_item.h:306
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
Handle actions specific to filling copper zones.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Definition cvpcb.cpp:178
static bool g_lastDRCRun
static BOARD * g_lastDRCBoard
static bool g_lastFootprintTestsRun
static PCB_MARKER * findMarker(BOARD *aBoard, const std::shared_ptr< RC_ITEM > &aItem)
static std::vector< std::pair< wxString, int > > g_lastIgnored
#define DIALOG_DRC_WINDOW_NAME
Definition dialog_drc.h:40
static SCH_MARKER * findMarker(SCHEMATIC *aSchematic, const std::shared_ptr< RC_ITEM > &aItem)
@ DRCE_DP_UNCOUPLED_LENGTH_TOO_LONG
Definition drc_item.h:126
@ DRCE_FOOTPRINT_FILTERS
Definition drc_item.h:94
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:48
@ DRCE_SCHEMATIC_FIELDS_PARITY
Definition drc_item.h:138
@ DRCE_FIRST
Definition drc_item.h:47
@ DRCE_UNRESOLVED_VARIABLE
Definition drc_item.h:103
@ DRCE_DUPLICATE_FOOTPRINT
Definition drc_item.h:90
@ DRCE_EXTRA_FOOTPRINT
Definition drc_item.h:91
@ DRCE_LAST
Definition drc_item.h:145
@ DRCE_NET_CONFLICT
Definition drc_item.h:92
@ DRCE_MISSING_FOOTPRINT
Definition drc_item.h:89
@ DRCE_SCHEMATIC_PARITY
Definition drc_item.h:93
#define _(s)
static int DEFAULT_SINGLE_COL_WIDTH
static const std::string ReportFileExtension
static const std::string JsonFileExtension
static wxString JsonFileWildcard()
static wxString ReportFileWildcard()
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
This file contains miscellaneous commonly used macros and functions.
void SetFloatLevel(wxWindow *aWindow)
Intended to set the floating window level in macOS on a window.
Definition wxgtk/ui.cpp:730
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition wxgtk/ui.cpp:211
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
STL namespace.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
std::vector< FAB_LAYER_COLOR > dummy
A filename or source description, a problem input line, a line number, a byte offset,...
KIBIS_MODEL * model
@ MD_ALT
Definition tool_event.h:141
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
Definition of file extensions used in Kicad.