diff --git a/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp b/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp index 5418fa4fdf..1d90c7ab17 100644 --- a/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp +++ b/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp @@ -127,6 +127,8 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow m_labelVRef = new wxStaticText( m_panelRegulators, wxID_ANY, _("Vref"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelVRef->Wrap( -1 ); + m_labelVRef->SetToolTip( _("The internal reference voltage of the regulator.\nShould not be 0.") ); + fgSizerRegParams->Add( m_labelVRef, 0, wxALL, 5 ); m_RegulVrefValue = new wxTextCtrl( m_panelRegulators, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); @@ -141,6 +143,8 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow m_RegulIadjTitle = new wxStaticText( m_panelRegulators, wxID_ANY, _("Iadj"), wxDefaultPosition, wxDefaultSize, 0 ); m_RegulIadjTitle->Wrap( -1 ); + m_RegulIadjTitle->SetToolTip( _("For 3 terminal regulators only, the Adjust pin current.") ); + fgSizerRegParams->Add( m_RegulIadjTitle, 0, wxALL, 5 ); m_RegulIadjValue = new wxTextCtrl( m_panelRegulators, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); @@ -155,6 +159,8 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow m_staticTextRegType = new wxStaticText( m_panelRegulators, wxID_ANY, _("Type"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextRegType->Wrap( -1 ); + m_staticTextRegType->SetToolTip( _("Type of the regulator.\nThere are 2 types:\n- regulators which have a dedicted sense pin for the voltage regulation.\n- 3 terminal pins.") ); + fgSizerRegParams->Add( m_staticTextRegType, 0, wxALL, 5 ); wxString m_choiceRegTypeChoices[] = { _("Standard Type"), _("3 Terminal Type") }; @@ -182,26 +188,28 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow m_staticTextRegFile = new wxStaticText( m_panelRegulators, wxID_ANY, _("Regulators data file:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextRegFile->Wrap( -1 ); + m_staticTextRegFile->SetToolTip( _("The name of the data file which stores known regulators parameters.") ); + sbSizerRegulatorsChooser->Add( m_staticTextRegFile, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - m_regulators_filePicker = new wxFilePickerCtrl( m_panelRegulators, wxID_ANY, wxEmptyString, _("Select a file"), wxT("*.pcbcalc"), wxDefaultPosition, wxDefaultSize, wxFLP_SAVE|wxFLP_USE_TEXTCTRL ); + m_regulators_filePicker = new wxFilePickerCtrl( m_panelRegulators, wxID_ANY, wxEmptyString, _("Select a Pcb Calculator data file"), wxT("*.pcbcalc"), wxDefaultPosition, wxDefaultSize, wxFLP_SAVE|wxFLP_USE_TEXTCTRL ); sbSizerRegulatorsChooser->Add( m_regulators_filePicker, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* bSizerReulBtn; bSizerReulBtn = new wxBoxSizer( wxHORIZONTAL ); m_buttonEditItem = new wxButton( m_panelRegulators, wxID_ANY, _("Edit Regulator"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonEditItem->SetToolTip( _("Enter a new item in the current list of availlable regulators") ); + m_buttonEditItem->SetToolTip( _("Edit the current selected regulator.") ); bSizerReulBtn->Add( m_buttonEditItem, 0, wxALL, 5 ); m_buttonAddItem = new wxButton( m_panelRegulators, wxID_ANY, _("Add Regulator"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonAddItem->SetToolTip( _("Enter a new item in the current list of availlable regulators") ); + m_buttonAddItem->SetToolTip( _("Enter a new item to the current list of available regulators") ); bSizerReulBtn->Add( m_buttonAddItem, 1, wxALL, 5 ); m_buttonRemoveItem = new wxButton( m_panelRegulators, wxID_ANY, _("Remove Regulator"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonRemoveItem->SetToolTip( _("Remove an item in the current list of availlable regulators") ); + m_buttonRemoveItem->SetToolTip( _("Remove an item from the current list of available regulators") ); bSizerReulBtn->Add( m_buttonRemoveItem, 1, wxALL, 5 ); @@ -1241,6 +1249,7 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow this->Centre( wxBOTH ); // Connect Events + this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( PCB_CALCULATOR_FRAME_BASE::OnClosePcbCalc ) ); m_choiceRegType->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRegulTypeSelection ), NULL, this ); m_buttonCalculate->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRegulatorCalcButtonClick ), NULL, this ); m_choiceRegulatorSelector->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRegulatorSelection ), NULL, this ); @@ -1269,6 +1278,7 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow PCB_CALCULATOR_FRAME_BASE::~PCB_CALCULATOR_FRAME_BASE() { // Disconnect Events + this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( PCB_CALCULATOR_FRAME_BASE::OnClosePcbCalc ) ); m_choiceRegType->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRegulTypeSelection ), NULL, this ); m_buttonCalculate->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRegulatorCalcButtonClick ), NULL, this ); m_choiceRegulatorSelector->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRegulatorSelection ), NULL, this ); diff --git a/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp b/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp index af1ddb6b7d..b5e78c2458 100644 --- a/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp +++ b/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp @@ -94,7 +94,7 @@ - + OnClosePcbCalc @@ -1920,7 +1920,7 @@ 0 - + The internal reference voltage of the regulator. Should not be 0. wxFILTER_NONE wxDefaultValidator @@ -2195,7 +2195,7 @@ 0 - + For 3 terminal regulators only, the Adjust pin current. wxFILTER_NONE wxDefaultValidator @@ -2470,7 +2470,7 @@ 0 - + Type of the regulator. There are 2 types: - regulators which have a dedicted sense pin for the voltage regulation. - 3 terminal pins. wxFILTER_NONE wxDefaultValidator @@ -2845,7 +2845,7 @@ 0 - + The name of the data file which stores known regulators parameters. wxFILTER_NONE wxDefaultValidator @@ -2914,7 +2914,7 @@ 0 - Select a file + Select a Pcb Calculator data file 0 @@ -3031,7 +3031,7 @@ 0 - Enter a new item in the current list of availlable regulators + Edit the current selected regulator. wxFILTER_NONE wxDefaultValidator @@ -3119,7 +3119,7 @@ 0 - Enter a new item in the current list of availlable regulators + Enter a new item to the current list of available regulators wxFILTER_NONE wxDefaultValidator @@ -3207,7 +3207,7 @@ 0 - Remove an item in the current list of availlable regulators + Remove an item from the current list of available regulators wxFILTER_NONE wxDefaultValidator @@ -7515,7 +7515,7 @@ Electrical Spacing 0 - + 1 1 1 @@ -7593,25 +7593,25 @@ - + bSizerElectricalClearance wxHORIZONTAL none - + 5 wxEXPAND 0 - + bLeftSizerElectricalClearance wxVERTICAL none - + 5 wxALL|wxEXPAND 0 - + 1 1 1 @@ -7695,11 +7695,11 @@ - + 5 wxEXPAND | wxALL 0 - + 1 1 1 @@ -7780,11 +7780,11 @@ - + 5 wxTOP|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -7867,11 +7867,11 @@ - + 5 wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -7958,11 +7958,11 @@ - + 5 wxALL|wxEXPAND 0 - + 1 1 1 @@ -8048,20 +8048,20 @@ - + 5 wxEXPAND 1 - + bElectricalSpacingSizerRight wxVERTICAL none - + 5 wxALIGN_CENTER_HORIZONTAL|wxTOP|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -8144,11 +8144,11 @@ - + 5 wxALL|wxEXPAND 0 - + 1 1 1 @@ -8291,11 +8291,11 @@ - + 5 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -14968,7 +14968,7 @@ RF Attenuators 0 - + 1 1 1 @@ -15046,7 +15046,7 @@ - + wxID_ANY label @@ -17266,7 +17266,7 @@ - + 5 wxEXPAND 1 diff --git a/pcb_calculator/dialogs/pcb_calculator_frame_base.h b/pcb_calculator/dialogs/pcb_calculator_frame_base.h index 350b975c91..25f01a9342 100644 --- a/pcb_calculator/dialogs/pcb_calculator_frame_base.h +++ b/pcb_calculator/dialogs/pcb_calculator_frame_base.h @@ -259,6 +259,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame wxPanel* m_panelShowClassPrms; // Virtual event handlers, overide them in your derived class + virtual void OnClosePcbCalc( wxCloseEvent& event ) { event.Skip(); } virtual void OnRegulTypeSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulatorSelection( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcb_calculator/pcb_calculator.cpp b/pcb_calculator/pcb_calculator.cpp index ea80bc9493..09cb48d3f4 100644 --- a/pcb_calculator/pcb_calculator.cpp +++ b/pcb_calculator/pcb_calculator.cpp @@ -57,7 +57,7 @@ IMPLEMENT_APP( EDA_APP ) bool EDA_APP::OnInit() { - InitEDA_Appl( wxT( "PCBcalc" ) ); + InitEDA_Appl( wxT( "pcb_calculator" ) ); wxFrame* frame = new PCB_CALCULATOR_FRAME( NULL ); SetTopWindow( frame ); diff --git a/pcb_calculator/pcb_calculator.h b/pcb_calculator/pcb_calculator.h index 69fe84ccaf..afbd959a8e 100644 --- a/pcb_calculator/pcb_calculator.h +++ b/pcb_calculator/pcb_calculator.h @@ -46,6 +46,8 @@ public: private: // Event handlers + void OnClosePcbCalc( wxCloseEvent& event ); + // These 3 functions are called by the OnPaint event, to draw // icons that show the current item on the specific panels void OnPaintTranslinePanel( wxPaintEvent& event ); @@ -64,6 +66,11 @@ private: return m_regulators_filePicker->GetPath(); } + void SetDataFilename( const wxString & aFilename) + { + m_regulators_filePicker->SetPath( aFilename ); + } + // tracks width versus current functions: /** * Function OnTWCalculateButt diff --git a/pcb_calculator/pcb_calculator_frame.cpp b/pcb_calculator/pcb_calculator_frame.cpp index 7bd169e721..8277bd6dea 100644 --- a/pcb_calculator/pcb_calculator_frame.cpp +++ b/pcb_calculator/pcb_calculator_frame.cpp @@ -44,10 +44,10 @@ #define KEYWORD_REGUL_R2 wxT( "RegulR2" ) #define KEYWORD_REGUL_VREF wxT( "RegulVREF" ) #define KEYWORD_REGUL_VOUT wxT( "RegulVOUT" ) -#define KEYWORD_REGUL_FILENAME wxT( "RegulListFilename" ) #define KEYWORD_REGUL_SELECTED wxT( "RegulName" ) #define KEYWORD_REGUL_TYPE wxT( "RegulType" ) #define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" ) +#define KEYWORD_DATAFILE_FILENAME wxT( "DataFilename" ) PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow* parent ) : PCB_CALCULATOR_FRAME_BASE( parent ) @@ -116,10 +116,6 @@ PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME() { WriteConfig(); - if( m_RegulatorListChanged ) - WriteDataFile(); - - for( unsigned ii = 0; ii < m_transline_list.size(); ii++ ) delete m_transline_list[ii]; @@ -134,6 +130,37 @@ PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME() this->Freeze(); } +void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event ) +{ + if( m_RegulatorListChanged ) + { + if( GetDataFilename().IsEmpty() ) + { + int opt = wxMessageBox( _("Data modified, and no data filename to save modifications\n"\ +"Do you want to exit and abandon your change?"), + _("Regulator list change"), + wxYES_NO | wxICON_QUESTION ); + if( opt == wxNO ) + return; + } + else + { + if( !WriteDataFile() ) + { + wxString msg; + msg.Printf( _("Unable to write file<%s>\n"\ +"Do you want to exit and abandon your change?"), GetDataFilename() ); + + int opt = wxMessageBox( msg, _("Write Data File Errror"), + wxYES_NO | wxICON_QUESTION ); + if( opt == wxNO ) + return; + } + } + } + + Destroy(); +} void PCB_CALCULATOR_FRAME::ReadConfig() { @@ -166,8 +193,8 @@ void PCB_CALCULATOR_FRAME::ReadConfig() m_RegulVrefValue->SetValue( msg ); m_Config->Read( KEYWORD_REGUL_VOUT, &msg, wxT( "12" ) ); m_RegulVoutValue->SetValue( msg ); - m_Config->Read( KEYWORD_REGUL_FILENAME, &msg, wxT( "" ) ); - m_regulators_filePicker->SetPath( msg ); + m_Config->Read( KEYWORD_DATAFILE_FILENAME, &msg, wxT( "" ) ); + SetDataFilename( msg ); m_Config->Read( KEYWORD_REGUL_SELECTED, &msg, wxT( "" ) ); m_lastSelectedRegulatorName = msg; m_Config->Read( KEYWORD_REGUL_TYPE, <mp, 0 ); @@ -221,7 +248,7 @@ void PCB_CALCULATOR_FRAME::WriteConfig() m_Config->Write( KEYWORD_REGUL_R2, m_RegulR2Value->GetValue() ); m_Config->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() ); m_Config->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() ); - m_Config->Write( KEYWORD_REGUL_FILENAME, m_regulators_filePicker->GetPath() ); + m_Config->Write( KEYWORD_DATAFILE_FILENAME, GetDataFilename() ); m_Config->Write( KEYWORD_REGUL_SELECTED, m_lastSelectedRegulatorName ); m_Config->Write( KEYWORD_REGUL_TYPE, m_choiceRegType->GetSelection() ); diff --git a/pcb_calculator/regulators_funct.cpp b/pcb_calculator/regulators_funct.cpp index 4366000ffe..d7840161dc 100644 --- a/pcb_calculator/regulators_funct.cpp +++ b/pcb_calculator/regulators_funct.cpp @@ -47,6 +47,15 @@ public: ~DIALOG_EDITOR_DATA() {}; + // Event called functions: + void OnOKClick( wxCommandEvent& event ); + + /** + * Function IsOK() + * @return true if regulator parameters are acceptable + */ + bool IsOK(); + /** * Function CopyRegulatorDataToDialog * Transfert data from dialog to aItem @@ -83,6 +92,33 @@ public: }; +void DIALOG_EDITOR_DATA::OnOKClick( wxCommandEvent& event ) +{ + if( !IsOK() ) + { + wxMessageBox( _("Bad or missing parameters!") ); + return; + } + + EndModal( wxID_OK ); +} + +bool DIALOG_EDITOR_DATA::IsOK() +{ + bool ok = true; + if( m_textCtrlName->GetValue().IsEmpty() ) + ok = false; + if( m_textCtrlVref->GetValue().IsEmpty() ) + ok = false; + if( m_choiceRegType->GetSelection() == 1 ) + { + if( m_RegulIadjValue->GetValue().IsEmpty() ) + ok = false; + } + + return ok; +} + void DIALOG_EDITOR_DATA::CopyRegulatorDataToDialog( REGULATOR_DATA * aItem ) { m_textCtrlName->SetValue( aItem->m_Name ); @@ -137,6 +173,12 @@ void PCB_CALCULATOR_FRAME::RegulatorPageUpdate() } // 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(); } @@ -158,9 +200,11 @@ void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event ) m_RegulVrefValue->SetValue( value ); value.Printf( wxT("%g"), item->m_Iadj ); m_RegulIadjValue->SetValue( value ); - - RegulatorPageUpdate(); } + + // Call RegulatorPageUpdate to enable/sisable tools, + // even if no item selected + RegulatorPageUpdate(); } void PCB_CALCULATOR_FRAME::OnDataFileSelection( wxFileDirPickerEvent& event ) @@ -172,6 +216,11 @@ 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(); @@ -183,6 +232,7 @@ void PCB_CALCULATOR_FRAME::OnAddRegulator( wxCommandEvent& event ) m_RegulatorListChanged = true; m_choiceRegulatorSelector->Clear(); m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() ); + m_lastSelectedRegulatorName = new_item->m_Name; SelectLastSelectedRegulator(); } else @@ -196,7 +246,11 @@ 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; @@ -305,7 +359,8 @@ void PCB_CALCULATOR_FRAME::RegulatorsSolve() // Calculate if( m_choiceRegType->GetSelection() == 1) - { // 3 terminal regulator + { + // 3 terminal regulator txt = m_RegulIadjValue->GetValue(); double iadj = ReturnDoubleFromString(txt); // iadj is given in micro amp, so convert it in amp. @@ -318,7 +373,6 @@ void PCB_CALCULATOR_FRAME::RegulatorsSolve() break; case 1: - // to do r2 = ( vout - vref ) / ( iadj + (vref/r1) ); break;