Commit 100ea3a5 authored by jean-pierre charras's avatar jean-pierre charras

Finish Pcb Calculator work

parent 3d643786
...@@ -192,8 +192,17 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow ...@@ -192,8 +192,17 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow
sbSizerRegulatorsChooser->Add( m_staticTextRegFile, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); 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 ); wxBoxSizer* bSizerDataFile;
sbSizerRegulatorsChooser->Add( m_regulators_filePicker, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); 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; wxBoxSizer* bSizerReulBtn;
bSizerReulBtn = new wxBoxSizer( wxHORIZONTAL ); bSizerReulBtn = new wxBoxSizer( wxHORIZONTAL );
...@@ -1253,7 +1262,7 @@ PCB_CALCULATOR_FRAME_BASE::PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindow ...@@ -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_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_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_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_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_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 ); 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() ...@@ -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_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_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_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_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_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 ); m_buttonRemoveItem->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PCB_CALCULATOR_FRAME_BASE::OnRemoveRegulator ), NULL, this );
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/choice.h> #include <wx/choice.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/filepicker.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/html/htmlwin.h> #include <wx/html/htmlwin.h>
#include <wx/statline.h> #include <wx/statline.h>
...@@ -80,7 +79,8 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame ...@@ -80,7 +79,8 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
wxButton* m_buttonCalculate; wxButton* m_buttonCalculate;
wxChoice* m_choiceRegulatorSelector; wxChoice* m_choiceRegulatorSelector;
wxStaticText* m_staticTextRegFile; wxStaticText* m_staticTextRegFile;
wxFilePickerCtrl* m_regulators_filePicker; wxTextCtrl* m_regulators_fileNameCtrl;
wxButton* m_buttonDataFile;
wxButton* m_buttonEditItem; wxButton* m_buttonEditItem;
wxButton* m_buttonAddItem; wxButton* m_buttonAddItem;
wxButton* m_buttonRemoveItem; wxButton* m_buttonRemoveItem;
...@@ -263,7 +263,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame ...@@ -263,7 +263,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
virtual void OnRegulTypeSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulTypeSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRegulatorSelection( 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 OnEditRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnAddRegulator( wxCommandEvent& event ) { event.Skip(); } virtual void OnAddRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveRegulator( wxCommandEvent& event ) { event.Skip(); } virtual void OnRemoveRegulator( wxCommandEvent& event ) { event.Skip(); }
......
...@@ -61,15 +61,18 @@ private: ...@@ -61,15 +61,18 @@ private:
// R/W data files: // R/W data files:
bool ReadDataFile(); bool ReadDataFile();
bool WriteDataFile(); bool WriteDataFile();
const wxString GetDataFilename()
{
return m_regulators_filePicker->GetPath();
}
void SetDataFilename( const wxString & aFilename) /**
{ * @return the full filename of the selected pcb_calculator data file
m_regulators_filePicker->SetPath( aFilename ); */
} 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: // tracks width versus current functions:
/** /**
...@@ -177,7 +180,7 @@ private: ...@@ -177,7 +180,7 @@ private:
void OnRegulatorCalcButtonClick( wxCommandEvent& event ); void OnRegulatorCalcButtonClick( wxCommandEvent& event );
void OnRegulTypeSelection( wxCommandEvent& event ); void OnRegulTypeSelection( wxCommandEvent& event );
void OnRegulatorSelection( wxCommandEvent& event ); void OnRegulatorSelection( wxCommandEvent& event );
void OnDataFileSelection( wxFileDirPickerEvent& event ); void OnDataFileSelection( wxCommandEvent& event );
void OnAddRegulator( wxCommandEvent& event ); void OnAddRegulator( wxCommandEvent& event );
void OnEditRegulator( wxCommandEvent& event ); void OnEditRegulator( wxCommandEvent& event );
void OnRemoveRegulator( wxCommandEvent& event ); void OnRemoveRegulator( wxCommandEvent& event );
...@@ -241,4 +244,7 @@ public: ...@@ -241,4 +244,7 @@ public:
}; };
extern const wxString DataFileNameExt;
#endif // PCB_CALCULATOR_H #endif // PCB_CALCULATOR_H
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
#define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" ) #define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" )
#define KEYWORD_DATAFILE_FILENAME wxT( "DataFilename" ) #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::PCB_CALCULATOR_FRAME( wxWindow* parent ) :
PCB_CALCULATOR_FRAME_BASE( parent ) PCB_CALCULATOR_FRAME_BASE( parent )
{ {
...@@ -93,7 +96,6 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow* parent ) : ...@@ -93,7 +96,6 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow* parent ) :
ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() ); ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() );
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() ); m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
SelectLastSelectedRegulator(); SelectLastSelectedRegulator();
...@@ -327,6 +329,36 @@ void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event ) ...@@ -327,6 +329,36 @@ void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event )
event.Skip(); 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 * @copydoc
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/config.h> #include <wx/config.h>
#include <macros.h>
#include <pcb_calculator.h> #include <pcb_calculator.h>
#include <class_regulator_data.h> #include <class_regulator_data.h>
#include <dialog_regulator_data_base.h> #include <dialog_regulator_data_base.h>
...@@ -110,6 +111,12 @@ bool DIALOG_EDITOR_DATA::IsOK() ...@@ -110,6 +111,12 @@ bool DIALOG_EDITOR_DATA::IsOK()
ok = false; ok = false;
if( m_textCtrlVref->GetValue().IsEmpty() ) if( m_textCtrlVref->GetValue().IsEmpty() )
ok = false; ok = false;
else
{
double vref = ReturnDoubleFromString( m_textCtrlVref->GetValue() );
if( fabs(vref) < 0.01 )
ok = false;
}
if( m_choiceRegType->GetSelection() == 1 ) if( m_choiceRegType->GetSelection() == 1 )
{ {
if( m_RegulIadjValue->GetValue().IsEmpty() ) if( m_RegulIadjValue->GetValue().IsEmpty() )
...@@ -207,8 +214,54 @@ void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event ) ...@@ -207,8 +214,54 @@ void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event )
RegulatorPageUpdate(); 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 ) void PCB_CALCULATOR_FRAME::OnAddRegulator( wxCommandEvent& event )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment