diff options
author | Thales1330 <thaleslima.ufu@gmail.com> | 2017-01-28 14:50:12 -0200 |
---|---|---|
committer | Thales1330 <thaleslima.ufu@gmail.com> | 2017-01-28 14:50:12 -0200 |
commit | 5e7c19ae397164dd718b2593663cee5d1be687cd (patch) | |
tree | ea14141c3f4bb83ea8448cf017dfeb5b211611a0 /Project/TransferFunctionForm.cpp | |
parent | 10bb7105946bc0a892a9daf42ec5181ad9994fcf (diff) | |
download | PSP.git-5e7c19ae397164dd718b2593663cee5d1be687cd.tar.gz PSP.git-5e7c19ae397164dd718b2593663cee5d1be687cd.tar.xz PSP.git-5e7c19ae397164dd718b2593663cee5d1be687cd.zip |
Node bug fixes, tf form implemented
Diffstat (limited to 'Project/TransferFunctionForm.cpp')
-rw-r--r-- | Project/TransferFunctionForm.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Project/TransferFunctionForm.cpp b/Project/TransferFunctionForm.cpp new file mode 100644 index 0000000..5814339 --- /dev/null +++ b/Project/TransferFunctionForm.cpp @@ -0,0 +1,78 @@ +#include "TransferFunctionForm.h" +#include "TransferFunction.h" + +TransferFunctionForm::TransferFunctionForm(wxWindow* parent, TransferFunction* transferFunction) + : TransferFunctionFormBase(parent) +{ + m_parent = parent; + m_tf = transferFunction; + LoadTFData(); +} + +TransferFunctionForm::~TransferFunctionForm() {} + +void TransferFunctionForm::OnCancelClick(wxCommandEvent& event) { EndModal(wxID_CANCEL); } + +void TransferFunctionForm::OnOKClick(wxCommandEvent& event) +{ + if(ValidateData()) EndModal(wxID_OK); +} + +void TransferFunctionForm::LoadTFData() +{ + auto num = m_tf->GetNumerator(); + auto den = m_tf->GetDenominator(); + + wxString numStr = ""; + for(auto it = num.begin(), itEnd = num.end(); it != itEnd; ++it) { + double value = *it; + if(it == num.begin()) + numStr = m_tf->StringFromDouble(value, 0); + else + numStr += " " + m_tf->StringFromDouble(value, 0); + } + m_textCtrlNumerator->SetValue(numStr); + + wxString denStr = ""; + for(auto it = den.begin(), itEnd = den.end(); it != itEnd; ++it) { + double value = *it; + if(it == den.begin()) + denStr = m_tf->StringFromDouble(value, 0); + else + denStr += " " + m_tf->StringFromDouble(value, 0); + } + m_textCtrlDenominator->SetValue(denStr); +} + +bool TransferFunctionForm::ValidateData() +{ + wxString num = m_textCtrlNumerator->GetValue(); + std::vector<double> numerator; + while(num != "") { + wxString rest; + wxString strValue = num.BeforeFirst(' ', &rest); + num = rest; + double value = 0; + if(!m_tf->DoubleFromString( + this, strValue, value, _("Value entered incorrectly in the field \"Numerator parameters\"."))) + return false; + numerator.push_back(value); + } + + wxString den = m_textCtrlDenominator->GetValue(); + std::vector<double> denominator; + while(den != "") { + wxString rest; + wxString strValue = den.BeforeFirst(' ', &rest); + den = rest; + double value = 0; + if(!m_tf->DoubleFromString( + this, strValue, value, _("Value entered incorrectly in the field \"Denominator parameters\"."))) + return false; + denominator.push_back(value); + } + m_tf->SetNumerator(numerator); + m_tf->SetDenominator(denominator); + m_tf->UpdateTFText(); + return true; +} |