CanadianMachines / CanadianExperienceLib / MachineDlg.cpp
MachineDlg.cpp
Raw
/**
 * @file MachineDlg.cpp
 * @author sriram
 */

#include "pch.h"
#include "MachineDlg.h"
#include <wx/xrc/xmlres.h>
#include <wx/valnum.h>

/**
 * * machine dialog constructor
 * @param parent The parent window we will center in
 * @param drawable1 machine drawable 1
 * @param drawable2 machine drawable 2
 */
MachineDlg::MachineDlg(wxWindow *parent, std::shared_ptr<MachineDrawable> drawable1,
					   std::shared_ptr<MachineDrawable> drawable2):
					   mDrawable1(drawable1),mDrawable2(drawable2)
{
	wxXmlResource::Get()->LoadDialog(this, parent, L"MachineDlg");

	auto timeline = mDrawable1->GetTimeline();

	Bind(wxEVT_BUTTON, &MachineDlg::OnOK, this, wxID_OK);
	auto maxTime = timeline->GetNumFrames();

	auto machineTime1 = XRCCTRL(*this, "MachineOneStartTime", wxTextCtrl);
	wxIntegerValidator<int> Validator1(&mMachineStartTime1);
	Validator1.SetRange(1, maxTime);
	machineTime1->SetValidator(Validator1);

	auto machineTime3 = XRCCTRL(*this, "MachineOneEndTime", wxTextCtrl);
	wxIntegerValidator<int> Validator3(&mMachineEndTime1);
	Validator3.SetRange(1, maxTime);
	machineTime3->SetValidator(Validator3);

	auto machineTime2 = XRCCTRL(*this, "MachineTwoStartTime", wxTextCtrl);
	wxIntegerValidator<int> Validator2(&mMachineStartTime2);
	Validator2.SetRange(1, maxTime);
	machineTime2->SetValidator(Validator2);

	auto machineTime4 = XRCCTRL(*this, "MachineTwoEndTime", wxTextCtrl);
	wxIntegerValidator<int> Validator4(&mMachineEndTime2);
	Validator4.SetRange(1, maxTime);
	machineTime4->SetValidator(Validator4);
}


/**
 * Handle an OK button press
 * @param event Button event
 */
void MachineDlg::OnOK(wxCommandEvent& event)
{
	if ( Validate() && TransferDataFromWindow() )
	{
		mDrawable1->SetStartTime(mMachineStartTime1);
		mDrawable2->SetStartTime(mMachineStartTime2);

		mDrawable1->SetEndTime(mMachineEndTime1);
		mDrawable2->SetEndTime(mMachineEndTime2);
		// Success! Set values in the class
		EndModal(wxID_OK);
	}
}