26#include <wx/display.h>
27#include <wx/fileconf.h>
31#include <wx/settings.h>
47 s = wxString::FromCDouble( *
static_cast<const PARAM_CFG_DOUBLE&
>( aParam ).m_Pt_param );
51 s << ( *static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Pt_param ? wxS(
"true" ) : wxS(
"false" ) );
54 wxLogError( wxS(
"Unsupported PARAM_CFG variant: " ) + wxString::Format( wxS(
"%d" ), aParam.
m_Type ) );
59 wxLogError( wxS(
"Error converting parameter value to string." ) );
74 s = wxString::FromCDouble(
static_cast<const PARAM_CFG_DOUBLE&
>( aParam ).m_Default );
78 s << ( static_cast<const PARAM_CFG_BOOL&>( aParam ).m_Default ? wxS(
"true" ) : wxS(
"false" ) );
85 wxLogError( wxS(
"Error converting parameter default value to string." ) );
105 if( aValue.CmpNoCase( wxS(
"true" ) ) == 0 || aValue.CmpNoCase( wxS(
"yes" ) ) == 0
106 || aValue.CmpNoCase( wxS(
"1" ) ) == 0 )
130 wxS(
"Unsupported PARAM_CFG variant: " ) + wxString::Format( wxS(
"%d" ), aParam.
m_Type ) );
135 wxDialog( aParent, wxID_ANY,
_(
"Edit Advanced Configuration" ), wxDefaultPosition, wxDefaultSize,
136 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
140 m_grid =
new wxGrid(
this, wxID_ANY );
141 m_grid->CreateGrid( 0, 3 );
142 m_grid->SetColLabelValue( 0,
_(
"Key" ) );
143 m_grid->SetColLabelValue( 1,
_(
"Value" ) );
144 m_grid->SetColLabelValue( 2,
_(
"Extant" ) );
146 m_grid->SetRowLabelSize( 0 );
150 wxStdDialogButtonSizer* buttonSizer =
new wxStdDialogButtonSizer();
151 wxButton* okButton =
new wxButton(
this, wxID_OK,
_(
"OK" ) );
152 okButton->SetDefault();
153 buttonSizer->AddButton( okButton );
154 buttonSizer->Realize();
156 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
157 sizer->Add(
m_grid, 1, wxEXPAND | wxALL, 5 );
158 sizer->Add( buttonSizer, 0, wxEXPAND | wxALL, 5 );
161 wxDisplay display( wxDisplay::GetFromWindow(
this ) );
162 wxRect displayRect = display.GetClientArea();
164 SetMinSize( wxSize( 500, 300 ) );
165 SetMaxSize( wxSize( displayRect.GetWidth() - 100, displayRect.GetHeight() - 100 ) );
166 SetSizeHints( wxSize( 700, 500 ) );
192 wxSize clientSize =
m_grid->GetClientSize();
193 int availableWidth = clientSize.GetWidth();
196 availableWidth -= wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
198 if( availableWidth < 200 )
199 availableWidth = 200;
201 int keyWidth = ( availableWidth * 6 ) / 10;
202 int valueWidth = availableWidth - keyWidth;
204 keyWidth = std::max( keyWidth, 100 );
205 valueWidth = std::max( valueWidth, 80 );
207 m_grid->SetColSize( 0, keyWidth );
208 m_grid->SetColSize( 1, valueWidth );
211 m_grid->SetColMinimalAcceptableWidth( 50 );
232 const std::vector<std::unique_ptr<PARAM_CFG>>& entries = adv.
GetEntries();
234 for(
const auto& entry : entries )
238 int row =
m_grid->GetNumberRows();
240 m_grid->SetCellValue( row, 0, entry->m_Ident );
241 m_grid->SetCellValue( row, 1, value );
242 m_grid->SetCellValue( row, 2, def == value ? wxS(
"0" ) : wxS(
"1" ) );
243 m_grid->SetReadOnly( row, 2 );
250 int rows =
m_grid->GetNumberRows();
252 for(
int row = 0; row < rows; ++row )
254 wxString key =
m_grid->GetCellValue( row, 0 );
255 wxString val =
m_grid->GetCellValue( row, 1 );
256 wxString ext =
m_grid->GetCellValue( row, 2 );
258 if( key.IsEmpty() || ext != wxS(
"1" ) )
262 for(
auto& entry : entries )
264 if( entry->m_Ident == key )
278 int row = aEvent.GetRow();
279 int col = aEvent.GetCol();
281 if( col == 0 || col == 1 )
283 m_grid->SetCellValue( row, 2, wxS(
"1" ) );
289 int lastRow =
m_grid->GetNumberRows() - 1;
290 if( !
m_grid->GetCellValue( lastRow, 0 ).IsEmpty() || !
m_grid->GetCellValue( lastRow, 1 ).IsEmpty() )
293 m_grid->SetCellValue(
m_grid->GetNumberRows() - 1, 2, wxS(
"0" ) );
305 menu.Append( wxID_ANY,
_(
"Reset to default" ) );
320 const std::vector<std::unique_ptr<PARAM_CFG>>& entries = adv.
GetEntries();
322 for(
const auto& entry : entries )
324 if( entry->m_Ident == key )
339 bool ext =
m_grid->GetCellValue( aRow, 2 ) == wxS(
"1" );
340 wxFont font =
m_grid->GetCellFont( aRow, 0 );
341 font.SetWeight( ext ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL );
342 m_grid->SetCellFont( aRow, 0, font );
343 m_grid->SetCellFont( aRow, 1, font );
const std::vector< std::unique_ptr< PARAM_CFG > > & GetEntries() const
void Save()
Save the configuration to the configuration file.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void OnSize(wxSizeEvent &aEvent)
DIALOG_EDIT_CFG(wxWindow *aParent)
void OnCellChange(wxGridEvent &aEvent)
void OnCellRightClick(wxGridEvent &aEvent)
void adjustColumnWidths()
void OnResetDefault(wxCommandEvent &aEvent)
void updateRowAppearance(int aRow)
Configuration object for booleans.
bool * m_Pt_param
Pointer to the parameter value.
Configuration object for double precision floating point numbers.
double * m_Pt_param
Pointer to the parameter value.
Configuration object for integers.
int * m_Pt_param
Pointer to the parameter value.
Configuration object for wxString objects.
wxString * m_Pt_param
Pointer to the parameter value.
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
paramcfg_id m_Type
Type of parameter.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
static wxString paramValueString(const PARAM_CFG &aParam)
static void writeParam(PARAM_CFG &aParam, const wxString &aValue)
static wxString paramDefaultString(const PARAM_CFG &aParam)