#pragma once

// Heliotis grabber parameters dialog
class HeliotisParamDialog : public CDialog
{
public:
  HeliotisParamDialog(float ss, float sr, float tvs, float er, float sp, float psl, bool fz):
    CDialog(IDD_HELIOTIS_PARAMETERS), scan_speed(ss), scan_range(sr), target_vertical_spacing(tvs), exposure_ratio(er),
    scan_position(sp), pixel_side_length(psl), filter_zmap(fz)
  {}

protected:
  DECLARE_MESSAGE_MAP()
  virtual void DoDataExchange(CDataExchange* pDX)
  {
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_SCANSPEED, scan_speed_ctrl);
    DDX_Control(pDX, IDC_SCANRANGE, scan_range_ctrl);
    DDX_Control(pDX, IDC_TARGETVERTICALSPACING, target_vertical_spacing_ctrl);
    DDX_Control(pDX, IDC_EXPOSURERATIO, exposure_ratio_ctrl);
    DDX_Control(pDX, IDC_SCANPOSITION, scan_position_ctrl);
    DDX_Control(pDX, IDC_PIXELSIDELENGTH, pixel_side_length_ctrl);
    DDX_Control(pDX, IDC_FILTERZMAP, filter_zmap_ctrl);
  }

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

    scan_speed_ctrl.SetWindowText(std::to_wstring(scan_speed).c_str());
    scan_range_ctrl.SetWindowText(std::to_wstring(scan_range).c_str());
    target_vertical_spacing_ctrl.SetWindowText(std::to_wstring(target_vertical_spacing).c_str());
    exposure_ratio_ctrl.SetWindowText(std::to_wstring(exposure_ratio).c_str());
    scan_position_ctrl.SetWindowText(std::to_wstring(scan_position).c_str());
    pixel_side_length_ctrl.SetWindowText(std::to_wstring(pixel_side_length).c_str());
    filter_zmap_ctrl.SetCheck(filter_zmap);

    return TRUE;
  }

  void OnOK()
  {
    CString str = _T("");
    scan_speed_ctrl.GetWindowTextW(str);
    float tmp = (float)_wtof(str);
    if (tmp > 0)  // a value <= 0 makes no sense for scan_speed
      scan_speed = tmp;

    scan_range_ctrl.GetWindowTextW(str);
    tmp = (float)_wtof(str);
    if (tmp > 0)
      scan_range = tmp;

    target_vertical_spacing_ctrl.GetWindowTextW(str);
    tmp = (float)_wtof(str);
    if (tmp > 0)
      target_vertical_spacing = tmp;

    exposure_ratio_ctrl.GetWindowTextW(str);
    exposure_ratio = (float)_wtof(str);

    scan_position_ctrl.GetWindowTextW(str);
    scan_position = (float)_wtof(str);

    pixel_side_length_ctrl.GetWindowTextW(str);
    tmp = (float)_wtof(str);
    if (tmp > 0)
      pixel_side_length = tmp;

    filter_zmap = filter_zmap_ctrl.GetCheck();

    CDialog::EndDialog(1);
  }

  // Edit controls
  CEdit scan_speed_ctrl;
  CEdit scan_range_ctrl;
  CEdit target_vertical_spacing_ctrl;
  CEdit exposure_ratio_ctrl;
  CEdit scan_position_ctrl;
  CEdit pixel_side_length_ctrl;
  CButton filter_zmap_ctrl;

public:
  float scan_speed;
  float scan_range;
  float target_vertical_spacing;
  float exposure_ratio;
  float scan_position;
  float pixel_side_length;
  bool filter_zmap;
};

BEGIN_MESSAGE_MAP(HeliotisParamDialog, CDialog)
END_MESSAGE_MAP()

