#pragma once

// AT grabber parameters dialog
class ATParamDialog : public CDialog
{
public:
  ATParamDialog(int e, const std::string& t, int p, float d, int x, int y, int w, int h, float d_sensor):
    CDialog(IDD_AT_PARAMETERS), exposure_time(e), trigger_mode(t), profiles_per_frame(p), profiles_distance(d),
    aoi_x(x), aoi_y(y), aoi_width(w), aoi_height(h), sensor_plan_distance(d_sensor)
  {}

protected:
  DECLARE_MESSAGE_MAP()
  virtual void DoDataExchange(CDataExchange* pDX)
  {
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EXPOSURETIME, exposure_ctrl);
    DDX_Control(pDX, IDC_TRIGGERMODE, trigger_mode_ctrl);
    DDX_Control(pDX, IDC_PROFILESPERFRAME, profiles_ctrl);
    DDX_Control(pDX, IDC_PROFILESDISTANCE, profiles_distance_ctrl);
    DDX_Control(pDX, IDC_AOIX, aoi_x_ctrl);
    DDX_Control(pDX, IDC_AOIY, aoi_y_ctrl);
    DDX_Control(pDX, IDC_AOIWIDTH, aoi_width_ctrl);
    DDX_Control(pDX, IDC_AOIHEIGHT, aoi_height_ctrl);
    DDX_Control(pDX, IDC_DISTANCE_SENSOR_PLAN, sensor_plan_distance_ctrl);
  }

  virtual BOOL OnInitDialog()
  {
    CDialog::OnInitDialog();

    exposure_ctrl.SetWindowText(std::to_wstring(exposure_time).c_str());
    trigger_mode_ctrl.SetWindowText(CString(trigger_mode.c_str()));
    profiles_ctrl.SetWindowText(std::to_wstring(profiles_per_frame).c_str());
    profiles_distance_ctrl.SetWindowText(std::to_wstring(profiles_distance).c_str());
    aoi_x_ctrl.SetWindowText(std::to_wstring(aoi_x).c_str());
    aoi_y_ctrl.SetWindowText(std::to_wstring(aoi_y).c_str());
    aoi_width_ctrl.SetWindowText(std::to_wstring(aoi_width).c_str());
    aoi_height_ctrl.SetWindowText(std::to_wstring(aoi_height).c_str());
    sensor_plan_distance_ctrl.SetWindowText(std::to_wstring(sensor_plan_distance).c_str());

    return TRUE;
  }

  void OnOK()
  {
    CString str = _T("");
    exposure_ctrl.GetWindowTextW(str);
    exposure_time = _wtoi(str);

    trigger_mode_ctrl.GetWindowTextW(str);
    trigger_mode = CT2CA(str);

    profiles_ctrl.GetWindowTextW(str);
    profiles_per_frame = _wtoi(str);

    profiles_distance_ctrl.GetWindowTextW(str);
    profiles_distance = (float)_wtof(str);

    aoi_x_ctrl.GetWindowTextW(str);
    aoi_x = _wtoi(str);

    aoi_y_ctrl.GetWindowTextW(str);
    aoi_y = _wtoi(str);

    aoi_width_ctrl.GetWindowTextW(str);
    aoi_width = _wtoi(str);

    aoi_height_ctrl.GetWindowTextW(str);
    aoi_height = _wtoi(str);

    sensor_plan_distance_ctrl.GetWindowTextW(str);
    sensor_plan_distance = (float)_wtof(str);

    CDialog::EndDialog(1);
  }

  // Edit controls
  CEdit exposure_ctrl;
  CEdit trigger_mode_ctrl;
  CEdit profiles_ctrl;
  CEdit profiles_distance_ctrl;
  CEdit aoi_x_ctrl;
  CEdit aoi_y_ctrl;
  CEdit aoi_width_ctrl;
  CEdit aoi_height_ctrl;
  CEdit sensor_plan_distance_ctrl;

public:
  int exposure_time;
  std::string trigger_mode;
  int profiles_per_frame;
  float profiles_distance;
  int aoi_x, aoi_y, aoi_width, aoi_height;
  float sensor_plan_distance;
};

BEGIN_MESSAGE_MAP(ATParamDialog, CDialog)
END_MESSAGE_MAP()

