KiCad PCB EDA Suite
SCH_PIN_TABLE_DATA_MODEL Class Reference
Inheritance diagram for SCH_PIN_TABLE_DATA_MODEL:

Public Member Functions

 SCH_PIN_TABLE_DATA_MODEL ()
 
 ~SCH_PIN_TABLE_DATA_MODEL ()
 
void BuildAttrs ()
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetColLabelValue (int aCol) override
 
bool IsEmptyCell (int row, int col) override
 
wxString GetValue (int aRow, int aCol) override
 
wxGridCellAttr * GetAttr (int aRow, int aCol, wxGridCellAttr::wxAttrKind) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void SortRows (int aSortCol, bool ascending)
 

Static Public Member Functions

static wxString GetValue (const SCH_PIN &aPin, int aCol)
 
static bool compare (const SCH_PIN &lhs, const SCH_PIN &rhs, int sortCol, bool ascending)
 

Protected Attributes

std::vector< wxGridCellAttr * > m_nameAttrs
 
wxGridCellAttr * m_readOnlyAttr
 
wxGridCellAttr * m_typeAttr
 
wxGridCellAttr * m_shapeAttr
 

Detailed Description

Definition at line 64 of file dialog_symbol_properties.cpp.

Constructor & Destructor Documentation

◆ SCH_PIN_TABLE_DATA_MODEL()

SCH_PIN_TABLE_DATA_MODEL::SCH_PIN_TABLE_DATA_MODEL ( )
inline

Definition at line 73 of file dialog_symbol_properties.cpp.

73  :
74  m_readOnlyAttr( nullptr ),
75  m_typeAttr( nullptr ),
76  m_shapeAttr( nullptr )
77  {
78  }

◆ ~SCH_PIN_TABLE_DATA_MODEL()

SCH_PIN_TABLE_DATA_MODEL::~SCH_PIN_TABLE_DATA_MODEL ( )
inline

Definition at line 80 of file dialog_symbol_properties.cpp.

81  {
82  for( wxGridCellAttr* attr : m_nameAttrs )
83  attr->DecRef();
84 
85  m_readOnlyAttr->DecRef();
86  m_typeAttr->DecRef();
87  m_shapeAttr->DecRef();
88  }
std::vector< wxGridCellAttr * > m_nameAttrs

References m_nameAttrs, m_readOnlyAttr, m_shapeAttr, and m_typeAttr.

Member Function Documentation

◆ BuildAttrs()

void SCH_PIN_TABLE_DATA_MODEL::BuildAttrs ( )
inline

Definition at line 90 of file dialog_symbol_properties.cpp.

91  {
92  m_readOnlyAttr = new wxGridCellAttr;
93  m_readOnlyAttr->SetReadOnly( true );
94 
95  for( const SCH_PIN& pin : *this )
96  {
97  LIB_PIN* lib_pin = pin.GetLibPin();
98  wxGridCellAttr* attr = nullptr;
99 
100  if( lib_pin->GetAlternates().empty() )
101  {
102  attr = new wxGridCellAttr;
103  attr->SetReadOnly( true );
104  }
105  else
106  {
107  wxArrayString choices;
108  choices.push_back( lib_pin->GetName() );
109 
110  for( const std::pair<const wxString, LIB_PIN::ALT>& alt : lib_pin->GetAlternates() )
111  choices.push_back( alt.first );
112 
113  attr = new wxGridCellAttr();
114  attr->SetEditor( new GRID_CELL_COMBOBOX( choices ) );
115  }
116 
117  m_nameAttrs.push_back( attr );
118  }
119 
120  m_typeAttr = new wxGridCellAttr;
122  m_typeAttr->SetReadOnly( true );
123 
124  m_shapeAttr = new wxGridCellAttr;
126  m_shapeAttr->SetReadOnly( true );
127  }
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:209
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:200
const wxString & GetName() const
Definition: lib_pin.h:108
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:182
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:132
std::vector< wxGridCellAttr * > m_nameAttrs
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:191

References LIB_PIN::GetAlternates(), LIB_PIN::GetName(), m_nameAttrs, m_readOnlyAttr, m_shapeAttr, m_typeAttr, pin, PinShapeIcons(), PinShapeNames(), PinTypeIcons(), and PinTypeNames().

Referenced by DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES().

◆ compare()

static bool SCH_PIN_TABLE_DATA_MODEL::compare ( const SCH_PIN lhs,
const SCH_PIN rhs,
int  sortCol,
bool  ascending 
)
inlinestatic

Definition at line 219 of file dialog_symbol_properties.cpp.

220  {
221  wxString lhStr = GetValue( lhs, sortCol );
222  wxString rhStr = GetValue( rhs, sortCol );
223 
224  if( lhStr == rhStr )
225  {
226  // Secondary sort key is always COL_NUMBER
227  sortCol = COL_NUMBER;
228  lhStr = GetValue( lhs, sortCol );
229  rhStr = GetValue( rhs, sortCol );
230  }
231 
232  bool res;
233 
234  // N.B. To meet the iterator sort conditions, we cannot simply invert the truth
235  // to get the opposite sort. i.e. ~(a<b) != (a>b)
236  auto cmp = [ ascending ]( const auto a, const auto b )
237  {
238  if( ascending )
239  return a < b;
240  else
241  return b < a;
242  };
243 
244  switch( sortCol )
245  {
246  case COL_NUMBER:
247  case COL_BASE_NAME:
248  case COL_ALT_NAME:
249  res = cmp( PinNumbers::Compare( lhStr, rhStr ), 0 );
250  break;
251  case COL_TYPE:
252  case COL_SHAPE:
253  res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
254  break;
255  default:
256  res = cmp( StrNumCmp( lhStr, rhStr ), 0 );
257  break;
258  }
259 
260  return res;
261  }
static int Compare(PinNumber const &lhs, PinNumber const &rhs)
Definition: pin_number.cpp:111
wxString GetValue(int aRow, int aCol) override
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:440

References COL_ALT_NAME, COL_BASE_NAME, COL_NUMBER, COL_SHAPE, COL_TYPE, PinNumbers::Compare(), GetValue(), and StrNumCmp().

Referenced by SortRows().

◆ GetAttr()

wxGridCellAttr* SCH_PIN_TABLE_DATA_MODEL::GetAttr ( int  aRow,
int  aCol,
wxGridCellAttr::wxAttrKind   
)
inlineoverride

Definition at line 168 of file dialog_symbol_properties.cpp.

169  {
170  switch( aCol )
171  {
172  case COL_NUMBER:
173  case COL_BASE_NAME:
174  m_readOnlyAttr->IncRef();
175  return m_readOnlyAttr;
176 
177  case COL_ALT_NAME:
178  m_nameAttrs[ aRow ]->IncRef();
179  return m_nameAttrs[ aRow ];
180 
181  case COL_TYPE:
182  m_typeAttr->IncRef();
183  return m_typeAttr;
184 
185  case COL_SHAPE:
186  m_shapeAttr->IncRef();
187  return m_shapeAttr;
188 
189  default:
190  wxFAIL;
191  return nullptr;
192  }
193  }
std::vector< wxGridCellAttr * > m_nameAttrs

References COL_ALT_NAME, COL_BASE_NAME, COL_NUMBER, COL_SHAPE, COL_TYPE, m_nameAttrs, m_readOnlyAttr, m_shapeAttr, and m_typeAttr.

◆ GetColLabelValue()

wxString SCH_PIN_TABLE_DATA_MODEL::GetColLabelValue ( int  aCol)
inlineoverride

Definition at line 132 of file dialog_symbol_properties.cpp.

133  {
134  switch( aCol )
135  {
136  case COL_NUMBER: return _( "Number" );
137  case COL_BASE_NAME: return _( "Base Name" );
138  case COL_ALT_NAME: return _( "Alternate Assignment" );
139  case COL_TYPE: return _( "Electrical Type" );
140  case COL_SHAPE: return _( "Graphic Style" );
141  default: wxFAIL; return wxEmptyString;
142  }
143  }
#define _(s)
Definition: 3d_actions.cpp:33

References _, COL_ALT_NAME, COL_BASE_NAME, COL_NUMBER, COL_SHAPE, and COL_TYPE.

◆ GetNumberCols()

int SCH_PIN_TABLE_DATA_MODEL::GetNumberCols ( )
inlineoverride

Definition at line 130 of file dialog_symbol_properties.cpp.

References COL_COUNT.

◆ GetNumberRows()

int SCH_PIN_TABLE_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 129 of file dialog_symbol_properties.cpp.

129 { return (int) size(); }

◆ GetValue() [1/2]

wxString SCH_PIN_TABLE_DATA_MODEL::GetValue ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 150 of file dialog_symbol_properties.cpp.

151  {
152  return GetValue( at( aRow ), aCol );
153  }
wxString GetValue(int aRow, int aCol) override

Referenced by compare(), and DIALOG_SYMBOL_PROPERTIES::OnPinTableCellEdited().

◆ GetValue() [2/2]

static wxString SCH_PIN_TABLE_DATA_MODEL::GetValue ( const SCH_PIN aPin,
int  aCol 
)
inlinestatic

Definition at line 155 of file dialog_symbol_properties.cpp.

156  {
157  switch( aCol )
158  {
159  case COL_NUMBER: return aPin.GetNumber();
160  case COL_BASE_NAME: return aPin.GetLibPin()->GetName();
161  case COL_ALT_NAME: return aPin.GetAlt();
162  case COL_TYPE: return PinTypeNames()[static_cast<int>( aPin.GetType() )];
163  case COL_SHAPE: return PinShapeNames()[static_cast<int>( aPin.GetShape() )];
164  default: wxFAIL; return wxEmptyString;
165  }
166  }
LIB_PIN * GetLibPin() const
Definition: sch_pin.h:58
wxString GetAlt() const
Definition: sch_pin.h:63
wxString GetNumber() const
Definition: sch_pin.h:107
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:200
const wxString & GetName() const
Definition: lib_pin.h:108
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:182
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:97
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:88

References COL_ALT_NAME, COL_BASE_NAME, COL_NUMBER, COL_SHAPE, COL_TYPE, SCH_PIN::GetAlt(), SCH_PIN::GetLibPin(), LIB_PIN::GetName(), SCH_PIN::GetNumber(), SCH_PIN::GetShape(), SCH_PIN::GetType(), PinShapeNames(), and PinTypeNames().

◆ IsEmptyCell()

bool SCH_PIN_TABLE_DATA_MODEL::IsEmptyCell ( int  row,
int  col 
)
inlineoverride

Definition at line 145 of file dialog_symbol_properties.cpp.

146  {
147  return false; // don't allow adjacent cell overflow, even if we are actually empty
148  }

◆ SetValue()

void SCH_PIN_TABLE_DATA_MODEL::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverride

Definition at line 195 of file dialog_symbol_properties.cpp.

196  {
197  switch( aCol )
198  {
199  case COL_ALT_NAME:
200  if( aValue == at( aRow ).GetLibPin()->GetName() )
201  at( aRow ).SetAlt( wxEmptyString );
202  else
203  at( aRow ).SetAlt( aValue );
204  break;
205 
206  case COL_NUMBER:
207  case COL_BASE_NAME:
208  case COL_TYPE:
209  case COL_SHAPE:
210  // Read-only.
211  break;
212 
213  default:
214  wxFAIL;
215  break;
216  }
217  }

References COL_ALT_NAME, COL_BASE_NAME, COL_NUMBER, COL_SHAPE, and COL_TYPE.

Referenced by DIALOG_SYMBOL_PROPERTIES::OnPinTableCellEdited().

◆ SortRows()

void SCH_PIN_TABLE_DATA_MODEL::SortRows ( int  aSortCol,
bool  ascending 
)
inline

Definition at line 263 of file dialog_symbol_properties.cpp.

264  {
265  std::sort( begin(), end(),
266  [ aSortCol, ascending ]( const SCH_PIN& lhs, const SCH_PIN& rhs ) -> bool
267  {
268  return compare( lhs, rhs, aSortCol, ascending );
269  } );
270  }
static bool compare(const SCH_PIN &lhs, const SCH_PIN &rhs, int sortCol, bool ascending)

References compare().

Referenced by DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES(), and DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort().

Member Data Documentation

◆ m_nameAttrs

std::vector<wxGridCellAttr*> SCH_PIN_TABLE_DATA_MODEL::m_nameAttrs
protected

Definition at line 67 of file dialog_symbol_properties.cpp.

Referenced by BuildAttrs(), GetAttr(), and ~SCH_PIN_TABLE_DATA_MODEL().

◆ m_readOnlyAttr

wxGridCellAttr* SCH_PIN_TABLE_DATA_MODEL::m_readOnlyAttr
protected

Definition at line 68 of file dialog_symbol_properties.cpp.

Referenced by BuildAttrs(), GetAttr(), and ~SCH_PIN_TABLE_DATA_MODEL().

◆ m_shapeAttr

wxGridCellAttr* SCH_PIN_TABLE_DATA_MODEL::m_shapeAttr
protected

Definition at line 70 of file dialog_symbol_properties.cpp.

Referenced by BuildAttrs(), GetAttr(), and ~SCH_PIN_TABLE_DATA_MODEL().

◆ m_typeAttr

wxGridCellAttr* SCH_PIN_TABLE_DATA_MODEL::m_typeAttr
protected

Definition at line 69 of file dialog_symbol_properties.cpp.

Referenced by BuildAttrs(), GetAttr(), and ~SCH_PIN_TABLE_DATA_MODEL().


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