/* Copyright (C) 2020 - 2024, Thornwave Labs Inc
* Written by Razvan Turiac <razvan.turiac@thornwave.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* Attribution shall be given to Thornwave Labs Inc. and shall be made visible to the final user.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <gui_calibrate_dialog.h>
#include <gui_parser.h>
GuiCalibrateDialog::GuiCalibrateDialog(wxWindow *parent, wxWindowID id, const wxString &title): wxDialog(parent, id, title)
{
const size_t BORDER_SIZE = FromDIP(6);
//main window sizer
wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(main_sizer);
mValueLabel = new wxStaticText(this, wxID_ANY, wxT("Calibration current"));
mValueText = new wxTextCtrl(this, ID_VALUE, wxT(""), wxDefaultPosition, wxDefaultSize);
main_sizer->AddSpacer(FromDIP(10));
main_sizer->Add(mValueLabel, 0, wxEXPAND);
main_sizer->Add(mValueText, 0, wxALL | wxEXPAND, BORDER_SIZE);
main_sizer->AddSpacer(FromDIP(10));
mErrorLabel = new wxStaticText(this, wxID_ANY, wxT(""));
mErrorLabel->SetForegroundColour(*wxRED);
main_sizer->Add(mErrorLabel, 0, wxALL | wxEXPAND, BORDER_SIZE);
wxBoxSizer *h_sizer = new wxBoxSizer(wxHORIZONTAL);
main_sizer->Add(h_sizer, 1, wxALL | wxEXPAND, BORDER_SIZE);
wxButton* button = new wxButton(this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, FromDIP(wxSize(150, 40)));
h_sizer->Add(button, 0, wxALL | wxCENTER, BORDER_SIZE);
mContinueButton = new wxButton(this, wxID_OK, wxT("Continue"), wxDefaultPosition, FromDIP(wxSize(150, 40)));
h_sizer->Add(mContinueButton, 0, wxALL | wxCENTER, BORDER_SIZE);
main_sizer->SetSizeHints(this);
Centre();
Bind(wxEVT_COMMAND_TEXT_UPDATED, &GuiCalibrateDialog::OnTextCtrlUpdated, this, ID_VALUE);
}
GuiCalibrateDialog::~GuiCalibrateDialog()
{
}
void GuiCalibrateDialog::OnTextCtrlUpdated(wxCommandEvent &event)
{
wxString str = mValueText->GetValue();
bool enable = true;
if (str.size())
{
try
{
mValue = ParseTextCtrlFloat(mValueText, wxT("Calibration current"));
mErrorLabel->SetLabel(wxT(""));
}
catch(const ParserException &e)
{
mErrorLabel->SetLabel(e.what());
enable = false;
}
}
else
{
mErrorLabel->SetLabel(wxT("value is empty"));
enable = false;
}
mErrorLabel->Refresh();
mContinueButton->Enable(enable);
}