44#include <wx/filedlg.h>
46#include <wx/wupdlock.h>
134 listItem.SetText( str );
135 listItem.SetData( code );
147 { wxID_CANCEL,
_(
"Close" ) } } );
180 g_lastIgnored.push_back( { m_ignoredList->GetItemText( ii ), m_ignoredList->GetItemData( ii ) } );
201 SetReturnCode( wxID_CANCEL );
218 int newValue =
KiROUND( cur * 1000.0 );
226 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
227 if( std::chrono::duration_cast<std::chrono::milliseconds>( now -
m_lastUpdateUi ).count()
230 Pgm().
App().SafeYieldFor(
this, wxEVT_CATEGORY_NATIVE_EVENTS );
269 menu.Append( 4205,
_(
"Report All Errors for Each Track" ),
270 _(
"If unchecked, only the first error will be reported for each track" ),
274 menu.AppendSeparator();
276 menu.Append( 4206,
_(
"Cross-probe Selected Items" ),
277 _(
"Highlight corresponding items on canvas when selected in the DRC list" ),
281 menu.Append( 4207,
_(
"Center on Cross-probe" ),
282 _(
"When cross-probing, scroll the canvas so that the item is visible" ),
287 int menu_id =
m_bMenu->GetPopupMenuSelectionFromUser( menu );
289 if( menu_id == 0 || menu_id == 4205 )
293 else if( menu_id == 2 || menu_id == 4206 )
297 else if( menu_id == 3 || menu_id == 4207 )
306 m_frame->ShowBoardSetupDialog(
_(
"Custom Rules" ),
this );
312 if(
int hotkey = aEvt.GetKeyCode() )
314 if( aEvt.ControlDown() )
316 if( aEvt.ShiftDown() )
340 if( zoneFillerTool->IsBusy() )
360 m_messages->Report(
_(
"DRC incomplete: could not compile custom design rules." )
361 + wxS(
" " )
362 + wxS(
"<a href='$CUSTOM_RULES'>" ) +
_(
"Show design rules." ) + wxT(
"</a>" ) );
375 m_frame->GetBoard()->RecordDRCExclusions();
381 for( std::reference_wrapper<RC_ITEM>& item : violations )
387 listItem.SetText( wxT(
" • " ) + item.get().GetErrorText() );
388 listItem.SetData( item.get().GetErrorCode() );
415 m_messages->Report(
_(
"-------- DRC canceled by user.<br><br>" ) );
472 auto getActiveLayers =
480 for(
int layer : aItem->GetLayerSet() )
482 if(
pad->FlashLayer( layer ) )
490 return aItem->GetLayerSet();
499 double dist = selectedItemPos.
Distance( unSelectedItemPos );
502 return dist <= minimumMarkerSeparationDistance;
513 std::shared_ptr<RC_ITEM> rc_item = node->
m_RcItem;
535 LSET violationLayers;
561 if( a || b || c || d )
572 LSET layersList = getActiveLayers( it );
573 violationLayers &= layersList;
576 principalLayer = layersList.
Seq().front();
580 if( violationLayers.count() )
581 principalLayer = violationLayers.
Seq().front();
582 else if( principalLayer >= 0 )
583 violationLayers.
set( principalLayer );
588 m_frame->GetAppearancePanel()->SetLayerVisible( principalLayer,
true );
591 m_frame->SetActiveLayer( principalLayer );
595 if( !
m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest )
602 m_frame->GetBoard()->GetConnectivity()->RunOnUnconnectedEdges(
618 if( item == a && item == b )
646 std::vector<BOARD_ITEM*> items;
654 for(
const KIID&
id : rc_item->GetIDs() )
658 if( candidate && candidate->GetNetCode() == net )
659 items.push_back( candidate );
664 items.push_back( item );
673 std::vector<BOARD_ITEM*> items;
677 if( item->
m_Uuid != boardMarkerItem->m_Uuid && isOverlapping( item, boardMarkerItem ) )
678 items.push_back( boardMarkerItem );
681 items.push_back( item );
696 if( aEvent.GetItem().IsOk() )
717 std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
719 std::shared_ptr<CONNECTIVITY_DATA> conn =
m_currentBoard->GetConnectivity();
723 switch(
bds().m_DRCSeverities[ rcItem->GetErrorCode() ] )
727 default: listName =
_(
"appropriate" );
break;
732 ID_EDIT_EXCLUSION_COMMENT = 4467,
734 ID_REMOVE_EXCLUSION_ALL,
736 ID_ADD_EXCLUSION_WITH_COMMENT,
737 ID_ADD_EXCLUSION_ALL,
738 ID_INSPECT_VIOLATION,
739 ID_SET_SEVERITY_TO_ERROR,
740 ID_SET_SEVERITY_TO_WARNING,
741 ID_SET_SEVERITY_TO_IGNORE,
745 if( rcItem->GetParent()->IsExcluded() )
747 menu.Append( ID_REMOVE_EXCLUSION,
748 _(
"Remove exclusion for this violation" ),
749 wxString::Format(
_(
"It will be placed back in the %s list" ), listName ) );
751 menu.Append( ID_EDIT_EXCLUSION_COMMENT,
752 _(
"Edit exclusion comment..." ) );
756 menu.Append( ID_REMOVE_EXCLUSION_ALL,
757 wxString::Format(
_(
"Remove all exclusions for violations of rule '%s'" ),
759 wxString::Format(
_(
"They will be placed back in the %s list" ), listName ) );
764 menu.Append( ID_ADD_EXCLUSION,
765 _(
"Exclude this violation" ),
766 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
768 menu.Append( ID_ADD_EXCLUSION_WITH_COMMENT,
769 _(
"Exclude with comment..." ),
770 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
774 menu.Append( ID_ADD_EXCLUSION_ALL,
775 wxString::Format(
_(
"Exclude all violations of rule '%s'..." ),
777 wxString::Format(
_(
"They will be excluded from the %s list" ), listName ) );
783 if( !inspectDRCErrorMenuText.IsEmpty() )
784 menu.Append( ID_INSPECT_VIOLATION, inspectDRCErrorMenuText );
786 menu.AppendSeparator();
790 menu.Append( ID_SET_SEVERITY_TO_ERROR,
791 wxString::Format(
_(
"Change severity to Error for all '%s' violations" ),
792 rcItem->GetErrorText() ),
793 _(
"Violation severities can also be edited in the Board Setup... dialog" ) );
797 menu.Append( ID_SET_SEVERITY_TO_WARNING,
798 wxString::Format(
_(
"Change severity to Warning for all '%s' violations" ),
799 rcItem->GetErrorText() ),
800 _(
"Violation severities can also be edited in the Board Setup... dialog" ) );
803 menu.Append( ID_SET_SEVERITY_TO_IGNORE,
804 wxString::Format(
_(
"Ignore all '%s' violations" ), rcItem->GetErrorText() ),
805 _(
"Violations will not be checked or reported" ) );
807 menu.AppendSeparator();
809 menu.Append( ID_EDIT_SEVERITIES,
810 _(
"Edit violation severities..." ),
811 _(
"Open the Board Setup... dialog" ) );
813 bool modified =
false;
814 int command = GetPopupMenuSelectionFromUser( menu );
818 case ID_EDIT_EXCLUSION_COMMENT:
821 WX_TEXT_ENTRY_DIALOG dlg(
this, wxEmptyString,
_(
"Exclusion Comment" ), marker->GetComment(),
true );
826 marker->SetExcluded(
true, dlg.
GetValue() );
828 wxString serialized = marker->SerializeToString();
839 case ID_REMOVE_EXCLUSION:
842 marker->SetExcluded(
false );
844 wxString serialized = marker->SerializeToString();
850 m_frame->GetBoard()->UpdateRatsnestExclusions();
851 m_frame->GetCanvas()->RedrawRatsnest();
855 m_frame->GetCanvas()->GetView()->Update( marker );
865 case ID_ADD_EXCLUSION:
866 case ID_ADD_EXCLUSION_WITH_COMMENT:
871 if( command == ID_ADD_EXCLUSION_WITH_COMMENT )
881 marker->SetExcluded(
true, comment );
883 wxString serialized = marker->SerializeToString();
889 m_frame->GetBoard()->UpdateRatsnestExclusions();
890 m_frame->GetCanvas()->RedrawRatsnest();
894 m_frame->GetCanvas()->GetView()->Update( marker );
908 case ID_REMOVE_EXCLUSION_ALL:
911 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
915 marker->SetExcluded(
false );
917 wxString serialized = marker->SerializeToString();
928 case ID_ADD_EXCLUSION_ALL:
931 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
935 marker->SetExcluded(
true );
937 wxString serialized = marker->SerializeToString();
947 case ID_INSPECT_VIOLATION:
951 case ID_SET_SEVERITY_TO_ERROR:
956 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
957 m_frame->GetCanvas()->GetView()->Update( marker );
965 case ID_SET_SEVERITY_TO_WARNING:
970 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
971 m_frame->GetCanvas()->GetView()->Update( marker );
979 case ID_SET_SEVERITY_TO_IGNORE:
985 listItem.SetText( wxT(
" • " ) + rcItem->GetErrorText() );
986 listItem.SetData( rcItem->GetErrorCode() );
992 std::vector<BOARD_ITEM*> toRemove;
996 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
998 m_frame->GetCanvas()->GetView()->Remove( marker );
999 toRemove.emplace_back( marker );
1009 m_frame->GetCanvas()->RedrawRatsnest();
1017 case ID_EDIT_SEVERITIES:
1018 m_frame->ShowBoardSetupDialog(
_(
"Violation Severity" ),
this );
1033 int errorCode = (int) event.m_item.GetData();
1040 menu.Check(
bds().GetSeverity( errorCode ),
true );
1042 int severity = GetPopupMenuSelectionFromUser( menu );
1046 if(
bds().m_DRCSeverities[ errorCode ] != severity )
1060 m_frame->ShowBoardSetupDialog(
_(
"Violation Severity" ),
this );
1066 if( aEvent.GetEventObject() ==
m_showAll )
1081 wxFileDialog dlg(
this,
_(
"Save Report File" ),
Prj().GetProjectPath(), fn.GetFullName(),
1083 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1085 if( dlg.ShowModal() != wxID_OK )
1090 if( fn.GetExt().IsEmpty() )
1093 if( !fn.IsAbsolute() )
1096 fn.MakeAbsolute( prj_path );
1102 bool success =
false;
1109 m_messages->Report( wxString::Format(
_(
"Report file '%s' created<br>" ), fn.GetFullPath() ) );
1111 DisplayError(
this, wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ) );
1117 wxCommandEvent
dummy;
1132 SetReturnCode( wxID_CANCEL );
1155 m_frame->GetCanvas()->Refresh();
1226 m_frame->GetCanvas()->GetView()->Update( marker );
1252 m_frame->GetBoard()->DeleteMARKERs(
true, aIncludeExclusions );
1284 static bool s_includeExclusions =
false;
1286 int numExcluded = 0;
1297 if( numExcluded > 0 )
1299 wxMessageDialog dlg(
this,
_(
"Delete exclusions too?" ),
_(
"Delete All Markers" ),
1300 wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
1301 dlg.SetYesNoLabels(
_(
"Errors and Warnings Only" ),
1302 _(
"Errors, Warnings and Exclusions" ) );
1304 int ret = dlg.ShowModal();
1306 if( ret == wxID_CANCEL )
1308 else if( ret == wxID_NO )
1309 s_includeExclusions =
true;
1328 int numUnconnected = 0;
1329 int numFootprints = 0;
1332 int numWarnings = 0;
1333 int numExcluded = 0;
1359 bool errorsOverflowed =
false;
1360 bool warningsOverflowed =
false;
1361 bool markersOverflowed =
false;
1362 bool unconnectedOverflowed =
false;
1363 bool footprintsOverflowed =
false;
1369 if( drcEngine->IsErrorLimitExceeded( ii ) )
1372 errorsOverflowed =
true;
1374 warningsOverflowed =
true;
1379 unconnectedOverflowed =
true;
1381 unconnectedOverflowed =
true;
1391 footprintsOverflowed =
true;
1393 footprintsOverflowed =
true;
1398 markersOverflowed =
true;
1400 markersOverflowed =
true;
1412 num.Printf( markersOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numMarkers );
1418 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1425 num.Printf( unconnectedOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numUnconnected );
1431 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1438 num.Printf( footprintsOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numFootprints );
1444 msg.Replace( wxT(
"%s" ),
_(
"not run" ) );
1449 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1462 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1472 if( !
m_drcRun && numWarnings == 0 )
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
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.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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)
virtual VECTOR2I GetPosition() const
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
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
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_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
double m_MinimumMarkerSeparationDistance
When finding overlapped marker a minium distance (in mm) between two DRC markers required to mark it ...
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_MARKER_T
class PCB_MARKER, a marker used to show something
@ 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
VECTOR2< double > VECTOR2D
Definition of file extensions used in Kicad.