45#include <wx/filedlg.h>
47#include <wx/wupdlock.h>
76 m_footprintTestsRun( false ),
77 m_markersTreeModel( nullptr ),
78 m_unconnectedTreeModel( nullptr ),
79 m_fpWarningsTreeModel( nullptr ),
81 m_lastUpdateUi(
std::chrono::steady_clock::now() )
127 listItem.SetText( str );
128 listItem.SetData( code );
140 { wxID_CANCEL,
_(
"Close" ) } } );
185 catch(
const std::runtime_error& e )
187 wxFAIL_MSG( e.what() );
195 if( !
Kiface().IsSingle() )
213 SetReturnCode( wxID_CANCEL );
228 int newValue =
KiROUND( cur * 1000.0 );
235 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
236 if( std::chrono::duration_cast<std::chrono::milliseconds>( now -
m_lastUpdateUi ).count()
239 Pgm().
App().SafeYieldFor(
this, wxEVT_CATEGORY_NATIVE_EVENTS );
284 if( zoneFillerTool->IsBusy() )
304 m_messages->
Report(
_(
"DRC incomplete: could not compile custom design rules." )
305 + wxS(
" " )
306 + wxS(
"<a href='$CUSTOM_RULES'>" ) +
_(
"Show design rules." ) + wxT(
"</a>" ) );
325 for( std::reference_wrapper<RC_ITEM>& item : violations )
331 listItem.SetText( wxT(
" • " ) + item.get().GetErrorText() );
332 listItem.SetData( item.get().GetErrorCode() );
355 drcTool->
RunTests(
this, refillZones, reportAllTrackErrors, testFootprints );
408 auto getActiveLayers =
416 for(
int layer : aItem->GetLayerSet().Seq() )
418 if(
pad->FlashLayer( layer ) )
426 return aItem->GetLayerSet();
438 std::shared_ptr<RC_ITEM> rc_item = node->
m_RcItem;
461 LSET violationLayers;
487 if( a || b || c || d )
498 LSET layersList = getActiveLayers( it );
499 violationLayers &= layersList;
502 principalLayer = layersList.
Seq().front();
506 if( violationLayers.count() )
507 principalLayer = violationLayers.
Seq().front();
509 violationLayers.set( principalLayer );
544 if( item == a && item == b )
546 focusPos = ( node->m_Type == RC_TREE_NODE::MAIN_ITEM )
547 ? edge.GetSourcePos()
548 : edge.GetTargetPos();
552 focusPos = ( item == edge.GetSourceNode()->Parent() )
553 ? edge.GetSourcePos()
554 : edge.GetTargetPos();
574 std::vector<BOARD_ITEM*> items;
582 for(
const KIID&
id : rc_item->GetIDs() )
586 if( candidate && candidate->GetNetCode() == net )
587 items.push_back( candidate );
592 items.push_back( item );
595 m_frame->FocusOnItems( items, principalLayer );
599 m_frame->FocusOnItem( item, principalLayer );
608 if( aEvent.GetItem().IsOk() )
630 std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
640 default: listName =
_(
"appropriate" );
break;
645 ID_EDIT_EXCLUSION_COMMENT = 4467,
647 ID_REMOVE_EXCLUSION_ALL,
649 ID_ADD_EXCLUSION_ALL,
650 ID_INSPECT_VIOLATION,
651 ID_SET_SEVERITY_TO_ERROR,
652 ID_SET_SEVERITY_TO_WARNING,
653 ID_SET_SEVERITY_TO_IGNORE,
657 if( rcItem->GetParent()->IsExcluded() )
659 menu.Append( ID_EDIT_EXCLUSION_COMMENT,
660 _(
"Edit exclusion comment..." ) );
662 menu.Append( ID_REMOVE_EXCLUSION,
663 _(
"Remove exclusion for this violation" ),
664 wxString::Format(
_(
"It will be placed back in the %s list" ), listName ) );
668 menu.Append( ID_REMOVE_EXCLUSION_ALL,
669 wxString::Format(
_(
"Remove all exclusions for violations of rule '%s'" ),
671 wxString::Format(
_(
"They will be placed back in the %s list" ), listName ) );
676 menu.Append( ID_ADD_EXCLUSION,
677 _(
"Exclude this violation..." ),
678 wxString::Format(
_(
"It will be excluded from the %s list" ), listName ) );
682 menu.Append( ID_ADD_EXCLUSION_ALL,
683 wxString::Format(
_(
"Exclude all violations of rule '%s'..." ),
685 wxString::Format(
_(
"They will be excluded from the %s list" ), listName ) );
691 if( !inspectDRCErrorMenuText.IsEmpty() )
692 menu.Append( ID_INSPECT_VIOLATION, inspectDRCErrorMenuText );
694 menu.AppendSeparator();
698 menu.Append( ID_SET_SEVERITY_TO_ERROR,
699 wxString::Format(
_(
"Change severity to Error for all '%s' violations" ),
700 rcItem->GetErrorText() ),
701 _(
"Violation severities can also be edited in the Board Setup... dialog" ) );
705 menu.Append( ID_SET_SEVERITY_TO_WARNING,
706 wxString::Format(
_(
"Change severity to Warning for all '%s' violations" ),
707 rcItem->GetErrorText() ),
708 _(
"Violation severities can also be edited in the Board Setup... dialog" ) );
711 menu.Append( ID_SET_SEVERITY_TO_IGNORE,
712 wxString::Format(
_(
"Ignore all '%s' violations" ), rcItem->GetErrorText() ),
713 _(
"Violations will not be checked or reported" ) );
715 menu.AppendSeparator();
717 menu.Append( ID_EDIT_SEVERITIES,
718 _(
"Edit violation severities..." ),
719 _(
"Open the Board Setup... dialog" ) );
721 bool modified =
false;
723 switch( GetPopupMenuSelectionFromUser( menu ) )
725 case ID_EDIT_EXCLUSION_COMMENT:
729 marker->GetComment(),
true );
731 if( dlg.ShowModal() == wxID_CANCEL )
734 marker->SetExcluded(
true, dlg.
GetValue() );
736 wxString serialized = marker->SerializeToString();
741 static_cast<RC_TREE_MODEL*
>( aEvent.GetModel() )->ValueChanged( node );
747 case ID_REMOVE_EXCLUSION:
750 marker->SetExcluded(
false );
752 wxString serialized = marker->SerializeToString();
767 static_cast<RC_TREE_MODEL*
>( aEvent.GetModel() )->ValueChanged( node );
773 case ID_ADD_EXCLUSION:
777 wxEmptyString,
true );
779 if( dlg.ShowModal() == wxID_CANCEL )
782 marker->SetExcluded(
true, dlg.
GetValue() );
784 wxString serialized = marker->SerializeToString();
800 static_cast<RC_TREE_MODEL*
>( aEvent.GetModel() )->ValueChanged( node );
802 static_cast<RC_TREE_MODEL*
>( aEvent.GetModel() )->DeleteCurrentItem(
false );
809 case ID_REMOVE_EXCLUSION_ALL:
812 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
816 marker->SetExcluded(
false );
818 wxString serialized = marker->SerializeToString();
829 case ID_ADD_EXCLUSION_ALL:
832 DRC_ITEM* candidateDrcItem =
static_cast<DRC_ITEM*
>( marker->GetRCItem().get() );
836 marker->SetExcluded(
true );
838 wxString serialized = marker->SerializeToString();
848 case ID_INSPECT_VIOLATION:
852 case ID_SET_SEVERITY_TO_ERROR:
857 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
866 case ID_SET_SEVERITY_TO_WARNING:
871 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
880 case ID_SET_SEVERITY_TO_IGNORE:
886 listItem.SetText( wxT(
" • " ) + rcItem->GetErrorText() );
887 listItem.SetData( rcItem->GetErrorCode() );
893 std::vector<BOARD_ITEM*> toRemove;
897 if( marker->GetRCItem()->GetErrorCode() == rcItem->GetErrorCode() )
900 toRemove.emplace_back( marker );
905 board->
Remove( marker, REMOVE_MODE::BULK );
918 case ID_EDIT_SEVERITIES:
934 int errorCode = (int) event.m_item.GetData();
943 int severity = GetPopupMenuSelectionFromUser( menu );
947 if(
bds().m_DRCSeverities[ errorCode ] != severity )
969 if( aEvent.GetEventObject() ==
m_showAll )
978 if( aEvent.IsChecked() )
980 else if( aEvent.GetEventObject() ==
m_showAll )
994 wxFileDialog dlg(
this,
_(
"Save Report File" ),
Prj().GetProjectPath(), fn.GetFullName(),
996 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
998 if( dlg.ShowModal() != wxID_OK )
1003 if( fn.GetExt().IsEmpty() )
1006 if( !fn.IsAbsolute() )
1009 fn.MakeAbsolute( prj_path );
1015 bool success =
false;
1024 fn.GetFullPath() ) );
1028 DisplayError(
this, wxString::Format(
_(
"Failed to create file '%s'." ),
1029 fn.GetFullPath() ) );
1039 wxCommandEvent
dummy;
1055 SetReturnCode( wxID_CANCEL );
1195 static bool s_includeExclusions =
false;
1197 int numExcluded = 0;
1208 if( numExcluded > 0 )
1210 wxMessageDialog dlg(
this,
_(
"Delete exclusions too?" ),
_(
"Delete All Markers" ),
1211 wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
1212 dlg.SetYesNoLabels(
_(
"Errors and Warnings Only" ),
1213 _(
"Errors, Warnings and Exclusions" ) );
1215 int ret = dlg.ShowModal();
1217 if( ret == wxID_CANCEL )
1219 else if( ret == wxID_NO )
1220 s_includeExclusions =
true;
1239 int numUnconnected = 0;
1240 int numFootprints = 0;
1243 int numWarnings = 0;
1244 int numExcluded = 0;
1272 bool errorsOverflowed =
false;
1273 bool warningsOverflowed =
false;
1274 bool markersOverflowed =
false;
1275 bool unconnectedOverflowed =
false;
1276 bool footprintsOverflowed =
false;
1280 if( drcEngine->IsErrorLimitExceeded( ii ) )
1283 errorsOverflowed =
true;
1285 warningsOverflowed =
true;
1290 unconnectedOverflowed =
true;
1292 unconnectedOverflowed =
true;
1301 footprintsOverflowed =
true;
1303 footprintsOverflowed =
true;
1308 markersOverflowed =
true;
1310 markersOverflowed =
true;
1322 num.Printf( markersOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numMarkers );
1328 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1335 num.Printf( unconnectedOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numUnconnected );
1341 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1348 num.Printf( footprintsOverflowed ? wxT(
"%d+" ) : wxT(
"%d" ), numFootprints );
1354 msg.Replace( wxT(
"%s" ),
_(
"not run" ) );
1359 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1372 msg.Replace( wxT(
"(%s)" ), wxEmptyString );
1382 if( !
m_drcRun && numWarnings == 0 )
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void SetLayerVisible(int aLayer, bool isVisible)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Container for design settings for a BOARD object.
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.
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
BOARD_ITEM * GetItem(const KIID &aID) const
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
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 UpdateRatsnestExclusions()
Update the visibility flags on the current unconnected ratsnest lines.
void DeleteMARKERs()
Delete all MARKERS from the board.
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
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
static DELETED_BOARD_ITEM * GetInstance()
wxCheckBox * m_cbRefillZones
wxButton * m_DeleteAllMarkersButton
wxCheckBox * m_showExclusions
wxCheckBox * m_showErrors
wxDataViewCtrl * m_unconnectedDataView
wxDataViewCtrl * m_footprintsDataView
NUMBER_BADGE * m_warningsBadge
wxCheckBox * m_cbReportAllTrackErrors
NUMBER_BADGE * m_exclusionsBadge
wxSimplebook * m_runningResultsBook
wxButton * m_DeleteCurrentMarkerButton
wxButton * m_sdbSizerCancel
wxCheckBox * m_cbTestFootprints
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 OnErrorLinkClicked(wxHtmlLinkEvent &event) override
BOARD_DESIGN_SETTINGS & bds()
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 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
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...
EDA_UNITS GetUserUnits() const
Design Rule Checker object that performs all the DRC tests.
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
DRC_RULE * GetViolatingRule() const
bool WriteJsonReport(const wxString &aFullFileName)
bool WriteTextReport(const wxString &aFullFileName)
void RefreshCanvas() override
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KICAD_T Type() const
Returns the type of object.
EDA_ITEM_FLAGS GetFlags() const
bool IsSingle() const
Is this KIFACE running under single_top?
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
LSET is a set of PCB_LAYER_IDs.
static LSET AllLayersMask()
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
void SetMaximumNumber(int aMax)
Set the maximum number to be shown on the badge.
void UpdateNumber(int aNumber, SEVERITY aSeverity)
Update the number displayed on the badge.
DISPLAY_OPTIONS m_Display
static TOOL_ACTION showRatsnest
static TOOL_ACTION selectionClear
Clear the current selection.
wxString GetDesignRulesPath()
Return the absolute path to the design rules file for the currently-loaded board.
APPEARANCE_CONTROLS * GetAppearancePanel()
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void RedrawRatsnest()
Return the bounding box of the view that should be used if model is not valid.
The main frame for Pcbnew.
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString)
void SetActiveLayer(PCB_LAYER_ID aLayer) override
Change the currently active layer to aLayer and also update the APPEARANCE_CONTROLS.
void OnModify() override
Must be called after a board change to set the modified flag.
SEVERITY GetSeverity() const override
wxString SerializeToString() const
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
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).
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.
void SelectMarker(const MARKER_BASE *aMarker)
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 DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
void DeleteCurrentItem(bool aDeep)
void CenterMarker(const MARKER_BASE *aMarker)
static KIID ToUUID(wxDataViewItem aItem)
std::shared_ptr< RC_ITEM > m_RcItem
void Clear()
Delete the stored messages.
void SetImmediateMode()
In immediate mode, messages are flushed as they are added.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void Flush()
Build the HTML messages page.
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
static int RPT_SEVERITY_ALL
static int DEFAULT_SINGLE_COL_WIDTH
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
@ DRCE_SCHEMATIC_PARITY_ISSUES
#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.
T clamp(T min, T value, T max)
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,...
bool test_all_track_errors
bool m_ShowGlobalRatsnest
@ 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.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition of file extensions used in Kicad.
static int RPT_SEVERITY_ALL