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

148  :
149  m_editFrame( aParentFrame ),
150  m_view( aView ),
151  m_severities( 0 ),
152  m_rcItemsProvider( nullptr )
153 {
154  m_view->GetMainWindow()->Connect( wxEVT_SIZE,
155  wxSizeEventHandler( RC_TREE_MODEL::onSizeView ),
156  NULL, this );
157 }
wxDataViewCtrl * m_view
Definition: rc_item.h:294
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:296
#define NULL
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:293
void onSizeView(wxSizeEvent &aEvent)
Definition: rc_item.cpp:576
int m_severities
Definition: rc_item.h:295

References m_view, NULL, and onSizeView().

◆ ~RC_TREE_MODEL()

RC_TREE_MODEL::~RC_TREE_MODEL ( )

Definition at line 160 of file rc_item.cpp.

161 {
162  delete m_rcItemsProvider;
163 
164  for( RC_TREE_NODE* topLevelNode : m_tree )
165  delete topLevelNode;
166 }
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:296
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:298

References m_rcItemsProvider, and m_tree.

Member Function Documentation

◆ DeleteCurrentItem()

void RC_TREE_MODEL::DeleteCurrentItem ( bool  aDeep)

Definition at line 432 of file rc_item.cpp.

433 {
434  DeleteItems( true, true, aDeep );
435 }
void DeleteItems(bool aCurrentOnly, bool aIncludeExclusions, bool aDeep)
Deletes the current item or all items.
Definition: rc_item.cpp:438

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

439 {
440  RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() );
441  const std::shared_ptr<RC_ITEM> current_item = current_node ? current_node->m_RcItem : nullptr;
442 
444  std::vector<RC_TREE_NODE*> to_delete;
445 
446  if( aCurrentOnly && !current_item )
447  {
448  wxBell();
449  return;
450  }
451 
452  if( !m_rcItemsProvider )
453  return;
454 
455  int lastGood = -1;
456  bool itemDeleted = false;
457 
458  if( m_view )
459  {
460  m_view->UnselectAll();
461  wxYield();
462  m_view->Freeze();
463  }
464 
465  for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
466  {
467  std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
468  MARKER_BASE* marker = rcItem->GetParent();
469  bool excluded = marker ? marker->IsExcluded() : false;
470 
471  if( aCurrentOnly && itemDeleted && lastGood >= 0 )
472  break;
473 
474  if( aCurrentOnly && rcItem != current_item )
475  {
476  lastGood = i;
477  continue;
478  }
479 
480  if( excluded && !aIncludeExclusions )
481  continue;
482 
483  if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets
484  {
485  wxDataViewItem markerItem = ToItem( m_tree[i] );
486  wxDataViewItemArray childItems;
487  wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
488 
489  for( RC_TREE_NODE* child : m_tree[i]->m_Children )
490  {
491  childItems.push_back( ToItem( child ) );
492  to_delete.push_back( child );
493  }
494 
495  m_tree[i]->m_Children.clear();
496  ItemsDeleted( markerItem, childItems );
497 
498  to_delete.push_back( m_tree[i] );
499  m_tree.erase( m_tree.begin() + i );
500  ItemDeleted( parentItem, markerItem );
501  }
502 
503  // Only deep delete the current item here; others will be done through the
504  // DeleteAllItems() call below, which is more efficient.
505  m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
506 
507  if( lastGood > i )
508  lastGood--;
509 
510  itemDeleted = true;
511  }
512 
513  if( m_view && aCurrentOnly && lastGood >= 0 )
514  m_view->Select( ToItem( m_tree[ lastGood ] ) );
515 
516  for( RC_TREE_NODE* item : to_delete )
517  delete( item );
518 
519  if( !aCurrentOnly )
520  m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );
521 
522  if( m_view )
523  m_view->Thaw();
524 }
virtual void DeleteAllItems(bool aIncludeExclusions, bool aDeep)=0
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
wxDataViewCtrl * m_view
Definition: rc_item.h:294
virtual int GetCount(int aSeverity=-1) const =0
RC_ITEMS_PROVIDER * m_rcItemsProvider
Definition: rc_item.h:296
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:205
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
bool IsExcluded() const
Definition: marker_base.h:94
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:298
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 276 of file rc_item.cpp.

277 {
278  for( RC_TREE_NODE* topLevelNode : m_tree )
279  m_view->Expand( ToItem( topLevelNode ) );
280 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
wxDataViewCtrl * m_view
Definition: rc_item.h:294
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:298

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.

Return true iff the item has non-default attributes.

Definition at line 382 of file rc_item.cpp.

385 {
386  const RC_TREE_NODE* node = ToNode( aItem );
387  wxASSERT( node );
388 
389  bool ret = false;
390  bool heading = node->m_Type == RC_TREE_NODE::MARKER;
391 
392  if( heading )
393  {
394  aAttr.SetBold( true );
395  ret = true;
396  }
397 
398  if( node->m_RcItem->GetParent() && node->m_RcItem->GetParent()->IsExcluded() )
399  {
400  wxColour textColour = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXTEXT );
401 
402  if( KIGFX::COLOR4D( textColour ).GetBrightness() > 0.5 )
403  aAttr.SetColour( textColour.ChangeLightness( heading ? 30 : 35 ) );
404  else
405  aAttr.SetColour( textColour.ChangeLightness( heading ? 170 : 165 ) );
406 
407  aAttr.SetItalic( true ); // Strikethrough would be better, if wxWidgets supported it
408  ret = true;
409  }
410 
411  return ret;
412 }
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:205
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
NODE_TYPE m_Type
Definition: rc_item.h:204
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

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

300 {
301  const RC_TREE_NODE* node = ToNode( aItem );
302  const std::vector<RC_TREE_NODE*>& children = node ? node->m_Children : m_tree;
303 
304  for( const RC_TREE_NODE* child: children )
305  aChildren.push_back( ToItem( child ) );
306 
307  return children.size();
308 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:208
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:298

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

◆ GetColumnCount()

unsigned int RC_TREE_MODEL::GetColumnCount ( ) const
inlineoverride

Definition at line 249 of file rc_item.h.

249 { return 1; }

◆ GetColumnType()

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

Definition at line 250 of file rc_item.h.

250 { return "string"; }

◆ GetDRCItemCount()

int RC_TREE_MODEL::GetDRCItemCount ( ) const
inline

Definition at line 234 of file rc_item.h.

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

References m_tree.

◆ GetParent()

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

Definition at line 292 of file rc_item.cpp.

293 {
294  return ToItem( ToNode( aItem)->m_Parent );
295 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220

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

317 {
318  const RC_TREE_NODE* node = ToNode( aItem );
319  const std::shared_ptr<RC_ITEM> rcItem = node->m_RcItem;
320 
321  switch( node->m_Type )
322  {
324  {
325  wxString prefix;
326 
327  if( rcItem->GetParent() && rcItem->GetParent()->IsExcluded() )
328  prefix = _( "Excluded " );
329 
330  switch( m_editFrame->GetSeverity( rcItem->GetErrorCode() ) )
331  {
332  case RPT_SEVERITY_ERROR: prefix += _( "Error: " ); break;
333  case RPT_SEVERITY_WARNING: prefix += _( "Warning: " ); break;
334 
337  case RPT_SEVERITY_INFO:
338  case RPT_SEVERITY_ACTION:
339  case RPT_SEVERITY_IGNORE:
340  break;
341  }
342 
343  aVariant = prefix + rcItem->GetErrorMessage();
344  }
345  break;
346 
348  {
349  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetMainItemID() );
350  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
351  }
352  break;
353 
355  {
356  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItemID() );
357  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
358  }
359  break;
360 
362  {
363  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem2ID() );
364  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
365  }
366  break;
367 
369  {
370  EDA_ITEM* item = m_editFrame->GetItem( rcItem->GetAuxItem3ID() );
371  aVariant = item->GetSelectMenuText( m_editFrame->GetUserUnits() );
372  }
373  break;
374  }
375 }
virtual SEVERITY GetSeverity(int aErrorCode) const
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:205
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
EDA_DRAW_FRAME * m_editFrame
Definition: rc_item.h:293
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
NODE_TYPE m_Type
Definition: rc_item.h:204
#define _(s)
Definition: 3d_actions.cpp:33
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:107
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
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 251 of file rc_item.h.

251 { return true; }

◆ IsContainer()

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

Definition at line 283 of file rc_item.cpp.

284 {
285  if( ToNode( aItem ) == nullptr ) // must be tree root...
286  return true;
287  else
288  return ToNode( aItem )->m_Type == RC_TREE_NODE::MARKER;
289 }
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
NODE_TYPE m_Type
Definition: rc_item.h:204

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

◆ NextMarker()

void RC_TREE_MODEL::NextMarker ( )

Definition at line 548 of file rc_item.cpp.

549 {
550  RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
551 
552  while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
553  currentNode = currentNode->m_Parent;
554 
555  RC_TREE_NODE* nextMarker = nullptr;
556  bool trigger = currentNode == nullptr;
557 
558  for( RC_TREE_NODE* candidate : m_tree )
559  {
560  if( candidate == currentNode )
561  {
562  trigger = true;
563  }
564  else if( trigger )
565  {
566  nextMarker = candidate;
567  break;
568  }
569  }
570 
571  if( nextMarker )
572  m_view->Select( ToItem( nextMarker ) );
573 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
RC_TREE_NODE * m_Parent
Definition: rc_item.h:207
wxDataViewCtrl * m_view
Definition: rc_item.h:294
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
NODE_TYPE m_Type
Definition: rc_item.h:204
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:298

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

577 {
578  int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;
579 
580  if( m_view->GetColumnCount() > 0 )
581  m_view->GetColumn( 0 )->SetWidth( width );
582 
583  // Pass size event to other widgets
584  aEvent.Skip();
585 }
wxDataViewCtrl * m_view
Definition: rc_item.h:294
#define WX_DATAVIEW_WINDOW_PADDING
Definition: rc_item.cpp:34

References m_view, and WX_DATAVIEW_WINDOW_PADDING.

Referenced by RC_TREE_MODEL().

◆ PrevMarker()

void RC_TREE_MODEL::PrevMarker ( )

Definition at line 527 of file rc_item.cpp.

528 {
529  RC_TREE_NODE* currentNode = ToNode( m_view->GetCurrentItem() );
530  RC_TREE_NODE* prevMarker = nullptr;
531 
532  while( currentNode && currentNode->m_Type != RC_TREE_NODE::MARKER )
533  currentNode = currentNode->m_Parent;
534 
535  for( RC_TREE_NODE* candidate : m_tree )
536  {
537  if( candidate == currentNode )
538  break;
539  else
540  prevMarker = candidate;
541  }
542 
543  if( prevMarker )
544  m_view->Select( ToItem( prevMarker ) );
545 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
RC_TREE_NODE * m_Parent
Definition: rc_item.h:207
wxDataViewCtrl * m_view
Definition: rc_item.h:294
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
NODE_TYPE m_Type
Definition: rc_item.h:204
std::vector< RC_TREE_NODE * > m_tree
Definition: rc_item.h:298

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

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

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

266  {
267  // Editing not supported
268  return false;
269  }

◆ ToItem()

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

Definition at line 215 of file rc_item.h.

216  {
217  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
218  }

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

120 {
121  const RC_TREE_NODE* node = RC_TREE_MODEL::ToNode( aItem );
122 
123  if( node && node->m_RcItem )
124  {
125  const std::shared_ptr<RC_ITEM> rc_item = node->m_RcItem;
126 
127  switch( node->m_Type )
128  {
130  // rc_item->GetParent() can be null, if the parent is not existing
131  // when a RC item has no corresponding ERC/DRC marker
132  if( rc_item->GetParent() )
133  return rc_item->GetParent()->GetUUID();
134 
135  break;
136 
137  case RC_TREE_NODE::MAIN_ITEM: return rc_item->GetMainItemID();
138  case RC_TREE_NODE::AUX_ITEM: return rc_item->GetAuxItemID();
139  case RC_TREE_NODE::AUX_ITEM2: return rc_item->GetAuxItem2ID();
140  case RC_TREE_NODE::AUX_ITEM3: return rc_item->GetAuxItem3ID();
141  }
142  }
143 
144  return niluuid;
145 }
KIID niluuid(0)
std::shared_ptr< RC_ITEM > m_RcItem
Definition: rc_item.h:205
static RC_TREE_NODE * ToNode(wxDataViewItem aItem)
Definition: rc_item.h:220
NODE_TYPE m_Type
Definition: rc_item.h:204

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

416 {
417  if( aNode->m_Type == RC_TREE_NODE::MAIN_ITEM || aNode->m_Type == RC_TREE_NODE::AUX_ITEM )
418  {
419  ValueChanged( aNode->m_Parent );
420  }
421 
422  if( aNode->m_Type == RC_TREE_NODE::MARKER )
423  {
424  wxDataViewModel::ValueChanged( ToItem( aNode ), 0 );
425 
426  for( const RC_TREE_NODE* child : aNode->m_Children )
427  wxDataViewModel::ValueChanged( ToItem( child ), 0 );
428  }
429 }
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition: rc_item.h:215
RC_TREE_NODE * m_Parent
Definition: rc_item.h:207
std::vector< RC_TREE_NODE * > m_Children
Definition: rc_item.h:208
NODE_TYPE m_Type
Definition: rc_item.h:204
void ValueChanged(const RC_TREE_NODE *aNode)
Definition: rc_item.cpp:415

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

Referenced by GetValue().

◆ m_rcItemsProvider

RC_ITEMS_PROVIDER* RC_TREE_MODEL::m_rcItemsProvider
private

Definition at line 296 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 295 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: