KiCad PCB EDA Suite
RC_TREE_MODEL Class Reference

#include <rc_item.h>

Inheritance diagram for RC_TREE_MODEL:

Public Member Functions

 RC_TREE_MODEL (EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
 
 ~RC_TREE_MODEL ()
 
void SetProvider (RC_ITEMS_PROVIDER *aProvider)
 
void SetSeverities (int aSeverities)
 
int GetDRCItemCount () const
 
void ExpandAll ()
 
void PrevMarker ()
 
void NextMarker ()
 
void SelectMarker (const MARKER_BASE *aMarker)
 
void CenterMarker (const MARKER_BASE *aMarker)
 
bool IsContainer (wxDataViewItem const &aItem) const override
 
wxDataViewItem GetParent (wxDataViewItem const &aItem) const override
 
unsigned int GetChildren (wxDataViewItem const &aItem, wxDataViewItemArray &aChildren) const override
 
unsigned int GetColumnCount () const override
 
wxString GetColumnType (unsigned int aCol) const override
 
bool HasContainerColumns (wxDataViewItem const &aItem) const override
 
void GetValue (wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
 Called by the wxDataView to fetch an item's value. More...
 
bool SetValue (wxVariant const &aVariant, wxDataViewItem const &aItem, unsigned int aCol) override
 Called by the wxDataView to edit an item's content. More...
 
bool GetAttr (wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
 Called by the wxDataView to fetch an item's formatting. More...
 
void ValueChanged (const RC_TREE_NODE *aNode)
 
void DeleteCurrentItem (bool aDeep)
 
void DeleteItems (bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
 Deletes the current item or all items. More...
 

Static Public Member Functions

static wxDataViewItem ToItem (RC_TREE_NODE const *aNode)
 
static RC_TREE_NODEToNode (wxDataViewItem aItem)
 
static KIID ToUUID (wxDataViewItem aItem)
 

Private Member Functions

void rebuildModel (RC_ITEMS_PROVIDER *aProvider, int aSeverities)
 
void onSizeView (wxSizeEvent &aEvent)
 

Private Attributes

EDA_DRAW_FRAMEm_editFrame
 
wxDataViewCtrl * m_view
 
int m_severities
 
RC_ITEMS_PROVIDERm_rcItemsProvider
 
std::vector< RC_TREE_NODE * > m_tree
 

Detailed Description

Definition at line 202 of file rc_item.h.

Constructor & Destructor Documentation

◆ RC_TREE_MODEL()

RC_TREE_MODEL::RC_TREE_MODEL ( EDA_DRAW_FRAME aParentFrame,
wxDataViewCtrl *  aView 
)

Definition at line 176 of file rc_item.cpp.

176  :
177  m_editFrame( aParentFrame ),
178  m_view( aView ),
179  m_severities( 0 ),
180  m_rcItemsProvider( nullptr )
181 {
182  m_view->GetMainWindow()->Connect( wxEVT_SIZE,
183  wxSizeEventHandler( RC_TREE_MODEL::onSizeView ),
184  nullptr, this );
185 }
wxDataViewCtrl * m_view
Definition: rc_item.h:286
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:288
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:285
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:629
int m_severities
Definition: rc_item.h:287

References m_view, and onSizeView().

◆ ~RC_TREE_MODEL()

RC_TREE_MODEL::~RC_TREE_MODEL ( )

Definition at line 188 of file rc_item.cpp.

189 {
190  delete m_rcItemsProvider;
191 
192  for( RC_TREE_NODE* topLevelNode : m_tree )
193  delete topLevelNode;
194 }
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:288
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References m_rcItemsProvider, and m_tree.

Member Function Documentation

◆ CenterMarker()

void RC_TREE_MODEL::CenterMarker ( const MARKER_BASE aMarker)

Definition at line 616 of file rc_item.cpp.

617 {
618  for( RC_TREE_NODE* candidate : m_tree )
619  {
620  if( candidate->m_RcItem->GetParent() == aMarker )
621  {
622  m_view->EnsureVisible( ToItem( candidate ) );
623  return;
624  }
625  }
626 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
wxDataViewCtrl * m_view
Definition: rc_item.h:286
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References m_tree, m_view, and ToItem().

Referenced by DIALOG_DRC::centerMarkerIdleHandler().

◆ DeleteCurrentItem()

void RC_TREE_MODEL::DeleteCurrentItem ( bool  aDeep)

Definition at line 459 of file rc_item.cpp.

460 {
461  DeleteItems( true, true, aDeep );
462 }
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:465

References DeleteItems().

Referenced by DIALOG_DRC::ExcludeMarker(), DIALOG_ERC::ExcludeMarker(), DIALOG_FOOTPRINT_CHECKER::OnDeleteOneClick(), and DIALOG_DRC::OnDeleteOneClick().

◆ DeleteItems()

void RC_TREE_MODEL::DeleteItems ( bool  aCurrentOnly,
bool  aIncludeExclusions,
bool  aDeep 
)

Deletes the current item or all items.

If all, aIncludeExclusions determines whether or not exclusions are also deleted.

Keep a vector of elements to free after wxWidgets is definitely done accessing them

Definition at line 465 of file rc_item.cpp.

466 {
467  RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() );
468  const std::shared_ptr<RC_ITEM> current_item = current_node ? current_node->m_RcItem : nullptr;
469 
471  std::vector<RC_TREE_NODE*> to_delete;
472 
473  if( aCurrentOnly && !current_item )
474  {
475  wxBell();
476  return;
477  }
478 
479  if( !m_rcItemsProvider )
480  return;
481 
482  int lastGood = -1;
483  bool itemDeleted = false;
484 
485  if( m_view )
486  {
487  m_view->UnselectAll();
488  wxSafeYield();
489  m_view->Freeze();
490  }
491 
492  for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
493  {
494  std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
495  MARKER_BASE* marker = rcItem->GetParent();
496  bool excluded = marker ? marker->IsExcluded() : false;
497 
498  if( aCurrentOnly && itemDeleted && lastGood >= 0 )
499  break;
500 
501  if( aCurrentOnly && rcItem != current_item )
502  {
503  lastGood = i;
504  continue;
505  }
506 
507  if( excluded && !aIncludeExclusions )
508  continue;
509 
510  if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets
511  {
512  wxDataViewItem markerItem = ToItem( m_tree[i] );
513  wxDataViewItemArray childItems;
514  wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
515 
516  for( RC_TREE_NODE* child : m_tree[i]->m_Children )
517  {
518  childItems.push_back( ToItem( child ) );
519  to_delete.push_back( child );
520  }
521 
522  m_tree[i]->m_Children.clear();
523  ItemsDeleted( markerItem, childItems );
524 
525  to_delete.push_back( m_tree[i] );
526  m_tree.erase( m_tree.begin() + i );
527  ItemDeleted( parentItem, markerItem );
528  }
529 
530  // Only deep delete the current item here; others will be done through the
531  // DeleteAllItems() call below, which is more efficient.
532  m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
533 
534  if( lastGood > i )
535  lastGood--;
536 
537  itemDeleted = true;
538  }
539 
540  if( m_view && aCurrentOnly && lastGood >= 0 )
541  m_view->Select( ToItem( m_tree[ lastGood ] ) );
542 
543  for( RC_TREE_NODE* item : to_delete )
544  delete( item );
545 
546  if( !aCurrentOnly )
547  m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );
548 
549  if( m_view )
550  m_view->Thaw();
551 }
virtual void DeleteAllItems(bool aIncludeExclusions, bool aDeep)=0
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
wxDataViewCtrl * m_view
Definition: rc_item.h:286
virtual int GetCount(int aSeverity=-1) const =0
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:288
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:195
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
bool IsExcluded() const
Definition: marker_base.h:95
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290
virtual std::shared_ptr< RC_ITEM > GetItem(int aIndex) const =0
Retrieve a RC_ITEM by index.
virtual void DeleteItem(int aIndex, bool aDeep)=0
Remove (and optionally deletes) the indexed item from the list.

References RC_ITEMS_PROVIDER::DeleteAllItems(), RC_ITEMS_PROVIDER::DeleteItem(), RC_ITEMS_PROVIDER::GetCount(), RC_ITEMS_PROVIDER::GetItem(), MARKER_BASE::IsExcluded(), RC_TREE_NODE::m_RcItem, m_rcItemsProvider, m_tree, m_view, ToItem(), and ToNode().

Referenced by DIALOG_FOOTPRINT_CHECKER::deleteAllMarkers(), DIALOG_ERC::deleteAllMarkers(), DIALOG_DRC::deleteAllMarkers(), DeleteCurrentItem(), and DIALOG_DRC::OnRunDRCClick().

◆ ExpandAll()

void RC_TREE_MODEL::ExpandAll ( )

Definition at line 304 of file rc_item.cpp.

305 {
306  for( RC_TREE_NODE* topLevelNode : m_tree )
307  m_view->Expand( ToItem( topLevelNode ) );
308 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
wxDataViewCtrl * m_view
Definition: rc_item.h:286
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References m_tree, m_view, and ToItem().

Referenced by rebuildModel().

◆ GetAttr()

bool RC_TREE_MODEL::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
override

Called by the wxDataView to fetch an item's formatting.

Return true if the item has non-default attributes.

Definition at line 403 of file rc_item.cpp.

406 {
407  const RC_TREE_NODE* node = ToNode( aItem );
408  wxASSERT( node );
409 
410  bool ret = false;
411  bool heading = node->m_Type == RC_TREE_NODE::MARKER;
412 
413  if( heading )
414  {
415  aAttr.SetBold( true );
416  ret = true;
417  }
418 
419  if( node->m_RcItem->GetParent() && node->m_RcItem->GetParent()->IsExcluded() )
420  {
421  wxColour textColour = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXTEXT );
422  double brightness = KIGFX::COLOR4D( textColour ).GetBrightness();
423 
424  if( brightness > 0.5 )
425  {
426  int lightness = static_cast<int>( brightness * ( heading ? 50 : 60 ) );
427  aAttr.SetColour( textColour.ChangeLightness( lightness ) );
428  }
429  else
430  {
431  aAttr.SetColour( textColour.ChangeLightness( heading ? 170 : 165 ) );
432  }
433 
434  aAttr.SetItalic( true ); // Strikethrough would be better, if wxWidgets supported it
435  ret = true;
436  }
437 
438  return ret;
439 }
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
Definition: color4d.h:343
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:195
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
NODE_TYPE m_Type
Definition: rc_item.h:194
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References KIGFX::COLOR4D::GetBrightness(), RC_TREE_NODE::m_RcItem, RC_TREE_NODE::m_Type, RC_TREE_NODE::MARKER, and ToNode().

◆ GetChildren()

unsigned int RC_TREE_MODEL::GetChildren ( wxDataViewItem const &  aItem,
wxDataViewItemArray &  aChildren 
) const
override

Definition at line 326 of file rc_item.cpp.

328 {
329  const RC_TREE_NODE* node = ToNode( aItem );
330  const std::vector<RC_TREE_NODE*>& children = node ? node->m_Children : m_tree;
331 
332  for( const RC_TREE_NODE* child: children )
333  aChildren.push_back( ToItem( child ) );
334 
335  return children.size();
336 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:198
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References RC_TREE_NODE::m_Children, m_tree, ToItem(), and ToNode().

◆ GetColumnCount()

unsigned int RC_TREE_MODEL::GetColumnCount ( ) const
inlineoverride

Definition at line 241 of file rc_item.h.

241 { return 1; }

◆ GetColumnType()

wxString RC_TREE_MODEL::GetColumnType ( unsigned int  aCol) const
inlineoverride

Definition at line 242 of file rc_item.h.

242 { return "string"; }

◆ GetDRCItemCount()

int RC_TREE_MODEL::GetDRCItemCount ( ) const
inline

Definition at line 224 of file rc_item.h.

224 { return m_tree.size(); }
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References m_tree.

◆ GetParent()

wxDataViewItem RC_TREE_MODEL::GetParent ( wxDataViewItem const &  aItem) const
override

Definition at line 320 of file rc_item.cpp.

321 {
322  return ToItem( ToNode( aItem)->m_Parent );
323 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210

References ToItem(), and ToNode().

◆ GetValue()

void RC_TREE_MODEL::GetValue ( wxVariant &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
) const
override

Called by the wxDataView to fetch an item's value.

Definition at line 339 of file rc_item.cpp.

342 {
343  const RC_TREE_NODE* node = ToNode( aItem );
344  const std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
345 
346  switch( node->m_Type )
347  {
349  {
350  wxString prefix;
351 
352  if( rcItem->GetParent() && rcItem->GetParent()->IsExcluded() )
353  prefix = _( "Excluded " );
354 
355  switch( m_editFrame->GetSeverity( rcItem->GetErrorCode() ) )
356  {
357  case RPT_SEVERITY_ERROR: prefix += _( "Error: " ); break;
358  case RPT_SEVERITY_WARNING: prefix += _( "Warning: " ); break;
359 
362  case RPT_SEVERITY_INFO:
363  case RPT_SEVERITY_ACTION:
364  case RPT_SEVERITY_IGNORE:
365  break;
366  }
367 
368  aVariant = prefix + rcItem->GetErrorMessage();
369  }
370  break;
371 
373  {
374  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetMainItemID() );
375  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
376  }
377  break;
378 
380  {
381  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItemID() );
382  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
383  }
384  break;
385 
387  {
388  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem2ID() );
389  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
390  }
391  break;
392 
394  {
395  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem3ID() );
396  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
397  }
398  break;
399  }
400 }
virtual SEVERITY GetSeverity(int aErrorCode) const
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:195
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
#define _(s)
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:285
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
NODE_TYPE m_Type
Definition: rc_item.h:194
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:109
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References _, RC_TREE_NODE::AUX_ITEM, RC_TREE_NODE::AUX_ITEM2, RC_TREE_NODE::AUX_ITEM3, EDA_DRAW_FRAME::GetItem(), EDA_ITEM::GetSelectMenuText(), EDA_BASE_FRAME::GetSeverity(), EDA_BASE_FRAME::GetUserUnits(), m_editFrame, RC_TREE_NODE::m_RcItem, RC_TREE_NODE::m_Type, RC_TREE_NODE::MAIN_ITEM, RC_TREE_NODE::MARKER, RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, RPT_SEVERITY_EXCLUSION, RPT_SEVERITY_IGNORE, RPT_SEVERITY_INFO, RPT_SEVERITY_UNDEFINED, RPT_SEVERITY_WARNING, and ToNode().

◆ HasContainerColumns()

bool RC_TREE_MODEL::HasContainerColumns ( wxDataViewItem const &  aItem) const
inlineoverride

Definition at line 243 of file rc_item.h.

243 { return true; }

◆ IsContainer()

bool RC_TREE_MODEL::IsContainer ( wxDataViewItem const &  aItem) const
override

Definition at line 311 of file rc_item.cpp.

312 {
313  if( ToNode( aItem ) == nullptr ) // must be tree root...
314  return true;
315  else
316  return ToNode( aItem )->m_Type == RC_TREE_NODE::MARKER;
317 }
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
NODE_TYPE m_Type
Definition: rc_item.h:194

References RC_TREE_NODE::m_Type, RC_TREE_NODE::MARKER, and ToNode().

◆ NextMarker()

void RC_TREE_MODEL::NextMarker ( )

Definition at line 575 of file rc_item.cpp.

576 {
577  RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
578 
579  while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
580  currentNode = currentNode->m_Parent;
581 
582  RC_TREE_NODE* nextMarker = nullptr;
583  bool trigger = currentNode == nullptr;
584 
585  for( RC_TREE_NODE* candidate : m_tree )
586  {
587  if( candidate == currentNode )
588  {
589  trigger = true;
590  }
591  else if( trigger )
592  {
593  nextMarker = candidate;
594  break;
595  }
596  }
597 
598  if( nextMarker )
599  m_view->Select( ToItem( nextMarker ) );
600 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
RC_TREE_NODE * m_Parent
Definition: rc_item.h:197
wxDataViewCtrl * m_view
Definition: rc_item.h:286
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
NODE_TYPE m_Type
Definition: rc_item.h:194
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References RC_TREE_NODE::m_Parent, m_tree, RC_TREE_NODE::m_Type, m_view, RC_TREE_NODE::MARKER, ToItem(), and ToNode().

Referenced by DIALOG_ERC::NextMarker(), and DIALOG_DRC::NextMarker().

◆ onSizeView()

void RC_TREE_MODEL::onSizeView ( wxSizeEvent &  aEvent)
private

Definition at line 629 of file rc_item.cpp.

630 {
631  int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;
632 
633  if( m_view->GetColumnCount() > 0 )
634  m_view->GetColumn( 0 )->SetWidth( width );
635 
636  // Pass size event to other widgets
637  aEvent.Skip();
638 }
wxDataViewCtrl * m_view
Definition: rc_item.h:286
#define WX_DATAVIEW_WINDOW_PADDING
Definition: rc_item.cpp:35

References m_view, and WX_DATAVIEW_WINDOW_PADDING.

Referenced by RC_TREE_MODEL().

◆ PrevMarker()

void RC_TREE_MODEL::PrevMarker ( )

Definition at line 554 of file rc_item.cpp.

555 {
556  RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
557  RC_TREE_NODE* prevMarker = nullptr;
558 
559  while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
560  currentNode = currentNode->m_Parent;
561 
562  for( RC_TREE_NODE* candidate : m_tree )
563  {
564  if( candidate == currentNode )
565  break;
566  else
567  prevMarker = candidate;
568  }
569 
570  if( prevMarker )
571  m_view->Select( ToItem( prevMarker ) );
572 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
RC_TREE_NODE * m_Parent
Definition: rc_item.h:197
wxDataViewCtrl * m_view
Definition: rc_item.h:286
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
NODE_TYPE m_Type
Definition: rc_item.h:194
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References RC_TREE_NODE::m_Parent, m_tree, RC_TREE_NODE::m_Type, m_view, RC_TREE_NODE::MARKER, ToItem(), and ToNode().

Referenced by DIALOG_ERC::PrevMarker(), and DIALOG_DRC::PrevMarker().

◆ rebuildModel()

void RC_TREE_MODEL::rebuildModel ( RC_ITEMS_PROVIDER aProvider,
int  aSeverities 
)
private

Definition at line 197 of file rc_item.cpp.

198 {
199  wxWindowUpdateLocker updateLock( m_view );
200 
201  std::shared_ptr<RC_ITEM> selectedRcItem = nullptr;
202 
203  if( m_view )
204  {
205  RC_TREE_NODE* selectedNode = ToNode( m_view->GetSelection() );
206  selectedRcItem = selectedNode ? selectedNode->m_RcItem : nullptr;
207 
208  // Even with the updateLock, wxWidgets sometimes ties its knickers in a knot trying
209  // to run a wxdataview_selection_changed_callback() on a row that has been deleted.
210  m_view->UnselectAll();
211  }
212 
213  if( aProvider != m_rcItemsProvider )
214  {
215  delete m_rcItemsProvider;
216  m_rcItemsProvider = aProvider;
217  }
218 
219  if( aSeverities != m_severities )
220  m_severities = aSeverities;
221 
222  if( m_rcItemsProvider )
224 
225  for( RC_TREE_NODE* topLevelNode : m_tree )
226  delete topLevelNode;
227 
228  m_tree.clear();
229 
230  // wxDataView::ExpandAll() pukes with large lists
231  int count = 0;
232 
233  if( m_rcItemsProvider )
234  count = std::min( 1000, m_rcItemsProvider->GetCount() );
235 
236  for( int i = 0; i < count; ++i )
237  {
238  std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
239 
240  m_tree.push_back( new RC_TREE_NODE( nullptr, rcItem, RC_TREE_NODE::MARKER ) );
241  RC_TREE_NODE* n = m_tree.back();
242 
243  if( rcItem->GetMainItemID() != niluuid )
244  n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::MAIN_ITEM ) );
245 
246  if( rcItem->GetAuxItemID() != niluuid )
247  n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::AUX_ITEM ) );
248 
249  if( rcItem->GetAuxItem2ID() != niluuid )
250  n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::AUX_ITEM2 ) );
251 
252  if( rcItem->GetAuxItem3ID() != niluuid )
253  n->m_Children.push_back( new RC_TREE_NODE( n, rcItem, RC_TREE_NODE::AUX_ITEM3 ) );
254  }
255 
256  // Must be called after a significant change of items to force the
257  // wxDataViewModel to reread all of them, repopulating itself entirely.
258  Cleared();
259 
260 #ifdef __WXGTK__
261  // The fastest method to update wxDataViewCtrl is to rebuild from
262  // scratch by calling Cleared(). Linux requires to reassociate model to
263  // display data, but Windows will create multiple associations.
264  // On MacOS, this crashes KiCad. See https://gitlab.com/kicad/code/kicad/issues/3666
265  // and https://gitlab.com/kicad/code/kicad/issues/3653
266  m_view->AssociateModel( this );
267 #endif
268 
269  m_view->ClearColumns();
270  int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;
271  m_view->AppendTextColumn( wxEmptyString, 0, wxDATAVIEW_CELL_INERT, width );
272 
273  ExpandAll();
274 
275  // Most annoyingly wxWidgets won't tell us the scroll position (and no, all the usual
276  // routines don't work), so we can only restore the scroll position based on a selection.
277  if( selectedRcItem )
278  {
279  for( RC_TREE_NODE* candidate : m_tree )
280  {
281  if( candidate->m_RcItem == selectedRcItem )
282  {
283  m_view->Select( ToItem( candidate ) );
284  m_view->EnsureVisible( ToItem( candidate ) );
285  break;
286  }
287  }
288  }
289 }
KIID niluuid(0)
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
wxDataViewCtrl * m_view
Definition: rc_item.h:286
#define WX_DATAVIEW_WINDOW_PADDING
Definition: rc_item.cpp:35
virtual int GetCount(int aSeverity=-1) const =0
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:198
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:288
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:195
void ExpandAll()
Definition: rc_item.cpp:304
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
virtual void SetSeverities(int aSeverities)=0
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290
virtual std::shared_ptr< RC_ITEM > GetItem(int aIndex) const =0
Retrieve a RC_ITEM by index.
int m_severities
Definition: rc_item.h:287

References RC_TREE_NODE::AUX_ITEM, RC_TREE_NODE::AUX_ITEM2, RC_TREE_NODE::AUX_ITEM3, ExpandAll(), RC_ITEMS_PROVIDER::GetCount(), RC_ITEMS_PROVIDER::GetItem(), RC_TREE_NODE::m_Children, RC_TREE_NODE::m_RcItem, m_rcItemsProvider, m_severities, m_tree, m_view, RC_TREE_NODE::MAIN_ITEM, RC_TREE_NODE::MARKER, niluuid, RC_ITEMS_PROVIDER::SetSeverities(), ToItem(), ToNode(), and WX_DATAVIEW_WINDOW_PADDING.

Referenced by SetProvider(), and SetSeverities().

◆ SelectMarker()

void RC_TREE_MODEL::SelectMarker ( const MARKER_BASE aMarker)

Definition at line 603 of file rc_item.cpp.

604 {
605  for( RC_TREE_NODE* candidate : m_tree )
606  {
607  if( candidate->m_RcItem->GetParent() == aMarker )
608  {
609  m_view->Select( ToItem( candidate ) );
610  return;
611  }
612  }
613 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
wxDataViewCtrl * m_view
Definition: rc_item.h:286
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:290

References m_tree, m_view, and ToItem().

Referenced by DIALOG_ERC::ExcludeMarker(), and DIALOG_DRC::SelectMarker().

◆ SetProvider()

◆ SetSeverities()

◆ SetValue()

bool RC_TREE_MODEL::SetValue ( wxVariant const &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
)
inlineoverride

Called by the wxDataView to edit an item's content.

Definition at line 255 of file rc_item.h.

258  {
259  // Editing not supported
260  return false;
261  }

◆ ToItem()

static wxDataViewItem RC_TREE_MODEL::ToItem ( RC_TREE_NODE const *  aNode)
inlinestatic

Definition at line 205 of file rc_item.h.

206  {
207  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
208  }

Referenced by CenterMarker(), DeleteItems(), ExpandAll(), GetChildren(), GetParent(), NextMarker(), PrevMarker(), rebuildModel(), SelectMarker(), and ValueChanged().

◆ ToNode()

static RC_TREE_NODE* RC_TREE_MODEL::ToNode ( wxDataViewItem  aItem)
inlinestatic

◆ ToUUID()

KIID RC_TREE_MODEL::ToUUID ( wxDataViewItem  aItem)
static

Definition at line 147 of file rc_item.cpp.

148 {
149  const RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( aItem );
150 
151  if( node && node->m_RcItem )
152  {
153  const std::shared_ptr<RC_ITEM> rc_item = node->m_RcItem;
154 
155  switch( node->m_Type )
156  {
158  // rc_item->GetParent() can be null, if the parent is not existing
159  // when a RC item has no corresponding ERC/DRC marker
160  if( rc_item->GetParent() )
161  return rc_item->GetParent()->GetUUID();
162 
163  break;
164 
165  case RC_TREE_NODE::MAIN_ITEM: return rc_item->GetMainItemID();
166  case RC_TREE_NODE::AUX_ITEM: return rc_item->GetAuxItemID();
167  case RC_TREE_NODE::AUX_ITEM2: return rc_item->GetAuxItem2ID();
168  case RC_TREE_NODE::AUX_ITEM3: return rc_item->GetAuxItem3ID();
169  }
170  }
171 
172  return niluuid;
173 }
KIID niluuid(0)
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:195
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:210
NODE_TYPE m_Type
Definition: rc_item.h:194

References RC_TREE_NODE::AUX_ITEM, RC_TREE_NODE::AUX_ITEM2, RC_TREE_NODE::AUX_ITEM3, RC_TREE_NODE::m_RcItem, RC_TREE_NODE::m_Type, RC_TREE_NODE::MAIN_ITEM, RC_TREE_NODE::MARKER, niluuid, and ToNode().

Referenced by DIALOG_DRC::OnDRCItemSelected(), DIALOG_ERC::OnERCItemSelected(), DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem(), DIALOG_CLEANUP_GRAPHICS::OnSelectItem(), and DIALOG_FOOTPRINT_CHECKER::OnSelectItem().

◆ ValueChanged()

void RC_TREE_MODEL::ValueChanged ( const RC_TREE_NODE aNode)

Definition at line 442 of file rc_item.cpp.

443 {
444  if( aNode->m_Type == RC_TREE_NODE::MAIN_ITEM || aNode->m_Type == RC_TREE_NODE::AUX_ITEM )
445  {
446  ValueChanged( aNode->m_Parent );
447  }
448 
449  if( aNode->m_Type == RC_TREE_NODE::MARKER )
450  {
451  wxDataViewModel::ValueChanged( ToItem( aNode ), 0 );
452 
453  for( const RC_TREE_NODE* child : aNode->m_Children )
454  wxDataViewModel::ValueChanged( ToItem( child ), 0 );
455  }
456 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:205
RC_TREE_NODE * m_Parent
Definition: rc_item.h:197
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:198
NODE_TYPE m_Type
Definition: rc_item.h:194
void ValueChanged(const RC_TREE_NODE *aNode)
Definition: rc_item.cpp:442

References RC_TREE_NODE::AUX_ITEM, RC_TREE_NODE::m_Children, RC_TREE_NODE::m_Parent, RC_TREE_NODE::m_Type, RC_TREE_NODE::MAIN_ITEM, RC_TREE_NODE::MARKER, and ToItem().

Referenced by DIALOG_DRC::ExcludeMarker(), and DIALOG_ERC::ExcludeMarker().

Member Data Documentation

◆ m_editFrame

EDA_DRAW_FRAME* RC_TREE_MODEL::m_editFrame
private

Definition at line 285 of file rc_item.h.

Referenced by GetValue().

◆ m_rcItemsProvider

RC_ITEMS_PROVIDER* RC_TREE_MODEL::m_rcItemsProvider
private

Definition at line 288 of file rc_item.h.

Referenced by DeleteItems(), rebuildModel(), SetSeverities(), and ~RC_TREE_MODEL().

◆ m_severities

int RC_TREE_MODEL::m_severities
private

Definition at line 287 of file rc_item.h.

Referenced by rebuildModel(), and SetProvider().

◆ m_tree

std::vector<RC_TREE_NODE*> RC_TREE_MODEL::m_tree
private

◆ m_view

wxDataViewCtrl* RC_TREE_MODEL::m_view
private

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