KiCad PCB EDA Suite
PANEL_REGULATOR Class Reference

#include <panel_regulator.h>

Inheritance diagram for PANEL_REGULATOR:
PANEL_REGULATOR_BASE CALCULATOR_PANEL

Public Member Functions

 PANEL_REGULATOR (wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
 
 ~PANEL_REGULATOR ()
 
void OnRegulatorCalcButtonClick (wxCommandEvent &event) override
 
void OnRegulatorResetButtonClick (wxCommandEvent &event) override
 
void OnRegulTypeSelection (wxCommandEvent &event) override
 
void OnRegulatorSelection (wxCommandEvent &event) override
 
void OnDataFileSelection (wxCommandEvent &event) override
 
void OnAddRegulator (wxCommandEvent &event) override
 
void OnEditRegulator (wxCommandEvent &event) override
 
void OnRemoveRegulator (wxCommandEvent &event) override
 
void LoadSettings (PCB_CALCULATOR_SETTINGS *aCfg) override
 Load the settings into the panel. More...
 
void SaveSettings (PCB_CALCULATOR_SETTINGS *aCfg) override
 Save the settings from the panel. More...
 
void ThemeChanged () override
 Update UI elements of the panel when the theme changes to ensure the images and fonts/colors are appropriate for the new theme. More...
 
void RegulatorPageUpdate ()
 Update the regulator page dialog display. More...
 
void SelectLastSelectedRegulator ()
 If m_lastSelectedRegulatorName is empty, just calls RegulatorPageUpdate() More...
 
void RegulatorsSolve ()
 
void Regulators_WriteConfig (PCB_CALCULATOR_SETTINGS *aCfg)
 Write regulators parameters in configuration. More...
 
const wxString GetDataFilename ()
 
void SetDataFilename (const wxString &aFilename)
 Initialize the full filename of the selected pcb_calculator data file force the standard extension of the file (.pcbcalc). More...
 
bool ReadDataFile ()
 
bool WriteDataFile ()
 

Public Attributes

REGULATOR_LIST m_RegulatorList
 
wxString m_lastSelectedRegulatorName
 
bool m_RegulatorListChanged
 

Protected Attributes

wxStaticText * m_staticTextRegType
 
wxChoice * m_choiceRegType
 
wxStaticBitmap * m_bitmapRegul4pins
 
wxStaticBitmap * m_bitmapRegul3pins
 
wxStaticText * m_RegulFormula
 
wxRadioButton * m_rbRegulR1
 
wxStaticText * m_labelRegultR1
 
wxTextCtrl * m_RegulR1Value
 
wxStaticText * m_r1Units
 
wxRadioButton * m_rbRegulR2
 
wxStaticText * m_labelRegultR2
 
wxTextCtrl * m_RegulR2Value
 
wxStaticText * m_r2Units
 
wxRadioButton * m_rbRegulVout
 
wxStaticText * m_labelVout
 
wxTextCtrl * m_RegulVoutValue
 
wxStaticText * m_unitsVout
 
wxStaticText * m_labelVRef
 
wxTextCtrl * m_RegulVrefValue
 
wxStaticText * m_unitsVref
 
wxStaticText * m_RegulIadjTitle
 
wxTextCtrl * m_RegulIadjValue
 
wxStaticText * m_IadjUnitLabel
 
wxButton * m_buttonCalculate
 
wxButton * m_buttonRegulReset
 
wxStaticText * m_RegulMessage
 
wxChoice * m_choiceRegulatorSelector
 
wxStaticText * m_staticTextRegFile
 
wxTextCtrl * m_regulators_fileNameCtrl
 
wxButton * m_buttonDataFile
 
wxButton * m_buttonEditItem
 
wxButton * m_buttonAddItem
 
wxButton * m_buttonRemoveItem
 

Detailed Description

Definition at line 27 of file panel_regulator.h.

Constructor & Destructor Documentation

◆ PANEL_REGULATOR()

PANEL_REGULATOR::PANEL_REGULATOR ( wxWindow *  parent,
wxWindowID  id = wxID_ANY,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxTAB_TRAVERSAL,
const wxString &  name = wxEmptyString 
)

Definition at line 40 of file panel_regulator.cpp.

42 :
43 PANEL_REGULATOR_BASE( parent, id, pos, size, style, name ),
45{
46 m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
47 m_r1Units->SetLabel( wxT( "kΩ" ) );
48 m_r2Units->SetLabel( wxT( "kΩ" ) );
49
52
55
56 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
57 GetSizer()->SetSizeHints( this );
58}
const char * name
Definition: DXF_plotter.cpp:56
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
wxStaticText * m_IadjUnitLabel
wxStaticBitmap * m_bitmapRegul4pins
wxChoice * m_choiceRegulatorSelector
wxStaticBitmap * m_bitmapRegul3pins
PANEL_REGULATOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(688, 436), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
REGULATOR_LIST m_RegulatorList
void SelectLastSelectedRegulator()
If m_lastSelectedRegulatorName is empty, just calls RegulatorPageUpdate()
wxArrayString GetRegList() const

References REGULATOR_LIST::GetRegList(), KiBitmap(), PANEL_REGULATOR_BASE::m_bitmapRegul3pins, PANEL_REGULATOR_BASE::m_bitmapRegul4pins, PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, PANEL_REGULATOR_BASE::m_IadjUnitLabel, PANEL_REGULATOR_BASE::m_r1Units, PANEL_REGULATOR_BASE::m_r2Units, m_RegulatorList, regul, regul_3pins, and SelectLastSelectedRegulator().

◆ ~PANEL_REGULATOR()

PANEL_REGULATOR::~PANEL_REGULATOR ( )

Definition at line 60 of file panel_regulator.cpp.

61{
62}

Member Function Documentation

◆ GetDataFilename()

const wxString PANEL_REGULATOR::GetDataFilename ( )
Returns
the full filename of the selected pcb_calculator data file

Definition at line 454 of file panel_regulator.cpp.

455{
456 if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
457 return wxEmptyString;
458
459 wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
460 fn.SetExt( DataFileNameExt );
461 return fn.GetFullPath();
462}
wxTextCtrl * m_regulators_fileNameCtrl
static const wxString DataFileNameExt(wxT("pcbcalc"))

References DataFileNameExt(), and PANEL_REGULATOR_BASE::m_regulators_fileNameCtrl.

Referenced by PCB_CALCULATOR_FRAME::OnClosePcbCalc(), OnDataFileSelection(), ReadDataFile(), Regulators_WriteConfig(), and WriteDataFile().

◆ LoadSettings()

void PANEL_REGULATOR::LoadSettings ( PCB_CALCULATOR_SETTINGS aCfg)
overridevirtual

Load the settings into the panel.

Parameters
aCfgis the settings structure to load from

Implements CALCULATOR_PANEL.

Definition at line 427 of file panel_regulator.cpp.

428{
429 m_RegulR1Value->SetValue( aCfg->m_Regulators.r1 );
430 m_RegulR2Value->SetValue( aCfg->m_Regulators.r2 );
431 m_RegulVrefValue->SetValue( aCfg->m_Regulators.vref );
432 m_RegulVoutValue->SetValue( aCfg->m_Regulators.vout );
435 m_choiceRegType->SetSelection( aCfg->m_Regulators.type );
436
437 wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
438
439 if( aCfg->m_Regulators.last_param >= 3 )
440 aCfg->m_Regulators.last_param = 0;
441
442 for( int ii = 0; ii < 3; ii++ )
443 regprms[ii]->SetValue( aCfg->m_Regulators.last_param == ii );
444
445}
wxRadioButton * m_rbRegulVout
wxRadioButton * m_rbRegulR2
wxRadioButton * m_rbRegulR1
void SetDataFilename(const wxString &aFilename)
Initialize the full filename of the selected pcb_calculator data file force the standard extension of...
wxString m_lastSelectedRegulatorName

References PCB_CALCULATOR_SETTINGS::REGULATORS::data_file, PCB_CALCULATOR_SETTINGS::REGULATORS::last_param, PANEL_REGULATOR_BASE::m_choiceRegType, m_lastSelectedRegulatorName, PANEL_REGULATOR_BASE::m_rbRegulR1, PANEL_REGULATOR_BASE::m_rbRegulR2, PANEL_REGULATOR_BASE::m_rbRegulVout, PCB_CALCULATOR_SETTINGS::m_Regulators, PANEL_REGULATOR_BASE::m_RegulR1Value, PANEL_REGULATOR_BASE::m_RegulR2Value, PANEL_REGULATOR_BASE::m_RegulVoutValue, PANEL_REGULATOR_BASE::m_RegulVrefValue, PCB_CALCULATOR_SETTINGS::REGULATORS::r1, PCB_CALCULATOR_SETTINGS::REGULATORS::r2, PCB_CALCULATOR_SETTINGS::REGULATORS::selected_regulator, SetDataFilename(), PCB_CALCULATOR_SETTINGS::REGULATORS::type, PCB_CALCULATOR_SETTINGS::REGULATORS::vout, and PCB_CALCULATOR_SETTINGS::REGULATORS::vref.

◆ OnAddRegulator()

void PANEL_REGULATOR::OnAddRegulator ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 199 of file panel_regulator.cpp.

200{
201 DIALOG_REGULATOR_FORM dlg( this, wxEmptyString );
202
203 if( dlg.ShowModal() != wxID_OK )
204 return;
205
206 REGULATOR_DATA* new_item = dlg.BuildRegulatorFromData();
207
208 // Add new item, if not existing
209 if( m_RegulatorList.GetReg( new_item->m_Name ) == nullptr )
210 {
211 // Add item in list
212 m_RegulatorList.Add( new_item );
218 }
219 else
220 {
221 wxMessageBox( _("This regulator is already in list. Aborted") );
222 delete new_item;
223 }
224}
Subclass of DIALOG_REGULATOR_FORM_BASE, which is generated by wxFormBuilder.
void Add(REGULATOR_DATA *aItem)
REGULATOR_DATA * GetReg(const wxString &aName)
#define _(s)

References _, REGULATOR_LIST::Add(), DIALOG_REGULATOR_FORM::BuildRegulatorFromData(), REGULATOR_LIST::GetReg(), REGULATOR_LIST::GetRegList(), PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, m_lastSelectedRegulatorName, REGULATOR_DATA::m_Name, m_RegulatorList, m_RegulatorListChanged, and SelectLastSelectedRegulator().

◆ OnDataFileSelection()

void PANEL_REGULATOR::OnDataFileSelection ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 153 of file panel_regulator.cpp.

154{
155 wxString fullfilename = GetDataFilename();
156
157 wxString wildcard;
158 wildcard.Printf( _("PCB Calculator data file" ) + wxT( " (*.%s)|*.%s"),
160
161 wxFileDialog dlg( this, _("Select PCB Calculator Data File"),
162 wxEmptyString, fullfilename, wildcard, wxFD_OPEN );
163
164 if( dlg.ShowModal() == wxID_CANCEL )
165 return;
166
167 fullfilename = dlg.GetPath();
168
169 if( fullfilename == GetDataFilename() )
170 return;
171
172 SetDataFilename( fullfilename );
173
174 if( wxFileExists( fullfilename ) && m_RegulatorList.GetCount() > 0 ) // Read file
175 {
176 if( wxMessageBox( _( "Do you want to load this file and replace current regulator list?" ) )
177 != wxID_OK )
178 {
179 return;
180 }
181 }
182
183 if( ReadDataFile() )
184 {
189 }
190 else
191 {
192 wxString msg;
193 msg.Printf( _("Unable to read data file '%s'."), fullfilename );
194 wxMessageBox( msg );
195 }
196}
const wxString GetDataFilename()
unsigned int GetCount()

References _, DataFileNameExt(), REGULATOR_LIST::GetCount(), GetDataFilename(), REGULATOR_LIST::GetRegList(), PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, m_RegulatorList, m_RegulatorListChanged, ReadDataFile(), SelectLastSelectedRegulator(), and SetDataFilename().

◆ OnEditRegulator()

void PANEL_REGULATOR::OnEditRegulator ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 227 of file panel_regulator.cpp.

228{
229 wxString name = m_choiceRegulatorSelector->GetStringSelection();
231
232 if( item == nullptr )
233 return;
234
235 DIALOG_REGULATOR_FORM dlg( this, name );
236
237 dlg.CopyRegulatorDataToDialog( item );
238
239 if( dlg.ShowModal() != wxID_OK )
240 return;
241
242 REGULATOR_DATA* new_item = dlg.BuildRegulatorFromData();
243 m_RegulatorList.Replace( new_item );
244
246
248}
void Replace(REGULATOR_DATA *aItem)
Replace an old REGULATOR_DATA by a new one The old one is deleted the 2 items must have the same name...

References DIALOG_REGULATOR_FORM::BuildRegulatorFromData(), DIALOG_REGULATOR_FORM::CopyRegulatorDataToDialog(), REGULATOR_LIST::GetReg(), PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, m_RegulatorList, m_RegulatorListChanged, name, REGULATOR_LIST::Replace(), and SelectLastSelectedRegulator().

◆ OnRegulatorCalcButtonClick()

void PANEL_REGULATOR::OnRegulatorCalcButtonClick ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 73 of file panel_regulator.cpp.

74{
76}

References RegulatorsSolve().

◆ OnRegulatorResetButtonClick()

void PANEL_REGULATOR::OnRegulatorResetButtonClick ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 79 of file panel_regulator.cpp.

80{
81 m_RegulR1Value->SetValue( wxT( "10" ) );
82 m_RegulR2Value->SetValue( wxT( "10" ) );
83 m_RegulVrefValue->SetValue( wxT( "3" ) );
84 m_RegulVoutValue->SetValue( wxT( "12" ) );
85 m_choiceRegType->SetSelection( 0 );
86 m_rbRegulR1->SetValue( true );
87 m_rbRegulR2->SetValue( false );
88 m_rbRegulVout->SetValue( false );
90}
void RegulatorPageUpdate()
Update the regulator page dialog display.

References PANEL_REGULATOR_BASE::m_choiceRegType, PANEL_REGULATOR_BASE::m_rbRegulR1, PANEL_REGULATOR_BASE::m_rbRegulR2, PANEL_REGULATOR_BASE::m_rbRegulVout, PANEL_REGULATOR_BASE::m_RegulR1Value, PANEL_REGULATOR_BASE::m_RegulR2Value, PANEL_REGULATOR_BASE::m_RegulVoutValue, PANEL_REGULATOR_BASE::m_RegulVrefValue, and RegulatorPageUpdate().

◆ OnRegulatorSelection()

void PANEL_REGULATOR::OnRegulatorSelection ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 131 of file panel_regulator.cpp.

132{
133 wxString name = m_choiceRegulatorSelector->GetStringSelection();
135
136 if( item )
137 {
139 m_choiceRegType->SetSelection( item->m_Type );
140 wxString value;
141 value.Printf( wxT( "%g" ), item->m_Vref );
142 m_RegulVrefValue->SetValue( value );
143 value.Printf( wxT( "%g" ), item->m_Iadj );
144 m_RegulIadjValue->SetValue( value );
145 }
146
147 // Call RegulatorPageUpdate to enable/disable tools,
148 // even if no item selected
150}

References REGULATOR_LIST::GetReg(), PANEL_REGULATOR_BASE::m_choiceRegType, PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, REGULATOR_DATA::m_Iadj, m_lastSelectedRegulatorName, REGULATOR_DATA::m_Name, m_RegulatorList, PANEL_REGULATOR_BASE::m_RegulIadjValue, PANEL_REGULATOR_BASE::m_RegulVrefValue, REGULATOR_DATA::m_Type, REGULATOR_DATA::m_Vref, name, and RegulatorPageUpdate().

Referenced by SelectLastSelectedRegulator().

◆ OnRegulTypeSelection()

void PANEL_REGULATOR::OnRegulTypeSelection ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 125 of file panel_regulator.cpp.

126{
128}

References RegulatorPageUpdate().

◆ OnRemoveRegulator()

void PANEL_REGULATOR::OnRemoveRegulator ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 251 of file panel_regulator.cpp.

252{
253 wxString name = wxGetSingleChoice( _("Remove Regulator"), wxEmptyString,
255 if( name.IsEmpty() )
256 return;
257
262
265
267}
void Remove(const wxString &aRegName)

References _, REGULATOR_LIST::GetRegList(), PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, m_lastSelectedRegulatorName, m_RegulatorList, m_RegulatorListChanged, name, REGULATOR_LIST::Remove(), and SelectLastSelectedRegulator().

◆ ReadDataFile()

bool PANEL_REGULATOR::ReadDataFile ( )

Definition at line 49 of file datafile_read_write.cpp.

50{
51 FILE* file = wxFopen( GetDataFilename(), wxT( "rt" ) );
52
53 if( file == nullptr )
54 return false;
55
56 // Switch the locale to standard C (needed to read/write floating point numbers)
57 LOCALE_IO toggle;
58
60
61 // dataReader dtor will close file
62 FILE_LINE_READER dataReader( file, GetDataFilename() );
63 PCB_CALCULATOR_DATAFILE_PARSER datafile_parser( &dataReader );
64
65 try
66 {
67 datafile_parser.Parse( datafile );
68 }
69 catch( const IO_ERROR& ioe )
70 {
71 delete datafile;
72
73 wxString msg = ioe.What();
74
75 msg += wxChar('\n');
76 msg += _("Data file error.");
77
78 wxMessageBox( msg );
79 return false;
80 }
81
85
86 delete datafile;
87
88 return true;
89}
A LINE_READER that reads from an open file.
Definition: richio.h:173
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
Parser for PCB_CALCULATOR_DATAFILE.
PCB_CALCULATOR_DATAFILE handles data to calculate regulators parameters.

References _, GetDataFilename(), REGULATOR_LIST::GetRegList(), PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, m_RegulatorList, PCB_CALCULATOR_DATAFILE_PARSER::Parse(), SelectLastSelectedRegulator(), and IO_ERROR::What().

Referenced by OnDataFileSelection().

◆ RegulatorPageUpdate()

void PANEL_REGULATOR::RegulatorPageUpdate ( )

Update the regulator page dialog display.

Enable the current regulator drawings and the formula used for calculations.

Definition at line 93 of file panel_regulator.cpp.

94{
95 switch( m_choiceRegType->GetSelection() )
96 {
97 default:
98 case 0:
99 m_bitmapRegul4pins->Show( true );
100 m_bitmapRegul3pins->Show( false );
101 m_RegulIadjValue->Enable( false );
102 m_RegulFormula->SetLabel( wxT( "Vout = Vref * (R1 + R2) / R2" ) );
103 break;
104
105 case 1:
106 m_bitmapRegul4pins->Show( false );
107 m_bitmapRegul3pins->Show( true );
108 m_RegulIadjValue->Enable( true );
109 m_RegulFormula->SetLabel( wxT( "Vout = Vref * (R1 + R2) / R1 + Iadj * R2" ) );
110 break;
111 }
112
113 // The new icon size must be taken in account
114 GetSizer()->Layout();
115
116 // Enable/disable buttons:
117 bool enbl = m_choiceRegulatorSelector->GetCount() > 0;
118 m_buttonEditItem->Enable( enbl );
119 m_buttonRemoveItem->Enable( enbl );
120
121 Refresh();
122}
wxStaticText * m_RegulFormula
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References PANEL_REGULATOR_BASE::m_bitmapRegul3pins, PANEL_REGULATOR_BASE::m_bitmapRegul4pins, PANEL_REGULATOR_BASE::m_buttonEditItem, PANEL_REGULATOR_BASE::m_buttonRemoveItem, PANEL_REGULATOR_BASE::m_choiceRegType, PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, PANEL_REGULATOR_BASE::m_RegulFormula, PANEL_REGULATOR_BASE::m_RegulIadjValue, and Refresh().

Referenced by OnRegulatorResetButtonClick(), OnRegulatorSelection(), and OnRegulTypeSelection().

◆ Regulators_WriteConfig()

void PANEL_REGULATOR::Regulators_WriteConfig ( PCB_CALCULATOR_SETTINGS aCfg)

Write regulators parameters in configuration.

Parameters
aCfgis the configuration settings.

Definition at line 402 of file panel_regulator.cpp.

403{
404 // Save current parameter values in config.
405 aCfg->m_Regulators.r1 = m_RegulR1Value->GetValue();
406 aCfg->m_Regulators.r2 = m_RegulR2Value->GetValue();
407 aCfg->m_Regulators.vref = m_RegulVrefValue->GetValue();
408 aCfg->m_Regulators.vout = m_RegulVoutValue->GetValue();
411 aCfg->m_Regulators.type = m_choiceRegType->GetSelection();
412
413 // Store the parameter selection that was recently calculated (R1, R2 or Vout)
414 wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
415
416 for( int ii = 0; ii < 3; ii++ )
417 {
418 if( regprms[ii]->GetValue() )
419 {
420 aCfg->m_Regulators.last_param = ii;
421 break;
422 }
423 }
424}

References PCB_CALCULATOR_SETTINGS::REGULATORS::data_file, GetDataFilename(), PCB_CALCULATOR_SETTINGS::REGULATORS::last_param, PANEL_REGULATOR_BASE::m_choiceRegType, m_lastSelectedRegulatorName, PANEL_REGULATOR_BASE::m_rbRegulR1, PANEL_REGULATOR_BASE::m_rbRegulR2, PANEL_REGULATOR_BASE::m_rbRegulVout, PCB_CALCULATOR_SETTINGS::m_Regulators, PANEL_REGULATOR_BASE::m_RegulR1Value, PANEL_REGULATOR_BASE::m_RegulR2Value, PANEL_REGULATOR_BASE::m_RegulVoutValue, PANEL_REGULATOR_BASE::m_RegulVrefValue, PCB_CALCULATOR_SETTINGS::REGULATORS::r1, PCB_CALCULATOR_SETTINGS::REGULATORS::r2, PCB_CALCULATOR_SETTINGS::REGULATORS::selected_regulator, PCB_CALCULATOR_SETTINGS::REGULATORS::type, PCB_CALCULATOR_SETTINGS::REGULATORS::vout, and PCB_CALCULATOR_SETTINGS::REGULATORS::vref.

◆ RegulatorsSolve()

void PANEL_REGULATOR::RegulatorsSolve ( )

Definition at line 293 of file panel_regulator.cpp.

294{
295 int id;
296
297 if( m_rbRegulR1->GetValue() )
298 {
299 id = 0; // for R1 calculation
300 }
301 else if( m_rbRegulR2->GetValue() )
302 {
303 id = 1; // for R2 calculation
304 }
305 else if( m_rbRegulVout->GetValue() )
306 {
307 id = 2; // for Vout calculation
308 }
309 else
310 {
311 wxMessageBox( wxT("Selection error" ) );
312 return;
313 }
314
315 double r1, r2, vref, vout;
316
317 wxString txt;
318
319 m_RegulMessage->SetLabel( wxEmptyString);
320
321 // Convert r1 and r2 in ohms
322 int r1scale = 1000;
323 int r2scale = 1000;
324
325 // Read values from panel:
326 txt = m_RegulR1Value->GetValue();
327 r1 = DoubleFromString( txt ) * r1scale;
328 txt = m_RegulR2Value->GetValue();
329 r2 = DoubleFromString( txt ) * r2scale;
330 txt = m_RegulVrefValue->GetValue();
331 vref = DoubleFromString( txt );
332 txt = m_RegulVoutValue->GetValue();
333 vout = DoubleFromString( txt );
334
335 // Some tests:
336 if( vout < vref && id != 2 )
337 {
338 m_RegulMessage->SetLabel( _("Vout must be greater than vref" ) );
339 return;
340 }
341
342 if( vref == 0.0 )
343 {
344 m_RegulMessage->SetLabel( _( "Vref set to 0 !" ) );
345 return;
346 }
347
348 if( ( r1 < 0 && id != 0 ) || ( r2 <= 0 && id != 1 ) )
349 {
350 m_RegulMessage->SetLabel( _("Incorrect value for R1 R2" ) );
351 return;
352 }
353
354 // Calculate
355 if( m_choiceRegType->GetSelection() == 1)
356 {
357 // 3 terminal regulator
358 txt = m_RegulIadjValue->GetValue();
359 double iadj = DoubleFromString( txt );
360
361 // iadj is given in micro amp, so convert it in amp.
362 iadj /= 1000000;
363
364 switch( id )
365 {
366 case 0:
367 r1 = vref * r2 / ( vout - vref - ( r2 * iadj ) );
368 break;
369
370 case 1:
371 r2 = ( vout - vref ) / ( iadj + ( vref / r1 ) );
372 break;
373
374 case 2:
375 vout = vref * ( r1 + r2 ) / r1;
376 vout += r2 * iadj;
377 break;
378 }
379 }
380 else
381 { // Standard 4 terminal regulator
382 switch( id )
383 {
384 case 0: r1 = ( vout / vref - 1 ) * r2; break;
385 case 1: r2 = r1 / ( vout / vref - 1 ); break;
386 case 2: vout = vref * ( r1 + r2 ) / r2; break;
387 }
388 }
389
390 // write values to panel:
391 txt.Printf( wxT( "%g" ), r1 / r1scale );
392 m_RegulR1Value->SetValue( txt );
393 txt.Printf( wxT( "%g" ), r2 / r2scale );
394 m_RegulR2Value->SetValue( txt );
395 txt.Printf( wxT( "%g" ), vref );
396 m_RegulVrefValue->SetValue( txt );
397 txt.Printf( wxT( "%g" ), vout );
398 m_RegulVoutValue->SetValue( txt );
399}
wxStaticText * m_RegulMessage
double DoubleFromString(const wxString &TextValue)

References _, DoubleFromString(), PANEL_REGULATOR_BASE::m_choiceRegType, PANEL_REGULATOR_BASE::m_rbRegulR1, PANEL_REGULATOR_BASE::m_rbRegulR2, PANEL_REGULATOR_BASE::m_rbRegulVout, PANEL_REGULATOR_BASE::m_RegulIadjValue, PANEL_REGULATOR_BASE::m_RegulMessage, PANEL_REGULATOR_BASE::m_RegulR1Value, PANEL_REGULATOR_BASE::m_RegulR2Value, PANEL_REGULATOR_BASE::m_RegulVoutValue, and PANEL_REGULATOR_BASE::m_RegulVrefValue.

Referenced by OnRegulatorCalcButtonClick().

◆ SaveSettings()

void PANEL_REGULATOR::SaveSettings ( PCB_CALCULATOR_SETTINGS aCfg)
overridevirtual

Save the settings from the panel.

Parameters
aCfgis the settings structure to save to

Implements CALCULATOR_PANEL.

Definition at line 448 of file panel_regulator.cpp.

449{
450 // TODO: This was empty for some reason, should we actually save settings here?
451}

◆ SelectLastSelectedRegulator()

void PANEL_REGULATOR::SelectLastSelectedRegulator ( )

If m_lastSelectedRegulatorName is empty, just calls RegulatorPageUpdate()

Definition at line 270 of file panel_regulator.cpp.

271{
272 // Find last selected in regulator list:
273 int idx = -1;
274
275 if( !m_lastSelectedRegulatorName.IsEmpty() )
276 {
277 for( unsigned ii = 0; ii < m_RegulatorList.GetCount(); ii++ )
278 {
280 {
281 idx = ii;
282 break;
283 }
284 }
285 }
286
287 m_choiceRegulatorSelector->SetSelection( idx );
288 wxCommandEvent event;
289 OnRegulatorSelection( event );
290}
void OnRegulatorSelection(wxCommandEvent &event) override
std::vector< REGULATOR_DATA * > m_List

References REGULATOR_LIST::GetCount(), PANEL_REGULATOR_BASE::m_choiceRegulatorSelector, m_lastSelectedRegulatorName, REGULATOR_LIST::m_List, m_RegulatorList, and OnRegulatorSelection().

Referenced by OnAddRegulator(), OnDataFileSelection(), OnEditRegulator(), OnRemoveRegulator(), PANEL_REGULATOR(), and ReadDataFile().

◆ SetDataFilename()

void PANEL_REGULATOR::SetDataFilename ( const wxString &  aFilename)

Initialize the full filename of the selected pcb_calculator data file force the standard extension of the file (.pcbcalc).

Parameters
aFilenameis the full filename, with or without extension.

Definition at line 465 of file panel_regulator.cpp.

466{
467 if( aFilename.IsEmpty() )
468 {
469 m_regulators_fileNameCtrl->SetValue( wxEmptyString );
470 }
471 else
472 {
473 wxFileName fn( aFilename );
474 fn.SetExt( DataFileNameExt );
475 m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
476 }
477}

References DataFileNameExt(), and PANEL_REGULATOR_BASE::m_regulators_fileNameCtrl.

Referenced by LoadSettings(), and OnDataFileSelection().

◆ ThemeChanged()

void PANEL_REGULATOR::ThemeChanged ( )
overridevirtual

Update UI elements of the panel when the theme changes to ensure the images and fonts/colors are appropriate for the new theme.

Implements CALCULATOR_PANEL.

Definition at line 65 of file panel_regulator.cpp.

66{
67 // Update the bitmaps
70}

References KiBitmap(), PANEL_REGULATOR_BASE::m_bitmapRegul3pins, PANEL_REGULATOR_BASE::m_bitmapRegul4pins, regul, and regul_3pins.

◆ WriteDataFile()

bool PANEL_REGULATOR::WriteDataFile ( )

Definition at line 92 of file datafile_read_write.cpp.

93{
94 // Switch the locale to standard C (needed to read/write floating point numbers)
95 LOCALE_IO toggle;
96
97 auto datafile = std::make_unique<PCB_CALCULATOR_DATAFILE>( &m_RegulatorList );
98
99 try
100 {
102
103 int nestlevel = datafile->WriteHeader( &formatter );
104
105 datafile->Format( &formatter, nestlevel );
106
107 while( nestlevel-- )
108 formatter.Print( nestlevel, ")\n" );
109 }
110 catch( const IO_ERROR& )
111 {
112 return false;
113 }
114
116 return true;
117}
Used for text file output.
Definition: richio.h:457

References GetDataFilename(), m_RegulatorList, m_RegulatorListChanged, and OUTPUTFORMATTER::Print().

Referenced by PCB_CALCULATOR_FRAME::OnClosePcbCalc().

Member Data Documentation

◆ m_bitmapRegul3pins

wxStaticBitmap* PANEL_REGULATOR_BASE::m_bitmapRegul3pins
protectedinherited

◆ m_bitmapRegul4pins

wxStaticBitmap* PANEL_REGULATOR_BASE::m_bitmapRegul4pins
protectedinherited

◆ m_buttonAddItem

wxButton* PANEL_REGULATOR_BASE::m_buttonAddItem
protectedinherited

◆ m_buttonCalculate

wxButton* PANEL_REGULATOR_BASE::m_buttonCalculate
protectedinherited

◆ m_buttonDataFile

wxButton* PANEL_REGULATOR_BASE::m_buttonDataFile
protectedinherited

◆ m_buttonEditItem

wxButton* PANEL_REGULATOR_BASE::m_buttonEditItem
protectedinherited

◆ m_buttonRegulReset

wxButton* PANEL_REGULATOR_BASE::m_buttonRegulReset
protectedinherited

◆ m_buttonRemoveItem

wxButton* PANEL_REGULATOR_BASE::m_buttonRemoveItem
protectedinherited

◆ m_choiceRegType

◆ m_choiceRegulatorSelector

◆ m_IadjUnitLabel

wxStaticText* PANEL_REGULATOR_BASE::m_IadjUnitLabel
protectedinherited

◆ m_labelRegultR1

wxStaticText* PANEL_REGULATOR_BASE::m_labelRegultR1
protectedinherited

Definition at line 49 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_labelRegultR2

wxStaticText* PANEL_REGULATOR_BASE::m_labelRegultR2
protectedinherited

Definition at line 53 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_labelVout

wxStaticText* PANEL_REGULATOR_BASE::m_labelVout
protectedinherited

Definition at line 57 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_labelVRef

wxStaticText* PANEL_REGULATOR_BASE::m_labelVRef
protectedinherited

Definition at line 60 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_lastSelectedRegulatorName

wxString PANEL_REGULATOR::m_lastSelectedRegulatorName

◆ m_r1Units

wxStaticText* PANEL_REGULATOR_BASE::m_r1Units
protectedinherited

◆ m_r2Units

wxStaticText* PANEL_REGULATOR_BASE::m_r2Units
protectedinherited

◆ m_rbRegulR1

wxRadioButton* PANEL_REGULATOR_BASE::m_rbRegulR1
protectedinherited

◆ m_rbRegulR2

wxRadioButton* PANEL_REGULATOR_BASE::m_rbRegulR2
protectedinherited

◆ m_rbRegulVout

wxRadioButton* PANEL_REGULATOR_BASE::m_rbRegulVout
protectedinherited

◆ m_RegulatorList

◆ m_RegulatorListChanged

bool PANEL_REGULATOR::m_RegulatorListChanged

◆ m_regulators_fileNameCtrl

wxTextCtrl* PANEL_REGULATOR_BASE::m_regulators_fileNameCtrl
protectedinherited

◆ m_RegulFormula

wxStaticText* PANEL_REGULATOR_BASE::m_RegulFormula
protectedinherited

◆ m_RegulIadjTitle

wxStaticText* PANEL_REGULATOR_BASE::m_RegulIadjTitle
protectedinherited

Definition at line 63 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_RegulIadjValue

wxTextCtrl* PANEL_REGULATOR_BASE::m_RegulIadjValue
protectedinherited

◆ m_RegulMessage

wxStaticText* PANEL_REGULATOR_BASE::m_RegulMessage
protectedinherited

◆ m_RegulR1Value

wxTextCtrl* PANEL_REGULATOR_BASE::m_RegulR1Value
protectedinherited

◆ m_RegulR2Value

wxTextCtrl* PANEL_REGULATOR_BASE::m_RegulR2Value
protectedinherited

◆ m_RegulVoutValue

wxTextCtrl* PANEL_REGULATOR_BASE::m_RegulVoutValue
protectedinherited

◆ m_RegulVrefValue

wxTextCtrl* PANEL_REGULATOR_BASE::m_RegulVrefValue
protectedinherited

◆ m_staticTextRegFile

wxStaticText* PANEL_REGULATOR_BASE::m_staticTextRegFile
protectedinherited

Definition at line 70 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_staticTextRegType

wxStaticText* PANEL_REGULATOR_BASE::m_staticTextRegType
protectedinherited

Definition at line 43 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_unitsVout

wxStaticText* PANEL_REGULATOR_BASE::m_unitsVout
protectedinherited

Definition at line 59 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().

◆ m_unitsVref

wxStaticText* PANEL_REGULATOR_BASE::m_unitsVref
protectedinherited

Definition at line 62 of file panel_regulator_base.h.

Referenced by PANEL_REGULATOR_BASE::PANEL_REGULATOR_BASE().


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