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, bool aGlobal)
 
 ~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES () override
 
void ImportSettingsFrom (TEMPLATES *templateMgr)
 

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
 
bool m_global
 
int m_checkboxColWidth
 
wxBoxSizer * m_leftMargin
 
wxBoxSizer * m_topMargin
 
wxStaticText * m_title
 
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::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES ( SCH_EDIT_FRAME aFrame,
wxWindow *  aWindow,
bool  aGlobal 
)

Definition at line 34 of file panel_eeschema_template_fieldnames.cpp.

36  :
38  m_frame( aFrame ),
39  m_global( aGlobal )
40 {
41  m_title->SetLabel( aGlobal ? _( "Global field name templates:" )
42  : _( "Project field name templates:" ) );
43 
44  // Yep, it's a hack. I haven't a clue why the global and project versions don't lay
45  // out the same.
46  if( !aGlobal )
47  {
48  m_leftMargin->PrependSpacer( 10 );
49  m_topMargin->PrependSpacer( 10 );
50  }
51 
52  m_addFieldButton->SetBitmap( KiBitmap( small_plus_xpm ) );
53  m_deleteFieldButton->SetBitmap( KiBitmap( trash_xpm ) );
54 
55  m_checkboxColWidth = m_grid->GetColSize( 1 );
56 
57  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
58 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
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:80
#define _(s)
Definition: 3d_actions.cpp:33
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)
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20

References _, KiBitmap(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_addFieldButton, m_checkboxColWidth, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_deleteFieldButton, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_leftMargin, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_title, PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_topMargin, small_plus_xpm, and trash_xpm.

◆ ~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES()

PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES ( )
override

Definition at line 61 of file panel_eeschema_template_fieldnames.cpp.

62 {
63  // Delete the GRID_TRICKS.
64  m_grid->PopEventHandler( true );
65 }

References PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Member Function Documentation

◆ AdjustGridColumns()

void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::AdjustGridColumns ( int  aWidth)
private

Definition at line 176 of file panel_eeschema_template_fieldnames.cpp.

177 {
178  if( aWidth <= 0 )
179  return;
180 
181  // Account for scroll bars
182  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
183 
184  m_grid->SetColSize( 0, aWidth - 2 * m_checkboxColWidth );
185  m_grid->SetColSize( 1, m_checkboxColWidth );
186  m_grid->SetColSize( 2, m_checkboxColWidth );
187 }

References m_checkboxColWidth, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by OnSizeGrid().

◆ ImportSettingsFrom()

void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::ImportSettingsFrom ( TEMPLATES templateMgr)

Definition at line 198 of file panel_eeschema_template_fieldnames.cpp.

199 {
200  m_fields = templateMgr->GetTemplateFieldNames( m_global );
202 }
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Function GetTemplateFieldName returns a template fieldnames list for read only access.

References TEMPLATES::GetTemplateFieldNames(), m_fields, m_global, and TransferDataToGrid().

Referenced by DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction().

◆ OnAddButtonClick()

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 75 of file panel_eeschema_template_fieldnames.cpp.

76 {
78  return;
79 
80  int row = m_grid->GetNumberRows();
82 
83  TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( _( "Untitled Field" ) );
84  newFieldname.m_Visible = false;
85  m_fields.insert( m_fields.end(), newFieldname );
87 
88  // wx documentation is wrong, SetGridCursor does not make visible.
89  m_grid->MakeCellVisible( row, 0 );
90  m_grid->SetGridCursor( row, 0 );
91 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
#define _(s)
Definition: 3d_actions.cpp:33
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

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

◆ OnDeleteButtonClick()

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 94 of file panel_eeschema_template_fieldnames.cpp.

95 {
97  return;
98 
99  int curRow = m_grid->GetGridCursorRow();
100 
101  if( curRow >= 0 && curRow < (int)m_fields.size() )
102  {
103  m_fields.erase( m_fields.begin() + curRow );
104  m_grid->DeleteRows( curRow );
105  }
106 
107  m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
108  m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
109 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

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

◆ OnSizeGrid()

void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::OnSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE.

Definition at line 190 of file panel_eeschema_template_fieldnames.cpp.

191 {
192  AdjustGridColumns( event.GetSize().GetX() );
193 
194  event.Skip();
195 }

References AdjustGridColumns().

◆ TransferDataFromGrid()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromGrid ( )
private

Definition at line 146 of file panel_eeschema_template_fieldnames.cpp.

147 {
148  if( !m_grid->CommitPendingChanges() )
149  return false;
150 
151  for( int row = 0; row < m_grid->GetNumberRows(); ++row )
152  {
153  m_fields[row].m_Name = m_grid->GetCellValue( row, 0 );
154  m_fields[row].m_Visible = m_grid->GetCellValue( row, 1 ) != wxEmptyString;
155  m_fields[row].m_URL = m_grid->GetCellValue( row, 2 ) != wxEmptyString;
156  }
157 
158  return true;
159 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

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

Referenced by OnAddButtonClick(), and TransferDataFromWindow().

◆ TransferDataFromWindow()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow ( )
overrideprivate

Definition at line 162 of file panel_eeschema_template_fieldnames.cpp.

163 {
164  if( !TransferDataFromGrid() )
165  return false;
166 
168 
169  for( const TEMPLATE_FIELDNAME& field : m_fields )
171 
172  return true;
173 }
void DeleteAllTemplateFieldNames(bool aGlobal)
Remove all global or project fieldname templates.
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

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

◆ TransferDataToGrid()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToGrid ( )
private

Definition at line 112 of file panel_eeschema_template_fieldnames.cpp.

113 {
114  m_grid->Freeze();
115 
116  if( m_grid->GetNumberRows() )
117  m_grid->DeleteRows( 0, m_grid->GetNumberRows() );
118 
119  m_grid->AppendRows( m_fields.size() );
120 
121  for( int row = 0; row < m_grid->GetNumberRows(); ++row )
122  {
123  m_grid->SetCellValue( row, 0, m_fields[row].m_Name );
124  m_grid->SetCellValue( row, 1, m_fields[row].m_Visible ? wxT( "1" ) : wxEmptyString );
125  m_grid->SetCellValue( row, 2, m_fields[row].m_URL ? wxT( "1" ) : wxEmptyString );
126 
127  // Set cell properties
128  m_grid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
129 
130  // Render the Visible and URL columns as check boxes
131  m_grid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() );
132  m_grid->SetReadOnly( row, 1 ); // Not really; we delegate interactivity to GRID_TRICKS
133  m_grid->SetCellAlignment( row, 1, wxALIGN_CENTRE, wxALIGN_CENTRE );
134 
135  m_grid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
136  m_grid->SetReadOnly( row, 2 ); // Not really; we delegate interactivity to GRID_TRICKS
137  m_grid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
138  }
139 
140  m_grid->Thaw();
141 
142  return true;
143 }

References m_fields, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by ImportSettingsFrom(), OnAddButtonClick(), and TransferDataToWindow().

◆ TransferDataToWindow()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToWindow ( )
overrideprivate

Member Data Documentation

◆ m_addFieldButton

◆ m_checkboxColWidth

int PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::m_checkboxColWidth
protected

◆ m_deleteFieldButton

◆ m_fields

◆ m_frame

SCH_EDIT_FRAME* PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::m_frame
protected

◆ m_global

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::m_global
protected

◆ m_grid

◆ m_leftMargin

wxBoxSizer* PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_leftMargin
protectedinherited

◆ m_title

wxStaticText* PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_title
protectedinherited

◆ m_topMargin

wxBoxSizer* PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_topMargin
protectedinherited

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