KiCad PCB EDA Suite
DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel Class Reference
Inheritance diagram for DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel:

Classes

class  Group
 
class  Item
 
class  Pin
 

Public Types

enum  {
  NONE = -1, PIN_NUMBER = 0, PIN_NAME = 1, PIN_TYPE = 2,
  PIN_POSITION = 3
}
 

Public Member Functions

 DataViewModel (LIB_PART &aPart)
 
virtual unsigned int GetColumnCount () const override
 
virtual wxString GetColumnType (unsigned int col) const override
 
virtual void GetValue (wxVariant &, const wxDataViewItem &, unsigned int) const override
 
virtual bool SetValue (const wxVariant &, const wxDataViewItem &, unsigned int) override
 
virtual wxDataViewItem GetParent (const wxDataViewItem &) const override
 
virtual bool IsContainer (const wxDataViewItem &) const override
 
virtual bool HasContainerColumns (const wxDataViewItem &) const override
 
virtual unsigned int GetChildren (const wxDataViewItem &, wxDataViewItemArray &) const override
 
virtual int Compare (const wxDataViewItem &lhs, const wxDataViewItem &rhs, unsigned int col, bool ascending) const override
 
void SetGroupingColumn (int aCol)
 
void CalculateGrouping ()
 
void Refresh ()
 
PinNumbers GetAllPinNumbers ()
 
void SetWidget (wxDataViewCtrl *aWidget)
 

Private Member Functions

wxString GetString (const wxDataViewItem &, unsigned int) const
 

Private Attributes

LIB_PARTm_Part
 
LIB_PINS m_Backing
 
int m_GroupingColumn
 
int m_UnitCount
 
std::list< Pinm_Pins
 
std::map< wxString, Groupm_Groups
 
wxDataViewCtrl * m_Widget
 

Detailed Description

Definition at line 44 of file dialog_lib_edit_pin_table.cpp.

Member Enumeration Documentation

Constructor & Destructor Documentation

DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::DataViewModel ( LIB_PART aPart)
Todo:
C++11

Definition at line 235 of file dialog_lib_edit_pin_table.cpp.

References CalculateGrouping(), LIB_PART::GetPins(), m_Backing, m_Pins, and m_Widget.

235  :
236  m_Part( aPart ),
237  m_GroupingColumn( 1 ),
239 {
240 #ifdef REASSOCIATE_HACK
241  m_Widget = NULL;
242 #endif
243  aPart.GetPins( m_Backing );
245  for( LIB_PINS::const_iterator i = m_Backing.begin(); i != m_Backing.end(); ++i )
246  m_Pins.push_back( Pin( *this, *i ) );
247 
249 }
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
int GetUnitCount() const

Member Function Documentation

void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::CalculateGrouping ( )

Definition at line 371 of file dialog_lib_edit_pin_table.cpp.

References DIALOG_LIB_EDIT_PIN_TABLE_BASE::m_Pins.

Referenced by DataViewModel().

372 {
373  m_Groups.clear();
374 
375  if( m_GroupingColumn != -1 )
376  {
377  wxVariant value;
378 
379  for( std::list<Pin>::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
380  {
381  wxString str = i->GetString( m_GroupingColumn );
382  std::map<wxString, Group>::iterator j = m_Groups.find( str );
383 
384  if( j == m_Groups.end() )
385  j = m_Groups.insert( std::make_pair( str, m_GroupingColumn ) ).first;
386 
387  j->second.Add( &*i );
388  }
389  }
390  else
391  {
392  for( std::list<Pin>::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
393  i->SetGroup( 0 );
394  }
395 }
int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Compare ( const wxDataViewItem &  lhs,
const wxDataViewItem &  rhs,
unsigned int  col,
bool  ascending 
) const
overridevirtual

Definition at line 342 of file dialog_lib_edit_pin_table.cpp.

References PinNumbers::Compare().

346 {
347  wxString str1 = GetString( aItem1, aCol );
348  wxString str2 = GetString( aItem2, aCol );
349  int res = PinNumbers::Compare( str1, str2 );
350 
351  if( res == 0 )
352  res = ( aItem1.GetID() < aItem2.GetID() ) ? -1 : 1;
353 
354  return res * ( aAscending ? 1 : -1 );
355 }
static int Compare(PinNumber const &lhs, PinNumber const &rhs)
Definition: pin_number.cpp:110
wxString GetString(const wxDataViewItem &, unsigned int) const
PinNumbers DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetAllPinNumbers ( )

Definition at line 427 of file dialog_lib_edit_pin_table.cpp.

References PinNumbers::insert(), and DIALOG_LIB_EDIT_PIN_TABLE_BASE::m_Pins.

428 {
429  PinNumbers ret;
430 
431  for( std::list<Pin>::const_iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
432  ret.insert( i->GetString( PIN_NUMBER ) );
433 
434  return ret;
435 }
void insert(value_type const &v)
Definition: pin_number.h:57
unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetChildren ( const wxDataViewItem &  aItem,
wxDataViewItemArray &  aItems 
) const
overridevirtual

Definition at line 322 of file dialog_lib_edit_pin_table.cpp.

References DIALOG_LIB_EDIT_PIN_TABLE_BASE::m_Pins.

324 {
325  if( !aItem.IsOk() )
326  {
327  for( std::map<wxString, Group>::iterator i = m_Groups.begin(); i != m_Groups.end(); ++i )
328  if( i->second.GetCount() > 1 )
329  aItems.push_back( wxDataViewItem( &i->second ) );
330 
331  for( std::list<Pin>::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
332  if( !i->GetParent().IsOk() )
333  aItems.push_back( wxDataViewItem( &*i ) );
334 
335  return aItems.size();
336  }
337  else
338  return reinterpret_cast<Item const*>( aItem.GetID() )->GetChildren( aItems );
339 }
virtual unsigned int GetChildren(const wxDataViewItem &, wxDataViewItemArray &) const override
unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnCount ( ) const
overridevirtual

Definition at line 252 of file dialog_lib_edit_pin_table.cpp.

253 {
254  return 4;
255 }
wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnType ( unsigned int  col) const
overridevirtual

Definition at line 258 of file dialog_lib_edit_pin_table.cpp.

259 {
260  switch( aCol )
261  {
262  case PIN_NUMBER:
263  return wxT( "string" );
264 
265  case PIN_NAME:
266  return wxT( "string" );
267 
268  case PIN_TYPE:
269  return wxT( "wxDataViewIconText" );
270 
271  case PIN_POSITION:
272  return wxT( "string" );
273  }
274 
275  assert( ! "Unhandled column" );
276  return wxT( "" );
277 }
wxDataViewItem DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetParent ( const wxDataViewItem &  aItem) const
overridevirtual

Definition at line 298 of file dialog_lib_edit_pin_table.cpp.

300 {
301  assert( aItem.IsOk() );
302 
303  return reinterpret_cast<Item const*>( aItem.GetID() )->GetParent();
304 }
virtual wxDataViewItem GetParent(const wxDataViewItem &) const override
wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetString ( const wxDataViewItem &  aItem,
unsigned int  aCol 
) const
private

Definition at line 438 of file dialog_lib_edit_pin_table.cpp.

439 {
440  assert( aItem.IsOk() );
441 
442  return reinterpret_cast<Item const*>( aItem.GetID() )->GetString( aCol );
443 }
wxString GetString(const wxDataViewItem &, unsigned int) const
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetValue ( wxVariant &  aVal,
const wxDataViewItem &  aItem,
unsigned int  aCol 
) const
overridevirtual

Definition at line 280 of file dialog_lib_edit_pin_table.cpp.

283 {
284  assert( aItem.IsOk() );
285 
286  reinterpret_cast<Item const*>( aItem.GetID() )->GetValue( aVal, aCol );
287 }
virtual void GetValue(wxVariant &, const wxDataViewItem &, unsigned int) const override
bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::HasContainerColumns ( const wxDataViewItem &  ) const
overridevirtual

Definition at line 316 of file dialog_lib_edit_pin_table.cpp.

317 {
318  return true;
319 }
bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::IsContainer ( const wxDataViewItem &  aItem) const
overridevirtual

Definition at line 307 of file dialog_lib_edit_pin_table.cpp.

308 {
309  if( aItem.IsOk() )
310  return reinterpret_cast<Item const*>( aItem.GetID() )->IsContainer();
311  else
312  return true;
313 }
virtual bool IsContainer(const wxDataViewItem &) const override
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Refresh ( )

Definition at line 398 of file dialog_lib_edit_pin_table.cpp.

399 {
400 #ifdef REASSOCIATE_HACK
401  m_Widget->AssociateModel( this );
402 #else
403  std::queue<wxDataViewItem> todo;
404  todo.push( wxDataViewItem() );
405 
406  while( !todo.empty() )
407  {
408  wxDataViewItem current = todo.front();
409  wxDataViewItemArray items;
410 
411  GetChildren( current, items );
412  ItemsAdded( current, items );
413 
414  for( wxDataViewItemArray::const_iterator i = items.begin(); i != items.end(); ++i )
415  {
416  if( IsContainer( *i ) )
417  todo.push( *i );
418  }
419 
420  todo.pop();
421  }
422 
423 #endif
424 }
virtual unsigned int GetChildren(const wxDataViewItem &, wxDataViewItemArray &) const override
virtual bool IsContainer(const wxDataViewItem &) const override
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::SetGroupingColumn ( int  aCol)
bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::SetValue ( const wxVariant &  ,
const wxDataViewItem &  ,
unsigned  int 
)
overridevirtual

Definition at line 290 of file dialog_lib_edit_pin_table.cpp.

293 {
294  return false;
295 }
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::SetWidget ( wxDataViewCtrl *  aWidget)
inline

Definition at line 72 of file dialog_lib_edit_pin_table.cpp.

References m_Widget.

Member Data Documentation

LIB_PINS DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_Backing
private

Definition at line 86 of file dialog_lib_edit_pin_table.cpp.

Referenced by DataViewModel().

int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_GroupingColumn
private

Definition at line 87 of file dialog_lib_edit_pin_table.cpp.

std::map<wxString, Group> DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_Groups
mutableprivate

Definition at line 95 of file dialog_lib_edit_pin_table.cpp.

LIB_PART& DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_Part
private

Definition at line 85 of file dialog_lib_edit_pin_table.cpp.

std::list<Pin> DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_Pins
mutableprivate

Definition at line 92 of file dialog_lib_edit_pin_table.cpp.

Referenced by DataViewModel().

int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_UnitCount
private

Definition at line 88 of file dialog_lib_edit_pin_table.cpp.

wxDataViewCtrl* DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::m_Widget
private

Definition at line 101 of file dialog_lib_edit_pin_table.cpp.

Referenced by DataViewModel(), and SetWidget().


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