KiCad PCB EDA Suite
PANEL_TEMPLATE_FIELDNAMES Class Reference

#include <panel_template_fieldnames.h>

Inheritance diagram for PANEL_TEMPLATE_FIELDNAMES:
PANEL_TEMPLATE_FIELDNAMES_BASE

Public Member Functions

 PANEL_TEMPLATE_FIELDNAMES (wxWindow *aWindow, TEMPLATES *aProjectTemplateMgr)
 
 ~PANEL_TEMPLATE_FIELDNAMES () override
 
void ImportSettingsFrom (TEMPLATES *templateMgr)
 

Protected Member Functions

void OnAddButtonClick (wxCommandEvent &event) override
 Adds a new template fieldname (with default values) to the template fieldnames data. More...
 
void OnDeleteButtonClick (wxCommandEvent &event) override
 Deletes the selected template fieldname from the template fieldnames data. More...
 

Protected Attributes

TEMPLATESm_templateMgr
 
TEMPLATE_FIELDNAMES m_fields
 
bool m_global
 
int m_checkboxColWidth
 
TEMPLATES m_templateMgrInstance
 
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_template_fieldnames.h.

Constructor & Destructor Documentation

◆ PANEL_TEMPLATE_FIELDNAMES()

PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES ( wxWindow *  aWindow,
TEMPLATES aProjectTemplateMgr 
)

Definition at line 35 of file panel_template_fieldnames.cpp.

36 :
38{
39 if( aProjectTemplateMgr )
40 {
41 m_title->SetLabel( _( "Project field name templates:" ) );
42 m_global = false;
43 m_templateMgr = aProjectTemplateMgr;
44 }
45 else
46 {
47 m_title->SetLabel( _( "Global field name templates:" ) );
48 m_global = true;
50
51 EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
52
53 if( cfg )
54 {
55 // Read global fieldname templates
56 wxString templateFieldNames = cfg->m_Drawing.field_names;
57
58 if( !templateFieldNames.IsEmpty() )
59 {
60 TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) );
61
62 try
63 {
64 m_templateMgr->Parse( &field_lexer, true );
65 }
66 catch( const IO_ERROR& )
67 {
68 }
69 }
70 }
71 }
72
75
76 m_checkboxColWidth = m_grid->GetColSize( 1 );
77
78 m_grid->PushEventHandler( new GRID_TRICKS( m_grid, [this]( wxCommandEvent& aEvent )
79 {
80 OnAddButtonClick( aEvent );
81 } ) );
82 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
83}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
PANEL_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)
void OnAddButtonClick(wxCommandEvent &event) override
Adds a new template fieldname (with default values) to the template fieldnames data.
void Parse(TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
Fill this object from information in the input stream handled by #TEMPLATE_FIELDNAMES_LEXER.
#define _(s)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References _, EESCHEMA_SETTINGS::DRAWING::field_names, KiBitmap(), PANEL_TEMPLATE_FIELDNAMES_BASE::m_addFieldButton, m_checkboxColWidth, PANEL_TEMPLATE_FIELDNAMES_BASE::m_deleteFieldButton, EESCHEMA_SETTINGS::m_Drawing, m_global, PANEL_TEMPLATE_FIELDNAMES_BASE::m_grid, m_templateMgr, m_templateMgrInstance, PANEL_TEMPLATE_FIELDNAMES_BASE::m_title, OnAddButtonClick(), TEMPLATES::Parse(), Pgm(), small_plus, small_trash, and TO_UTF8.

◆ ~PANEL_TEMPLATE_FIELDNAMES()

PANEL_TEMPLATE_FIELDNAMES::~PANEL_TEMPLATE_FIELDNAMES ( )
override

Definition at line 86 of file panel_template_fieldnames.cpp.

87{
88 // Delete the GRID_TRICKS.
89 m_grid->PopEventHandler( true );
90}

References PANEL_TEMPLATE_FIELDNAMES_BASE::m_grid.

Member Function Documentation

◆ AdjustGridColumns()

void PANEL_TEMPLATE_FIELDNAMES::AdjustGridColumns ( int  aWidth)
private

Definition at line 228 of file panel_template_fieldnames.cpp.

229{
230 if( aWidth <= 0 )
231 return;
232
233 // Account for scroll bars
234 aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
235
236 m_grid->SetColSize( 0, std::max( 40, aWidth - 2 * m_checkboxColWidth ) );
237 m_grid->SetColSize( 1, m_checkboxColWidth );
238 m_grid->SetColSize( 2, m_checkboxColWidth );
239}

References m_checkboxColWidth, and PANEL_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by OnSizeGrid().

◆ ImportSettingsFrom()

void PANEL_TEMPLATE_FIELDNAMES::ImportSettingsFrom ( TEMPLATES templateMgr)

Definition at line 250 of file panel_template_fieldnames.cpp.

251{
252 m_fields = templateMgr->GetTemplateFieldNames( m_global );
254}
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.

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

Referenced by DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction().

◆ OnAddButtonClick()

void PANEL_TEMPLATE_FIELDNAMES::OnAddButtonClick ( wxCommandEvent &  event)
overrideprotectedvirtual

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

Process the wxWidgets event produced when the user presses the Add button for the template fieldnames control.

Parameters
eventThe wxWidgets produced event information

Reimplemented from PANEL_TEMPLATE_FIELDNAMES_BASE.

Definition at line 101 of file panel_template_fieldnames.cpp.

102{
104 return;
105
106 int row = m_grid->GetNumberRows();
108
109 TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( _( "Untitled Field" ) );
110 newFieldname.m_Visible = false;
111 m_fields.insert( m_fields.end(), newFieldname );
113
114 // wx documentation is wrong, SetGridCursor does not make visible.
115 m_grid->MakeCellVisible( row, 0 );
116 m_grid->SetGridCursor( row, 0 );
117}
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
Hold a name of a symbol's field, field value, and default visibility.

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

Referenced by PANEL_TEMPLATE_FIELDNAMES().

◆ OnDeleteButtonClick()

void PANEL_TEMPLATE_FIELDNAMES::OnDeleteButtonClick ( wxCommandEvent &  event)
overrideprotectedvirtual

Deletes the selected template fieldname from the template fieldnames data.

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

Parameters
eventThe wxWidgets produced event information

Reimplemented from PANEL_TEMPLATE_FIELDNAMES_BASE.

Definition at line 120 of file panel_template_fieldnames.cpp.

121{
123 return;
124
125 wxArrayInt selectedRows = m_grid->GetSelectedRows();
126
127 if( selectedRows.empty() && m_grid->GetGridCursorRow() >= 0 )
128 selectedRows.push_back( m_grid->GetGridCursorRow() );
129
130 if( selectedRows.empty() )
131 return;
132
133 // Reverse sort so deleting a row doesn't change the indexes of the other rows.
134 selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
135
136 for( int row : selectedRows )
137 {
138 m_fields.erase( m_fields.begin() + row );
139 m_grid->DeleteRows( row );
140
141 m_grid->MakeCellVisible( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
142 m_grid->SetGridCursor( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
143 }
144}

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

◆ OnSizeGrid()

void PANEL_TEMPLATE_FIELDNAMES::OnSizeGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_TEMPLATE_FIELDNAMES_BASE.

Definition at line 242 of file panel_template_fieldnames.cpp.

243{
244 AdjustGridColumns( event.GetSize().GetX() );
245
246 event.Skip();
247}

References AdjustGridColumns().

◆ TransferDataFromGrid()

bool PANEL_TEMPLATE_FIELDNAMES::TransferDataFromGrid ( )
private

Definition at line 180 of file panel_template_fieldnames.cpp.

181{
183 return false;
184
185 for( int row = 0; row < m_grid->GetNumberRows(); ++row )
186 {
187 m_fields[row].m_Name = m_grid->GetCellValue( row, 0 );
188 m_fields[row].m_Visible = m_grid->GetCellValue( row, 1 ) == "1";
189 m_fields[row].m_URL = m_grid->GetCellValue( row, 2 ) == "1";
190 }
191
192 return true;
193}

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

Referenced by OnAddButtonClick(), and TransferDataFromWindow().

◆ TransferDataFromWindow()

bool PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow ( )
overrideprivate

Definition at line 196 of file panel_template_fieldnames.cpp.

197{
198 if( !TransferDataFromGrid() )
199 return false;
200
202
203 for( const TEMPLATE_FIELDNAME& field : m_fields )
205
206 if( m_global )
207 {
208 EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
209
210 if( cfg )
211 {
212 // Save global fieldname templates
214 m_templateMgr->Format( &sf, 0, true );
215
216 wxString record = FROM_UTF8( sf.GetString().c_str() );
217 record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines
218 record.Replace( wxT(" "), wxT(" "), true ); // double space to single
219
220 cfg->m_Drawing.field_names = record.ToStdString();
221 }
222 }
223
224 return true;
225}
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:415
const std::string & GetString()
Definition: richio.h:438
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
void Format(OUTPUTFORMATTER *out, int nestLevel, bool aGlobal) const
Serialize this object out as text into the given OUTPUTFORMATTER.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110

References TEMPLATES::AddTemplateFieldName(), TEMPLATES::DeleteAllFieldNameTemplates(), EESCHEMA_SETTINGS::DRAWING::field_names, TEMPLATES::Format(), FROM_UTF8(), STRING_FORMATTER::GetString(), EESCHEMA_SETTINGS::m_Drawing, m_fields, m_global, m_templateMgr, Pgm(), and TransferDataFromGrid().

◆ TransferDataToGrid()

bool PANEL_TEMPLATE_FIELDNAMES::TransferDataToGrid ( )
private

Definition at line 147 of file panel_template_fieldnames.cpp.

148{
149 m_grid->Freeze();
150
151 m_grid->ClearRows();
152 m_grid->AppendRows( m_fields.size() );
153
154 for( int row = 0; row < m_grid->GetNumberRows(); ++row )
155 {
156 m_grid->SetCellValue( row, 0, m_fields[row].m_Name );
157 // columns 1 and 2 show a boolean value (in a check box):
158 m_grid->SetCellValue( row, 1, m_fields[row].m_Visible ? "1" : "0" );
159 m_grid->SetCellValue( row, 2, m_fields[row].m_URL ? "1" : "0" );
160
161 // Set cell properties
162 m_grid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
163
164 // Render the Visible and URL columns as check boxes
165 m_grid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() );
166 m_grid->SetReadOnly( row, 1 ); // Not really; we delegate interactivity to GRID_TRICKS
167 m_grid->SetCellAlignment( row, 1, wxALIGN_CENTRE, wxALIGN_CENTRE );
168
169 m_grid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
170 m_grid->SetReadOnly( row, 2 ); // Not really; we delegate interactivity to GRID_TRICKS
171 m_grid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
172 }
173
174 m_grid->Thaw();
175
176 return true;
177}
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:109

References WX_GRID::ClearRows(), m_fields, and PANEL_TEMPLATE_FIELDNAMES_BASE::m_grid.

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

◆ TransferDataToWindow()

bool PANEL_TEMPLATE_FIELDNAMES::TransferDataToWindow ( )
overrideprivate

Member Data Documentation

◆ m_addFieldButton

wxBitmapButton* PANEL_TEMPLATE_FIELDNAMES_BASE::m_addFieldButton
protectedinherited

◆ m_checkboxColWidth

int PANEL_TEMPLATE_FIELDNAMES::m_checkboxColWidth
protected

Definition at line 74 of file panel_template_fieldnames.h.

Referenced by AdjustGridColumns(), and PANEL_TEMPLATE_FIELDNAMES().

◆ m_deleteFieldButton

wxBitmapButton* PANEL_TEMPLATE_FIELDNAMES_BASE::m_deleteFieldButton
protectedinherited

◆ m_fields

◆ m_global

bool PANEL_TEMPLATE_FIELDNAMES::m_global
protected

◆ m_grid

◆ m_leftMargin

wxBoxSizer* PANEL_TEMPLATE_FIELDNAMES_BASE::m_leftMargin
protectedinherited

◆ m_templateMgr

TEMPLATES* PANEL_TEMPLATE_FIELDNAMES::m_templateMgr
protected

◆ m_templateMgrInstance

TEMPLATES PANEL_TEMPLATE_FIELDNAMES::m_templateMgrInstance
protected

Definition at line 75 of file panel_template_fieldnames.h.

Referenced by PANEL_TEMPLATE_FIELDNAMES().

◆ m_title

wxStaticText* PANEL_TEMPLATE_FIELDNAMES_BASE::m_title
protectedinherited

◆ m_topMargin

wxBoxSizer* PANEL_TEMPLATE_FIELDNAMES_BASE::m_topMargin
protectedinherited

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