Correctly handle excluding an ERC marker in eeschema when right clicking

In addition, hide the option to exclude a marker if the selected marker
is already excluded.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/10173

(cherry picked from commit 701e256b3f)
This commit is contained in:
Roberto Fernandez Bautista 2021-12-30 16:51:04 +00:00
parent 11c967b259
commit e19acb4632
5 changed files with 48 additions and 22 deletions

View File

@ -675,15 +675,22 @@ void DIALOG_ERC::NextMarker()
}
void DIALOG_ERC::ExcludeMarker()
void DIALOG_ERC::ExcludeMarker( SCH_MARKER* aMarker )
{
SCH_MARKER* marker = aMarker;
if( marker != nullptr )
m_markerTreeModel->SelectMarker( marker );
if( m_notebook->GetSelection() != 1 )
return;
RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( m_markerDataView->GetCurrentItem() );
SCH_MARKER* marker = dynamic_cast<SCH_MARKER*>( node->m_RcItem->GetParent() );
if( marker && !marker->IsExcluded() )
if( node && node->m_RcItem )
marker = dynamic_cast<SCH_MARKER*>( node->m_RcItem->GetParent() );
if( node && marker && !marker->IsExcluded() )
{
marker->SetExcluded( true );
m_parent->GetCanvas()->GetView()->Update( marker );

View File

@ -37,6 +37,9 @@
#define DIALOG_ERC_WINDOW_NAME "DialogErcWindowName"
class SCH_MARKER;
class DIALOG_ERC : public DIALOG_ERC_BASE, PROGRESS_REPORTER_BASE
{
public:
@ -50,7 +53,14 @@ public:
void PrevMarker();
void NextMarker();
void ExcludeMarker();
/**
* Exclude aMarker from the ERC list. If aMarker is nullptr, exclude the selected marker
* in this dialog.
*
* @param aMarker aMarker to exclude
*/
void ExcludeMarker( SCH_MARKER* aMarker = nullptr );
void UpdateAnnotationWarning();

View File

@ -70,14 +70,11 @@ bool EE_INSPECTION_TOOL::Init()
{
EE_TOOL_BASE::Init();
auto singleMarkerCondition = SELECTION_CONDITIONS::OnlyType( SCH_MARKER_T )
&& SELECTION_CONDITIONS::Count( 1 );
// Add inspection actions to the selection tool menu
//
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
selToolMenu.AddItem( EE_ACTIONS::excludeMarker, singleMarkerCondition, 100 );
selToolMenu.AddItem( EE_ACTIONS::excludeMarker, EE_CONDITIONS::SingleNonExcludedMarker, 100 );
selToolMenu.AddItem( EE_ACTIONS::showDatasheet,
EE_CONDITIONS::SingleSymbol && EE_CONDITIONS::Idle, 220 );
@ -171,26 +168,27 @@ int EE_INSPECTION_TOOL::NextMarker( const TOOL_EVENT& aEvent )
int EE_INSPECTION_TOOL::ExcludeMarker( const TOOL_EVENT& aEvent )
{
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EE_SELECTION& selection = selTool->GetSelection();
SCH_MARKER* marker = nullptr;
if( selection.GetSize() == 1 && selection.Front()->Type() == SCH_MARKER_T )
marker = static_cast<SCH_MARKER*>( selection.Front() );
if( m_ercDialog )
{
// Let the ERC dialog handle it since it has more update hassles to worry about
m_ercDialog->ExcludeMarker();
// Note that if marker is nullptr the dialog will exclude whichever marker is selected
// in the dialog itself
m_ercDialog->ExcludeMarker( marker );
}
else
else if( marker != nullptr )
{
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EE_SELECTION& selection = selTool->GetSelection();
if( selection.GetSize() == 1 && selection.Front()->Type() == SCH_MARKER_T )
{
SCH_MARKER* marker = static_cast<SCH_MARKER*>( selection.Front() );
marker->SetExcluded( true );
m_frame->GetCanvas()->GetView()->Update( marker );
m_frame->GetCanvas()->Refresh();
m_frame->OnModify();
}
}
return 0;
}

View File

@ -45,6 +45,7 @@
#include <sch_item.h>
#include <sch_line.h>
#include <sch_junction.h>
#include <sch_marker.h>
#include <sch_sheet.h>
#include <sch_sheet_pin.h>
#include <lib_shape.h>
@ -107,6 +108,15 @@ SELECTION_CONDITION EE_CONDITIONS::SingleMultiUnitSymbol = []( const SELECTION&
};
SELECTION_CONDITION EE_CONDITIONS::SingleNonExcludedMarker = []( const SELECTION& aSel )
{
if( aSel.CountType( SCH_MARKER_T ) != 1 )
return false;
return !static_cast<SCH_MARKER*>( aSel.Front() )->IsExcluded();
};
#define HITTEST_THRESHOLD_PIXELS 5

View File

@ -49,6 +49,7 @@ public:
static SELECTION_CONDITION SingleSymbolOrPower;
static SELECTION_CONDITION SingleDeMorganSymbol;
static SELECTION_CONDITION SingleMultiUnitSymbol;
static SELECTION_CONDITION SingleNonExcludedMarker;
};