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
 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

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 
46 
47  m_checkboxColWidth = m_grid->GetColSize( 1 );
48 
49  m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
50  m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
51 }
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:55
#define _(s)
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
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)

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_title, small_plus, and small_trash.

◆ ~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES()

PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::~PANEL_EESCHEMA_TEMPLATE_FIELDNAMES ( )
override

Definition at line 54 of file panel_eeschema_template_fieldnames.cpp.

55 {
56  // Delete the GRID_TRICKS.
57  m_grid->PopEventHandler( true );
58 }

References PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Member Function Documentation

◆ AdjustGridColumns()

void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::AdjustGridColumns ( int  aWidth)
private

Definition at line 199 of file panel_eeschema_template_fieldnames.cpp.

200 {
201  if( aWidth <= 0 )
202  return;
203 
204  // Account for scroll bars
205  aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
206 
207  m_grid->SetColSize( 0, aWidth - 2 * m_checkboxColWidth );
208  m_grid->SetColSize( 1, m_checkboxColWidth );
209  m_grid->SetColSize( 2, m_checkboxColWidth );
210 }

References m_checkboxColWidth, and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

Referenced by OnSizeGrid().

◆ ImportSettingsFrom()

void PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::ImportSettingsFrom ( TEMPLATES templateMgr)

◆ OnAddButtonClick()

void PANEL_EESCHEMA_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_EESCHEMA_TEMPLATE_FIELDNAMES_BASE.

Definition at line 70 of file panel_eeschema_template_fieldnames.cpp.

71 {
73  return;
74 
75  int row = m_grid->GetNumberRows();
77 
78  TEMPLATE_FIELDNAME newFieldname = TEMPLATE_FIELDNAME( _( "Untitled Field" ) );
79  newFieldname.m_Visible = false;
80  m_fields.insert( m_fields.end(), newFieldname );
82 
83  // wx documentation is wrong, SetGridCursor does not make visible.
84  m_grid->MakeCellVisible( row, 0 );
85  m_grid->SetGridCursor( row, 0 );
86 }
#define _(s)
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_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid, TEMPLATE_FIELDNAME::m_Visible, TransferDataFromGrid(), and TransferDataToGrid().

◆ OnDeleteButtonClick()

void PANEL_EESCHEMA_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_EESCHEMA_TEMPLATE_FIELDNAMES_BASE.

Definition at line 89 of file panel_eeschema_template_fieldnames.cpp.

90 {
92  return;
93 
94  wxArrayInt selectedRows = m_grid->GetSelectedRows();
95 
96  if( selectedRows.empty() && m_grid->GetGridCursorRow() >= 0 )
97  selectedRows.push_back( m_grid->GetGridCursorRow() );
98 
99  if( selectedRows.empty() )
100  return;
101 
102  // Reverse sort so deleting a row doesn't change the indexes of the other rows.
103  selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
104 
105  for( int row : selectedRows )
106  {
107  m_fields.erase( m_fields.begin() + row );
108  m_grid->DeleteRows( row );
109 
110  m_grid->MakeCellVisible( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
111  m_grid->SetGridCursor( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
112  }
113 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226

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

214 {
215  AdjustGridColumns( event.GetSize().GetX() );
216 
217  event.Skip();
218 }

References AdjustGridColumns().

◆ TransferDataFromGrid()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromGrid ( )
private

Definition at line 149 of file panel_eeschema_template_fieldnames.cpp.

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

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

166 {
167  if( !TransferDataFromGrid() )
168  return false;
169 
170  SCHEMATIC& schematic = m_frame->Schematic();
171 
173 
174  for( const TEMPLATE_FIELDNAME& field : m_fields )
176 
177  if( m_global )
178  {
179  auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
180 
181  if( cfg )
182  {
183  // Save global fieldname templates
184  STRING_FORMATTER sf;
185  schematic.Settings().m_TemplateFieldNames.Format( &sf, 0, true );
186 
187  wxString record = FROM_UTF8( sf.GetString().c_str() );
188  record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines
189  record.Replace( wxT(" "), wxT(" "), true ); // double space to single
190 
191  cfg->m_Drawing.field_names = record.ToStdString();
192  }
193  }
194 
195  return true;
196 }
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
Holds all the data relating to one schematic.
Definition: schematic.h:59
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
TEMPLATES m_TemplateFieldNames
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
SCHEMATIC & Schematic() const
const std::string & GetString()
Definition: richio.h:438
Hold a name of a symbol's field, field value, and default visibility.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:414

References TEMPLATES::AddTemplateFieldName(), TEMPLATES::DeleteAllFieldNameTemplates(), TEMPLATES::Format(), FROM_UTF8(), STRING_FORMATTER::GetString(), Kiface(), m_fields, m_frame, m_global, SCHEMATIC_SETTINGS::m_TemplateFieldNames, SCH_EDIT_FRAME::Schematic(), SCHEMATIC::Settings(), and TransferDataFromGrid().

◆ TransferDataToGrid()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToGrid ( )
private

Definition at line 116 of file panel_eeschema_template_fieldnames.cpp.

117 {
118  m_grid->Freeze();
119 
120  m_grid->ClearRows();
121  m_grid->AppendRows( m_fields.size() );
122 
123  for( int row = 0; row < m_grid->GetNumberRows(); ++row )
124  {
125  m_grid->SetCellValue( row, 0, m_fields[row].m_Name );
126  // columns 1 and 2 show a boolean value (in a check box):
127  m_grid->SetCellValue( row, 1, m_fields[row].m_Visible ? "1" : "0" );
128  m_grid->SetCellValue( row, 2, m_fields[row].m_URL ? "1" : "0" );
129 
130  // Set cell properties
131  m_grid->SetCellAlignment( row, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
132 
133  // Render the Visible and URL columns as check boxes
134  m_grid->SetCellRenderer( row, 1, new wxGridCellBoolRenderer() );
135  m_grid->SetReadOnly( row, 1 ); // Not really; we delegate interactivity to GRID_TRICKS
136  m_grid->SetCellAlignment( row, 1, wxALIGN_CENTRE, wxALIGN_CENTRE );
137 
138  m_grid->SetCellRenderer( row, 2, new wxGridCellBoolRenderer() );
139  m_grid->SetReadOnly( row, 2 ); // Not really; we delegate interactivity to GRID_TRICKS
140  m_grid->SetCellAlignment( row, 2, wxALIGN_CENTRE, wxALIGN_CENTRE );
141  }
142 
143  m_grid->Thaw();
144 
145  return true;
146 }
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_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::m_grid.

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

◆ TransferDataToWindow()

bool PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToWindow ( )
overrideprivate

Definition at line 61 of file panel_eeschema_template_fieldnames.cpp.

62 {
63  SCHEMATIC& schematic = m_frame->Schematic();
64 
66  return TransferDataToGrid();
67 }
Holds all the data relating to one schematic.
Definition: schematic.h:59
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
TEMPLATES m_TemplateFieldNames
SCHEMATIC & Schematic() const
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.

References TEMPLATES::GetTemplateFieldNames(), m_fields, m_frame, m_global, SCHEMATIC_SETTINGS::m_TemplateFieldNames, SCH_EDIT_FRAME::Schematic(), SCHEMATIC::Settings(), and TransferDataToGrid().

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: