KiCad PCB EDA Suite
SHEETLIST_ERC_ITEMS_PROVIDER Class Reference

An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contract. More...

#include <erc_settings.h>

Inheritance diagram for SHEETLIST_ERC_ITEMS_PROVIDER:
RC_ITEMS_PROVIDER

Public Member Functions

 SHEETLIST_ERC_ITEMS_PROVIDER (SCHEMATIC *aSchematic)
 
void SetSeverities (int aSeverities) override
 
int GetCount (int aSeverity=-1) const override
 
std::shared_ptr< RC_ITEMGetItem (int aIndex) const override
 Retrieve a RC_ITEM by index. More...
 
std::shared_ptr< ERC_ITEMGetERCItem (int aIndex) const
 
void DeleteItem (int aIndex, bool aDeep) override
 Remove (and optionally deletes) the indexed item from the list. More...
 
void DeleteAllItems (bool aIncludeExclusions, bool aDeep) override
 

Private Member Functions

void visitMarkers (std::function< void(SCH_MARKER *)> aVisitor) const
 

Private Attributes

SCHEMATICm_schematic
 
int m_severities
 
std::vector< SCH_MARKER * > m_filteredMarkers
 

Detailed Description

An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contract.

Definition at line 183 of file erc_settings.h.

Constructor & Destructor Documentation

◆ SHEETLIST_ERC_ITEMS_PROVIDER()

SHEETLIST_ERC_ITEMS_PROVIDER::SHEETLIST_ERC_ITEMS_PROVIDER ( SCHEMATIC aSchematic)
inline

Definition at line 191 of file erc_settings.h.

191  :
192  m_schematic( aSchematic ),
193  m_severities( 0 )
194  { }

Member Function Documentation

◆ DeleteAllItems()

void SHEETLIST_ERC_ITEMS_PROVIDER::DeleteAllItems ( bool  aIncludeExclusions,
bool  aDeep 
)
overridevirtual

Implements RC_ITEMS_PROVIDER.

Definition at line 381 of file erc_settings.cpp.

382 {
383  // Filtered list was already handled through DeleteItem() by the tree control
384 
385  if( aDeep )
386  {
387  SCH_SCREENS screens( m_schematic->Root() );
388  screens.DeleteAllMarkers( MARKER_BASE::MARKER_ERC, aIncludeExclusions );
389  }
390 }
void DeleteAllMarkers(enum MARKER_BASE::TYPEMARKER aMarkerType, bool aIncludeExclusions)
Delete all electronic rules check markers of aMarkerType from all the screens in the list.
SCH_SHEET & Root() const
Definition: schematic.h:92
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:593

References SCH_SCREENS::DeleteAllMarkers(), m_schematic, MARKER_BASE::MARKER_ERC, and SCHEMATIC::Root().

◆ DeleteItem()

void SHEETLIST_ERC_ITEMS_PROVIDER::DeleteItem ( int  aIndex,
bool  aDeep 
)
overridevirtual

Remove (and optionally deletes) the indexed item from the list.

Parameters
aDeepIf true, the source item should be deleted as well as its entry in the list.

Implements RC_ITEMS_PROVIDER.

Definition at line 368 of file erc_settings.cpp.

369 {
370  SCH_MARKER* marker = m_filteredMarkers[ aIndex ];
371  m_filteredMarkers.erase( m_filteredMarkers.begin() + aIndex );
372 
373  if( aDeep )
374  {
375  SCH_SCREENS screens( m_schematic->Root() );
376  screens.DeleteMarker( marker );
377  }
378 }
std::vector< SCH_MARKER * > m_filteredMarkers
Definition: erc_settings.h:188
void DeleteMarker(SCH_MARKER *aMarker)
Delete a specific marker.
SCH_SHEET & Root() const
Definition: schematic.h:92
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:593

References SCH_SCREENS::DeleteMarker(), m_filteredMarkers, m_schematic, and SCHEMATIC::Root().

◆ GetCount()

int SHEETLIST_ERC_ITEMS_PROVIDER::GetCount ( int  aSeverity = -1) const
overridevirtual

Implements RC_ITEMS_PROVIDER.

Definition at line 327 of file erc_settings.cpp.

328 {
329  if( aSeverity < 0 )
330  return m_filteredMarkers.size();
331 
332  int count = 0;
333 
334  const ERC_SETTINGS& settings = m_schematic->ErcSettings();
335 
336  visitMarkers(
337  [&]( SCH_MARKER* aMarker )
338  {
339  SEVERITY markerSeverity;
340 
341  if( aMarker->IsExcluded() )
342  markerSeverity = RPT_SEVERITY_EXCLUSION;
343  else
344  markerSeverity = settings.GetSeverity( aMarker->GetRCItem()->GetErrorCode() );
345 
346  if( markerSeverity == aSeverity )
347  count++;
348  } );
349 
350  return count;
351 }
void visitMarkers(std::function< void(SCH_MARKER *)> aVisitor) const
std::vector< SCH_MARKER * > m_filteredMarkers
Definition: erc_settings.h:188
bool IsExcluded() const
Definition: marker_base.h:94
Container for ERC settings.
Definition: erc_settings.h:106
SEVERITY
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:174
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:100
SEVERITY GetSeverity(int aErrorCode) const

References SCHEMATIC::ErcSettings(), MARKER_BASE::GetRCItem(), ERC_SETTINGS::GetSeverity(), MARKER_BASE::IsExcluded(), m_filteredMarkers, m_schematic, RPT_SEVERITY_EXCLUSION, and visitMarkers().

◆ GetERCItem()

std::shared_ptr< ERC_ITEM > SHEETLIST_ERC_ITEMS_PROVIDER::GetERCItem ( int  aIndex) const

Definition at line 354 of file erc_settings.cpp.

355 {
356  SCH_MARKER* marker = m_filteredMarkers[ aIndex ];
357 
358  return marker ? std::static_pointer_cast<ERC_ITEM>( marker->GetRCItem() ) : nullptr;
359 }
std::vector< SCH_MARKER * > m_filteredMarkers
Definition: erc_settings.h:188
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:100

References MARKER_BASE::GetRCItem(), and m_filteredMarkers.

Referenced by GetItem().

◆ GetItem()

std::shared_ptr< RC_ITEM > SHEETLIST_ERC_ITEMS_PROVIDER::GetItem ( int  aIndex) const
overridevirtual

Retrieve a RC_ITEM by index.

Implements RC_ITEMS_PROVIDER.

Definition at line 362 of file erc_settings.cpp.

363 {
364  return GetERCItem( aIndex );
365 }
std::shared_ptr< ERC_ITEM > GetERCItem(int aIndex) const

References GetERCItem().

◆ SetSeverities()

void SHEETLIST_ERC_ITEMS_PROVIDER::SetSeverities ( int  aSeverities)
overridevirtual

Implements RC_ITEMS_PROVIDER.

Definition at line 303 of file erc_settings.cpp.

304 {
305  m_severities = aSeverities;
306 
307  m_filteredMarkers.clear();
308 
309  ERC_SETTINGS& settings = m_schematic->ErcSettings();
310 
311  visitMarkers(
312  [&]( SCH_MARKER* aMarker )
313  {
314  SEVERITY markerSeverity;
315 
316  if( aMarker->IsExcluded() )
317  markerSeverity = RPT_SEVERITY_EXCLUSION;
318  else
319  markerSeverity = settings.GetSeverity( aMarker->GetRCItem()->GetErrorCode() );
320 
321  if( markerSeverity & m_severities )
322  m_filteredMarkers.push_back( aMarker );
323  } );
324 }
void visitMarkers(std::function< void(SCH_MARKER *)> aVisitor) const
std::vector< SCH_MARKER * > m_filteredMarkers
Definition: erc_settings.h:188
bool IsExcluded() const
Definition: marker_base.h:94
Container for ERC settings.
Definition: erc_settings.h:106
SEVERITY
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:174
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:100
SEVERITY GetSeverity(int aErrorCode) const

References SCHEMATIC::ErcSettings(), MARKER_BASE::GetRCItem(), ERC_SETTINGS::GetSeverity(), MARKER_BASE::IsExcluded(), m_filteredMarkers, m_schematic, m_severities, RPT_SEVERITY_EXCLUSION, and visitMarkers().

◆ visitMarkers()

void SHEETLIST_ERC_ITEMS_PROVIDER::visitMarkers ( std::function< void(SCH_MARKER *)>  aVisitor) const
private

Definition at line 270 of file erc_settings.cpp.

271 {
272  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
273 
274  std::set<SCH_SCREEN*> seenScreens;
275 
276  for( unsigned i = 0; i < sheetList.size(); i++ )
277  {
278  bool firstTime = seenScreens.count( sheetList[i].LastScreen() ) == 0;
279 
280  if( firstTime )
281  seenScreens.insert( sheetList[i].LastScreen() );
282 
283  for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
284  {
285  SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
286 
287  if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
288  continue;
289 
290  // Don't show non-specific markers more than once
291  if( !firstTime &&
292  !static_cast<const ERC_ITEM*>( marker->GetRCItem().get() )->IsSheetSpecific() )
293  {
294  continue;
295  }
296 
297  aVisitor( marker );
298  }
299  }
300 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:92
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:100

References MARKER_BASE::GetMarkerType(), MARKER_BASE::GetRCItem(), SCHEMATIC::GetSheets(), m_schematic, MARKER_BASE::MARKER_ERC, and SCH_MARKER_T.

Referenced by GetCount(), and SetSeverities().

Member Data Documentation

◆ m_filteredMarkers

std::vector<SCH_MARKER*> SHEETLIST_ERC_ITEMS_PROVIDER::m_filteredMarkers
private

Definition at line 188 of file erc_settings.h.

Referenced by DeleteItem(), GetCount(), GetERCItem(), and SetSeverities().

◆ m_schematic

SCHEMATIC* SHEETLIST_ERC_ITEMS_PROVIDER::m_schematic
private

Definition at line 186 of file erc_settings.h.

Referenced by DeleteAllItems(), DeleteItem(), GetCount(), SetSeverities(), and visitMarkers().

◆ m_severities

int SHEETLIST_ERC_ITEMS_PROVIDER::m_severities
private

Definition at line 187 of file erc_settings.h.

Referenced by SetSeverities().


The documentation for this class was generated from the following files: