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 240 of file dialog_lib_edit_pin_table.cpp.

References CalculateGrouping(), DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::Compare(), LIB_PART::GetPins(), m_Backing, m_Pins, and m_Widget.

240  :
241  m_Part( aPart ),
242  m_GroupingColumn( 1 ),
244 {
245 #ifdef REASSOCIATE_HACK
246  m_Widget = NULL;
247 #endif
248  aPart.GetPins( m_Backing );
250  for( LIB_PINS::const_iterator i = m_Backing.begin(); i != m_Backing.end(); ++i )
251  m_Pins.push_back( Pin( *this, *i ) );
252 
253  m_Pins.sort(Pin::Compare);
254 
256 }
static bool Compare(const Pin &lhs, const Pin &rhs)
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 378 of file dialog_lib_edit_pin_table.cpp.

References DIALOG_LIB_EDIT_PIN_TABLE_BASE::m_Pins.

Referenced by DataViewModel().

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

Definition at line 349 of file dialog_lib_edit_pin_table.cpp.

References PinNumbers::Compare().

353 {
354  wxString str1 = GetString( aItem1, aCol );
355  wxString str2 = GetString( aItem2, aCol );
356  int res = PinNumbers::Compare( str1, str2 );
357 
358  if( res == 0 )
359  res = ( aItem1.GetID() < aItem2.GetID() ) ? -1 : 1;
360 
361  return res * ( aAscending ? 1 : -1 );
362 }
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 434 of file dialog_lib_edit_pin_table.cpp.

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

435 {
436  PinNumbers ret;
437 
438  for( std::list<Pin>::const_iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
439  ret.insert( i->GetString( PIN_NUMBER ) );
440 
441  return ret;
442 }
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 329 of file dialog_lib_edit_pin_table.cpp.

References DIALOG_LIB_EDIT_PIN_TABLE_BASE::m_Pins.

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

Definition at line 259 of file dialog_lib_edit_pin_table.cpp.

260 {
261  return 4;
262 }
wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetColumnType ( unsigned int  col) const
overridevirtual

Definition at line 265 of file dialog_lib_edit_pin_table.cpp.

266 {
267  switch( aCol )
268  {
269  case PIN_NUMBER:
270  return wxT( "string" );
271 
272  case PIN_NAME:
273  return wxT( "string" );
274 
275  case PIN_TYPE:
276  return wxT( "wxDataViewIconText" );
277 
278  case PIN_POSITION:
279  return wxT( "string" );
280  }
281 
282  assert( ! "Unhandled column" );
283  return wxT( "" );
284 }
wxDataViewItem DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetParent ( const wxDataViewItem &  aItem) const
overridevirtual

Definition at line 305 of file dialog_lib_edit_pin_table.cpp.

307 {
308  assert( aItem.IsOk() );
309 
310  return reinterpret_cast<Item const*>( aItem.GetID() )->GetParent();
311 }
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 445 of file dialog_lib_edit_pin_table.cpp.

446 {
447  assert( aItem.IsOk() );
448 
449  return reinterpret_cast<Item const*>( aItem.GetID() )->GetString( aCol );
450 }
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 287 of file dialog_lib_edit_pin_table.cpp.

290 {
291  assert( aItem.IsOk() );
292 
293  reinterpret_cast<Item const*>( aItem.GetID() )->GetValue( aVal, aCol );
294 }
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 323 of file dialog_lib_edit_pin_table.cpp.

324 {
325  return true;
326 }
bool DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::IsContainer ( const wxDataViewItem &  aItem) const
overridevirtual

Definition at line 314 of file dialog_lib_edit_pin_table.cpp.

315 {
316  if( aItem.IsOk() )
317  return reinterpret_cast<Item const*>( aItem.GetID() )->IsContainer();
318  else
319  return true;
320 }
virtual bool IsContainer(const wxDataViewItem &) const override
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Refresh ( )

Definition at line 405 of file dialog_lib_edit_pin_table.cpp.

406 {
407 #ifdef REASSOCIATE_HACK
408  m_Widget->AssociateModel( this );
409 #else
410  std::queue<wxDataViewItem> todo;
411  todo.push( wxDataViewItem() );
412 
413  while( !todo.empty() )
414  {
415  wxDataViewItem current = todo.front();
416  wxDataViewItemArray items;
417 
418  GetChildren( current, items );
419  ItemsAdded( current, items );
420 
421  for( wxDataViewItemArray::const_iterator i = items.begin(); i != items.end(); ++i )
422  {
423  if( IsContainer( *i ) )
424  todo.push( *i );
425  }
426 
427  todo.pop();
428  }
429 
430 #endif
431 }
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 297 of file dialog_lib_edit_pin_table.cpp.

300 {
301  return false;
302 }
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: