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 ()
 
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 197 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 173 of file rc_item.cpp.

173  :
174  m_editFrame( aParentFrame ),
175  m_view( aView ),
176  m_severities( 0 ),
177  m_rcItemsProvider( nullptr )
178 {
179  m_view->GetMainWindow()->Connect( wxEVT_SIZE,
180  wxSizeEventHandler( RC_TREE_MODEL::onSizeView ),
181  nullptr, this );
182 }
wxDataViewCtrl * m_view
Definition: rc_item.h:279
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:281
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:278
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:594
int m_severities
Definition: rc_item.h:280

References m_view, and onSizeView().

◆ ~RC_TREE_MODEL()

RC_TREE_MODEL::~RC_TREE_MODEL ( )

Definition at line 185 of file rc_item.cpp.

186 {
187  delete m_rcItemsProvider;
188 
189  for( RC_TREE_NODE* topLevelNode : m_tree )
190  delete topLevelNode;
191 }
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:281
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283

References m_rcItemsProvider, and m_tree.

Member Function Documentation

◆ DeleteCurrentItem()

void RC_TREE_MODEL::DeleteCurrentItem ( bool  aDeep)

Definition at line 450 of file rc_item.cpp.

451 {
452  DeleteItems( true, true, aDeep );
453 }
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:456

References DeleteItems().

Referenced by DIALOG_ERC::ExcludeMarker(), DIALOG_DRC::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 456 of file rc_item.cpp.

457 {
458  RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() );
459  const std::shared_ptr<RC_ITEM> current_item = current_node ? current_node->m_RcItem : nullptr;
460 
462  std::vector<RC_TREE_NODE*> to_delete;
463 
464  if( aCurrentOnly && !current_item )
465  {
466  wxBell();
467  return;
468  }
469 
470  if( !m_rcItemsProvider )
471  return;
472 
473  int lastGood = -1;
474  bool itemDeleted = false;
475 
476  if( m_view )
477  {
478  m_view->UnselectAll();
479  wxSafeYield();
480  m_view->Freeze();
481  }
482 
483  for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
484  {
485  std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
486  MARKER_BASE* marker = rcItem->GetParent();
487  bool excluded = marker ? marker->IsExcluded() : false;
488 
489  if( aCurrentOnly && itemDeleted && lastGood >= 0 )
490  break;
491 
492  if( aCurrentOnly && rcItem != current_item )
493  {
494  lastGood = i;
495  continue;
496  }
497 
498  if( excluded && !aIncludeExclusions )
499  continue;
500 
501  if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets
502  {
503  wxDataViewItem markerItem = ToItem( m_tree[i] );
504  wxDataViewItemArray childItems;
505  wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
506 
507  for( RC_TREE_NODE* child : m_tree[i]->m_Children )
508  {
509  childItems.push_back( ToItem( child ) );
510  to_delete.push_back( child );
511  }
512 
513  m_tree[i]->m_Children.clear();
514  ItemsDeleted( markerItem, childItems );
515 
516  to_delete.push_back( m_tree[i] );
517  m_tree.erase( m_tree.begin() + i );
518  ItemDeleted( parentItem, markerItem );
519  }
520 
521  // Only deep delete the current item here; others will be done through the
522  // DeleteAllItems() call below, which is more efficient.
523  m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
524 
525  if( lastGood > i )
526  lastGood--;
527 
528  itemDeleted = true;
529  }
530 
531  if( m_view && aCurrentOnly && lastGood >= 0 )
532  m_view->Select( ToItem( m_tree[ lastGood ] ) );
533 
534  for( RC_TREE_NODE* item : to_delete )
535  delete( item );
536 
537  if( !aCurrentOnly )
538  m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );
539 
540  if( m_view )
541  m_view->Thaw();
542 }
virtual void DeleteAllItems(bool aIncludeExclusions, bool aDeep)=0
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
wxDataViewCtrl * m_view
Definition: rc_item.h:279
virtual int GetCount(int aSeverity=-1) const =0
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:281
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:190
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
bool IsExcluded() const
Definition: marker_base.h:94
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283
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 301 of file rc_item.cpp.

302 {
303  for( RC_TREE_NODE* topLevelNode : m_tree )
304  m_view->Expand( ToItem( topLevelNode ) );
305 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
wxDataViewCtrl * m_view
Definition: rc_item.h:279
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283

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 400 of file rc_item.cpp.

403 {
404  const RC_TREE_NODE* node = ToNode( aItem );
405  wxASSERT( node );
406 
407  bool ret = false;
408  bool heading = node->m_Type == RC_TREE_NODE::MARKER;
409 
410  if( heading )
411  {
412  aAttr.SetBold( true );
413  ret = true;
414  }
415 
416  if( node->m_RcItem->GetParent() && node->m_RcItem->GetParent()->IsExcluded() )
417  {
418  wxColour textColour = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXTEXT );
419 
420  if( KIGFX::COLOR4D( textColour ).GetBrightness() > 0.5 )
421  aAttr.SetColour( textColour.ChangeLightness( heading ? 30 : 35 ) );
422  else
423  aAttr.SetColour( textColour.ChangeLightness( heading ? 170 : 165 ) );
424 
425  aAttr.SetItalic( true ); // Strikethrough would be better, if wxWidgets supported it
426  ret = true;
427  }
428 
429  return ret;
430 }
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:190
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
NODE_TYPE m_Type
Definition: rc_item.h:189
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References 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 323 of file rc_item.cpp.

325 {
326  const RC_TREE_NODE* node = ToNode( aItem );
327  const std::vector<RC_TREE_NODE*>& children = node ? node->m_Children : m_tree;
328 
329  for( const RC_TREE_NODE* child: children )
330  aChildren.push_back( ToItem( child ) );
331 
332  return children.size();
333 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:193
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283

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

◆ GetColumnCount()

unsigned int RC_TREE_MODEL::GetColumnCount ( ) const
inlineoverride

Definition at line 234 of file rc_item.h.

234 { return 1; }

◆ GetColumnType()

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

Definition at line 235 of file rc_item.h.

235 { return "string"; }

◆ GetDRCItemCount()

int RC_TREE_MODEL::GetDRCItemCount ( ) const
inline

Definition at line 219 of file rc_item.h.

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

References m_tree.

◆ GetParent()

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

Definition at line 317 of file rc_item.cpp.

318 {
319  return ToItem( ToNode( aItem)->m_Parent );
320 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205

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 336 of file rc_item.cpp.

339 {
340  const RC_TREE_NODE* node = ToNode( aItem );
341  const std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
342 
343  switch( node->m_Type )
344  {
346  {
347  wxString prefix;
348 
349  if( rcItem->GetParent() && rcItem->GetParent()->IsExcluded() )
350  prefix = _( "Excluded " );
351 
352  switch( m_editFrame->GetSeverity( rcItem->GetErrorCode() ) )
353  {
354  case RPT_SEVERITY_ERROR: prefix += _( "Error: " ); break;
355  case RPT_SEVERITY_WARNING: prefix += _( "Warning: " ); break;
356 
359  case RPT_SEVERITY_INFO:
360  case RPT_SEVERITY_ACTION:
361  case RPT_SEVERITY_IGNORE:
362  break;
363  }
364 
365  aVariant = prefix + rcItem->GetErrorMessage();
366  }
367  break;
368 
370  {
371  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetMainItemID() );
372  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
373  }
374  break;
375 
377  {
378  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItemID() );
379  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
380  }
381  break;
382 
384  {
385  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem2ID() );
386  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
387  }
388  break;
389 
391  {
392  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem3ID() );
393  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
394  }
395  break;
396  }
397 }
virtual SEVERITY GetSeverity(int aErrorCode) const
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:190
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
#define _(s)
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:278
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
NODE_TYPE m_Type
Definition: rc_item.h:189
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:100
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 236 of file rc_item.h.

236 { return true; }

◆ IsContainer()

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

Definition at line 308 of file rc_item.cpp.

309 {
310  if( ToNode( aItem ) == nullptr ) // must be tree root...
311  return true;
312  else
313  return ToNode( aItem )->m_Type == RC_TREE_NODE::MARKER;
314 }
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
NODE_TYPE m_Type
Definition: rc_item.h:189

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

◆ NextMarker()

void RC_TREE_MODEL::NextMarker ( )

Definition at line 566 of file rc_item.cpp.

567 {
568  RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
569 
570  while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
571  currentNode = currentNode->m_Parent;
572 
573  RC_TREE_NODE* nextMarker = nullptr;
574  bool trigger = currentNode == nullptr;
575 
576  for( RC_TREE_NODE* candidate : m_tree )
577  {
578  if( candidate == currentNode )
579  {
580  trigger = true;
581  }
582  else if( trigger )
583  {
584  nextMarker = candidate;
585  break;
586  }
587  }
588 
589  if( nextMarker )
590  m_view->Select( ToItem( nextMarker ) );
591 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
RC_TREE_NODE * m_Parent
Definition: rc_item.h:192
wxDataViewCtrl * m_view
Definition: rc_item.h:279
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
NODE_TYPE m_Type
Definition: rc_item.h:189
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283

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 594 of file rc_item.cpp.

595 {
596  int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;
597 
598  if( m_view->GetColumnCount() > 0 )
599  m_view->GetColumn( 0 )->SetWidth( width );
600 
601  // Pass size event to other widgets
602  aEvent.Skip();
603 }
wxDataViewCtrl * m_view
Definition: rc_item.h:279
#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 545 of file rc_item.cpp.

546 {
547  RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
548  RC_TREE_NODE* prevMarker = nullptr;
549 
550  while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
551  currentNode = currentNode->m_Parent;
552 
553  for( RC_TREE_NODE* candidate : m_tree )
554  {
555  if( candidate == currentNode )
556  break;
557  else
558  prevMarker = candidate;
559  }
560 
561  if( prevMarker )
562  m_view->Select( ToItem( prevMarker ) );
563 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
RC_TREE_NODE * m_Parent
Definition: rc_item.h:192
wxDataViewCtrl * m_view
Definition: rc_item.h:279
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:205
NODE_TYPE m_Type
Definition: rc_item.h:189
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:283

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 194 of file rc_item.cpp.

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

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().

◆ 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 248 of file rc_item.h.

251  {
252  // Editing not supported
253  return false;
254  }

◆ ToItem()

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

Definition at line 200 of file rc_item.h.

201  {
202  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
203  }

Referenced by DeleteItems(), ExpandAll(), GetChildren(), GetParent(), NextMarker(), PrevMarker(), rebuildModel(), 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 144 of file rc_item.cpp.

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

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 433 of file rc_item.cpp.

434 {
435  if( aNode->m_Type == RC_TREE_NODE::MAIN_ITEM || aNode->m_Type == RC_TREE_NODE::AUX_ITEM )
436  {
437  ValueChanged( aNode->m_Parent );
438  }
439 
440  if( aNode->m_Type == RC_TREE_NODE::MARKER )
441  {
442  wxDataViewModel::ValueChanged( ToItem( aNode ), 0 );
443 
444  for( const RC_TREE_NODE* child : aNode->m_Children )
445  wxDataViewModel::ValueChanged( ToItem( child ), 0 );
446  }
447 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:200
RC_TREE_NODE * m_Parent
Definition: rc_item.h:192
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:193
NODE_TYPE m_Type
Definition: rc_item.h:189
void ValueChanged(const RC_TREE_NODE *aNode)
Definition: rc_item.cpp:433

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_ERC::ExcludeMarker(), and DIALOG_DRC::ExcludeMarker().

Member Data Documentation

◆ m_editFrame

EDA_DRAW_FRAME* RC_TREE_MODEL::m_editFrame
private

Definition at line 278 of file rc_item.h.

Referenced by GetValue().

◆ m_rcItemsProvider

RC_ITEMS_PROVIDER* RC_TREE_MODEL::m_rcItemsProvider
private

Definition at line 281 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 280 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: