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

80 :
81 m_readOnlyAttr( nullptr ),
82 m_typeAttr( nullptr ),
83 m_shapeAttr( nullptr )
84 {
85 }

◆ ~SCH_PIN_TABLE_DATA_MODEL()

SCH_PIN_TABLE_DATA_MODEL::~SCH_PIN_TABLE_DATA_MODEL ( )
inline

Definition at line 87 of file dialog_symbol_properties.cpp.

88 {
89 for( wxGridCellAttr* attr : m_nameAttrs )
90 attr->DecRef();
91
92 m_readOnlyAttr->DecRef();
93 m_typeAttr->DecRef();
94 m_shapeAttr->DecRef();
95 }
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 97 of file dialog_symbol_properties.cpp.

98 {
99 for( wxGridCellAttr* attr : m_nameAttrs )
100 attr->DecRef();
101
102 m_nameAttrs.clear();
103
104 if( m_readOnlyAttr )
105 m_readOnlyAttr->DecRef();
106
107 m_readOnlyAttr = new wxGridCellAttr;
108 m_readOnlyAttr->SetReadOnly( true );
109
110 for( const SCH_PIN& pin : *this )
111 {
112 LIB_PIN* lib_pin = pin.GetLibPin();
113 wxGridCellAttr* attr = nullptr;
114
115 if( lib_pin->GetAlternates().empty() )
116 {
117 attr = new wxGridCellAttr;
118 attr->SetReadOnly( true );
119 }
120 else
121 {
122 wxArrayString choices;
123 choices.push_back( lib_pin->GetName() );
124
125 for( const std::pair<const wxString, LIB_PIN::ALT>& alt : lib_pin->GetAlternates() )
126 choices.push_back( alt.first );
127
128 attr = new wxGridCellAttr();
129 attr->SetEditor( new GRID_CELL_COMBOBOX( choices ) );
130 }
131
132 m_nameAttrs.push_back( attr );
133 }
134
135 if( m_typeAttr )
136 m_typeAttr->DecRef();
137
138 m_typeAttr = new wxGridCellAttr;
140 PinTypeNames() ) );
141 m_typeAttr->SetReadOnly( true );
142
143 if( m_shapeAttr )
144 m_shapeAttr->DecRef();
145
146 m_shapeAttr = new wxGridCellAttr;
148 PinShapeNames() ) );
149 m_shapeAttr->SetReadOnly( true );
150 }
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:139
const wxString & GetName() const
Definition: lib_pin.h:113
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:195
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:186
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:204
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:213

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(), and DIALOG_SYMBOL_PROPERTIES::OnPinTableColSort().

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

243 {
244 wxString lhStr = GetValue( lhs, sortCol );
245 wxString rhStr = GetValue( rhs, sortCol );
246
247 if( lhStr == rhStr )
248 {
249 // Secondary sort key is always COL_NUMBER
250 sortCol = COL_NUMBER;
251 lhStr = GetValue( lhs, sortCol );
252 rhStr = GetValue( rhs, sortCol );
253 }
254
255 bool res;
256
257 // N.B. To meet the iterator sort conditions, we cannot simply invert the truth
258 // to get the opposite sort. i.e. ~(a<b) != (a>b)
259 auto cmp = [ ascending ]( const auto a, const auto b )
260 {
261 if( ascending )
262 return a < b;
263 else
264 return b < a;
265 };
266
267 switch( sortCol )
268 {
269 case COL_NUMBER:
270 case COL_BASE_NAME:
271 case COL_ALT_NAME:
272 res = cmp( PIN_NUMBERS::Compare( lhStr, rhStr ), 0 );
273 break;
274 case COL_TYPE:
275 case COL_SHAPE:
276 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
277 break;
278 default:
279 res = cmp( StrNumCmp( lhStr, rhStr ), 0 );
280 break;
281 }
282
283 return res;
284 }
static int Compare(const wxString &lhs, const wxString &rhs)
wxString GetValue(int aRow, int aCol) override
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 191 of file dialog_symbol_properties.cpp.

192 {
193 switch( aCol )
194 {
195 case COL_NUMBER:
196 case COL_BASE_NAME:
197 m_readOnlyAttr->IncRef();
198 return m_readOnlyAttr;
199
200 case COL_ALT_NAME:
201 m_nameAttrs[ aRow ]->IncRef();
202 return m_nameAttrs[ aRow ];
203
204 case COL_TYPE:
205 m_typeAttr->IncRef();
206 return m_typeAttr;
207
208 case COL_SHAPE:
209 m_shapeAttr->IncRef();
210 return m_shapeAttr;
211
212 default:
213 wxFAIL;
214 return nullptr;
215 }
216 }

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

156 {
157 switch( aCol )
158 {
159 case COL_NUMBER: return _( "Number" );
160 case COL_BASE_NAME: return _( "Base Name" );
161 case COL_ALT_NAME: return _( "Alternate Assignment" );
162 case COL_TYPE: return _( "Electrical Type" );
163 case COL_SHAPE: return _( "Graphic Style" );
164 default: wxFAIL; return wxEmptyString;
165 }
166 }
#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 153 of file dialog_symbol_properties.cpp.

153{ return COL_COUNT; }

References COL_COUNT.

◆ GetNumberRows()

int SCH_PIN_TABLE_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 152 of file dialog_symbol_properties.cpp.

152{ return (int) size(); }

◆ GetValue() [1/2]

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

Definition at line 178 of file dialog_symbol_properties.cpp.

179 {
180 switch( aCol )
181 {
182 case COL_NUMBER: return aPin.GetNumber();
183 case COL_BASE_NAME: return aPin.GetLibPin()->GetName();
184 case COL_ALT_NAME: return aPin.GetAlt();
185 case COL_TYPE: return PinTypeNames()[static_cast<int>( aPin.GetType() )];
186 case COL_SHAPE: return PinShapeNames()[static_cast<int>( aPin.GetShape() )];
187 default: wxFAIL; return wxEmptyString;
188 }
189 }
wxString GetAlt() const
Definition: sch_pin.h:64
LIB_PIN * GetLibPin() const
Definition: sch_pin.h:59
wxString GetNumber() const
Definition: sch_pin.h:134
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:125
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:116

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().

◆ GetValue() [2/2]

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

Definition at line 173 of file dialog_symbol_properties.cpp.

174 {
175 return GetValue( at( aRow ), aCol );
176 }

References GetValue().

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

◆ IsEmptyCell()

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

Definition at line 168 of file dialog_symbol_properties.cpp.

169 {
170 return false; // don't allow adjacent cell overflow, even if we are actually empty
171 }

◆ SetValue()

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

Definition at line 218 of file dialog_symbol_properties.cpp.

219 {
220 switch( aCol )
221 {
222 case COL_ALT_NAME:
223 if( aValue == at( aRow ).GetLibPin()->GetName() )
224 at( aRow ).SetAlt( wxEmptyString );
225 else
226 at( aRow ).SetAlt( aValue );
227 break;
228
229 case COL_NUMBER:
230 case COL_BASE_NAME:
231 case COL_TYPE:
232 case COL_SHAPE:
233 // Read-only.
234 break;
235
236 default:
237 wxFAIL;
238 break;
239 }
240 }

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

287 {
288 std::sort( begin(), end(),
289 [ aSortCol, ascending ]( const SCH_PIN& lhs, const SCH_PIN& rhs ) -> bool
290 {
291 return compare( lhs, rhs, aSortCol, ascending );
292 } );
293 }
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 74 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 75 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 77 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 76 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: