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
 
wxChoice * m_choiceRegulatorSelector
 
wxStaticText * m_staticTextRegFile
 
wxTextCtrl * m_regulators_fileNameCtrl
 
wxButton * m_buttonDataFile
 
wxButton * m_buttonEditItem
 
wxButton * m_buttonAddItem
 
wxButton * m_buttonRemoveItem
 
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
 
wxStaticText * m_RegulMessage
 
wxButton * m_buttonRegulReset
 

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 37 of file panel_regulator.cpp.

38 :
39 PANEL_REGULATOR_BASE( parent, id, pos, size, style, name ),
41{
42 m_IadjUnitLabel->SetLabel( wxT( "µA" ) );
43 m_r1Units->SetLabel( wxT( "kΩ" ) );
44 m_r2Units->SetLabel( wxT( "kΩ" ) );
45
48
51
52 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
53 GetSizer()->SetSizeHints( this );
54}
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:106
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(-1,-1), 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 56 of file panel_regulator.cpp.

57{
58}

Member Function Documentation

◆ GetDataFilename()

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

Definition at line 450 of file panel_regulator.cpp.

451{
452 if( m_regulators_fileNameCtrl->GetValue().IsEmpty() )
453 return wxEmptyString;
454
455 wxFileName fn( m_regulators_fileNameCtrl->GetValue() );
456 fn.SetExt( DataFileNameExt );
457 return fn.GetFullPath();
458}
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 423 of file panel_regulator.cpp.

424{
425 m_RegulR1Value->SetValue( aCfg->m_Regulators.r1 );
426 m_RegulR2Value->SetValue( aCfg->m_Regulators.r2 );
427 m_RegulVrefValue->SetValue( aCfg->m_Regulators.vref );
428 m_RegulVoutValue->SetValue( aCfg->m_Regulators.vout );
431 m_choiceRegType->SetSelection( aCfg->m_Regulators.type );
432
433 wxRadioButton* regprms[3] = { m_rbRegulR1, m_rbRegulR2, m_rbRegulVout };
434
435 if( aCfg->m_Regulators.last_param >= 3 )
436 aCfg->m_Regulators.last_param = 0;
437
438 for( int ii = 0; ii < 3; ii++ )
439 regprms[ii]->SetValue( aCfg->m_Regulators.last_param == ii );
440
441}
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 195 of file panel_regulator.cpp.

196{
197 DIALOG_REGULATOR_FORM dlg( this, wxEmptyString );
198
199 if( dlg.ShowModal() != wxID_OK )
200 return;
201
202 REGULATOR_DATA* new_item = dlg.BuildRegulatorFromData();
203
204 // Add new item, if not existing
205 if( m_RegulatorList.GetReg( new_item->m_Name ) == nullptr )
206 {
207 // Add item in list
208 m_RegulatorList.Add( new_item );
214 }
215 else
216 {
217 wxMessageBox( _( "This regulator is already in list. Aborted" ) );
218 delete new_item;
219 }
220}
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 149 of file panel_regulator.cpp.

150{
151 wxString fullfilename = GetDataFilename();
152
153 wxString wildcard;
154 wildcard.Printf( _( "PCB Calculator data file" ) + wxT( " (*.%s)|*.%s" ),
156
157 wxFileDialog dlg( this, _( "Select PCB Calculator Data File" ), wxEmptyString, fullfilename,
158 wildcard, wxFD_OPEN );
159
160 if( dlg.ShowModal() == wxID_CANCEL )
161 return;
162
163 fullfilename = dlg.GetPath();
164
165 if( fullfilename == GetDataFilename() )
166 return;
167
168 SetDataFilename( fullfilename );
169
170 if( wxFileExists( fullfilename ) && m_RegulatorList.GetCount() > 0 ) // Read file
171 {
172 if( wxMessageBox( _( "Do you want to load this file and replace current regulator list?" ) )
173 != wxID_OK )
174 {
175 return;
176 }
177 }
178
179 if( ReadDataFile() )
180 {
185 }
186 else
187 {
188 wxString msg;
189 msg.Printf( _( "Unable to read data file '%s'." ), fullfilename );
190 wxMessageBox( msg );
191 }
192}
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 223 of file panel_regulator.cpp.

224{
225 wxString name = m_choiceRegulatorSelector->GetStringSelection();
227
228 if( item == nullptr )
229 return;
230
231 DIALOG_REGULATOR_FORM dlg( this, name );
232
233 dlg.CopyRegulatorDataToDialog( item );
234
235 if( dlg.ShowModal() != wxID_OK )
236 return;
237
238 REGULATOR_DATA* new_item = dlg.BuildRegulatorFromData();
239 m_RegulatorList.Replace( new_item );
240
242
244}
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 69 of file panel_regulator.cpp.

70{
72}

References RegulatorsSolve().

◆ OnRegulatorResetButtonClick()

void PANEL_REGULATOR::OnRegulatorResetButtonClick ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 75 of file panel_regulator.cpp.

76{
77 m_RegulR1Value->SetValue( wxT( "10" ) );
78 m_RegulR2Value->SetValue( wxT( "10" ) );
79 m_RegulVrefValue->SetValue( wxT( "3" ) );
80 m_RegulVoutValue->SetValue( wxT( "12" ) );
81 m_choiceRegType->SetSelection( 0 );
82 m_rbRegulR1->SetValue( true );
83 m_rbRegulR2->SetValue( false );
84 m_rbRegulVout->SetValue( false );
86}
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 127 of file panel_regulator.cpp.

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

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 121 of file panel_regulator.cpp.

122{
124}

References RegulatorPageUpdate().

◆ OnRemoveRegulator()

void PANEL_REGULATOR::OnRemoveRegulator ( wxCommandEvent &  event)
overridevirtual

Reimplemented from PANEL_REGULATOR_BASE.

Definition at line 247 of file panel_regulator.cpp.

248{
249 wxString name = wxGetSingleChoice( _( "Remove Regulator" ), wxEmptyString,
251 if( name.IsEmpty() )
252 return;
253
258
261
263}
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 89 of file panel_regulator.cpp.

90{
91 switch( m_choiceRegType->GetSelection() )
92 {
93 default:
94 case 0:
95 m_bitmapRegul4pins->Show( true );
96 m_bitmapRegul3pins->Show( false );
97 m_RegulIadjValue->Enable( false );
98 m_RegulFormula->SetLabel( wxT( "Vout = Vref * (R1 + R2) / R2" ) );
99 break;
100
101 case 1:
102 m_bitmapRegul4pins->Show( false );
103 m_bitmapRegul3pins->Show( true );
104 m_RegulIadjValue->Enable( true );
105 m_RegulFormula->SetLabel( wxT( "Vout = Vref * (R1 + R2) / R1 + Iadj * R2" ) );
106 break;
107 }
108
109 // The new icon size must be taken in account
110 GetSizer()->Layout();
111
112 // Enable/disable buttons:
113 bool enbl = m_choiceRegulatorSelector->GetCount() > 0;
114 m_buttonEditItem->Enable( enbl );
115 m_buttonRemoveItem->Enable( enbl );
116
117 Refresh();
118}
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 398 of file panel_regulator.cpp.

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

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 289 of file panel_regulator.cpp.

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

445{
446 // TODO: This was empty for some reason, should we actually save settings here?
447}

◆ SelectLastSelectedRegulator()

void PANEL_REGULATOR::SelectLastSelectedRegulator ( )

If m_lastSelectedRegulatorName is empty, just calls RegulatorPageUpdate()

Definition at line 266 of file panel_regulator.cpp.

267{
268 // Find last selected in regulator list:
269 int idx = -1;
270
271 if( !m_lastSelectedRegulatorName.IsEmpty() )
272 {
273 for( unsigned ii = 0; ii < m_RegulatorList.GetCount(); ii++ )
274 {
276 {
277 idx = ii;
278 break;
279 }
280 }
281 }
282
283 m_choiceRegulatorSelector->SetSelection( idx );
284 wxCommandEvent event;
285 OnRegulatorSelection( event );
286}
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 461 of file panel_regulator.cpp.

462{
463 if( aFilename.IsEmpty() )
464 {
465 m_regulators_fileNameCtrl->SetValue( wxEmptyString );
466 }
467 else
468 {
469 wxFileName fn( aFilename );
470 fn.SetExt( DataFileNameExt );
471 m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() );
472 }
473}

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 61 of file panel_regulator.cpp.

62{
63 // Update the bitmaps
66}

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 56 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 60 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 64 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 67 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 70 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 49 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 66 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 69 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: