KiCad PCB EDA Suite
dialog_erc.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2020 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, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <gestfich.h>
27 #include <pgm_base.h>
28 #include <sch_screen.h>
29 #include <sch_edit_frame.h>
30 #include <schematic.h>
31 #include <project.h>
32 #include <kiface_i.h>
33 #include <bitmaps.h>
34 #include <reporter.h>
36 #include <sch_view.h>
37 #include <sch_marker.h>
38 #include <connection_graph.h>
39 #include <tools/ee_actions.h>
41 #include <tool/tool_manager.h>
42 #include <dialog_erc.h>
43 #include <erc.h>
44 #include <id.h>
45 #include <confirm.h>
46 #include <widgets/infobar.h>
48 #include <wx/ffile.h>
49 #include <wx/hyperlink.h>
50 #include <erc_item.h>
51 #include <eeschema_settings.h>
52 #include <kicad_string.h>
53 #include <kiplatform/ui.h>
54 
56  DIALOG_ERC_BASE( parent ),
57  PROGRESS_REPORTER( 1 ),
58  m_parent( parent ),
59  m_running( false ),
60  m_ercRun( false ),
62 {
63  EESCHEMA_SETTINGS* settings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
65 
67 
70  m_markerDataView->AssociateModel( m_markerTreeModel );
71 
76 
77  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
78  // that requires us to correct the button labels here.
79  m_sdbSizer1OK->SetLabel( _( "Run ERC" ) );
80  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
81  m_sdbSizer1->Layout();
82 
83  m_sdbSizer1OK->SetDefault();
84 
88 
90  {
91  wxHyperlinkCtrl* button = new wxHyperlinkCtrl( m_infoBar, wxID_ANY,
92  _("Show Annotation dialog"),
93  wxEmptyString );
94 
95  button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
96  [&]( wxHyperlinkEvent& aEvent )
97  {
98  wxHtmlLinkEvent htmlEvent( aEvent.GetId(),
99  wxHtmlLinkInfo( aEvent.GetURL() ) );
100  OnLinkClicked( htmlEvent );
101  } ) );
102 
104  m_infoBar->AddButton( button );
105  m_infoBar->ShowMessage( _( "Annotation not complete. ERC cannot be run." ) );
106  }
107 
108  // Now all widgets have the size fixed, call FinishDialogSettings
110 }
111 
112 
114 {
115  EESCHEMA_SETTINGS* settings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
116  wxASSERT( settings );
117 
118  if( settings )
120 
121  m_markerTreeModel->DecRef();
122 }
123 
124 
125 // PROGRESS_REPORTER calls
126 
128 {
129  // If ERC checks ever get slow enough we'll want a progress indicator...
130  //
131  // double cur = (double) m_progress.load() / m_maxProgress;
132  // cur = std::max( 0.0, std::min( cur, 1.0 ) );
133  //
134  // m_gauge->SetValue( KiROUND( cur * 1000.0 ) );
135  // wxSafeYield( this );
136 
137  return !m_cancelled;
138 }
139 
140 
141 void DIALOG_ERC::AdvancePhase( const wxString& aMessage )
142 {
144  SetCurrentProgress( 0.0 );
145 
146  m_messages->Report( aMessage );
147 }
148 
149 
150 void DIALOG_ERC::Report( const wxString& aMessage )
151 {
152  m_messages->Report( aMessage );
153 }
154 
155 
157 {
158  int numErrors = 0;
159  int numWarnings = 0;
160  int numExcluded = 0;
161 
162  if( m_markerProvider )
163  {
167  }
168 
169  if( !m_ercRun )
170  {
171  numErrors = -1;
172  numWarnings = -1;
173  }
174 
178 }
179 
180 
181 /* Delete the old ERC markers, over the whole hierarchy
182  */
183 void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event )
184 {
185  bool includeExclusions = false;
186  int numExcluded = 0;
187 
188  if( m_markerProvider )
190 
191  if( numExcluded > 0 )
192  {
193  wxMessageDialog dlg( this, _( "Delete exclusions too?" ), _( "Delete All Markers" ),
194  wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
195  dlg.SetYesNoLabels( _( "Errors and Warnings Only" ) , _( "Errors, Warnings and Exclusions" ) );
196 
197  int ret = dlg.ShowModal();
198 
199  if( ret == wxID_CANCEL )
200  return;
201  else if( ret == wxID_NO )
202  includeExclusions = true;
203  }
204 
205  deleteAllMarkers( includeExclusions );
206 
207  m_ercRun = false;
209  m_parent->GetCanvas()->Refresh();
210 }
211 
212 
213 // This is a modeless dialog so we have to handle these ourselves.
214 void DIALOG_ERC::OnCancelClick( wxCommandEvent& aEvent )
215 {
216  if( m_running )
217  {
218  m_cancelled = true;
219  return;
220  }
221 
222  m_parent->FocusOnItem( nullptr );
223 
224  Close();
225 }
226 
227 
228 void DIALOG_ERC::OnCloseErcDialog( wxCloseEvent& event )
229 {
230  m_parent->FocusOnItem( nullptr );
231 
232  m_parent->GetToolManager()->GetTool<EE_INSPECTION_TOOL>()->DestroyERCDialog();
233 }
234 
235 
237 
238 
240 {
241  m_showAll->SetValue( m_severities == RPT_SEVERITY_ALL );
245 }
246 
247 
248 void DIALOG_ERC::OnLinkClicked( wxHtmlLinkEvent& event )
249 {
250  wxCommandEvent dummy;
252 
253  // We don't actually get notified when the annotation error is resolved, but we can assume
254  // that the user will take corrective action. If they don't, we can just show the infobar
255  // again.
256  m_infoBar->Hide();
257 }
258 
259 
260 void DIALOG_ERC::OnRunERCClick( wxCommandEvent& event )
261 {
262  wxBusyCursor busy;
263 
264  SCHEMATIC* sch = &m_parent->Schematic();
265 
266  // Build the whole sheet list in hierarchy (sheet, not screen)
268 
270  {
271  m_notebook->ChangeSelection( 0 ); // Display the "Tests Running..." tab
272 
273  m_messages->Clear();
274  m_messages->Report( _( "Annotation not complete. ERC cannot be run." )
275  + wxT( " <a href='annotate'>" )
276  + _( "Show Annotation dialog." )
277  + wxT( "</a>" ) );
278 
279  m_messages->Flush();
280  m_infoBar->Hide(); // No need for duplicated error messages
281  return;
282  }
283 
284  m_infoBar->Hide();
285 
287  deleteAllMarkers( true );
288 
289  m_notebook->ChangeSelection( 0 ); // Display the "Tests Running..." tab
290  m_messages->Clear();
291  wxYield(); // Allow time slice to refresh Messages
292 
293  m_running = true;
294  m_sdbSizer1Cancel->SetLabel( _( "Cancel" ) );
295  m_sdbSizer1OK->Enable( false );
296  m_buttondelmarkers->Enable( false );
297  m_saveReport->Enable( false );
298 
299  testErc();
300 
301  if( m_cancelled )
302  m_messages->Report( _( "-------- ERC cancelled by user.<br><br>" ) );
303  else
304  m_messages->Report( _( "Done.<br><br>" ) );
305 
306  Raise();
307  wxYield(); // Allow time slice to refresh Messages
308 
309  m_running = false;
310  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
311  m_sdbSizer1OK->Enable( true );
312  m_buttondelmarkers->Enable( true );
313  m_saveReport->Enable( true );
314 
315  if( !m_cancelled )
316  {
317  wxMilliSleep( 500 );
318  m_notebook->ChangeSelection( 1 );
320  }
321 
322  m_ercRun = true;
324 }
325 
326 
328 {
329  WINDOW_THAWER thawer( m_parent );
330 
331  m_parent->GetCanvas()->Refresh();
332 }
333 
334 
336 {
337  wxFileName fn;
338 
339  SCHEMATIC* sch = &m_parent->Schematic();
340 
341  // Build the whole sheet list in hierarchy (sheet, not screen)
343 
345  {
346  Report( _( "Annotation not complete. ERC cannot be run." )
347  + wxT( " <a href='annotate'>" )
348  + _( "Show Annotation dialog." )
349  + wxT( "</a>" ) );
350 
351  m_infoBar->Hide(); // No need for duplicated error messages
352  return;
353  }
354 
355  m_infoBar->Hide();
356 
357  SCH_SCREENS screens( sch->Root() );
358  ERC_SETTINGS& settings = sch->ErcSettings();
359  ERC_TESTER tester( sch );
360 
361  // Test duplicate sheet names inside a given sheet. While one can have multiple references
362  // to the same file, each must have a unique name.
363  if( settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_NAME ) )
364  {
365  AdvancePhase( _( "Checking sheet names..." ) );
366  tester.TestDuplicateSheetNames( true );
367  }
368 
369  if( settings.IsTestEnabled( ERCE_BUS_ALIAS_CONFLICT ) )
370  {
371  AdvancePhase( _( "Checking bus conflicts..." ) );
372  tester.TestConflictingBusAliases();
373  }
374 
375  // The connection graph has a whole set of ERC checks it can run
376  AdvancePhase( _( "Checking conflicts..." ) );
378  sch->ConnectionGraph()->RunERC();
379 
380  // Test is all units of each multiunit component have the same footprint assigned.
381  if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
382  {
383  AdvancePhase( _( "Checking footprints..." ) );
384  tester.TestMultiunitFootprints();
385  }
386 
387  AdvancePhase( _( "Checking pins..." ) );
388 
389  if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
390  tester.TestMultUnitPinConflicts();
391 
392  // Test pins on each net against the pin connection table
393  if( settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR ) )
394  tester.TestPinToPin();
395 
396  // Test similar labels (i;e. labels which are identical when
397  // using case insensitive comparisons)
398  if( settings.IsTestEnabled( ERCE_SIMILAR_LABELS ) )
399  {
400  AdvancePhase( _( "Checking labels..." ) );
401  tester.TestSimilarLabels();
402  }
403 
404  if( settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
405  {
406  AdvancePhase( _( "Checking for unresolved variables..." ) );
408  }
409 
410  if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
411  {
412  AdvancePhase( _( "Checking no connect pins for connections..." ) );
413  tester.TestNoConnectPins();
414  }
415 
416  if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
417  {
418  AdvancePhase( _( "Checking for library symbol issues..." ) );
419  tester.TestLibSymbolIssues();
420  }
421 
423 
424  // Display diags:
426 
427  // Display new markers from the current screen:
428  KIGFX::VIEW* view = m_parent->GetCanvas()->GetView();
429 
430  for( auto item : m_parent->GetScreen()->Items().OfType( SCH_MARKER_T ) )
431  view->Add( item );
432 
433  m_parent->GetCanvas()->Refresh();
434 
435  // Display message
436  Report( _( "Done.<br><br>" ) );
437 }
438 
439 
440 void DIALOG_ERC::OnERCItemSelected( wxDataViewEvent& aEvent )
441 {
442  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
443  SCH_SHEET_PATH sheet;
444  SCH_ITEM* item = m_parent->Schematic().GetSheets().GetItem( itemID, &sheet );
445 
446  if( item && item->GetClass() != wxT( "DELETED_SHEET_ITEM" ) )
447  {
448  WINDOW_THAWER thawer( m_parent );
449 
450  if( !sheet.empty() && sheet != m_parent->GetCurrentSheet() )
451  {
454 
455  m_parent->SetCurrentSheet( sheet );
457  m_parent->RedrawScreen( (wxPoint) m_parent->GetScreen()->m_ScrollCenter, false );
458  }
459 
460  m_parent->FocusOnItem( item );
461  redrawDrawPanel();
462  }
463 
464  aEvent.Skip();
465 }
466 
467 
468 void DIALOG_ERC::OnERCItemDClick( wxDataViewEvent& aEvent )
469 {
470  if( aEvent.GetItem().IsOk() )
471  {
472  // turn control over to m_parent, hide this DIALOG_ERC window,
473  // no destruction so we can preserve listbox cursor
474  if( !IsModal() )
475  Show( false );
476  }
477 
478  aEvent.Skip();
479 }
480 
481 
482 void DIALOG_ERC::OnERCItemRClick( wxDataViewEvent& aEvent )
483 {
484  RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( aEvent.GetItem() );
485 
486  if( !node )
487  return;
488 
489  ERC_SETTINGS& settings = m_parent->Schematic().ErcSettings();
490 
491  std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
492  wxString listName;
493  wxMenu menu;
494  wxString msg;
495 
496  switch( settings.GetSeverity( rcItem->GetErrorCode() ) )
497  {
498  case RPT_SEVERITY_ERROR: listName = _( "errors" ); break;
499  case RPT_SEVERITY_WARNING: listName = _( "warnings" ); break;
500  default: listName = _( "appropriate" ); break;
501  }
502 
503  if( rcItem->GetParent()->IsExcluded() )
504  {
505  menu.Append( 1, _( "Remove exclusion for this violation" ),
506  wxString::Format( _( "It will be placed back in the %s list" ), listName ) );
507  }
508  else
509  {
510  menu.Append( 2, _( "Exclude this violation" ),
511  wxString::Format( _( "It will be excluded from the %s list" ), listName ) );
512  }
513 
514  menu.AppendSeparator();
515 
516  if( rcItem->GetErrorCode() == ERCE_PIN_TO_PIN_WARNING
517  || rcItem->GetErrorCode() == ERCE_PIN_TO_PIN_ERROR )
518  {
519  // Pin to pin severities edited through pin conflict map
520  }
521  else if( settings.GetSeverity( rcItem->GetErrorCode() ) == RPT_SEVERITY_WARNING )
522  {
523  menu.Append( 4, wxString::Format( _( "Change severity to Error for all '%s' violations" ),
524  rcItem->GetErrorText() ),
525  _( "Violation severities can also be edited in the Board Setup... dialog" ) );
526  }
527  else
528  {
529  menu.Append( 5, wxString::Format( _( "Change severity to Warning for all '%s' violations" ),
530  rcItem->GetErrorText() ),
531  _( "Violation severities can also be edited in the Board Setup... dialog" ) );
532  }
533 
534  menu.Append( 6, wxString::Format( _( "Ignore all '%s' violations" ), rcItem->GetErrorText() ),
535  _( "Violations will not be checked or reported" ) );
536 
537  menu.AppendSeparator();
538 
539  if( rcItem->GetErrorCode() == ERCE_PIN_TO_PIN_WARNING
540  || rcItem->GetErrorCode() == ERCE_PIN_TO_PIN_ERROR )
541  {
542  menu.Append( 7, _( "Edit pin-to-pin conflict map..." ) );
543  }
544  else
545  {
546  menu.Append( 8, _( "Edit violation severities..." ),
547  _( "Open the Schematic Setup... dialog" ) );
548  }
549 
550  bool modified = false;
551 
552  switch( GetPopupMenuSelectionFromUser( menu ) )
553  {
554  case 1:
555  {
556  SCH_MARKER* marker = dynamic_cast<SCH_MARKER*>( node->m_RcItem->GetParent() );
557 
558  if( marker )
559  {
560  marker->SetExcluded( false );
561  m_parent->GetCanvas()->GetView()->Update( marker );
562 
563  // Update view
564  static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->ValueChanged( node );
565  modified = true;
566  }
567  }
568  break;
569 
570  case 2:
571  {
572  SCH_MARKER* marker = dynamic_cast<SCH_MARKER*>( node->m_RcItem->GetParent() );
573 
574  if( marker )
575  {
576  marker->SetExcluded( true );
577  m_parent->GetCanvas()->GetView()->Update( marker );
578 
579  // Update view
581  static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->ValueChanged( node );
582  else
583  static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->DeleteCurrentItem( false );
584 
585  modified = true;
586  }
587  }
588  break;
589 
590  case 4:
591  settings.SetSeverity( rcItem->GetErrorCode(), RPT_SEVERITY_ERROR );
592 
593  for( SCH_ITEM* item : m_parent->GetScreen()->Items().OfType( SCH_MARKER_T ) )
594  {
595  SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
596 
597  if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
598  m_parent->GetCanvas()->GetView()->Update( marker );
599  }
600 
601  // Rebuild model and view
602  static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->SetProvider( m_markerProvider );
603  modified = true;
604  break;
605 
606  case 5:
607  settings.SetSeverity( rcItem->GetErrorCode(), RPT_SEVERITY_WARNING );
608 
609  for( SCH_ITEM* item : m_parent->GetScreen()->Items().OfType( SCH_MARKER_T ) )
610  {
611  SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
612 
613  if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
614  m_parent->GetCanvas()->GetView()->Update( marker );
615  }
616 
617  // Rebuild model and view
618  static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->SetProvider( m_markerProvider );
619  modified = true;
620  break;
621 
622  case 6:
623  {
624  settings.SetSeverity( rcItem->GetErrorCode(), RPT_SEVERITY_IGNORE );
625 
626  if( rcItem->GetErrorCode() == ERCE_PIN_TO_PIN_ERROR )
628 
629  SCH_SCREENS ScreenList( m_parent->Schematic().Root() );
630  ScreenList.DeleteMarkers( MARKER_BASE::MARKER_ERC, rcItem->GetErrorCode() );
631 
632  // Rebuild model and view
633  static_cast<RC_TREE_MODEL*>( aEvent.GetModel() )->SetProvider( m_markerProvider );
634  modified = true;
635  }
636  break;
637 
638  case 7:
639  m_parent->ShowSchematicSetupDialog( _( "Pin Conflicts Map" ) );
640  break;
641 
642  case 8:
643  m_parent->ShowSchematicSetupDialog( _( "Violation Severity" ) );
644  break;
645  }
646 
647  if( modified )
648  {
650  redrawDrawPanel();
651  m_parent->OnModify();
652  }
653 }
654 
655 
657 {
658  if( m_notebook->GetSelection() != 1 )
659  m_notebook->SetSelection( 1 );
660 
662 }
663 
664 
666 {
667  if( m_notebook->GetSelection() != 1 )
668  m_notebook->SetSelection( 1 );
669 
671 }
672 
673 
675 {
676  if( m_notebook->GetSelection() != 1 )
677  return;
678 
679  RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( m_markerDataView->GetCurrentItem() );
680  SCH_MARKER* marker = dynamic_cast<SCH_MARKER*>( node->m_RcItem->GetParent() );
681 
682  if( marker && !marker->IsExcluded() )
683  {
684  marker->SetExcluded( true );
685  m_parent->GetCanvas()->GetView()->Update( marker );
686 
687  // Update view
690  else
692 
694  redrawDrawPanel();
695  m_parent->OnModify();
696  }
697 }
698 
699 
700 void DIALOG_ERC::OnSeverity( wxCommandEvent& aEvent )
701 {
702  int flag = 0;
703 
704  if( aEvent.GetEventObject() == m_showAll )
705  flag = RPT_SEVERITY_ALL;
706  else if( aEvent.GetEventObject() == m_showErrors )
707  flag = RPT_SEVERITY_ERROR;
708  else if( aEvent.GetEventObject() == m_showWarnings )
709  flag = RPT_SEVERITY_WARNING;
710  else if( aEvent.GetEventObject() == m_showExclusions )
711  flag = RPT_SEVERITY_EXCLUSION;
712 
713  if( aEvent.IsChecked() )
714  m_severities |= flag;
715  else if( aEvent.GetEventObject() == m_showAll )
717  else
718  m_severities &= ~flag;
719 
720  syncCheckboxes();
721 
722  // Set the provider's severity levels through the TreeModel so that the old tree
723  // can be torn down before the severity changes.
724  //
725  // It's not clear this is required, but we've had a lot of issues with wxDataView
726  // being cranky on various platforms.
727 
729 
731 }
732 
733 
734 void DIALOG_ERC::deleteAllMarkers( bool aIncludeExclusions )
735 {
736  // Clear current selection list to avoid selection of deleted items
738 
739  m_markerTreeModel->DeleteItems( false, aIncludeExclusions, true );
740 }
741 
742 
743 void DIALOG_ERC::OnSaveReport( wxCommandEvent& aEvent )
744 {
745  wxFileName fn( "./ERC." + ReportFileExtension );
746 
747  wxFileDialog dlg( this, _( "Save Report to File" ), fn.GetPath(), fn.GetFullName(),
748  ReportFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
749 
750  if( dlg.ShowModal() != wxID_OK )
751  return;
752 
753  fn = dlg.GetPath();
754 
755  if( fn.GetExt().IsEmpty() )
756  fn.SetExt( ReportFileExtension );
757 
758  if( !fn.IsAbsolute() )
759  {
760  wxString prj_path = Prj().GetProjectPath();
761  fn.MakeAbsolute( prj_path );
762  }
763 
764  if( writeReport( fn.GetFullPath() ) )
765  {
766  m_messages->Report( wxString::Format( _( "Report file '%s' created\n" ),
767  fn.GetFullPath() ) );
768  }
769  else
770  {
771  DisplayError( this, wxString::Format( _( "Unable to create report file '%s'" ),
772  fn.GetFullPath() ) );
773  }
774 }
775 
776 
777 bool DIALOG_ERC::writeReport( const wxString& aFullFileName )
778 {
779  wxFFile file( aFullFileName, wxT( "wt" ) );
780 
781  if( !file.IsOpened() )
782  return false;
783 
784  wxString msg = wxString::Format( _( "ERC report (%s, Encoding UTF8)\n" ), DateAndTime() );
785 
786  std::map<KIID, EDA_ITEM*> itemMap;
787 
788  int err_count = 0;
789  int warn_count = 0;
790  int total_count = 0;
791  SCH_SHEET_LIST sheetList = m_parent->Schematic().GetSheets();
792 
793  sheetList.FillItemMap( itemMap );
794 
795  ERC_SETTINGS& settings = m_parent->Schematic().ErcSettings();
796 
797  for( unsigned i = 0; i < sheetList.size(); i++ )
798  {
799  msg << wxString::Format( _( "\n***** Sheet %s\n" ), sheetList[i].PathHumanReadable() );
800 
801  for( SCH_ITEM* aItem : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
802  {
803  const SCH_MARKER* marker = static_cast<const SCH_MARKER*>( aItem );
804  RC_ITEM* item = marker->GetRCItem().get();
805  SEVERITY severity = (SEVERITY)settings.GetSeverity( item->GetErrorCode() );
806 
807  if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
808  continue;
809 
810  total_count++;
811 
812  switch( severity )
813  {
814  case RPT_SEVERITY_ERROR: err_count++; break;
815  case RPT_SEVERITY_WARNING: warn_count++; break;
816  default: break;
817  }
818 
819  msg << marker->GetRCItem()->ShowReport( GetUserUnits(), severity, itemMap );
820  }
821  }
822 
823  msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
824  total_count, err_count, warn_count );
825 
826  // Currently: write report using UTF8 (as usual in Kicad).
827  // TODO: see if we can use the current encoding page (mainly for Windows users),
828  // Or other format (HTML?)
829  file.Write( msg );
830 
831  // wxFFile dtor will close the file.
832 
833  return true;
834 }
835 
836 
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
virtual void AdvancePhase()
Uses the next vailable virtual zone of the dialog progress bar.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:240
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:431
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
KIGFX::SCH_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:120
void deleteAllMarkers(bool aIncludeExclusions)
Definition: dialog_erc.cpp:734
void NextMarker()
Definition: rc_item.cpp:541
void OnERCItemRClick(wxDataViewEvent &aEvent) override
Definition: dialog_erc.cpp:482
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:185
void OnCancelClick(wxCommandEvent &event) override
Definition: dialog_erc.cpp:214
wxButton * m_buttondelmarkers
void DeleteMarkers(enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode, bool aIncludeExclusions=true)
Delete all markers of a particular type and error code.
Different units of the same component have different footprints assigned.
Definition: erc_settings.h:50
virtual void RedrawScreen(const wxPoint &aCenterPoint, bool aWarpPointer)
NUMBER_BADGE * m_errorsBadge
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:97
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:264
This file is part of the common library TODO brief description.
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generates the connection data for the entire schematic hierarchy.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr)
Fetch a SCH_ITEM by ID.
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit components have been connected to different nets.
RC_TREE_MODEL * m_markerTreeModel
Definition: dialog_erc.h:44
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:44
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:137
bool m_running
Definition: dialog_erc.h:46
This file is part of the common library.
void ExcludeMarker()
Definition: dialog_erc.cpp:674
void syncCheckboxes()
Definition: dialog_erc.cpp:239
Class DIALOG_ERC_BASE.
SEVERITY
Definition: ui_common.h:83
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
A progress reporter for use in multi-threaded environments.
void OnLinkClicked(wxHtmlLinkEvent &event) override
Definition: dialog_erc.cpp:248
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Definition: rc_item.h:72
bool writeReport(const wxString &aFullFileName)
Definition: dialog_erc.cpp:777
void OnEraseDrcMarkersClick(wxCommandEvent &event) override
Definition: dialog_erc.cpp:183
void PrevMarker()
Definition: dialog_erc.cpp:656
void UpdateNumber(int aNumber, SEVERITY aSeverity)
Update the number displayed on the badge.
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
RC_ITEMS_PROVIDER * m_markerProvider
Definition: dialog_erc.h:43
void ResolveERCExclusions()
Update markers to match recorded exclusions.
wxCheckBox * m_showExclusions
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
void TestTextVars(KIGFX::WS_PROXY_VIEW_ITEM *aWorksheet)
Check for any unresolved text variable references.
void updateDisplayedCounts()
Definition: dialog_erc.cpp:156
Definition: erc.h:51
WS_PROXY_VIEW_ITEM * GetWorksheet() const
Definition: sch_view.h:98
virtual int GetCount(int aSeverity=-1)=0
Schematic editor (Eeschema) main window.
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:119
void DisplayCurrentSheet()
Draw the current sheet on the display.
Definition: hierarch.cpp:285
void OnSeverity(wxCommandEvent &aEvent) override
Definition: dialog_erc.cpp:700
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
Definition: erc_settings.h:173
wxButton * m_sdbSizer1Cancel
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:122
static int RPT_SEVERITY_ALL
Definition: dialog_erc.cpp:236
Library symbol changed from current symbol in schematic or the library symbol link no longer valid.
Definition: erc_settings.h:65
void DeleteCurrentItem(bool aDeep)
Definition: rc_item.cpp:425
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:270
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:131
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.
Definition: dialog_erc.cpp:150
void SetSeverity(int aErrorCode, int aSeverity)
Definition: kiid.h:44
virtual void SetCurrentProgress(double aProgress)
Set the progress value to aProgress (0..1)
wxCheckBox * m_showAll
void SetExcluded(bool aExcluded)
Definition: marker_base.h:110
int TestConflictingBusAliases()
Check that there are no conflicting bus alias definitions in the schematic.
int GetSeverity(int aErrorCode) const
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:205
wxButton * m_sdbSizer1OK
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
wxString ReportFileWildcard()
int TestMultiunitFootprints()
Test if all units of each multiunit component have the same footprint assigned.
wxStdDialogButtonSizer * m_sdbSizer1
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
std::atomic_bool m_cancelled
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Shared pin in a multi-unit component is connected to more than one net.
Definition: erc_settings.h:52
2 labels are equal for case insensitive comparisons.
Definition: erc_settings.h:49
int GetErrorCode() const
Definition: rc_item.h:162
SCHEMATIC & Schematic() const
Definition of file extensions used in Kicad.
int m_severities
Definition: dialog_erc.h:49
DIALOG_ERC(SCH_EDIT_FRAME *parent)
Definition: dialog_erc.cpp:55
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
wxNotebook * m_notebook
Container for ERC settings.
Definition: erc_settings.h:97
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void OnERCItemSelected(wxDataViewEvent &aEvent) override
Definition: dialog_erc.cpp:440
void PrevMarker()
Definition: rc_item.cpp:520
wxButton * m_saveReport
SCH_EDIT_FRAME * m_parent
Definition: dialog_erc.h:41
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:226
bool Show(bool show) override
void OnCloseErcDialog(wxCloseEvent &event) override
Definition: dialog_erc.cpp:228
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
NUMBER_BADGE * m_warningsBadge
int CheckAnnotate(REPORTER &aReporter, bool aOneSheetOnly)
Check for annotation errors.
void testErc()
Definition: dialog_erc.cpp:335
void OnERCItemDClick(wxDataViewEvent &aEvent) override
Definition: dialog_erc.cpp:468
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void OnAnnotate(wxCommandEvent &event)
wxCheckBox * m_showWarnings
A text variable could not be resolved.
Definition: erc_settings.h:63
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
WX_INFOBAR * m_infoBar
A no connect symbol is connected to more than 1 pin.
Definition: erc_settings.h:46
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
wxCheckBox * m_showErrors
SCH_SHEET & Root() const
Definition: schematic.h:102
bool updateUI() override
Definition: dialog_erc.cpp:127
NUMBER_BADGE * m_exclusionsBadge
see class PGM_BASE
wxDataViewCtrl * m_markerDataView
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:107
const std::string ReportFileExtension
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition: gtk/ui.cpp:44
#define _(s)
Definition: 3d_actions.cpp:33
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
EE_RTREE & Items()
Definition: sch_screen.h:159
Conflicting bus alias definitions across sheets.
Definition: erc_settings.h:54
void NextMarker()
Definition: dialog_erc.cpp:665
void OnSaveReport(wxCommandEvent &aEvent) override
Definition: dialog_erc.cpp:743
bool m_ercRun
Definition: dialog_erc.h:47
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:220
WX_HTML_REPORT_BOX * m_messages
SCH_SHEET_PATH & GetCurrentSheet() const
void FocusOnItem(SCH_ITEM *aItem)
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
Definition: base_screen.h:99
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:132
static REPORTER & GetInstance()
Definition: reporter.cpp:105
VIEW.
Definition: view.h:63
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Duplicate sheet names within a given sheet.
Definition: erc_settings.h:39
void ShowSchematicSetupDialog(const wxString &aInitialPage=wxEmptyString)
void SetMaximumNumber(int aMax)
Set the maximum number to be shown on the badge.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
void redrawDrawPanel()
Definition: dialog_erc.cpp:327
int RunERC()
Runs electrical rule checks on the connectivity graph.
std::shared_ptr< RC_ITEM > GetRCItem() const
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used.
Definition: marker_base.h:120
wxString DateAndTime()
Definition: string.cpp:406
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:521
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
void ValueChanged(RC_TREE_NODE *aNode)
Definition: rc_item.cpp:408
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
void OnRunERCClick(wxCommandEvent &event) override
Definition: dialog_erc.cpp:260