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  PinTypeNames() ) );
123  m_typeAttr->SetReadOnly( true );
124 
125  m_shapeAttr = new wxGridCellAttr;
127  PinShapeNames() ) );
128  m_shapeAttr->SetReadOnly( true );
129  }
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:210
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:201
const wxString & GetName() const
Definition: lib_pin.h:106
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:183
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:132
std::vector< wxGridCellAttr * > m_nameAttrs
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:192

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 221 of file dialog_symbol_properties.cpp.

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

References COL_ALT_NAME, COL_BASE_NAME, COL_NUMBER, COL_SHAPE, COL_TYPE, PIN_NUMBERS::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 170 of file dialog_symbol_properties.cpp.

171  {
172  switch( aCol )
173  {
174  case COL_NUMBER:
175  case COL_BASE_NAME:
176  m_readOnlyAttr->IncRef();
177  return m_readOnlyAttr;
178 
179  case COL_ALT_NAME:
180  m_nameAttrs[ aRow ]->IncRef();
181  return m_nameAttrs[ aRow ];
182 
183  case COL_TYPE:
184  m_typeAttr->IncRef();
185  return m_typeAttr;
186 
187  case COL_SHAPE:
188  m_shapeAttr->IncRef();
189  return m_shapeAttr;
190 
191  default:
192  wxFAIL;
193  return nullptr;
194  }
195  }
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 134 of file dialog_symbol_properties.cpp.

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

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 132 of file dialog_symbol_properties.cpp.

References COL_COUNT.

◆ GetNumberRows()

int SCH_PIN_TABLE_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 131 of file dialog_symbol_properties.cpp.

131 { return (int) size(); }

◆ GetValue() [1/2]

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

Definition at line 152 of file dialog_symbol_properties.cpp.

153  {
154  return GetValue( at( aRow ), aCol );
155  }
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 157 of file dialog_symbol_properties.cpp.

158  {
159  switch( aCol )
160  {
161  case COL_NUMBER: return aPin.GetNumber();
162  case COL_BASE_NAME: return aPin.GetLibPin()->GetName();
163  case COL_ALT_NAME: return aPin.GetAlt();
164  case COL_TYPE: return PinTypeNames()[static_cast<int>( aPin.GetType() )];
165  case COL_SHAPE: return PinShapeNames()[static_cast<int>( aPin.GetShape() )];
166  default: wxFAIL; return wxEmptyString;
167  }
168  }
LIB_PIN * GetLibPin() const
Definition: sch_pin.h:59
wxString GetAlt() const
Definition: sch_pin.h:64
wxString GetNumber() const
Definition: sch_pin.h:109
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:201
const wxString & GetName() const
Definition: lib_pin.h:106
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:183
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:122
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:113

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 147 of file dialog_symbol_properties.cpp.

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

◆ SetValue()

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

Definition at line 197 of file dialog_symbol_properties.cpp.

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

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 265 of file dialog_symbol_properties.cpp.

266  {
267  std::sort( begin(), end(),
268  [ aSortCol, ascending ]( const SCH_PIN& lhs, const SCH_PIN& rhs ) -> bool
269  {
270  return compare( lhs, rhs, aSortCol, ascending );
271  } );
272  }
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: