46#include <wx/filedlg.h>
48#include <wx/wupdlock.h>
142 listItem.SetText( str );
143 listItem.SetData( code );
155 { wxID_CANCEL,
_(
"Close" ) } } );
191 g_lastIgnored.push_back( { m_ignoredList->GetItemText( ii ), m_ignoredList->GetItemData( ii ) } );
212 SetReturnCode( wxID_CANCEL );
229 int newValue =
KiROUND( cur * 1000.0 );
243 Pgm().
App().SafeYieldFor(
this, wxEVT_CATEGORY_NATIVE_EVENTS );
280 menu.Append( 4205,
_(
"Report All Errors for Each Track" ),
281 _(
"If unchecked, only the first error will be reported for each track" ),
285 menu.AppendSeparator();
287 menu.Append( 4206,
_(
"Cross-probe Selected Items" ),
288 _(
"Highlight corresponding items on canvas when selected in the DRC list" ),
292 menu.Append( 4207,
_(
"Center on Cross-probe" ),
293 _(
"When cross-probing, scroll the canvas so that the item is visible" ),
298 int menu_id =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
300 if( menu_id == 0 || menu_id == 4205 )
304 else if( menu_id == 2 || menu_id == 4206 )
308 else if( menu_id == 3 || menu_id == 4207 )
317 m_frame->ShowBoardSetupDialog(
_(
"Custom Rules" ),
this );
323 if(
int hotkey = aEvt.GetKeyCode() )
325 if( aEvt.ControlDown() )
327 if( aEvt.ShiftDown() )
351 if( zoneFillerTool->IsBusy() )
360 m_frame->GetBoard()->RecordDRCExclusions();
377 m_messages->Report(
_(
"DRC incomplete: could not compile custom design rules." )
378 + wxS(
" " )
379 + wxS(
"<a href='$CUSTOM_RULES'>" ) +
_(
"Show design rules." ) + wxT(
"</a>" ) );
392 for( std::reference_wrapper<RC_ITEM>& item : violations )
398 listItem.SetText( wxT(
" • " ) + item.get().GetErrorText(
true ) );
399 listItem.SetData( item.get().GetErrorCode() );
426 m_messages->Report(
_(
"-------- DRC canceled by user.<br><br>" ) );
483 auto getActiveLayers =
491 for(
int layer : aItem->GetLayerSet() )
493 if(
pad->FlashLayer( layer ) )
501 return aItem->GetLayerSet();
513 std::shared_ptr<RC_ITEM> rc_item = node->
m_RcItem;
535 LSET violationLayers;
562 if(
auto* marker =
dynamic_cast<PCB_MARKER*
>( rc_item->GetParent() ) )
567 principalLayer = markerLayer;
573 if( a || b || c || d )
581 LSET layersList = getActiveLayers( it );
582 violationLayers &= layersList;
585 principalLayer = layersList.
Seq().front();
591 if( violationLayers.count() )
592 principalLayer = violationLayers.
Seq().front();
593 else if( principalLayer >= 0 )
594 violationLayers.
set( principalLayer );
599 m_frame->GetAppearancePanel()->SetLayerVisible( principalLayer,
true );
602 m_frame->SetActiveLayer( principalLayer );
606 if( !
m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest )
613 m_frame->GetBoard()->GetConnectivity()->RunOnUnconnectedEdges(
629 if( item == a && item == b )
657 std::vector<BOARD_ITEM*> items;
665 for(
const KIID&
id : rc_item->GetIDs() )
669 if( candidate && candidate->GetNetCode() == net )
670 items.push_back( candidate );
675 items.push_back( item );
691 if( aEvent.GetItem().IsOk() )
713 std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
715 std::shared_ptr<CONNECTIVITY_DATA> conn =
m_currentBoard->GetConnectivity();
719 switch(
bds().m_DRCSeverities[ rcItem->GetErrorCode() ] )
723 default: listName =
_(
"appropriate" );
break;
728 ID_EDIT_EXCLUSION_COMMENT = 4467,
730 ID_REMOVE_EXCLUSION_ALL,
732 ID_ADD_EXCLUSION_WITH_COMMENT,
733 ID_ADD_EXCLUSION_ALL,
734 ID_INSPECT_VIOLATION,
736 ID_SET_SEVERITY_TO_ERROR,
737 ID_SET_SEVERITY_TO_WARNING,
738 ID_SET_SEVERITY_TO_IGNORE,
742 if( rcItem->GetParent()->IsExcluded() )
744 menu.Append( ID_REMOVE_EXCLUSION,
745 _(
"Remove exclusion for this violation" ),
746 wxString::Format(
_(
"It will be placed back in the %s list" ), listName ) );
748 menu.Append( ID_EDIT_EXCLUSION_COMMENT,
749 _(
"Edit exclusion comment..." ) );
753 menu.Append( ID_REMOVE_EXCLUSION_ALL,
754 wxString::Format(
_(
"Remove all exclusions for violations of rule '%s'" ),
756 wxString::Format(
_(
"They will be placed back in the %s list" ), listName ) );
761 menu.Append( ID_ADD_EXCLUSION,
762 _(
"Exclude this violation" ),
763 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
765 menu.Append( ID_ADD_EXCLUSION_WITH_COMMENT,
766 _(
"Exclude with comment..." ),
767 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
771 menu.Append( ID_ADD_EXCLUSION_ALL,
772 wxString::Format(
_(
"Exclude all violations of rule '%s'..." ),
774 wxString::Format(
_(
"They will be excluded from the %s list" ), listName ) );
778 menu.AppendSeparator();
781 wxString fixDRCErrorMenuText = drcTool->FixDRCErrorMenuText( rcItem );
783 if( !inspectDRCErrorMenuText.IsEmpty() || !fixDRCErrorMenuText.IsEmpty() )
785 if( !inspectDRCErrorMenuText.IsEmpty() )
786 menu.Append( ID_INSPECT_VIOLATION, inspectDRCErrorMenuText );
788 if( !fixDRCErrorMenuText.IsEmpty() )
789 menu.Append( ID_FIX_VIOLATION, fixDRCErrorMenuText );
791 menu.AppendSeparator();
796 menu.Append( ID_SET_SEVERITY_TO_ERROR,
797 wxString::Format(
_(
"Change severity to Error for all '%s' violations" ),
798 rcItem->GetErrorText(
true ) ),
799 _(
"Violation severities can also be edited in Board Setup" ) );
803 menu.Append( ID_SET_SEVERITY_TO_WARNING,
804 wxString::Format(
_(
"Change severity to Warning for all '%s' violations" ),
805 rcItem->GetErrorText(
true ) ),
806 _(
"Violation severities can also be edited in Board Setup" ) );
809 menu.Append( ID_SET_SEVERITY_TO_IGNORE,
810 wxString::Format(
_(
"Ignore all '%s' violations" ), rcItem->GetErrorText(
true ) ),
811 _(
"Violations will not be checked or reported" ) );
813 menu.AppendSeparator();
815 menu.Append( ID_EDIT_SEVERITIES,
816 _(
"Edit violation severities..." ),
817 _(
"Open the Board Setup dialog" ) );
819 bool modified =
false;
820 int command = GetPopupMenuSelectionFromUser( menu );
824 case ID_EDIT_EXCLUSION_COMMENT:
827 WX_TEXT_ENTRY_DIALOG dlg(
this, wxEmptyString,
_(
"Exclusion Comment" ), marker->GetComment(),
true );
832 marker->SetExcluded(
true, dlg.
GetValue() );
834 wxString serialized = marker->SerializeToString();
845 case ID_REMOVE_EXCLUSION:
848 marker->SetExcluded(
false );
850 wxString serialized = marker->SerializeToString();
856 m_frame->GetBoard()->UpdateRatsnestExclusions();
857 m_frame->GetCanvas()->RedrawRatsnest();
861 m_frame->GetCanvas()->GetView()->Update( marker );
871 case ID_ADD_EXCLUSION:
872 case ID_ADD_EXCLUSION_WITH_COMMENT:
877 if( command == ID_ADD_EXCLUSION_WITH_COMMENT )
887 marker->SetExcluded(
true, comment );
889 wxString serialized = marker->SerializeToString();
895 m_frame->GetBoard()->UpdateRatsnestExclusions();
896 m_frame->GetCanvas()->RedrawRatsnest();
900 m_frame->GetCanvas()->GetView()->Update( marker );
914 case ID_REMOVE_EXCLUSION_ALL:
917 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
921 marker->SetExcluded(
false );
923 wxString serialized = marker->SerializeToString();
934 case ID_ADD_EXCLUSION_ALL:
937 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
941 marker->SetExcluded(
true );
943 wxString serialized = marker->SerializeToString();
953 case ID_INSPECT_VIOLATION:
957 case ID_FIX_VIOLATION:
958 drcTool->FixDRCError( node->m_RcItem );
961 case ID_SET_SEVERITY_TO_ERROR:
966 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
967 m_frame->GetCanvas()->GetView()->Update( marker );
975 case ID_SET_SEVERITY_TO_WARNING:
980 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
981 m_frame->GetCanvas()->GetView()->Update( marker );
989 case ID_SET_SEVERITY_TO_IGNORE:
995 listItem.SetText( wxT(
" • " ) + rcItem->GetErrorText(
true ) );
996 listItem.SetData( rcItem->GetErrorCode() );
1002 std::vector<BOARD_ITEM*> toRemove;
1006 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
1008 m_frame->GetCanvas()->GetView()->Remove( marker );
1009 toRemove.emplace_back( marker );
1019 m_frame->GetCanvas()->RedrawRatsnest();
1027 case ID_EDIT_SEVERITIES:
1028 m_frame->ShowBoardSetupDialog(
_(
"Violation Severity" ),
this );
1043 int errorCode = (int) event.m_item.GetData();
1050 menu.Check(
bds().GetSeverity( errorCode ),
true );
1052 int severity = GetPopupMenuSelectionFromUser( menu );
1056 if(
bds().m_DRCSeverities[ errorCode ] != severity )
1070 m_frame->ShowBoardSetupDialog(
_(
"Violation Severity" ),
this );
1076 if( aEvent.GetEventObject() ==
m_showAll )
1091 wxFileDialog dlg(
this,
_(
"Save Report File" ),
Prj().GetProjectPath(), fn.GetFullName(),
1093 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1097 if( dlg.ShowModal() != wxID_OK )
1102 if( fn.GetExt().IsEmpty() )
1105 if( !fn.IsAbsolute() )
1108 fn.MakeAbsolute( prj_path );
1114 bool success =
false;
1121 m_messages->Report( wxString::Format(
_(
"Report file '%s' created<br>" ), fn.GetFullPath() ) );
1123 DisplayError(
this, wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ) );
1129 wxCommandEvent
dummy;
1144 SetReturnCode( wxID_CANCEL );
1167 m_frame->GetCanvas()->Refresh();
1238 m_frame->GetCanvas()->GetView()->Update( marker );
1264 m_frame->GetBoard()->DeleteMARKERs(
true, aIncludeExclusions );
1296 static bool s_includeExclusions =
false;
1298 int numExcluded = 0;
1309 if( numExcluded > 0 )
1311 wxMessageDialog dlg(
this,
_(
"Delete exclusions too?" ),
_(
"Delete All Markers" ),
1312 wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
1313 dlg.SetYesNoLabels(
_(
"Errors and Warnings Only" ),
1314 _(
"Errors, Warnings and Exclusions" ) );
1316 int ret = dlg.ShowModal();
1318 if( ret == wxID_CANCEL )
1320 else if( ret == wxID_NO )
1321 s_includeExclusions =
true;
1340 int numUnconnected = 0;
1341 int numFootprints = 0;
1344 int numWarnings = 0;
1345 int numExcluded = 0;
1371 bool errorsOverflowed =
false;
1372 bool warningsOverflowed =
false;
1373 bool markersOverflowed =
false;
1374 bool unconnectedOverflowed =
false;
1375 bool footprintsOverflowed =
false;
1381 if( drcEngine->IsErrorLimitExceeded( ii ) )
1384 errorsOverflowed =
true;
1386 warningsOverflowed =
true;
1391 unconnectedOverflowed =
true;
1393 unconnectedOverflowed =
true;
1404 footprintsOverflowed =
true;
1406 footprintsOverflowed =
true;
1411 markersOverflowed =
true;
1413 markersOverflowed =
true;
1425 num.Printf( markersOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numMarkers );
1431 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1438 num.Printf( unconnectedOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numUnconnected );
1444 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1451 num.Printf( footprintsOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numFootprints );
1457 msg.Replace( wxT(
"%s" ),
_(
"not run" ) );
1462 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1475 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1485 if( !
m_drcRun && numWarnings == 0 )
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static TOOL_ACTION excludeMarker
static TOOL_ACTION selectionClear
Clear the current selection.
BASE_SET & set(size_t pos)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::map< wxString, wxString > m_DrcExclusionComments
std::map< int, SEVERITY > m_DRCSeverities
std::set< wxString > m_DrcExclusions
SEVERITY GetSeverity(int aDRCErrorCode)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
const MARKERS & Markers() const
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.
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) 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
wxButton * m_DeleteAllMarkersButton
wxCheckBox * m_showExclusions
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
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
wxListCtrl * m_ignoredList
NUMBER_BADGE * m_errorsBadge
WX_HTML_REPORT_BOX * m_messages
wxDataViewCtrl * m_markerDataView
void OnDRCItemSelected(wxDataViewEvent &aEvent) override
wxString m_footprintsTitleTemplate
void UpdateData()
Rebuild the contents of the violation tabs based on the current markers and severties.
std::shared_ptr< RC_ITEMS_PROVIDER > m_ratsnestProvider
wxString m_markersTitleTemplate
DIALOG_DRC(PCB_EDIT_FRAME *aEditorFrame, wxWindow *aParent)
Constructors.
void OnEditViolationSeverities(wxHyperlinkEvent &aEvent) override
void OnDeleteOneClick(wxCommandEvent &aEvent) override
RC_TREE_MODEL * m_fpWarningsTreeModel
void OnDeleteAllClick(wxCommandEvent &aEvent) override
void OnMenu(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void OnErrorLinkClicked(wxHtmlLinkEvent &event) override
BOARD_DESIGN_SETTINGS & bds()
bool m_report_all_track_errors
void SelectMarker(const PCB_MARKER *aMarker)
void OnClose(wxCloseEvent &event) override
void OnCharHook(wxKeyEvent &aEvt) override
void OnDRCItemRClick(wxDataViewEvent &aEvent) override
void OnRunDRCClick(wxCommandEvent &aEvent) override
wxString m_ignoredTitleTemplate
void OnDRCItemDClick(wxDataViewEvent &aEvent) override
THROTTLE m_updateThrottle
void deleteAllMarkers(bool aIncludeExclusions)
void updateDisplayedCounts()
RC_TREE_MODEL * m_unconnectedTreeModel
bool m_scroll_on_crossprobe
wxString m_unconnectedTitleTemplate
std::shared_ptr< RC_ITEMS_PROVIDER > m_fpWarningsProvider
std::shared_ptr< RC_ITEMS_PROVIDER > m_markersProvider
void OnSeverity(wxCommandEvent &aEvent) override
void OnIgnoredItemRClick(wxListEvent &event) override
void OnCancelClick(wxCommandEvent &aEvent) override
void OnActivateDlg(wxActivateEvent &aEvent) override
void OnChangingNotebookPage(wxNotebookEvent &aEvent) override
void OnSaveReport(wxCommandEvent &aEvent) override
RC_TREE_MODEL * m_markersTreeModel
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
Design Rule Checker object that performs all the DRC tests.
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
DRC_RULE * GetViolatingRule() const
bool WriteJsonReport(const wxString &aFullFileName)
bool WriteTextReport(const wxString &aFullFileName)
KICAD_T Type() const
Returns the type of object.
EDA_ITEM_FLAGS GetFlags() const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LSET is a set of PCB_LAYER_IDs.
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
static const LSET & AllLayersMask()
const VECTOR2I & GetPos() const
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
enum MARKER_T GetMarkerType() const
static TOOL_ACTION showRatsnest
The main frame for Pcbnew.
SEVERITY GetSeverity() const override
wxString SerializeToString() const
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
PROGRESS_REPORTER_BASE(int aNumPhases)
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
std::atomic_bool m_cancelled
std::atomic_int m_progress
std::atomic_int m_maxProgress
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.
MARKER_BASE * GetParent() const
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
void ValueChanged(RC_TREE_NODE *aNode)
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
void DeleteCurrentItem(bool aDeep)
static KIID ToUUID(wxDataViewItem aItem)
std::shared_ptr< RC_ITEM > m_RcItem
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
static BOARD * g_lastDRCBoard
static bool g_lastFootprintTestsRun
static std::vector< std::pair< wxString, int > > g_lastIgnored
#define DIALOG_DRC_WINDOW_NAME
@ DRCE_SCHEMATIC_FIELDS_PARITY
@ DRCE_DIFF_PAIR_UNCOUPLED_LENGTH_TOO_LONG
@ DRCE_MALFORMED_COURTYARD
@ DRCE_UNRESOLVED_VARIABLE
@ DRCE_DUPLICATE_FOOTPRINT
#define MALFORMED_F_COURTYARD
#define MALFORMED_B_COURTYARD
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:
This file contains miscellaneous commonly used macros and functions.
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< FAB_LAYER_COLOR > dummy
A filename or source description, a problem input line, a line number, a byte offset,...
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_PAD_T
class PAD, a pad in a footprint
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.