KiCad PCB EDA Suite
FIELDS_GRID_TABLE< T > Class Template Reference

#include <fields_grid_table.h>

Inheritance diagram for FIELDS_GRID_TABLE< T >:

Public Member Functions

 FIELDS_GRID_TABLE (DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, WX_GRID *aGrid, LIB_SYMBOL *aSymbol)
 
 FIELDS_GRID_TABLE (DIALOG_SHIM *aDialog, SCH_EDIT_FRAME *aFrame, WX_GRID *aGrid, SCH_SYMBOL *aSymbol)
 
 FIELDS_GRID_TABLE (DIALOG_SHIM *aDialog, SCH_EDIT_FRAME *aFrame, WX_GRID *aGrid, SCH_SHEET *aSheet)
 
 FIELDS_GRID_TABLE (DIALOG_SHIM *aDialog, SCH_EDIT_FRAME *aFrame, WX_GRID *aGrid, SCH_LABEL_BASE *aLabel)
 
 ~FIELDS_GRID_TABLE ()
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetColLabelValue (int aCol) override
 
bool IsEmptyCell (int row, int col) override
 
bool CanGetValueAs (int aRow, int aCol, const wxString &aTypeName) override
 
bool CanSetValueAs (int aRow, int aCol, const wxString &aTypeName) override
 
wxGridCellAttr * GetAttr (int row, int col, wxGridCellAttr::wxAttrKind kind) override
 
wxString GetValue (int aRow, int aCol) override
 
bool GetValueAsBool (int aRow, int aCol) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void SetValueAsBool (int aRow, int aCol, bool aValue) override
 
wxString StringFromBool (bool aValue) const
 
bool BoolFromString (wxString aValue) const
 

Protected Member Functions

void initGrid (WX_GRID *aGrid)
 
void onUnitsChanged (wxCommandEvent &aEvent)
 

Private Attributes

SCH_BASE_FRAMEm_frame
 
DIALOG_SHIMm_dialog
 
WX_GRIDm_grid
 
KICAD_T m_parentType
 
int m_mandatoryFieldCount
 
LIB_SYMBOLm_part
 
wxString m_symbolNetlist
 
wxString m_curdir
 
SCH_FIELD_VALIDATOR m_fieldNameValidator
 
SCH_FIELD_VALIDATOR m_referenceValidator
 
SCH_FIELD_VALIDATOR m_valueValidator
 
LIB_ID_VALIDATOR m_libIdValidator
 
SCH_FIELD_VALIDATOR m_urlValidator
 
SCH_FIELD_VALIDATOR m_nonUrlValidator
 
SCH_FIELD_VALIDATOR m_filepathValidator
 
wxGridCellAttr * m_readOnlyAttr
 
wxGridCellAttr * m_fieldNameAttr
 
wxGridCellAttr * m_referenceAttr
 
wxGridCellAttr * m_valueAttr
 
wxGridCellAttr * m_footprintAttr
 
wxGridCellAttr * m_urlAttr
 
wxGridCellAttr * m_nonUrlAttr
 
wxGridCellAttr * m_filepathAttr
 
wxGridCellAttr * m_boolAttr
 
wxGridCellAttr * m_vAlignAttr
 
wxGridCellAttr * m_hAlignAttr
 
wxGridCellAttr * m_orientationAttr
 
wxGridCellAttr * m_netclassAttr
 
wxGridCellAttr * m_fontAttr
 
wxGridCellAttr * m_colorAttr
 

Detailed Description

template<class T>
class FIELDS_GRID_TABLE< T >

Definition at line 75 of file fields_grid_table.h.

Constructor & Destructor Documentation

◆ FIELDS_GRID_TABLE() [1/4]

template<class T >
FIELDS_GRID_TABLE< T >::FIELDS_GRID_TABLE ( DIALOG_SHIM aDialog,
SCH_BASE_FRAME aFrame,
WX_GRID aGrid,
LIB_SYMBOL aSymbol 
)

Definition at line 92 of file fields_grid_table.cpp.

93 :
94 m_frame( aFrame ),
95 m_dialog( aDialog ),
96 m_grid( aGrid ),
99 m_part( aSymbol ),
107{
108 initGrid( aGrid );
109}
bool IsType(FRAME_T aType) const
LIB_ID_VALIDATOR m_libIdValidator
SCH_FIELD_VALIDATOR m_fieldNameValidator
DIALOG_SHIM * m_dialog
SCH_FIELD_VALIDATOR m_urlValidator
SCH_BASE_FRAME * m_frame
SCH_FIELD_VALIDATOR m_valueValidator
SCH_FIELD_VALIDATOR m_referenceValidator
SCH_FIELD_VALIDATOR m_nonUrlValidator
void initGrid(WX_GRID *aGrid)
SCH_FIELD_VALIDATOR m_filepathValidator
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ SHEETFILENAME
Definition: sch_sheet.h:44
#define FIELD_NAME
#define FIELD_VALUE
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ SCH_SYMBOL_T
Definition: typeinfo.h:147

◆ FIELDS_GRID_TABLE() [2/4]

template<class T >
FIELDS_GRID_TABLE< T >::FIELDS_GRID_TABLE ( DIALOG_SHIM aDialog,
SCH_EDIT_FRAME aFrame,
WX_GRID aGrid,
SCH_SYMBOL aSymbol 
)

Definition at line 113 of file fields_grid_table.cpp.

114 :
115 m_frame( aFrame ),
116 m_dialog( aDialog ),
117 m_grid( aGrid ),
120 m_part( aSymbol->GetLibSymbolRef().get() ),
121 m_symbolNetlist( netList( aSymbol, aFrame->GetCurrentSheet() ) ),
129{
130 initGrid( aGrid );
131}
SCH_SHEET_PATH & GetCurrentSheet() const
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:174
static wxString netList(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH &aSheetPath)

◆ FIELDS_GRID_TABLE() [3/4]

template<class T >
FIELDS_GRID_TABLE< T >::FIELDS_GRID_TABLE ( DIALOG_SHIM aDialog,
SCH_EDIT_FRAME aFrame,
WX_GRID aGrid,
SCH_SHEET aSheet 
)

Definition at line 135 of file fields_grid_table.cpp.

136 :
137 m_frame( aFrame ),
138 m_dialog( aDialog ),
139 m_grid( aGrid ),
142 m_part( nullptr ),
150{
151 initGrid( aGrid );
152}
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
#define SHEETFILENAME_V
#define SHEETNAME_V
@ SCH_SHEET_T
Definition: typeinfo.h:149

References FIELDS_GRID_TABLE< T >::initGrid().

◆ FIELDS_GRID_TABLE() [4/4]

template<class T >
FIELDS_GRID_TABLE< T >::FIELDS_GRID_TABLE ( DIALOG_SHIM aDialog,
SCH_EDIT_FRAME aFrame,
WX_GRID aGrid,
SCH_LABEL_BASE aLabel 
)

Definition at line 156 of file fields_grid_table.cpp.

157 :
158 m_frame( aFrame ),
159 m_dialog( aDialog ),
160 m_grid( aGrid ),
163 m_part( nullptr ),
171{
172 initGrid( aGrid );
173}
virtual int GetMandatoryFieldCount()
Definition: sch_label.h:81
@ SCH_LABEL_LOCATE_ANY_T
Definition: typeinfo.h:166

References FIELDS_GRID_TABLE< T >::initGrid().

◆ ~FIELDS_GRID_TABLE()

template<class T >
FIELDS_GRID_TABLE< T >::~FIELDS_GRID_TABLE

Definition at line 298 of file fields_grid_table.cpp.

299{
300 m_readOnlyAttr->DecRef();
301 m_fieldNameAttr->DecRef();
302 m_boolAttr->DecRef();
303 m_referenceAttr->DecRef();
304 m_valueAttr->DecRef();
305 m_footprintAttr->DecRef();
306 m_urlAttr->DecRef();
307 m_nonUrlAttr->DecRef();
308 m_filepathAttr->DecRef();
309 m_vAlignAttr->DecRef();
310 m_hAlignAttr->DecRef();
311 m_orientationAttr->DecRef();
312 m_netclassAttr->DecRef();
313 m_fontAttr->DecRef();
314 m_colorAttr->DecRef();
315
316 m_frame->Unbind( UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
317}
wxGridCellAttr * m_nonUrlAttr
wxGridCellAttr * m_readOnlyAttr
wxGridCellAttr * m_vAlignAttr
wxGridCellAttr * m_netclassAttr
wxGridCellAttr * m_boolAttr
wxGridCellAttr * m_footprintAttr
wxGridCellAttr * m_filepathAttr
wxGridCellAttr * m_orientationAttr
wxGridCellAttr * m_fontAttr
wxGridCellAttr * m_referenceAttr
wxGridCellAttr * m_colorAttr
wxGridCellAttr * m_urlAttr
wxGridCellAttr * m_valueAttr
wxGridCellAttr * m_fieldNameAttr
wxGridCellAttr * m_hAlignAttr

Member Function Documentation

◆ BoolFromString()

template<class T >
bool FIELDS_GRID_TABLE< T >::BoolFromString ( wxString  aValue) const

Definition at line 852 of file fields_grid_table.cpp.

853{
854 if( aValue == "1" )
855 {
856 return true;
857 }
858 else if( aValue == "0" )
859 {
860 return false;
861 }
862 else
863 {
864 wxFAIL_MSG( wxString::Format( "string '%s' can't be converted to boolean correctly and "
865 "will be perceived as FALSE", aValue ) );
866 return false;
867 }
868}
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format().

◆ CanGetValueAs()

template<class T >
bool FIELDS_GRID_TABLE< T >::CanGetValueAs ( int  aRow,
int  aCol,
const wxString &  aTypeName 
)
override

Definition at line 354 of file fields_grid_table.cpp.

355{
356 switch( aCol )
357 {
358 case FDC_NAME:
359 case FDC_VALUE:
360 case FDC_H_ALIGN:
361 case FDC_V_ALIGN:
362 case FDC_TEXT_SIZE:
363 case FDC_ORIENTATION:
364 case FDC_POSX:
365 case FDC_POSY:
366 case FDC_FONT:
367 case FDC_COLOR:
368 return aTypeName == wxGRID_VALUE_STRING;
369
370 case FDC_SHOWN:
371 case FDC_ITALIC:
372 case FDC_BOLD:
373 return aTypeName == wxGRID_VALUE_BOOL;
374
375 default:
376 wxFAIL;
377 return false;
378 }
379}
@ FDC_TEXT_SIZE
@ FDC_BOLD
@ FDC_POSY
@ FDC_ITALIC
@ FDC_NAME
@ FDC_H_ALIGN
@ FDC_COLOR
@ FDC_SHOWN
@ FDC_VALUE
@ FDC_POSX
@ FDC_ORIENTATION
@ FDC_V_ALIGN
@ FDC_FONT

References FDC_BOLD, FDC_COLOR, FDC_FONT, FDC_H_ALIGN, FDC_ITALIC, FDC_NAME, FDC_ORIENTATION, FDC_POSX, FDC_POSY, FDC_SHOWN, FDC_TEXT_SIZE, FDC_V_ALIGN, and FDC_VALUE.

◆ CanSetValueAs()

template<class T >
bool FIELDS_GRID_TABLE< T >::CanSetValueAs ( int  aRow,
int  aCol,
const wxString &  aTypeName 
)
override

Definition at line 383 of file fields_grid_table.cpp.

384{
385 return CanGetValueAs( aRow, aCol, aTypeName );
386}
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override

◆ GetAttr()

template<class T >
wxGridCellAttr * FIELDS_GRID_TABLE< T >::GetAttr ( int  row,
int  col,
wxGridCellAttr::wxAttrKind  kind 
)
override

Definition at line 390 of file fields_grid_table.cpp.

391{
392 wxGridCellAttr* tmp;
393
394 switch( aCol )
395 {
396 case FDC_NAME:
397 if( aRow < m_mandatoryFieldCount )
398 {
399 tmp = m_fieldNameAttr->Clone();
400 tmp->SetReadOnly( true );
401 return tmp;
402 }
403 else
404 {
405 m_fieldNameAttr->IncRef();
406 return m_fieldNameAttr;
407 }
408
409 case FDC_VALUE:
410 if( m_parentType == SCH_SYMBOL_T && aRow == REFERENCE_FIELD )
411 {
412 m_referenceAttr->IncRef();
413 return m_referenceAttr;
414 }
415 else if( m_parentType == SCH_SYMBOL_T && aRow == VALUE_FIELD )
416 {
417 // For power symbols, the value is not editable, because value and pin name must
418 // be the same and can be edited only in library editor.
420 {
421 tmp = m_readOnlyAttr->Clone();
422 tmp->SetReadOnly( true );
423 tmp->SetTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
424 return tmp;
425 }
426 else
427 {
428 m_valueAttr->IncRef();
429 return m_valueAttr;
430 }
431 }
432 else if( m_parentType == SCH_SYMBOL_T && aRow == FOOTPRINT_FIELD )
433 {
434 m_footprintAttr->IncRef();
435 return m_footprintAttr;
436 }
437 else if( m_parentType == SCH_SYMBOL_T && aRow == DATASHEET_FIELD )
438 {
439 m_urlAttr->IncRef();
440 return m_urlAttr;
441 }
442 else if( m_parentType == SCH_SHEET_T && aRow == SHEETNAME )
443 {
444 m_referenceAttr->IncRef();
445 return m_referenceAttr;
446 }
447 else if( m_parentType == SCH_SHEET_T && aRow == SHEETFILENAME )
448 {
449 m_filepathAttr->IncRef();
450 return m_filepathAttr;
451 }
453 && this->at( (size_t) aRow ).GetCanonicalName() == wxT( "Netclass" ) )
454 {
455 m_netclassAttr->IncRef();
456 return m_netclassAttr;
457 }
458 else
459 {
460 wxString fn = GetValue( aRow, FDC_NAME );
461
463
464 const TEMPLATE_FIELDNAME* templateFn =
465 settings ? settings->m_TemplateFieldNames.GetFieldName( fn ) : nullptr;
466
467 if( templateFn && templateFn->m_URL )
468 {
469 m_urlAttr->IncRef();
470 return m_urlAttr;
471 }
472 else
473 {
474 m_nonUrlAttr->IncRef();
475 return m_nonUrlAttr;
476 }
477 }
478
479 case FDC_TEXT_SIZE:
480 case FDC_POSX:
481 case FDC_POSY:
482 return nullptr;
483
484 case FDC_H_ALIGN:
485 m_hAlignAttr->IncRef();
486 return m_hAlignAttr;
487
488 case FDC_V_ALIGN:
489 m_vAlignAttr->IncRef();
490 return m_vAlignAttr;
491
492 case FDC_ORIENTATION:
493 m_orientationAttr->IncRef();
494 return m_orientationAttr;
495
496 case FDC_SHOWN:
497 case FDC_ITALIC:
498 case FDC_BOLD:
499 m_boolAttr->IncRef();
500 return m_boolAttr;
501
502 case FDC_FONT:
503 m_fontAttr->IncRef();
504 return m_fontAttr;
505
506 case FDC_COLOR:
507 m_colorAttr->IncRef();
508 return m_colorAttr;
509
510 default:
511 wxFAIL;
512 return nullptr;
513 }
514}
wxString GetValue(int aRow, int aCol) override
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
bool IsPower() const
Definition: lib_symbol.cpp:473
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
These settings were stored in SCH_BASE_FRAME previously.
TEMPLATES m_TemplateFieldNames
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
@ SHEETNAME
Definition: sch_sheet.h:43
Hold a name of a symbol's field, field value, and default visibility.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".

References DATASHEET_FIELD, FDC_BOLD, FDC_COLOR, FDC_FONT, FDC_H_ALIGN, FDC_ITALIC, FDC_NAME, FDC_ORIENTATION, FDC_POSX, FDC_POSY, FDC_SHOWN, FDC_TEXT_SIZE, FDC_V_ALIGN, FDC_VALUE, FOOTPRINT_FIELD, FRAME_SCH_SYMBOL_EDITOR, TEMPLATES::GetFieldName(), SCHEMATIC_SETTINGS::m_TemplateFieldNames, TEMPLATE_FIELDNAME::m_URL, REFERENCE_FIELD, SCH_LABEL_LOCATE_ANY_T, SCH_SHEET_T, SCH_SYMBOL_T, SHEETFILENAME, SHEETNAME, and VALUE_FIELD.

◆ GetColLabelValue()

template<class T >
wxString FIELDS_GRID_TABLE< T >::GetColLabelValue ( int  aCol)
override

Definition at line 331 of file fields_grid_table.cpp.

332{
333 switch( aCol )
334 {
335 case FDC_NAME: return _( "Name" );
336 case FDC_VALUE: return _( "Value" );
337 case FDC_SHOWN: return _( "Show" );
338 case FDC_H_ALIGN: return _( "H Align" );
339 case FDC_V_ALIGN: return _( "V Align" );
340 case FDC_ITALIC: return _( "Italic" );
341 case FDC_BOLD: return _( "Bold" );
342 case FDC_TEXT_SIZE: return _( "Text Size" );
343 case FDC_ORIENTATION: return _( "Orientation" );
344 case FDC_POSX: return _( "X Position" );
345 case FDC_POSY: return _( "Y Position" );
346 case FDC_FONT: return _( "Font" );
347 case FDC_COLOR: return _( "Color" );
348 default: wxFAIL; return wxEmptyString;
349 }
350}
#define _(s)

References _, FDC_BOLD, FDC_COLOR, FDC_FONT, FDC_H_ALIGN, FDC_ITALIC, FDC_NAME, FDC_ORIENTATION, FDC_POSX, FDC_POSY, FDC_SHOWN, FDC_TEXT_SIZE, FDC_V_ALIGN, and FDC_VALUE.

◆ GetNumberCols()

template<class T >
int FIELDS_GRID_TABLE< T >::GetNumberCols ( )
inlineoverride

Definition at line 89 of file fields_grid_table.h.

89{ return FDC_COUNT; }
@ FDC_COUNT

References FDC_COUNT.

◆ GetNumberRows()

template<class T >
int FIELDS_GRID_TABLE< T >::GetNumberRows ( )
inlineoverride

Definition at line 88 of file fields_grid_table.h.

88{ return (int) this->size(); }

Referenced by DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown(), and DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow().

◆ GetValue()

template<class T >
wxString FIELDS_GRID_TABLE< T >::GetValue ( int  aRow,
int  aCol 
)
override

Definition at line 518 of file fields_grid_table.cpp.

519{
520 wxCHECK( aRow < GetNumberRows(), wxEmptyString );
521 const T& field = this->at( (size_t) aRow );
522
523 switch( aCol )
524 {
525 case FDC_NAME:
526 // Use default field names for mandatory and system fields because they are translated
527 // according to the current locale
529 {
530 if( aRow < m_mandatoryFieldCount )
532 else
533 return field.GetName( false );
534 }
535 else if( m_parentType == SCH_SHEET_T )
536 {
537 if( aRow < m_mandatoryFieldCount )
538 return SCH_SHEET::GetDefaultFieldName( aRow );
539 else
540 return field.GetName( false );
541 }
543 {
544 return SCH_LABEL_BASE::GetDefaultFieldName( field.GetCanonicalName(), false );
545 }
546 else
547 {
548 wxFAIL_MSG( "Unhandled field owner type." );
549 return field.GetName( false );
550 }
551
552 case FDC_VALUE:
553 return UnescapeString( field.GetText() );
554
555 case FDC_SHOWN:
556 return StringFromBool( field.IsVisible() );
557
558 case FDC_H_ALIGN:
559 switch ( field.GetHorizJustify() )
560 {
561 case GR_TEXT_H_ALIGN_LEFT: return _( "Left" );
562 case GR_TEXT_H_ALIGN_CENTER: return _( "Center" );
563 case GR_TEXT_H_ALIGN_RIGHT: return _( "Right" );
564 }
565
566 break;
567
568 case FDC_V_ALIGN:
569 switch ( field.GetVertJustify() )
570 {
571 case GR_TEXT_V_ALIGN_TOP: return _( "Top" );
572 case GR_TEXT_V_ALIGN_CENTER: return _( "Center" );
573 case GR_TEXT_V_ALIGN_BOTTOM: return _( "Bottom" );
574 }
575
576 break;
577
578 case FDC_ITALIC:
579 return StringFromBool( field.IsItalic() );
580
581 case FDC_BOLD:
582 return StringFromBool( field.IsBold() );
583
584 case FDC_TEXT_SIZE:
585 return StringFromValue( m_frame->GetUserUnits(), field.GetTextHeight(), true );
586
587 case FDC_ORIENTATION:
588 if( field.GetTextAngle().IsHorizontal() )
589 return _( "Horizontal" );
590 else
591 return _( "Vertical" );
592
593 case FDC_POSX:
594 return StringFromValue( m_frame->GetUserUnits(), field.GetTextPos().x, true );
595
596 case FDC_POSY:
597 return StringFromValue( m_frame->GetUserUnits(), field.GetTextPos().y, true );
598
599 case FDC_FONT:
600 if( field.GetFont() )
601 return field.GetFont()->GetName();
602 else
603 return DEFAULT_FONT_NAME;
604
605 case FDC_COLOR:
606 return field.GetTextColor().ToWxString( wxC2S_CSS_SYNTAX );
607
608 default:
609 // we can't assert here because wxWidgets sometimes calls this without checking
610 // the column type when trying to see if there's an overflow
611 break;
612 }
613
614 return wxT( "bad wxWidgets!" );
615}
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:209
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
wxString StringFromBool(bool aValue) const
int GetNumberRows() override
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Definition: sch_label.cpp:180
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:53
#define DEFAULT_FONT_NAME
wxString UnescapeString(const wxString &aSource)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
#define DO_TRANSLATE
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP

References _, DEFAULT_FONT_NAME, DO_TRANSLATE, FDC_BOLD, FDC_COLOR, FDC_FONT, FDC_H_ALIGN, FDC_ITALIC, FDC_NAME, FDC_ORIENTATION, FDC_POSX, FDC_POSY, FDC_SHOWN, FDC_TEXT_SIZE, FDC_V_ALIGN, FDC_VALUE, SCH_LABEL_BASE::GetDefaultFieldName(), SCH_SHEET::GetDefaultFieldName(), TEMPLATE_FIELDNAME::GetDefaultFieldName(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, SCH_LABEL_LOCATE_ANY_T, SCH_SHEET_T, SCH_SYMBOL_T, StringFromValue(), and UnescapeString().

◆ GetValueAsBool()

template<class T >
bool FIELDS_GRID_TABLE< T >::GetValueAsBool ( int  aRow,
int  aCol 
)
override

Definition at line 619 of file fields_grid_table.cpp.

620{
621 wxCHECK( aRow < GetNumberRows(), false );
622 const T& field = this->at( (size_t) aRow );
623
624 switch( aCol )
625 {
626 case FDC_SHOWN: return field.IsVisible();
627 case FDC_ITALIC: return field.IsItalic();
628 case FDC_BOLD: return field.IsBold();
629 default:
630 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
631 return false;
632 }
633}

References FDC_BOLD, FDC_ITALIC, FDC_SHOWN, and Format().

◆ initGrid()

template<class T >
void FIELDS_GRID_TABLE< T >::initGrid ( WX_GRID aGrid)
protected

Definition at line 177 of file fields_grid_table.cpp.

178{
179 // Build the various grid cell attributes.
180 // NOTE: validators and cellAttrs are member variables to get the destruction order
181 // right. wxGrid is VERY cranky about this.
182
183 m_readOnlyAttr = new wxGridCellAttr;
184 m_readOnlyAttr->SetReadOnly( true );
185
186 m_fieldNameAttr = new wxGridCellAttr;
188 nameEditor->SetValidator( m_fieldNameValidator );
189 m_fieldNameAttr->SetEditor( nameEditor );
190
191 m_referenceAttr = new wxGridCellAttr;
192 GRID_CELL_TEXT_EDITOR* referenceEditor = new GRID_CELL_TEXT_EDITOR();
193 referenceEditor->SetValidator( m_referenceValidator );
194 m_referenceAttr->SetEditor( referenceEditor );
195
196 m_valueAttr = new wxGridCellAttr;
197 GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
198 valueEditor->SetValidator( m_valueValidator );
199 m_valueAttr->SetEditor( valueEditor );
200
201 m_footprintAttr = new wxGridCellAttr;
203 fpIdEditor->SetValidator( m_libIdValidator );
204 m_footprintAttr->SetEditor( fpIdEditor );
205
206 m_urlAttr = new wxGridCellAttr;
208 m_frame->Prj().SchSearchS() );
209 urlEditor->SetValidator( m_urlValidator );
210 m_urlAttr->SetEditor( urlEditor );
211
212 m_nonUrlAttr = new wxGridCellAttr;
213 GRID_CELL_TEXT_EDITOR* nonUrlEditor = new GRID_CELL_TEXT_EDITOR();
214 nonUrlEditor->SetValidator( m_nonUrlValidator );
215 m_nonUrlAttr->SetEditor( nonUrlEditor );
216
218 m_filepathAttr = new wxGridCellAttr;
219
220 // Create a wild card using wxFileDialog syntax.
221 wxString wildCard( _( "Schematic Files" ) );
222 std::vector<std::string> exts;
223 exts.push_back( KiCadSchematicFileExtension );
224 wildCard += AddFileExtListToFilter( exts );
225
226 auto filepathEditor = new GRID_CELL_PATH_EDITOR( m_dialog, aGrid, &m_curdir, wildCard );
227 filepathEditor->SetValidator( m_filepathValidator );
228 m_filepathAttr->SetEditor( filepathEditor );
229
230 m_boolAttr = new wxGridCellAttr;
231 m_boolAttr->SetRenderer( new wxGridCellBoolRenderer() );
232 m_boolAttr->SetEditor( new wxGridCellBoolEditor() );
233 m_boolAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
234
235 wxArrayString vAlignNames;
236 vAlignNames.Add( _( "Top" ) );
237 vAlignNames.Add( _( "Center" ) );
238 vAlignNames.Add( _( "Bottom" ) );
239 m_vAlignAttr = new wxGridCellAttr;
240 m_vAlignAttr->SetEditor( new wxGridCellChoiceEditor( vAlignNames ) );
241 m_vAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
242
243 wxArrayString hAlignNames;
244 hAlignNames.Add( _( "Left" ) );
245 hAlignNames.Add(_( "Center" ) );
246 hAlignNames.Add(_( "Right" ) );
247 m_hAlignAttr = new wxGridCellAttr;
248 m_hAlignAttr->SetEditor( new wxGridCellChoiceEditor( hAlignNames ) );
249 m_hAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
250
251 wxArrayString orientationNames;
252 orientationNames.Add( _( "Horizontal" ) );
253 orientationNames.Add(_( "Vertical" ) );
254 m_orientationAttr = new wxGridCellAttr;
255 m_orientationAttr->SetEditor( new wxGridCellChoiceEditor( orientationNames ) );
256 m_orientationAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );
257
258 SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
259 wxArrayString existingNetclasses;
260
261 if( editFrame )
262 {
263 // Load the combobox with existing existingNetclassNames
264 NET_SETTINGS& netSettings = editFrame->Schematic().Prj().GetProjectFile().NetSettings();
265
266 existingNetclasses.push_back( netSettings.m_NetClasses.GetDefault()->GetName() );
267
268 for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
269 existingNetclasses.push_back( pair.second->GetName() );
270 }
271
272 m_netclassAttr = new wxGridCellAttr;
273 m_netclassAttr->SetEditor( new GRID_CELL_COMBOBOX( existingNetclasses ) );
274
275 wxArrayString fonts;
276 std::vector<std::string> fontNames;
277 Fontconfig()->ListFonts( fontNames );
278
279 for( const std::string& name : fontNames )
280 fonts.Add( wxString( name ) );
281
282 fonts.Sort();
283 fonts.Insert( KICAD_FONT_NAME, 0 );
284 fonts.Insert( DEFAULT_FONT_NAME, 0 );
285
286 m_fontAttr = new wxGridCellAttr;
287 m_fontAttr->SetEditor( new GRID_CELL_COMBOBOX( fonts ) );
288
289 m_colorAttr = new wxGridCellAttr;
290 m_colorAttr->SetRenderer( new GRID_CELL_COLOR_RENDERER( m_dialog ) );
291 m_colorAttr->SetEditor( new GRID_CELL_COLOR_SELECTOR( m_dialog, aGrid ) );
292
293 m_frame->Bind( UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
294}
const char * name
Definition: DXF_plotter.cpp:56
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
Definition: validators.h:45
virtual void SetValidator(const wxValidator &validator) override
Definition: validators.cpp:46
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:33
NETCLASSES m_NetClasses
Definition: net_settings.h:40
NET_SETTINGS & NetSettings()
Definition: project_file.h:96
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
FONTCONFIG * Fontconfig()
Definition: fontconfig.cpp:52
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
const std::string KiCadSchematicFileExtension
#define KICAD_FONT_NAME

References _, AddFileExtListToFilter(), DEFAULT_FONT_NAME, Fontconfig(), fonts, NETCLASSES::GetDefault(), PROJECT::GetProjectFile(), KICAD_FONT_NAME, KiCadSchematicFileExtension, NET_SETTINGS::m_NetClasses, name, PROJECT_FILE::NetSettings(), SCHEMATIC::Prj(), SCH_EDIT_FRAME::Schematic(), and GRID_CELL_TEXT_EDITOR::SetValidator().

Referenced by FIELDS_GRID_TABLE< T >::FIELDS_GRID_TABLE(), and FIELDS_GRID_TABLE< SCH_FIELD >::onUnitsChanged().

◆ IsEmptyCell()

template<class T >
bool FIELDS_GRID_TABLE< T >::IsEmptyCell ( int  row,
int  col 
)
inlineoverride

Definition at line 93 of file fields_grid_table.h.

94 {
95 return false; // don't allow adjacent cell overflow, even if we are actually empty
96 }

◆ onUnitsChanged()

template<class T >
void FIELDS_GRID_TABLE< T >::onUnitsChanged ( wxCommandEvent &  aEvent)
protected

Definition at line 321 of file fields_grid_table.cpp.

322{
323 if( GetView() )
324 GetView()->ForceRefresh();
325
326 aEvent.Skip();
327}

◆ SetValue()

template<class T >
void FIELDS_GRID_TABLE< T >::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
override

Definition at line 637 of file fields_grid_table.cpp.

638{
639 wxCHECK( aRow < GetNumberRows(), /*void*/ );
640 T& field = this->at( (size_t) aRow );
641 VECTOR2I pos;
642
643 switch( aCol )
644 {
645 case FDC_NAME:
646 field.SetName( aValue );
647 break;
648
649 case FDC_VALUE:
650 {
651 wxString value( aValue );
652
653 if( m_parentType == SCH_SHEET_T && aRow == SHEETFILENAME )
654 {
655 wxFileName fn( value );
656
657 // It's annoying to throw up nag dialogs when the extension isn't right. Just
658 // fix it.
659 if( fn.GetExt().CmpNoCase( KiCadSchematicFileExtension ) != 0 )
660 {
661 fn.SetExt( KiCadSchematicFileExtension );
662 value = fn.GetFullPath();
663 }
664 }
665 else if( m_parentType == LIB_SYMBOL_T && aRow == VALUE_FIELD )
666 {
667 value = EscapeString( value, CTX_LIBID );
668 }
669
670 field.SetText( value );
671 break;
672 }
673
674 case FDC_SHOWN:
675 field.SetVisible( BoolFromString( aValue ) );
676 break;
677
678 case FDC_H_ALIGN:
679 if( aValue == _( "Left" ) )
680 field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
681 else if( aValue == _( "Center" ) )
682 field.SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
683 else if( aValue == _( "Right" ) )
684 field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
685 else
686 wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + aValue );
687
688 break;
689
690 case FDC_V_ALIGN:
691 if( aValue == _( "Top" ) )
692 field.SetVertJustify( GR_TEXT_V_ALIGN_TOP );
693 else if( aValue == _( "Center" ) )
694 field.SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
695 else if( aValue == _( "Bottom" ) )
696 field.SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
697 else
698 wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + aValue);
699
700 break;
701
702 case FDC_ITALIC:
703 field.SetItalic( BoolFromString( aValue ) );
704 break;
705
706 case FDC_BOLD:
707 field.SetBold( BoolFromString( aValue ) );
708 break;
709
710 case FDC_TEXT_SIZE:
711 field.SetTextSize( wxSize( ValueFromString( m_frame->GetUserUnits(), aValue ),
712 ValueFromString( m_frame->GetUserUnits(), aValue ) ) );
713 break;
714
715 case FDC_ORIENTATION:
716 if( aValue == _( "Horizontal" ) )
717 field.SetTextAngle( ANGLE_HORIZONTAL );
718 else if( aValue == _( "Vertical" ) )
719 field.SetTextAngle( ANGLE_VERTICAL );
720 else
721 wxFAIL_MSG( wxT( "unknown orientation: " ) + aValue );
722
723 break;
724
725 case FDC_POSX:
726 case FDC_POSY:
727 pos = field.GetTextPos();
728
729 if( aCol == FDC_POSX )
730 pos.x = ValueFromString( m_frame->GetUserUnits(), aValue );
731 else
732 pos.y = ValueFromString( m_frame->GetUserUnits(), aValue );
733
734 field.SetTextPos( pos );
735 break;
736
737 case FDC_FONT:
738 if( aValue == DEFAULT_FONT_NAME )
739 field.SetFont( nullptr );
740 else if( aValue == KICAD_FONT_NAME )
741 field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(), field.IsItalic() ) );
742 else
743 field.SetFont( KIFONT::FONT::GetFont( aValue, field.IsBold(), field.IsItalic() ) );
744
745 break;
746
747 case FDC_COLOR:
748 field.SetTextColor( wxColor( aValue ) );
749 break;
750
751 default:
752 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
753 break;
754 }
755
757
758 GetView()->Refresh();
759}
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:383
void OnModify()
bool BoolFromString(wxString aValue) const
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:65
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:419
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:420
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
Definition: string_utils.h:55
@ LIB_SYMBOL_T
Definition: typeinfo.h:189

References _, ANGLE_HORIZONTAL, ANGLE_VERTICAL, CTX_LIBID, DEFAULT_FONT_NAME, EscapeString(), FDC_BOLD, FDC_COLOR, FDC_FONT, FDC_H_ALIGN, FDC_ITALIC, FDC_NAME, FDC_ORIENTATION, FDC_POSX, FDC_POSY, FDC_SHOWN, FDC_TEXT_SIZE, FDC_V_ALIGN, FDC_VALUE, Format(), KIFONT::FONT::GetFont(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP, KICAD_FONT_NAME, KiCadSchematicFileExtension, LIB_SYMBOL_T, SCH_SHEET_T, SHEETFILENAME, VALUE_FIELD, ValueFromString(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SetValueAsBool()

template<class T >
void FIELDS_GRID_TABLE< T >::SetValueAsBool ( int  aRow,
int  aCol,
bool  aValue 
)
override

Definition at line 763 of file fields_grid_table.cpp.

764{
765 wxCHECK( aRow < GetNumberRows(), /*void*/ );
766 T& field = this->at( (size_t) aRow );
767
768 switch( aCol )
769 {
770 case FDC_SHOWN:
771 field.SetVisible( aValue );
772 break;
773
774 case FDC_ITALIC:
775 field.SetItalic( aValue );
776 break;
777
778 case FDC_BOLD:
779 field.SetBold( aValue );
780 break;
781
782 default:
783 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
784 break;
785 }
786
788}

References FDC_BOLD, FDC_ITALIC, FDC_SHOWN, and Format().

◆ StringFromBool()

template<class T >
wxString FIELDS_GRID_TABLE< T >::StringFromBool ( bool  aValue) const

Definition at line 842 of file fields_grid_table.cpp.

843{
844 if( aValue )
845 return wxT( "1" );
846 else
847 return wxT( "0" );
848}

Member Data Documentation

◆ m_boolAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_boolAttr
private

Definition at line 142 of file fields_grid_table.h.

◆ m_colorAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_colorAttr
private

Definition at line 148 of file fields_grid_table.h.

◆ m_curdir

template<class T >
wxString FIELDS_GRID_TABLE< T >::m_curdir
private

Definition at line 124 of file fields_grid_table.h.

◆ m_dialog

template<class T >
DIALOG_SHIM* FIELDS_GRID_TABLE< T >::m_dialog
private

Definition at line 118 of file fields_grid_table.h.

◆ m_fieldNameAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_fieldNameAttr
private

Definition at line 135 of file fields_grid_table.h.

◆ m_fieldNameValidator

template<class T >
SCH_FIELD_VALIDATOR FIELDS_GRID_TABLE< T >::m_fieldNameValidator
private

Definition at line 126 of file fields_grid_table.h.

◆ m_filepathAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_filepathAttr
private

Definition at line 141 of file fields_grid_table.h.

◆ m_filepathValidator

template<class T >
SCH_FIELD_VALIDATOR FIELDS_GRID_TABLE< T >::m_filepathValidator
private

Definition at line 132 of file fields_grid_table.h.

◆ m_fontAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_fontAttr
private

Definition at line 147 of file fields_grid_table.h.

◆ m_footprintAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_footprintAttr
private

Definition at line 138 of file fields_grid_table.h.

◆ m_frame

template<class T >
SCH_BASE_FRAME* FIELDS_GRID_TABLE< T >::m_frame
private

Definition at line 117 of file fields_grid_table.h.

◆ m_grid

template<class T >
WX_GRID* FIELDS_GRID_TABLE< T >::m_grid
private

Definition at line 119 of file fields_grid_table.h.

◆ m_hAlignAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_hAlignAttr
private

Definition at line 144 of file fields_grid_table.h.

◆ m_libIdValidator

template<class T >
LIB_ID_VALIDATOR FIELDS_GRID_TABLE< T >::m_libIdValidator
private

Definition at line 129 of file fields_grid_table.h.

◆ m_mandatoryFieldCount

template<class T >
int FIELDS_GRID_TABLE< T >::m_mandatoryFieldCount
private

Definition at line 121 of file fields_grid_table.h.

◆ m_netclassAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_netclassAttr
private

Definition at line 146 of file fields_grid_table.h.

◆ m_nonUrlAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_nonUrlAttr
private

Definition at line 140 of file fields_grid_table.h.

◆ m_nonUrlValidator

template<class T >
SCH_FIELD_VALIDATOR FIELDS_GRID_TABLE< T >::m_nonUrlValidator
private

Definition at line 131 of file fields_grid_table.h.

◆ m_orientationAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_orientationAttr
private

Definition at line 145 of file fields_grid_table.h.

◆ m_parentType

template<class T >
KICAD_T FIELDS_GRID_TABLE< T >::m_parentType
private

Definition at line 120 of file fields_grid_table.h.

◆ m_part

template<class T >
LIB_SYMBOL* FIELDS_GRID_TABLE< T >::m_part
private

Definition at line 122 of file fields_grid_table.h.

◆ m_readOnlyAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_readOnlyAttr
private

Definition at line 134 of file fields_grid_table.h.

◆ m_referenceAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_referenceAttr
private

Definition at line 136 of file fields_grid_table.h.

◆ m_referenceValidator

template<class T >
SCH_FIELD_VALIDATOR FIELDS_GRID_TABLE< T >::m_referenceValidator
private

Definition at line 127 of file fields_grid_table.h.

◆ m_symbolNetlist

template<class T >
wxString FIELDS_GRID_TABLE< T >::m_symbolNetlist
private

Definition at line 123 of file fields_grid_table.h.

◆ m_urlAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_urlAttr
private

Definition at line 139 of file fields_grid_table.h.

◆ m_urlValidator

template<class T >
SCH_FIELD_VALIDATOR FIELDS_GRID_TABLE< T >::m_urlValidator
private

Definition at line 130 of file fields_grid_table.h.

◆ m_vAlignAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_vAlignAttr
private

Definition at line 143 of file fields_grid_table.h.

◆ m_valueAttr

template<class T >
wxGridCellAttr* FIELDS_GRID_TABLE< T >::m_valueAttr
private

Definition at line 137 of file fields_grid_table.h.

◆ m_valueValidator

template<class T >
SCH_FIELD_VALIDATOR FIELDS_GRID_TABLE< T >::m_valueValidator
private

Definition at line 128 of file fields_grid_table.h.


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