From 100ea3a59bca8397adae5b137c1900e4f48900a7 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 5 Apr 2012 20:56:06 +0200 Subject: [PATCH] Finish Pcb Calculator work --- .../dialogs/pcb_calculator_frame_base.cpp | 17 +- .../dialogs/pcb_calculator_frame_base.fbp | 269 ++++++++++++------ .../dialogs/pcb_calculator_frame_base.h | 6 +- pcb_calculator/pcb_calculator.h | 24 +- pcb_calculator/pcb_calculator_frame.cpp | 34 ++- pcb_calculator/regulators_funct.cpp | 55 +++- 6 files changed, 303 insertions(+), 102 deletions(-) diff --git a/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp b/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp index 1d90c7ab17..63ef5b328f 100644 --- a/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp +++ b/pcb_calculator/dialogs/pcb_calculator_frame_base.cpp @@ -192,8 +192,17 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow sbSizerRegulatorsChooser->Add( m_staticTextRegFile, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - 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* bSizerDataFile; + bSizerDataFile = new wxBoxSizer( wxHORIZONTAL ); + + m_regulators_fileNameCtrl = new wxTextCtrl( m_panelRegulators, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + bSizerDataFile->Add( m_regulators_fileNameCtrl, 1, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + m_buttonDataFile = new wxButton( m_panelRegulators, wxID_ANY, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerDataFile->Add( m_buttonDataFile, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + + sbSizerRegulatorsChooser->Add( bSizerDataFile, 1, wxEXPAND, 5 ); wxBoxSizer* bSizerReulBtn; bSizerReulBtn = new wxBoxSizer( wxHORIZONTAL ); @@ -1253,7 +1262,7 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow 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 ); - m_regulators_filePicker->Connect( wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEventHandler( PCB_CALCULATOR_FRAME_BASE::OnDataFileSelection ), NULL, this ); + m_buttonDataFile->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnDataFileSelection ), NULL, this ); m_buttonEditItem->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnEditRegulator ), NULL, this ); m_buttonAddItem->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnAddRegulator ), NULL, this ); m_buttonRemoveItem->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRemoveRegulator ), NULL, this ); @@ -1282,7 +1291,7 @@ PCB_CALCULATOR_FRAME_BASE::~PCB_CALCULATOR_FRAME_BASE() 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 ); - m_regulators_filePicker->Disconnect( wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEventHandler( PCB_CALCULATOR_FRAME_BASE::OnDataFileSelection ), NULL, this ); + m_buttonDataFile->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnDataFileSelection ), NULL, this ); m_buttonEditItem->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnEditRegulator ), NULL, this ); m_buttonAddItem->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnAddRegulator ), NULL, this ); m_buttonRemoveItem->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRemoveRegulator ), NULL, this ); diff --git a/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp b/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp index b5e78c2458..3103035ae3 100644 --- a/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp +++ b/pcb_calculator/dialogs/pcb_calculator_frame_base.fbp @@ -2881,91 +2881,192 @@ 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - Select a Pcb Calculator data file - - 0 + wxEXPAND + 1 + - 1 - m_regulators_filePicker - 1 - - - protected - 1 - - Resizable - 1 - - wxFLP_SAVE|wxFLP_USE_TEXTCTRL - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - *.pcbcalc - - - - - - - OnDataFileSelection - - - - - - - - - - - - - - - - - - - - + bSizerDataFile + wxHORIZONTAL + none + + 5 + wxBOTTOM|wxRIGHT|wxLEFT + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_regulators_fileNameCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Browse + + 0 + + + 0 + + 1 + m_buttonDataFile + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + OnDataFileSelection + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pcb_calculator/dialogs/pcb_calculator_frame_base.h b/pcb_calculator/dialogs/pcb_calculator_frame_base.h index 25f01a9342..a4e7f80ae5 100644 --- a/pcb_calculator/dialogs/pcb_calculator_frame_base.h +++ b/pcb_calculator/dialogs/pcb_calculator_frame_base.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -80,7 +79,8 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame wxButton* m_buttonCalculate; wxChoice* m_choiceRegulatorSelector; wxStaticText* m_staticTextRegFile; - wxFilePickerCtrl* m_regulators_filePicker; + wxTextCtrl* m_regulators_fileNameCtrl; + wxButton* m_buttonDataFile; wxButton* m_buttonEditItem; wxButton* m_buttonAddItem; wxButton* m_buttonRemoveItem; @@ -263,7 +263,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame virtual void OnRegulTypeSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulatorSelection( wxCommandEvent& event ) { event.Skip(); } - virtual void OnDataFileSelection( wxFileDirPickerEvent& event ) { event.Skip(); } + virtual void OnDataFileSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnEditRegulator( wxCommandEvent& event ) { event.Skip(); } virtual void OnAddRegulator( wxCommandEvent& event ) { event.Skip(); } virtual void OnRemoveRegulator( wxCommandEvent& event ) { event.Skip(); } diff --git a/pcb_calculator/pcb_calculator.h b/pcb_calculator/pcb_calculator.h index afbd959a8e..4c09da39d9 100644 --- a/pcb_calculator/pcb_calculator.h +++ b/pcb_calculator/pcb_calculator.h @@ -61,15 +61,18 @@ private: // R/W data files: bool ReadDataFile(); bool WriteDataFile(); - const wxString GetDataFilename() - { - return m_regulators_filePicker->GetPath(); - } - void SetDataFilename( const wxString & aFilename) - { - m_regulators_filePicker->SetPath( aFilename ); - } + /** + * @return the full filename of the selected pcb_calculator data file + */ + const wxString GetDataFilename(); + + /** + * Initialize the full filename of the selected pcb_calculator data file + * force the standard extension of the file (.pcbcalc) + * @param aFilename = the full filename, with or without extension + */ + void SetDataFilename( const wxString & aFilename); // tracks width versus current functions: /** @@ -177,7 +180,7 @@ private: void OnRegulatorCalcButtonClick( wxCommandEvent& event ); void OnRegulTypeSelection( wxCommandEvent& event ); void OnRegulatorSelection( wxCommandEvent& event ); - void OnDataFileSelection( wxFileDirPickerEvent& event ); + void OnDataFileSelection( wxCommandEvent& event ); void OnAddRegulator( wxCommandEvent& event ); void OnEditRegulator( wxCommandEvent& event ); void OnRemoveRegulator( wxCommandEvent& event ); @@ -241,4 +244,7 @@ public: }; + +extern const wxString DataFileNameExt; + #endif // PCB_CALCULATOR_H diff --git a/pcb_calculator/pcb_calculator_frame.cpp b/pcb_calculator/pcb_calculator_frame.cpp index e026362df8..64d0a50775 100644 --- a/pcb_calculator/pcb_calculator_frame.cpp +++ b/pcb_calculator/pcb_calculator_frame.cpp @@ -49,6 +49,9 @@ #define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" ) #define KEYWORD_DATAFILE_FILENAME wxT( "DataFilename" ) +// extention of pcb_calculator data filename: +const wxString DataFileNameExt( wxT("pcbcalc") ); + PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow* parent ) : PCB_CALCULATOR_FRAME_BASE( parent ) { @@ -93,7 +96,6 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow* parent ) : ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() ); - m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() ); SelectLastSelectedRegulator(); @@ -327,6 +329,36 @@ void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event ) event.Skip(); } +/* returns the full filename of the selected pcb_calculator data file + * the extention file is forced + */ +const wxString PCB_CALCULATOR_FRAME::GetDataFilename() +{ + if( m_regulators_fileNameCtrl->GetValue().IsEmpty() ) + return wxEmptyString; + + wxFileName fn( m_regulators_fileNameCtrl->GetValue() ); + fn.SetExt( DataFileNameExt ); + return fn.GetFullPath(); +} + +/* Initialize the full filename of the selected pcb_calculator data file + * force the standard extension of the file (.pcbcalc) + * aFilename = the full filename, with or without extension + */ +void PCB_CALCULATOR_FRAME::SetDataFilename( const wxString & aFilename) +{ + if( aFilename.IsEmpty() ) + m_regulators_fileNameCtrl->SetValue( wxEmptyString ); + + else + { + wxFileName fn( aFilename ); + fn.SetExt( DataFileNameExt ); + m_regulators_fileNameCtrl->SetValue( fn.GetFullPath() ); + } +} + /** * @copydoc diff --git a/pcb_calculator/regulators_funct.cpp b/pcb_calculator/regulators_funct.cpp index d7840161dc..c3090001c2 100644 --- a/pcb_calculator/regulators_funct.cpp +++ b/pcb_calculator/regulators_funct.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -110,6 +111,12 @@ bool DIALOG_EDITOR_DATA::IsOK() ok = false; if( m_textCtrlVref->GetValue().IsEmpty() ) ok = false; + else + { + double vref = ReturnDoubleFromString( m_textCtrlVref->GetValue() ); + if( fabs(vref) < 0.01 ) + ok = false; + } if( m_choiceRegType->GetSelection() == 1 ) { if( m_RegulIadjValue->GetValue().IsEmpty() ) @@ -207,8 +214,54 @@ void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event ) RegulatorPageUpdate(); } -void PCB_CALCULATOR_FRAME::OnDataFileSelection( wxFileDirPickerEvent& event ) +/* + * 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; + wildcard.Printf( _("Pcb Calculator data file (*.%s)|*.%s"), + GetChars( DataFileNameExt ), + GetChars( DataFileNameExt ) ); + + wxFileDialog dlg( m_panelRegulators, + _("Select a Pcb Calculator data file"), + 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; + msg.Printf( _("Unable to read data file <%s>"), GetChars( fullfilename ) ); + wxMessageBox( msg ); + } } void PCB_CALCULATOR_FRAME::OnAddRegulator( wxCommandEvent& event )