44#include <wx/filedlg.h>
46#include <wx/wupdlock.h>
139 listItem.SetText( str );
140 listItem.SetData( code );
152 { wxID_CANCEL,
_(
"Close" ) } } );
185 g_lastIgnored.push_back( { m_ignoredList->GetItemText( ii ), m_ignoredList->GetItemData( ii ) } );
206 SetReturnCode( wxID_CANCEL );
223 int newValue =
KiROUND( cur * 1000.0 );
231 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
232 if( std::chrono::duration_cast<std::chrono::milliseconds>( now -
m_lastUpdateUi ).count()
235 Pgm().
App().SafeYieldFor(
this, wxEVT_CATEGORY_NATIVE_EVENTS );
274 menu.Append( 4205,
_(
"Report All Errors for Each Track" ),
275 _(
"If unchecked, only the first error will be reported for each track" ),
279 menu.AppendSeparator();
281 menu.Append( 4206,
_(
"Cross-probe Selected Items" ),
282 _(
"Highlight corresponding items on canvas when selected in the DRC list" ),
286 menu.Append( 4207,
_(
"Center on Cross-probe" ),
287 _(
"When cross-probing, scroll the canvas so that the item is visible" ),
292 int menu_id =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
294 if( menu_id == 0 || menu_id == 4205 )
298 else if( menu_id == 2 || menu_id == 4206 )
302 else if( menu_id == 3 || menu_id == 4207 )
311 m_frame->ShowBoardSetupDialog(
_(
"Custom Rules" ),
this );
317 if(
int hotkey = aEvt.GetKeyCode() )
319 if( aEvt.ControlDown() )
321 if( aEvt.ShiftDown() )
345 if( zoneFillerTool->IsBusy() )
365 m_messages->Report(
_(
"DRC incomplete: could not compile custom design rules." )
366 + wxS(
" " )
367 + wxS(
"<a href='$CUSTOM_RULES'>" ) +
_(
"Show design rules." ) + wxT(
"</a>" ) );
380 m_frame->GetBoard()->RecordDRCExclusions();
386 for( std::reference_wrapper<RC_ITEM>& item : violations )
392 listItem.SetText( wxT(
" • " ) + item.get().GetErrorText(
true ) );
393 listItem.SetData( item.get().GetErrorCode() );
420 m_messages->Report(
_(
"-------- DRC canceled by user.<br><br>" ) );
477 auto getActiveLayers =
485 for(
int layer : aItem->GetLayerSet() )
487 if(
pad->FlashLayer( layer ) )
495 return aItem->GetLayerSet();
507 std::shared_ptr<RC_ITEM> rc_item = node->
m_RcItem;
529 LSET violationLayers;
555 if( a || b || c || d )
566 LSET layersList = getActiveLayers( it );
567 violationLayers &= layersList;
570 principalLayer = layersList.
Seq().front();
574 if( violationLayers.count() )
575 principalLayer = violationLayers.
Seq().front();
576 else if( principalLayer >= 0 )
577 violationLayers.
set( principalLayer );
582 m_frame->GetAppearancePanel()->SetLayerVisible( principalLayer,
true );
585 m_frame->SetActiveLayer( principalLayer );
589 if( !
m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest )
596 m_frame->GetBoard()->GetConnectivity()->RunOnUnconnectedEdges(
612 if( item == a && item == b )
640 std::vector<BOARD_ITEM*> items;
648 for(
const KIID&
id : rc_item->GetIDs() )
652 if( candidate && candidate->GetNetCode() == net )
653 items.push_back( candidate );
658 items.push_back( item );
674 if( aEvent.GetItem().IsOk() )
696 std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
698 std::shared_ptr<CONNECTIVITY_DATA> conn =
m_currentBoard->GetConnectivity();
702 switch(
bds().m_DRCSeverities[ rcItem->GetErrorCode() ] )
706 default: listName =
_(
"appropriate" );
break;
711 ID_EDIT_EXCLUSION_COMMENT = 4467,
713 ID_REMOVE_EXCLUSION_ALL,
715 ID_ADD_EXCLUSION_WITH_COMMENT,
716 ID_ADD_EXCLUSION_ALL,
717 ID_INSPECT_VIOLATION,
719 ID_SET_SEVERITY_TO_ERROR,
720 ID_SET_SEVERITY_TO_WARNING,
721 ID_SET_SEVERITY_TO_IGNORE,
725 if( rcItem->GetParent()->IsExcluded() )
727 menu.Append( ID_REMOVE_EXCLUSION,
728 _(
"Remove exclusion for this violation" ),
729 wxString::Format(
_(
"It will be placed back in the %s list" ), listName ) );
731 menu.Append( ID_EDIT_EXCLUSION_COMMENT,
732 _(
"Edit exclusion comment..." ) );
736 menu.Append( ID_REMOVE_EXCLUSION_ALL,
737 wxString::Format(
_(
"Remove all exclusions for violations of rule '%s'" ),
739 wxString::Format(
_(
"They will be placed back in the %s list" ), listName ) );
744 menu.Append( ID_ADD_EXCLUSION,
745 _(
"Exclude this violation" ),
746 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
748 menu.Append( ID_ADD_EXCLUSION_WITH_COMMENT,
749 _(
"Exclude with comment..." ),
750 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
754 menu.Append( ID_ADD_EXCLUSION_ALL,
755 wxString::Format(
_(
"Exclude all violations of rule '%s'..." ),
757 wxString::Format(
_(
"They will be excluded from the %s list" ), listName ) );
761 menu.AppendSeparator();
764 wxString fixDRCErrorMenuText = drcTool->FixDRCErrorMenuText( rcItem );
766 if( !inspectDRCErrorMenuText.IsEmpty() || !fixDRCErrorMenuText.IsEmpty() )
768 if( !inspectDRCErrorMenuText.IsEmpty() )
769 menu.Append( ID_INSPECT_VIOLATION, inspectDRCErrorMenuText );
771 if( !fixDRCErrorMenuText.IsEmpty() )
772 menu.Append( ID_FIX_VIOLATION, fixDRCErrorMenuText );
774 menu.AppendSeparator();
779 menu.Append( ID_SET_SEVERITY_TO_ERROR,
780 wxString::Format(
_(
"Change severity to Error for all '%s' violations" ),
781 rcItem->GetErrorText(
true ) ),
782 _(
"Violation severities can also be edited in the Board Setup... dialog" ) );
786 menu.Append( ID_SET_SEVERITY_TO_WARNING,
787 wxString::Format(
_(
"Change severity to Warning for all '%s' violations" ),
788 rcItem->GetErrorText(
true ) ),
789 _(
"Violation severities can also be edited in the Board Setup... dialog" ) );
792 menu.Append( ID_SET_SEVERITY_TO_IGNORE,
793 wxString::Format(
_(
"Ignore all '%s' violations" ), rcItem->GetErrorText(
true ) ),
794 _(
"Violations will not be checked or reported" ) );
796 menu.AppendSeparator();
798 menu.Append( ID_EDIT_SEVERITIES,
799 _(
"Edit violation severities..." ),
800 _(
"Open the Board Setup... dialog" ) );
802 bool modified =
false;
803 int command = GetPopupMenuSelectionFromUser( menu );
807 case ID_EDIT_EXCLUSION_COMMENT:
810 WX_TEXT_ENTRY_DIALOG dlg(
this, wxEmptyString,
_(
"Exclusion Comment" ), marker->GetComment(),
true );
815 marker->SetExcluded(
true, dlg.
GetValue() );
817 wxString serialized = marker->SerializeToString();
828 case ID_REMOVE_EXCLUSION:
831 marker->SetExcluded(
false );
833 wxString serialized = marker->SerializeToString();
839 m_frame->GetBoard()->UpdateRatsnestExclusions();
840 m_frame->GetCanvas()->RedrawRatsnest();
844 m_frame->GetCanvas()->GetView()->Update( marker );
854 case ID_ADD_EXCLUSION:
855 case ID_ADD_EXCLUSION_WITH_COMMENT:
860 if( command == ID_ADD_EXCLUSION_WITH_COMMENT )
870 marker->SetExcluded(
true, comment );
872 wxString serialized = marker->SerializeToString();
878 m_frame->GetBoard()->UpdateRatsnestExclusions();
879 m_frame->GetCanvas()->RedrawRatsnest();
883 m_frame->GetCanvas()->GetView()->Update( marker );
897 case ID_REMOVE_EXCLUSION_ALL:
900 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
904 marker->SetExcluded(
false );
906 wxString serialized = marker->SerializeToString();
917 case ID_ADD_EXCLUSION_ALL:
920 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
924 marker->SetExcluded(
true );
926 wxString serialized = marker->SerializeToString();
936 case ID_INSPECT_VIOLATION:
940 case ID_FIX_VIOLATION:
941 drcTool->FixDRCError( node->m_RcItem );
944 case ID_SET_SEVERITY_TO_ERROR:
949 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
950 m_frame->GetCanvas()->GetView()->Update( marker );
958 case ID_SET_SEVERITY_TO_WARNING:
963 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
964 m_frame->GetCanvas()->GetView()->Update( marker );
972 case ID_SET_SEVERITY_TO_IGNORE:
978 listItem.SetText( wxT(
" • " ) + rcItem->GetErrorText(
true ) );
979 listItem.SetData( rcItem->GetErrorCode() );
985 std::vector<BOARD_ITEM*> toRemove;
989 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
991 m_frame->GetCanvas()->GetView()->Remove( marker );
992 toRemove.emplace_back( marker );
1002 m_frame->GetCanvas()->RedrawRatsnest();
1010 case ID_EDIT_SEVERITIES:
1011 m_frame->ShowBoardSetupDialog(
_(
"Violation Severity" ),
this );
1026 int errorCode = (int) event.m_item.GetData();
1033 menu.Check(
bds().GetSeverity( errorCode ),
true );
1035 int severity = GetPopupMenuSelectionFromUser( menu );
1039 if(
bds().m_DRCSeverities[ errorCode ] != severity )
1053 m_frame->ShowBoardSetupDialog(
_(
"Violation Severity" ),
this );
1059 if( aEvent.GetEventObject() ==
m_showAll )
1074 wxFileDialog dlg(
this,
_(
"Save Report File" ),
Prj().GetProjectPath(), fn.GetFullName(),
1076 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1080 if( dlg.ShowModal() != wxID_OK )
1085 if( fn.GetExt().IsEmpty() )
1088 if( !fn.IsAbsolute() )
1091 fn.MakeAbsolute( prj_path );
1097 bool success =
false;
1104 m_messages->Report( wxString::Format(
_(
"Report file '%s' created<br>" ), fn.GetFullPath() ) );
1106 DisplayError(
this, wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ) );
1112 wxCommandEvent
dummy;
1127 SetReturnCode( wxID_CANCEL );
1150 m_frame->GetCanvas()->Refresh();
1221 m_frame->GetCanvas()->GetView()->Update( marker );
1247 m_frame->GetBoard()->DeleteMARKERs(
true, aIncludeExclusions );
1279 static bool s_includeExclusions =
false;
1281 int numExcluded = 0;
1292 if( numExcluded > 0 )
1294 wxMessageDialog dlg(
this,
_(
"Delete exclusions too?" ),
_(
"Delete All Markers" ),
1295 wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
1296 dlg.SetYesNoLabels(
_(
"Errors and Warnings Only" ),
1297 _(
"Errors, Warnings and Exclusions" ) );
1299 int ret = dlg.ShowModal();
1301 if( ret == wxID_CANCEL )
1303 else if( ret == wxID_NO )
1304 s_includeExclusions =
true;
1323 int numUnconnected = 0;
1324 int numFootprints = 0;
1327 int numWarnings = 0;
1328 int numExcluded = 0;
1354 bool errorsOverflowed =
false;
1355 bool warningsOverflowed =
false;
1356 bool markersOverflowed =
false;
1357 bool unconnectedOverflowed =
false;
1358 bool footprintsOverflowed =
false;
1364 if( drcEngine->IsErrorLimitExceeded( ii ) )
1367 errorsOverflowed =
true;
1369 warningsOverflowed =
true;
1374 unconnectedOverflowed =
true;
1376 unconnectedOverflowed =
true;
1387 footprintsOverflowed =
true;
1389 footprintsOverflowed =
true;
1394 markersOverflowed =
true;
1396 markersOverflowed =
true;
1408 num.Printf( markersOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numMarkers );
1414 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1421 num.Printf( unconnectedOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numUnconnected );
1427 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1434 num.Printf( footprintsOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numFootprints );
1440 msg.Replace( wxT(
"%s" ),
_(
"not run" ) );
1445 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1458 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1468 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
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)
std::chrono::steady_clock::time_point m_lastUpdateUi
Used to slow down the rate of yields in updateUi()
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
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.