KiCad PCB EDA Suite
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES Class Reference

#include <panel_eeschema_template_fieldnames.h>

Inheritance diagram for PANEL_EESCHEMA_TEMPLATE_FIELDNAMES:
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE

Public Member Functions

 PANEL_EESCHEMA_TEMPLATE_FIELDNAMES (SCH_EDIT_FRAME *aFrame, wxWindow *aWindow)
 
 ~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES () override
 

Protected Member Functions

void OnAddButtonClick (wxCommandEvent &event) override
 Function OnAddButtonClick Process the wxWidgets event produced when the user presses the Add buton for the template fieldnames control. More...
 
void OnDeleteButtonClick (wxCommandEvent &event) override
 Function OnDeleteButtonClick Process the wxWidgets event produced when the user presses the Delete button for the template fieldnames control. More...
 

Protected Attributes

SCH_EDIT_FRAMEm_frame
 
TEMPLATE_FIELDNAMES m_fields
 
int m_checkboxColWidth
 
WX_GRIDm_grid
 
wxBitmapButton * m_addFieldButton
 
wxBitmapButton * m_deleteFieldButton
 

Private Member Functions

void AdjustGridColumns (int aWidth)
 
void OnSizeGrid (wxSizeEvent &event) override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
bool TransferDataToGrid ()
 
bool TransferDataFromGrid ()
 

Detailed Description

Definition at line 29 of file panel_eeschema_template_fieldnames.h.

Constructor & Destructor Documentation

PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES ( SCH_EDIT_FRAME aFrame,
wxWindow *  aWindow 
)

Definition at line 35 of file panel_eeschema_template_fieldnames.cpp.

References KiBitmap(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_addFieldButton, m_checkboxColWidth, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_deleteFieldButton, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

36  :
38  m_frame( aFrame )
39 {
40  m_addFieldButton->SetBitmap( KiBitmap( small_plus_xpm ) );
41  m_deleteFieldButton->SetBitmap( KiBitmap( trash_xpm ) );
42 
43  m_checkboxColWidth = m_grid->GetColSize( 1 );
44 
45  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
46 }
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:51
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES ( )
override

Definition at line 49 of file panel_eeschema_template_fieldnames.cpp.

References PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

50 {
51  // Delete the GRID_TRICKS.
52  m_grid->PopEventHandler( true );
53 }

Member Function Documentation

void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::AdjustGridColumns ( int  aWidth)
private

Definition at line 164 of file panel_eeschema_template_fieldnames.cpp.

References m_checkboxColWidth, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by OnSizeGrid().

165 {
166  if( aWidth <= 0 )
167  return;
168 
169  // Account for scroll bars
170  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
171 
172  m_grid->SetColSize( 0, aWidth - 2 * m_checkboxColWidth );
173  m_grid->SetColSize( 1, m_checkboxColWidth );
174  m_grid->SetColSize( 2, m_checkboxColWidth );
175 }
void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::OnAddButtonClick ( wxCommandEvent &  event)
overrideprotectedvirtual

Function OnAddButtonClick Process the wxWidgets event produced when the user presses the Add buton for the template fieldnames control.

Parameters
eventThe wxWidgets produced event information

Adds a new template fieldname (with default values) to the template fieldnames data

Reimplemented from PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE.

Definition at line 63 of file panel_eeschema_template_fieldnames.cpp.

References WX_GRID::CommitPendingChanges(), m_fields, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid, TEMPLATE_FIELDNAME::m_Visible, TransferDataFromGrid(), and TransferDataToGrid().

64 {
66  return;
67 
68  int row = m_grid->GetNumberRows();
70 
71  TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( "Fieldname" );
72  newFieldname.m_Visible = false;
73  m_fields.insert( m_fields.end(), newFieldname );
75 
76  // wx documentation is wrong, SetGridCursor does not make visible.
77  m_grid->MakeCellVisible( row, 0 );
78  m_grid->SetGridCursor( row, 0 );
79 }
bool m_Visible
If first appearance of the field&#39;s editor has as visible.
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
Struct TEMPLATE_FIELDNAME holds a name of a component&#39;s field, field value, and default visibility...
void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::OnDeleteButtonClick ( wxCommandEvent &  event)
overrideprotectedvirtual

Function OnDeleteButtonClick Process the wxWidgets event produced when the user presses the Delete button for the template fieldnames control.

Parameters
eventThe wxWidgets produced event information

Deletes the selected template fieldname from the template fieldnames data

Reimplemented from PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE.

Definition at line 82 of file panel_eeschema_template_fieldnames.cpp.

References WX_GRID::CommitPendingChanges(), m_fields, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid, and max.

83 {
85  return;
86 
87  int curRow = m_grid->GetGridCursorRow();
88 
89  if( curRow >= 0 )
90  {
91  m_fields.erase( m_fields.begin() + curRow );
92  m_grid->DeleteRows( curRow );
93  }
94 
95  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
96  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
97 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
#define max(a, b)
Definition: auxiliary.h:86
void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::OnSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE.

Definition at line 178 of file panel_eeschema_template_fieldnames.cpp.

References AdjustGridColumns().

179 {
180  AdjustGridColumns( event.GetSize().GetX() );
181 
182  event.Skip();
183 }
bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromGrid ( )
private

Definition at line 134 of file panel_eeschema_template_fieldnames.cpp.

References WX_GRID::CommitPendingChanges(), m_fields, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by OnAddButtonClick(), and TransferDataFromWindow().

135 {
136  if( !m_grid->CommitPendingChanges() )
137  return false;
138 
139  for( int row = 0; row < m_grid->GetNumberRows(); ++row )
140  {
141  m_fields[row].m_Name = m_grid->GetCellValue( row, 0 );
142  m_fields[row].m_Visible = ( m_grid->GetCellValue( row, 1 ) != wxEmptyString );
143  m_fields[row].m_URL = ( m_grid->GetCellValue( row, 2 ) != wxEmptyString );
144  }
145 
146  return true;
147 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:156
bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow ( )
overrideprivate

Definition at line 150 of file panel_eeschema_template_fieldnames.cpp.

References SCH_EDIT_FRAME::AddTemplateFieldName(), SCH_EDIT_FRAME::DeleteAllTemplateFieldNames(), m_fields, m_frame, and TransferDataFromGrid().

151 {
152  if( !TransferDataFromGrid() )
153  return false;
154 
156 
157  for( const TEMPLATE_FIELDNAME& field : m_fields )
158  m_frame->AddTemplateFieldName( field );
159 
160  return true;
161 }
int AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName)
Insert or append a wanted symbol field name into the field names template.
void DeleteAllTemplateFieldNames()
Remove all template field names.
Struct TEMPLATE_FIELDNAME holds a name of a component&#39;s field, field value, and default visibility...
bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToGrid ( )
private

Definition at line 100 of file panel_eeschema_template_fieldnames.cpp.

References m_fields, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by OnAddButtonClick(), and TransferDataToWindow().

101 {
102  m_grid->Freeze();
103 
104  if( m_grid->GetNumberRows() )
105  m_grid->DeleteRows( 0, m_grid->GetNumberRows() );
106 
107  m_grid->AppendRows( m_fields.size() );
108 
109  for( int row = 0; row < m_grid->GetNumberRows(); ++row )
110  {
111  m_grid->SetCellValue( row, 0, m_fields[row].m_Name );
112  m_grid->SetCellValue( row, 1, m_fields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
113  m_grid->SetCellValue( row, 2, m_fields[row].m_URL ? wxT( "1" ) : wxEmptyString );
114 
115  // Set cell properties
116  m_grid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
117 
118  // Render the Visible and URL columns as check boxes
119  m_grid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() );
120  m_grid->SetReadOnly( row, 1 ); // Not really; we delegate interactivity to GRID_TRICKS
121  m_grid->SetCellAlignment( row, 1, wxALIGN_CENTRE, wxALIGN_CENTRE );
122 
123  m_grid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
124  m_grid->SetReadOnly( row, 2 ); // Not really; we delegate interactivity to GRID_TRICKS
125  m_grid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
126  }
127 
128  m_grid->Thaw();
129 
130  return true;
131 }
bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToWindow ( )
overrideprivate

Definition at line 56 of file panel_eeschema_template_fieldnames.cpp.

References SCH_BASE_FRAME::GetTemplateFieldNames(), m_fields, m_frame, and TransferDataToGrid().

57 {
59  return TransferDataToGrid();
60 }
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames() const
Return a template field names list for read only access.

Member Data Documentation

int PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::m_checkboxColWidth
protected
SCH_EDIT_FRAME* PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::m_frame
protected

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