frmBCRegulate.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using OTSDataType;
  2. using OTSMeasureApp._0_OTSModel.OTSDataType;
  3. using OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow;
  4. using OTSModelSharp;
  5. using OTSModelSharp.ServiceCenter;
  6. using System;
  7. using System.Collections;
  8. using System.Drawing;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. namespace OTSMeasureApp._5_OTSMeasureStatuImageFun
  12. {
  13. public partial class frmBCRegulate : Form
  14. {
  15. public PointF stdPos;
  16. public string brightphaseMaterial;
  17. public int brightphasevalue;
  18. public string darkphaseMaterial;
  19. public int darkphasevalue;
  20. public bool isToRun = false;
  21. public double initialBrightness;
  22. public double initialContrast;
  23. public int mag = 100; //放大倍数
  24. public AutoRegulateType autoregulateType = AutoRegulateType.EveryPeriod; //自动调节类型
  25. public int period = 60; //minutes to run the regulation
  26. public CMeasure m_measureobj;
  27. private ISemController semController = SemController.GetSEMController();
  28. public CSEMStageData stageData = null;
  29. CBrightnessContrastAdjust BCregulater=null;
  30. public frmBCRegulate()
  31. {
  32. InitializeComponent();
  33. }
  34. private void frmBCRegulate_Load_1(object sender, EventArgs e)
  35. {
  36. // 国际化
  37. OTSCommon.Language lan = new OTSCommon.Language(this);
  38. Hashtable table = lan.GetNameTable(this.Name);
  39. this.Text = table["frmcaption"].ToString();
  40. this.label1.Text = table["stdpos"].ToString();
  41. this.label2.Text = table["bright"].ToString();
  42. this.label3.Text = table["dark"].ToString();
  43. this.label4.Text = table["initbright"].ToString();
  44. this.label5.Text = table["initcontrast"].ToString();
  45. this.label6.Text = table["mag"].ToString();
  46. //this.label7.Text = table["label7"].ToString();
  47. this.button2.Text = table["autobctest"].ToString();
  48. this.button1.Text = table["read"].ToString();
  49. this.button4.Text = table["read"].ToString();
  50. this.button5.Text = table["read"].ToString();
  51. this.button6.Text = table["write"].ToString();
  52. this.button8.Text = table["stop"].ToString();
  53. //this.button7.Text = table["ok"].ToString();
  54. this.button3.Text = table["record"].ToString();
  55. this.EnableAutoBC.Text = table["enableautobc"].ToString();
  56. this.radiobtnEveryPeriod.Text = table["everyperiod"].ToString();
  57. this.radiobtnEverySample.Text = table["everysample"].ToString();
  58. txtstdpos.Text = stdPos.ToString();
  59. cbobrele.Text = brightphaseMaterial;
  60. cbodarkele.Text = darkphaseMaterial;
  61. txtbrvalue.Text = brightphasevalue.ToString();
  62. txtdarkvalue.Text = darkphasevalue.ToString();
  63. txtinitbr.Text = initialBrightness.ToString();
  64. txtinitcontrast.Text = initialContrast.ToString();
  65. txtMag.Text = mag.ToString();
  66. radiobtnEveryPeriod.Checked = autoregulateType == AutoRegulateType.EveryPeriod;
  67. radiobtnEverySample.Checked = autoregulateType == AutoRegulateType.EverySample;
  68. txtperiod.Text = period.ToString();
  69. EnableAutoBC.Checked = isToRun;
  70. }
  71. private void button1_Click(object sender, EventArgs e)
  72. {
  73. stdPos = Point.Empty;
  74. double r = 0;
  75. double x=0, y = 0;
  76. semController.GetSemPositionXY(ref x, ref y, ref r);
  77. stageData.ConvertSEMToOTSCoord( new Point((int)x, (int)y),ref stdPos);
  78. txtstdpos.Text = stdPos.ToString();
  79. }
  80. private void button2_Click(object sender, EventArgs e)
  81. {
  82. var param = m_measureobj.m_pMeasureParam.GetDefaultParam().BrightnessContrastRegulationParam;
  83. param.stdMaterialOTSPos=new Point((int)stdPos.X,(int)stdPos.Y);
  84. param.brightphaseelement = cbobrele.Text;
  85. param.brightphaseGrayvalue = int.Parse(txtbrvalue.Text);
  86. param.darkphaseelement = cbodarkele.Text;
  87. param.darkphaseGrayvalue = int.Parse(txtdarkvalue.Text);
  88. param.mag = txtMag.Text == "" ? 100 : int.Parse(txtMag.Text);
  89. param.initialBrightness = double.Parse(txtinitbr.Text);
  90. param.initialContrast = double.Parse(txtinitcontrast.Text);
  91. param.toRun = EnableAutoBC.Checked;
  92. m_measureobj.m_pMeasureParam.GetDefaultParam().BrightnessContrastRegulationParam = param;
  93. BCregulater = new CBrightnessContrastAdjust(m_measureobj);
  94. Thread thread = new Thread(new ThreadStart(BCregulater.DoBrightnessContrastAdjust));
  95. thread.Start();
  96. }
  97. private void button3_Click(object sender, EventArgs e)
  98. {
  99. var param = m_measureobj.m_pMeasureParam.GetDefaultParam().BrightnessContrastRegulationParam;
  100. param.stdMaterialOTSPos = new Point((int)stdPos.X, (int)stdPos.Y);
  101. param.brightphaseelement = cbobrele.Text;
  102. param.brightphaseGrayvalue = int.Parse(txtbrvalue.Text);
  103. param.darkphaseelement = cbodarkele.Text;
  104. param.darkphaseGrayvalue = int.Parse(txtdarkvalue.Text);
  105. param.mag = txtMag.Text == "" ? 100 : int.Parse(txtMag.Text);
  106. param.initialBrightness = double.Parse(txtinitbr.Text);
  107. param.initialContrast = double.Parse(txtinitcontrast.Text);
  108. param.toRun = EnableAutoBC.Checked;
  109. param.period= txtperiod.Text == "" ? 60 : int.Parse(txtperiod.Text);
  110. param.autoRegulateType =radiobtnEveryPeriod.Checked ? AutoRegulateType.EveryPeriod : AutoRegulateType.EverySample;
  111. m_measureobj.m_pMeasureParam.GetDefaultParam().BrightnessContrastRegulationParam = param;
  112. Close();
  113. }
  114. private void button4_Click(object sender, EventArgs e)
  115. {
  116. CBrightnessContrastAdjust regulater = new CBrightnessContrastAdjust(m_measureobj);
  117. int dark = 0, bright = 0;
  118. regulater.GetCurrentTwoProminentGray(ref dark, ref bright);
  119. txtbrvalue.Text = bright.ToString();
  120. txtdarkvalue.Text = dark.ToString();
  121. }
  122. private void button5_Click(object sender, EventArgs e)
  123. {
  124. CBrightnessContrastAdjust regulater = new CBrightnessContrastAdjust(m_measureobj);
  125. double br = 0, contra = 0;
  126. regulater.GetCurrentBrightnessAndContrast(ref br, ref contra);
  127. txtinitbr.Text = br.ToString();
  128. txtinitcontrast.Text = contra.ToString();
  129. }
  130. private void button6_Click(object sender, EventArgs e)
  131. {
  132. CBrightnessContrastAdjust regulater = new CBrightnessContrastAdjust(m_measureobj);
  133. double br = double.Parse(txtinitbr.Text), contra =double.Parse(txtinitcontrast.Text);
  134. regulater.WriteBrightnessAndContrast(ref br,ref contra);
  135. }
  136. private void button7_Click(object sender, EventArgs e)
  137. {
  138. CBrightnessContrastAdjust regulater = new CBrightnessContrastAdjust(m_measureobj);
  139. regulater.MoveSEMToPoint(new PointF(stdPos.X, stdPos.Y));
  140. }
  141. private void button8_Click(object sender, EventArgs e)
  142. {
  143. if (BCregulater != null)
  144. BCregulater.StopBrightnessContrastAdjust();
  145. }
  146. }
  147. }