2013-05-26 04:36:44 +00:00
|
|
|
/**
|
|
|
|
* @file regulators_funct.cpp
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2011 jean-pierre.charras
|
2020-08-24 10:40:38 +00:00
|
|
|
* Copyright (C) 1992-2020 Kicad Developers, see AUTHORS.txt for contributors.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2019-05-01 18:57:59 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2013-05-26 04:36:44 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2019-05-01 18:57:59 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
|
|
|
#include <wx/wx.h>
|
|
|
|
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcb_calculator.h>
|
|
|
|
#include <class_regulator_data.h>
|
|
|
|
#include <dialog_regulator_data_base.h>
|
2020-08-24 10:40:38 +00:00
|
|
|
#include <pcb_calculator_settings.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
extern double DoubleFromString( const wxString& TextValue );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
class DIALOG_EDITOR_DATA: public DIALOG_EDITOR_DATA_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DIALOG_EDITOR_DATA( PCB_CALCULATOR_FRAME * parent, const wxString & aRegName )
|
|
|
|
: DIALOG_EDITOR_DATA_BASE( parent )
|
|
|
|
{
|
|
|
|
m_textCtrlName->SetValue( aRegName );
|
|
|
|
m_textCtrlName->Enable( aRegName.IsEmpty() );
|
|
|
|
UpdateDialog();
|
2019-08-10 08:05:13 +00:00
|
|
|
|
|
|
|
m_sdbSizerOK->SetDefault();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~DIALOG_EDITOR_DATA() {};
|
|
|
|
|
|
|
|
// Event called functions:
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnOKClick( wxCommandEvent& event ) override;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsOK()
|
|
|
|
* @return true if regulator parameters are acceptable
|
|
|
|
*/
|
|
|
|
bool IsOK();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function CopyRegulatorDataToDialog
|
|
|
|
* Transfert data from dialog to aItem
|
|
|
|
* @param aItem = a pointer to the REGULATOR_DATA
|
|
|
|
*/
|
|
|
|
void CopyRegulatorDataToDialog( REGULATOR_DATA * aItem );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function BuildRegulatorFromData
|
|
|
|
* Creates a new REGULATOR_DATA from dialog
|
|
|
|
* @return a pointer to the new REGULATOR_DATA
|
|
|
|
*/
|
|
|
|
REGULATOR_DATA * BuildRegulatorFromData();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/disable Iadj realted widgets, according to
|
|
|
|
* the regulator type
|
|
|
|
*/
|
|
|
|
void UpdateDialog()
|
|
|
|
{
|
|
|
|
bool enbl = m_choiceRegType->GetSelection() == 1;
|
|
|
|
m_RegulIadjValue->Enable( enbl );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called when the current regulator type is changed
|
|
|
|
*/
|
2016-09-25 17:06:49 +00:00
|
|
|
void OnRegTypeSelection( wxCommandEvent& event ) override
|
2013-05-26 04:36:44 +00:00
|
|
|
{
|
|
|
|
UpdateDialog();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EDITOR_DATA::OnOKClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( !IsOK() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _("Bad or missing parameters!") );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DIALOG_EDITOR_DATA::IsOK()
|
|
|
|
{
|
2016-01-16 14:27:42 +00:00
|
|
|
bool success = true;
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( m_textCtrlName->GetValue().IsEmpty() )
|
2016-01-16 14:27:42 +00:00
|
|
|
success = false;
|
2013-05-26 04:36:44 +00:00
|
|
|
if( m_textCtrlVref->GetValue().IsEmpty() )
|
2016-01-16 14:27:42 +00:00
|
|
|
success = false;
|
2013-05-26 04:36:44 +00:00
|
|
|
else
|
|
|
|
{
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
double vref = DoubleFromString( m_textCtrlVref->GetValue() );
|
2013-05-26 04:36:44 +00:00
|
|
|
if( fabs(vref) < 0.01 )
|
2016-01-16 14:27:42 +00:00
|
|
|
success = false;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
if( m_choiceRegType->GetSelection() == 1 )
|
|
|
|
{
|
|
|
|
if( m_RegulIadjValue->GetValue().IsEmpty() )
|
2016-01-16 14:27:42 +00:00
|
|
|
success = false;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
2016-01-16 14:27:42 +00:00
|
|
|
return success;
|
2013-05-26 04:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_EDITOR_DATA::CopyRegulatorDataToDialog( REGULATOR_DATA * aItem )
|
|
|
|
{
|
|
|
|
m_textCtrlName->SetValue( aItem->m_Name );
|
|
|
|
wxString value;
|
|
|
|
value.Printf( wxT("%g"), aItem->m_Vref );
|
|
|
|
m_textCtrlVref->SetValue( value );
|
|
|
|
value.Printf( wxT("%g"), aItem->m_Iadj );
|
|
|
|
m_RegulIadjValue->SetValue( value );
|
|
|
|
m_choiceRegType->SetSelection( aItem->m_Type );
|
|
|
|
UpdateDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
REGULATOR_DATA * DIALOG_EDITOR_DATA::BuildRegulatorFromData()
|
|
|
|
{
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
double vref = DoubleFromString( m_textCtrlVref->GetValue() );
|
|
|
|
double iadj = DoubleFromString( m_RegulIadjValue->GetValue() );
|
2013-05-26 04:36:44 +00:00
|
|
|
int type = m_choiceRegType->GetSelection();
|
2020-08-23 13:01:52 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
if( type != 1 )
|
|
|
|
iadj = 0.0;
|
2020-08-23 13:01:52 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
REGULATOR_DATA * item = new REGULATOR_DATA( m_textCtrlName->GetValue(),
|
|
|
|
vref, type, iadj );
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::OnRegulatorCalcButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
RegulatorsSolve();
|
|
|
|
}
|
|
|
|
|
2019-11-10 09:36:26 +00:00
|
|
|
void PCB_CALCULATOR_FRAME::OnRegulatorResetButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_RegulR1Value->SetValue( wxT( "10" ) );
|
|
|
|
m_RegulR2Value->SetValue( wxT( "10" ) );
|
|
|
|
m_RegulVrefValue->SetValue( wxT( "3" ) );
|
|
|
|
m_RegulVoutValue->SetValue( wxT( "12" ) );
|
|
|
|
m_choiceRegType->SetSelection( 0 );
|
|
|
|
m_rbRegulR1->SetValue(1);
|
|
|
|
m_rbRegulR2->SetValue(0);
|
|
|
|
m_rbRegulVout->SetValue(0);
|
|
|
|
RegulatorPageUpdate();
|
|
|
|
}
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
void PCB_CALCULATOR_FRAME::RegulatorPageUpdate()
|
|
|
|
{
|
|
|
|
switch( m_choiceRegType->GetSelection() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
m_bitmapRegul4pins->Show( true );
|
|
|
|
m_bitmapRegul3pins->Show( false );
|
|
|
|
m_RegulIadjValue->Enable( false );
|
|
|
|
m_RegulFormula->SetLabel( wxT("Vout = Vref * (R1 + R2) / R2") );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
m_bitmapRegul4pins->Show( false );
|
|
|
|
m_bitmapRegul3pins->Show( true );
|
|
|
|
m_RegulIadjValue->Enable( true );
|
|
|
|
m_RegulFormula->SetLabel( wxT("Vout = Vref * (R1 + R2) / R1 + Iadj * R2") );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// The new icon size must be taken in account
|
|
|
|
m_panelRegulators->GetSizer()->Layout();
|
|
|
|
|
|
|
|
// Enable/disable buttons:
|
|
|
|
bool enbl = m_choiceRegulatorSelector->GetCount() > 0;
|
|
|
|
m_buttonEditItem->Enable( enbl );
|
|
|
|
m_buttonRemoveItem->Enable( enbl );
|
|
|
|
|
|
|
|
m_panelRegulators->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::OnRegulTypeSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
RegulatorPageUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString name = m_choiceRegulatorSelector->GetStringSelection();
|
|
|
|
REGULATOR_DATA * item = m_RegulatorList.GetReg( name );
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
m_lastSelectedRegulatorName = item->m_Name;
|
|
|
|
m_choiceRegType->SetSelection( item->m_Type );
|
|
|
|
wxString value;
|
|
|
|
value.Printf( wxT("%g"), item->m_Vref );
|
|
|
|
m_RegulVrefValue->SetValue( value );
|
|
|
|
value.Printf( wxT("%g"), item->m_Iadj );
|
|
|
|
m_RegulIadjValue->SetValue( value );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call RegulatorPageUpdate to enable/sisable tools,
|
|
|
|
// even if no item selected
|
|
|
|
RegulatorPageUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when ckicking on button Browse:
|
|
|
|
* Select a new data file, and load it on request
|
|
|
|
*/
|
|
|
|
void PCB_CALCULATOR_FRAME::OnDataFileSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString fullfilename = GetDataFilename();
|
|
|
|
|
|
|
|
wxString wildcard;
|
2017-11-12 00:31:38 +00:00
|
|
|
wildcard.Printf( _("PCB Calculator data file (*.%s)|*.%s"),
|
2019-08-10 08:05:13 +00:00
|
|
|
DataFileNameExt, DataFileNameExt );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
wxFileDialog dlg( m_panelRegulators,
|
2017-11-12 00:31:38 +00:00
|
|
|
_("Select PCB Calculator Data File"),
|
2013-05-26 04:36:44 +00:00
|
|
|
wxEmptyString, fullfilename,
|
|
|
|
wildcard, wxFD_OPEN );
|
|
|
|
|
|
|
|
if (dlg.ShowModal() == wxID_CANCEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fullfilename = dlg.GetPath();
|
|
|
|
|
|
|
|
if( fullfilename == GetDataFilename() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetDataFilename( fullfilename );
|
|
|
|
if( wxFileExists( fullfilename ) && m_RegulatorList.GetCount() > 0 ) // Read file
|
|
|
|
{
|
|
|
|
if( wxMessageBox( _("Do you want to load this file and replace current regulator list?" ) )
|
|
|
|
!= wxID_OK )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ReadDataFile() )
|
|
|
|
{
|
|
|
|
m_RegulatorListChanged = false;
|
|
|
|
m_choiceRegulatorSelector->Clear();
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString msg;
|
2019-08-10 08:05:13 +00:00
|
|
|
msg.Printf( _("Unable to read data file \"%s\""), fullfilename );
|
2013-05-26 04:36:44 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::OnAddRegulator( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
DIALOG_EDITOR_DATA dlg( this, wxEmptyString );
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
if( !dlg.IsOK() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _("Bad or missing parameters!") );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REGULATOR_DATA * new_item = dlg.BuildRegulatorFromData();
|
|
|
|
|
|
|
|
// Add new item, if not existing
|
|
|
|
if( m_RegulatorList.GetReg( new_item->m_Name ) == NULL )
|
|
|
|
{
|
|
|
|
// Add item in list
|
|
|
|
m_RegulatorList.Add( new_item );
|
|
|
|
m_RegulatorListChanged = true;
|
|
|
|
m_choiceRegulatorSelector->Clear();
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
|
|
|
m_lastSelectedRegulatorName = new_item->m_Name;
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox( _("This regulator is already in list. Aborted") );
|
|
|
|
delete new_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::OnEditRegulator( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString name = m_choiceRegulatorSelector->GetStringSelection();
|
|
|
|
REGULATOR_DATA * item = m_RegulatorList.GetReg( name );
|
|
|
|
if( item == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
DIALOG_EDITOR_DATA dlg( this, name );
|
|
|
|
|
|
|
|
dlg.CopyRegulatorDataToDialog( item );
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
REGULATOR_DATA * new_item = dlg.BuildRegulatorFromData();
|
|
|
|
m_RegulatorList.Replace( new_item );
|
|
|
|
|
|
|
|
m_RegulatorListChanged = true;
|
|
|
|
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::OnRemoveRegulator( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString name = wxGetSingleChoice( _("Remove Regulator"), wxEmptyString,
|
|
|
|
m_RegulatorList.GetRegList() );
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_RegulatorList.Remove( name );
|
|
|
|
m_RegulatorListChanged = true;
|
|
|
|
m_choiceRegulatorSelector->Clear();
|
|
|
|
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
|
|
|
|
if( m_lastSelectedRegulatorName == name )
|
|
|
|
m_lastSelectedRegulatorName.Empty();
|
|
|
|
|
|
|
|
SelectLastSelectedRegulator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::SelectLastSelectedRegulator()
|
|
|
|
{
|
|
|
|
// Find last selected in regulator list:
|
|
|
|
int idx = -1;
|
|
|
|
if( ! m_lastSelectedRegulatorName.IsEmpty() )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < m_RegulatorList.GetCount(); ii++ )
|
|
|
|
if( m_RegulatorList.m_List[ii]->m_Name == m_lastSelectedRegulatorName )
|
|
|
|
{
|
|
|
|
idx = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_choiceRegulatorSelector->SetSelection( idx );
|
|
|
|
wxCommandEvent event;
|
|
|
|
OnRegulatorSelection( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate a value from the 3 other values
|
|
|
|
// Vref is given by the regulator properties, so
|
|
|
|
// we can calculate only R1, R2 or Vout
|
|
|
|
void PCB_CALCULATOR_FRAME::RegulatorsSolve()
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
if( m_rbRegulR1->GetValue() )
|
|
|
|
id = 0; // for R1 calculation
|
|
|
|
else if( m_rbRegulR2->GetValue() )
|
|
|
|
id = 1; // for R2 calculation
|
|
|
|
else if( m_rbRegulVout->GetValue() )
|
|
|
|
id = 2; // for Vout calculation
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT("Selection error" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double r1, r2, vref, vout;
|
|
|
|
|
|
|
|
wxString txt;
|
|
|
|
|
|
|
|
m_RegulMessage->SetLabel( wxEmptyString);
|
|
|
|
|
|
|
|
// Convert r1 and r2 in ohms
|
|
|
|
int r1scale = 1000;
|
|
|
|
int r2scale = 1000;
|
|
|
|
|
|
|
|
// Read values from panel:
|
|
|
|
txt = m_RegulR1Value->GetValue();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
r1 = DoubleFromString(txt) * r1scale;
|
2013-05-26 04:36:44 +00:00
|
|
|
txt = m_RegulR2Value->GetValue();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
r2 = DoubleFromString(txt) * r2scale;
|
2013-05-26 04:36:44 +00:00
|
|
|
txt = m_RegulVrefValue->GetValue();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
vref = DoubleFromString(txt);
|
2013-05-26 04:36:44 +00:00
|
|
|
txt = m_RegulVoutValue->GetValue();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
vout = DoubleFromString(txt);
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Some tests:
|
|
|
|
if( vout < vref && id != 2)
|
|
|
|
{
|
2017-06-07 10:56:20 +00:00
|
|
|
m_RegulMessage->SetLabel( _("Vout must be greater than vref" ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( vref == 0.0 )
|
|
|
|
{
|
2017-06-07 10:56:20 +00:00
|
|
|
m_RegulMessage->SetLabel( _("Vref set to 0 !" ) );
|
2013-05-26 04:36:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (r1 < 0 && id != 0 ) || (r2 <= 0 && id != 1) )
|
|
|
|
{
|
|
|
|
m_RegulMessage->SetLabel( _("Incorrect value for R1 R2" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate
|
|
|
|
if( m_choiceRegType->GetSelection() == 1)
|
|
|
|
{
|
|
|
|
// 3 terminal regulator
|
|
|
|
txt = m_RegulIadjValue->GetValue();
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
double iadj = DoubleFromString(txt);
|
2013-05-26 04:36:44 +00:00
|
|
|
// iadj is given in micro amp, so convert it in amp.
|
|
|
|
iadj /= 1000000;
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
r1 = vref * r2 / ( vout - vref - (r2 * iadj) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
r2 = ( vout - vref ) / ( iadj + (vref/r1) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
vout = vref * (r1 + r2) / r1;
|
|
|
|
vout += r2 * iadj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Standard 4 terminal regulator
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
r1 = ( vout / vref - 1 ) * r2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
r2 = r1 / ( vout / vref - 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
vout = vref * (r1 + r2) / r2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// write values to panel:
|
|
|
|
txt.Printf(wxT("%g"), r1 / r1scale );
|
|
|
|
m_RegulR1Value->SetValue(txt);
|
|
|
|
txt.Printf(wxT("%g"), r2 / r2scale);
|
|
|
|
m_RegulR2Value->SetValue(txt);
|
|
|
|
txt.Printf(wxT("%g"), vref);
|
|
|
|
m_RegulVrefValue->SetValue(txt);
|
|
|
|
txt.Printf(wxT("%g"), vout);
|
|
|
|
m_RegulVoutValue->SetValue(txt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-24 10:40:38 +00:00
|
|
|
|
|
|
|
void PCB_CALCULATOR_FRAME::Regulators_WriteConfig( PCB_CALCULATOR_SETTINGS* aCfg )
|
|
|
|
{
|
|
|
|
// Save current parameter values in config.
|
|
|
|
aCfg->m_Regulators.r1 = m_RegulR1Value->GetValue();
|
|
|
|
aCfg->m_Regulators.r2 = m_RegulR2Value->GetValue();
|
|
|
|
aCfg->m_Regulators.vref = m_RegulVrefValue->GetValue();
|
|
|
|
aCfg->m_Regulators.vout = m_RegulVoutValue->GetValue();
|
|
|
|
aCfg->m_Regulators.data_file = GetDataFilename();
|
|
|
|
aCfg->m_Regulators.selected_regulator = m_lastSelectedRegulatorName;
|
|
|
|
aCfg->m_Regulators.type = m_choiceRegType->GetSelection();
|
|
|
|
|
|
|
|
// Store the parameter selection that was recently calculated (R1, R2 or Vout)
|
|
|
|
wxRadioButton * regprms[3] =
|
|
|
|
{
|
|
|
|
m_rbRegulR1, m_rbRegulR2, m_rbRegulVout
|
|
|
|
};
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 3; ii++ )
|
|
|
|
{
|
|
|
|
if( regprms[ii]->GetValue() )
|
|
|
|
{
|
|
|
|
aCfg->m_Regulators.last_param = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|