//This is the Constructor macro which executes once when the application gets loaded

//*****************  rem Modified Mar/14/2023 by CNC4PC  *******************
//*****************************  CNC4PC block  *****************************
//*****************  PTS Block  *******************

string Z_Top = exec.Readkey("UserTextfields", "20001", "Z_Top");
if (Z_Top == "Z_Top")
{
double Z_Top_d = 5;
AS3.Setfield(Z_Top_d, 20001);
exec.Writekey("UserTextfields", "20001", "5");
}
else
{
double Z_Top_d = double.Parse(Z_Top);
AS3.Setfield(Z_Top_d, 20001);
}

string Z_min_height = exec.Readkey("UserTextfields", "20002", "Z_min_height");
if (Z_min_height == "Z_min_height")
{
double Z_min_height_d = -50;
AS3.Setfield(Z_min_height_d, 20002);
exec.Writekey("UserTextfields", "20002", "-50");
}
else
{
double Z_min_height_d = double.Parse(Z_min_height);
AS3.Setfield(Z_min_height_d, 20002);
}

string Offset_Z = exec.Readkey("UserTextfields", "20003", "Offset_Z");
if (Offset_Z == "Offset_Z")
{
double Offset_Z_d = 0;
AS3.Setfield(Offset_Z_d, 20003);
exec.Writekey("UserTextfields", "20003", "0");
}
else
{
double Offset_Z_d = double.Parse(Offset_Z);
AS3.Setfield(Offset_Z_d, 20003);
}

string Probing_FR = exec.Readkey("UserTextfields", "20006", "Probing_FR");
if (Probing_FR == "Probing_FR")
{
double Probing_FR_d = 30;
AS3.Setfield(Probing_FR_d, 20006);
exec.Writekey("UserTextfields", "20006", "30");
}
else
{
double Probing_FR_d = double.Parse(Probing_FR);
AS3.Setfield(Probing_FR_d, 20006);
}


string Cut_Height = exec.Readkey("UserTextfields", "20010", "Cut_Height");
if (Cut_Height == "Cut_Height")
{
double Cut_Height_d = 3;
AS3.Setfield(Cut_Height_d, 20010);
exec.Writekey("UserTextfields", "20010", "30");
}
else
{
double Cut_Height_d = double.Parse(Cut_Height);
AS3.Setfield(Cut_Height_d, 20010);
}

string Check_probe_disable = exec.Readkey("UserCheckboxes", "20006", "Check_probe_disable");
if (Check_probe_disable == "Check_probe_disable")
{
bool Check_probe_disable_b = false;
AS3.Setcheckboxstate(Check_probe_disable_b, 20006);
exec.Writekey("UserCheckboxes", "20006", "False");
}
else
{
bool Check_probe_disable_b = Convert.ToBoolean(Check_probe_disable);
AS3.Setcheckboxstate(Check_probe_disable_b, 20006);
}

//*****************  End PTS Block  *******************
//*****************************  add CNC4PC_THC-3 block  *****************************

//*****************************  Set_point  *****************************

string Set_Point = exec.Readkey("CNC4PC_THC-3", "Set_Point", "Set_Point");
if (Set_Point == "Set_Point")
{
  double Set_Point_d = 120;
  AS3.Setfield(Set_Point_d, 20004);
  exec.Writekey("CNC4PC_THC-3", "Set_Point", "120");
}
else
{
double Set_Point_do = double.Parse(Set_Point);
AS3.Setfield(Set_Point_do, 20004);
}
//*****************************  End Set_poin  *****************************

//*****************************  Histeresys  *****************************

string Histeresys = exec.Readkey("CNC4PC_THC-3", "Histeresys", "Histeresys");
if (Histeresys == "Histeresys")
{
  double Histeresys_d = 2;
  AS3.Setfield(Histeresys_d, 20007);
  exec.Writekey("CNC4PC_THC-3", "Histeresys", "2");
}
else
{
double Histeresys_do = double.Parse(Histeresys);
AS3.Setfield(Histeresys_do, 20007);
}
//*****************************  End Histeresys  *****************************

//*****************************  Auto_Set_Point_Button  *****************************

string Auto_Set_Point_Button = exec.Readkey("CNC4PC_THC-3", "Auto_Set_Point_Button", "Auto_Set_Point_Button");
if (Auto_Set_Point_Button == "Auto_Set_Point_Button")
{
 
    AS3.Switchbutton(false, 21001);
    exec.Writekey("CNC4PC_THC-3", "Auto_Set_Point_Button", "False");
}
else
{
 bool Auto_Set_Point_Button_b = Convert.ToBoolean(Auto_Set_Point_Button);
AS3.Switchbutton(Auto_Set_Point_Button_b, 21001);
}
//*****************************  End Auto_Set_Point_Button  *****************************

//*****************************  Test_Mode_Button  *****************************

string Test_Mode_Button = exec.Readkey("CNC4PC_THC-3", "Test_Mode_Button", "Test_Mode_Button");
if (Test_Mode_Button == "Test_Mode_Button")
{
 
    AS3.Switchbutton(false, 21002);
    exec.Writekey("CNC4PC_THC-3", "Test_Mode_Button", "False");
}
else
{
 bool Test_Mode_Button_b = Convert.ToBoolean(Test_Mode_Button);
AS3.Switchbutton(Test_Mode_Button_b, 21002);
}
//*****************************  End Test_Mode_Button  *****************************

//*****************************  Divider  *****************************

string Divider = exec.Readkey("CNC4PC_THC-3", "Divider", "Divider");
if (Divider == "Divider")
{
  double Divider_d = 50;
  AS3.Setfield(Divider_d, 20008);
  exec.Writekey("CNC4PC_THC-3", "Divider", "50");
}
else
{
double Divider_do = double.Parse(Divider);
AS3.Setfield(Divider_do, 20008);
}
//*****************************  End Divider  *****************************

//*****************************  Analog_Smoothing  *****************************

string Analog_Smoothing = exec.Readkey("CNC4PC_THC-3", "Analog_Smoothing", "Analog_Smoothing");
if (Analog_Smoothing == "Analog_Smoothing")
{
  double Analog_Smoothing_d = 0;
  AS3.Setfield(Analog_Smoothing_d, 20009);
  exec.Writekey("CNC4PC_THC-3", "Analog_Smoothing", "0");
}
else
{
double Analog_Smoothing_do = double.Parse(Analog_Smoothing);
AS3.Setfield(Analog_Smoothing_do, 20009);
}
//*****************************  End Analog_Smoothing  *****************************

//*****************************  Anti_dive  *****************************

string Anti_dive = exec.Readkey("CNC4PC_THC-3", "Anti_dive", "Anti_dive");
if (Anti_dive == "Anti_dive")
{
  double Anti_dive_d = 50;
  AS3.Setfield(Anti_dive_d, 20011);
  exec.Writekey("CNC4PC_THC-3", "Anti_dive", "50");
}
else
{
double Anti_dive_do = double.Parse(Anti_dive);
AS3.Setfield(Anti_dive_do, 20011);
}
//*****************************  End Anti_dive  *****************************

//***************************** add CNC4PC_THC-3 block *****************************

//***************************  End CNC4PC block  ****************************
