HaoShuang 5 лет назад
Родитель
Сommit
508c61b612
3 измененных файлов с 201 добавлено и 54 удалено
  1. 57 50
      ManulDo/MainForm.Designer.cs
  2. 120 3
      ManulDo/MainForm.cs
  3. 24 1
      MeasureThread/Measure.cs

+ 57 - 50
ManulDo/MainForm.Designer.cs

@@ -68,12 +68,12 @@
             this.label11 = new System.Windows.Forms.Label();
             this.label10 = new System.Windows.Forms.Label();
             this.label9 = new System.Windows.Forms.Label();
-            this.textBox6 = new System.Windows.Forms.TextBox();
-            this.textBox5 = new System.Windows.Forms.TextBox();
-            this.textBox4 = new System.Windows.Forms.TextBox();
-            this.textBox3 = new System.Windows.Forms.TextBox();
-            this.textBox2 = new System.Windows.Forms.TextBox();
-            this.tB = new System.Windows.Forms.TextBox();
+            this.tB_WD = new System.Windows.Forms.TextBox();
+            this.tB_fStep = new System.Windows.Forms.TextBox();
+            this.tB_fRange = new System.Windows.Forms.TextBox();
+            this.tB_Step = new System.Windows.Forms.TextBox();
+            this.tB_Down = new System.Windows.Forms.TextBox();
+            this.tB_Up = new System.Windows.Forms.TextBox();
             this.label8 = new System.Windows.Forms.Label();
             this.label7 = new System.Windows.Forms.Label();
             this.label6 = new System.Windows.Forms.Label();
@@ -404,6 +404,7 @@
             this.tbAutoFocus.TabIndex = 18;
             this.tbAutoFocus.Text = "对焦";
             this.tbAutoFocus.UseVisualStyleBackColor = true;
+            this.tbAutoFocus.Click += new System.EventHandler(this.tbAutoFocus_Click);
             // 
             // groupBox5
             // 
@@ -414,12 +415,12 @@
             this.groupBox5.Controls.Add(this.label11);
             this.groupBox5.Controls.Add(this.label10);
             this.groupBox5.Controls.Add(this.label9);
-            this.groupBox5.Controls.Add(this.textBox6);
-            this.groupBox5.Controls.Add(this.textBox5);
-            this.groupBox5.Controls.Add(this.textBox4);
-            this.groupBox5.Controls.Add(this.textBox3);
-            this.groupBox5.Controls.Add(this.textBox2);
-            this.groupBox5.Controls.Add(this.tB);
+            this.groupBox5.Controls.Add(this.tB_WD);
+            this.groupBox5.Controls.Add(this.tB_fStep);
+            this.groupBox5.Controls.Add(this.tB_fRange);
+            this.groupBox5.Controls.Add(this.tB_Step);
+            this.groupBox5.Controls.Add(this.tB_Down);
+            this.groupBox5.Controls.Add(this.tB_Up);
             this.groupBox5.Controls.Add(this.label8);
             this.groupBox5.Controls.Add(this.label7);
             this.groupBox5.Controls.Add(this.label6);
@@ -501,48 +502,54 @@
             this.label9.TabIndex = 33;
             this.label9.Text = "um";
             // 
-            // textBox6
+            // tB_WD
             // 
-            this.textBox6.Location = new System.Drawing.Point(616, 118);
-            this.textBox6.Name = "textBox6";
-            this.textBox6.ReadOnly = true;
-            this.textBox6.Size = new System.Drawing.Size(96, 28);
-            this.textBox6.TabIndex = 32;
+            this.tB_WD.Location = new System.Drawing.Point(616, 118);
+            this.tB_WD.Name = "tB_WD";
+            this.tB_WD.ReadOnly = true;
+            this.tB_WD.Size = new System.Drawing.Size(96, 28);
+            this.tB_WD.TabIndex = 32;
             // 
-            // textBox5
+            // tB_fStep
             // 
-            this.textBox5.Location = new System.Drawing.Point(385, 119);
-            this.textBox5.Name = "textBox5";
-            this.textBox5.Size = new System.Drawing.Size(96, 28);
-            this.textBox5.TabIndex = 31;
+            this.tB_fStep.Location = new System.Drawing.Point(385, 119);
+            this.tB_fStep.Name = "tB_fStep";
+            this.tB_fStep.Size = new System.Drawing.Size(96, 28);
+            this.tB_fStep.TabIndex = 31;
+            this.tB_fStep.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tB_fStep_KeyPress);
             // 
-            // textBox4
+            // tB_fRange
             // 
-            this.textBox4.Location = new System.Drawing.Point(120, 116);
-            this.textBox4.Name = "textBox4";
-            this.textBox4.Size = new System.Drawing.Size(96, 28);
-            this.textBox4.TabIndex = 30;
+            this.tB_fRange.Location = new System.Drawing.Point(120, 116);
+            this.tB_fRange.Name = "tB_fRange";
+            this.tB_fRange.Size = new System.Drawing.Size(96, 28);
+            this.tB_fRange.TabIndex = 30;
+            this.tB_fRange.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tB_fRange_KeyPress);
             // 
-            // textBox3
+            // tB_Step
             // 
-            this.textBox3.Location = new System.Drawing.Point(616, 78);
-            this.textBox3.Name = "textBox3";
-            this.textBox3.Size = new System.Drawing.Size(96, 28);
-            this.textBox3.TabIndex = 29;
+            this.tB_Step.Location = new System.Drawing.Point(616, 78);
+            this.tB_Step.Name = "tB_Step";
+            this.tB_Step.Size = new System.Drawing.Size(96, 28);
+            this.tB_Step.TabIndex = 29;
+            this.tB_Step.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tB_Step_KeyPress);
             // 
-            // textBox2
+            // tB_Down
             // 
-            this.textBox2.Location = new System.Drawing.Point(385, 80);
-            this.textBox2.Name = "textBox2";
-            this.textBox2.Size = new System.Drawing.Size(96, 28);
-            this.textBox2.TabIndex = 28;
+            this.tB_Down.Location = new System.Drawing.Point(385, 80);
+            this.tB_Down.Name = "tB_Down";
+            this.tB_Down.Size = new System.Drawing.Size(96, 28);
+            this.tB_Down.TabIndex = 28;
+            this.tB_Down.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tB_Down_KeyPress);
             // 
-            // tB
+            // tB_Up
             // 
-            this.tB.Location = new System.Drawing.Point(119, 78);
-            this.tB.Name = "tB";
-            this.tB.Size = new System.Drawing.Size(96, 28);
-            this.tB.TabIndex = 27;
+            this.tB_Up.Location = new System.Drawing.Point(119, 78);
+            this.tB_Up.Name = "tB_Up";
+            this.tB_Up.Size = new System.Drawing.Size(96, 28);
+            this.tB_Up.TabIndex = 27;
+            this.tB_Up.TextChanged += new System.EventHandler(this.tB_TextChanged);
+            this.tB_Up.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tB_Up_KeyPress);
             // 
             // label8
             // 
@@ -628,7 +635,7 @@
             this.Controls.Add(this.groupBox2);
             this.Controls.Add(this.groupBox1);
             this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
-            //this.Name = "MainForm";
+            this.Name = "MainForm";
             this.Text = "测量流程测试";
             this.groupBox1.ResumeLayout(false);
             this.groupBox2.ResumeLayout(false);
@@ -677,12 +684,12 @@
         private System.Windows.Forms.Button btImgPath;
         private System.Windows.Forms.TextBox tBImgPath;
         private System.Windows.Forms.Label label9;
-        private System.Windows.Forms.TextBox textBox6;
-        private System.Windows.Forms.TextBox textBox5;
-        private System.Windows.Forms.TextBox textBox4;
-        private System.Windows.Forms.TextBox textBox3;
-        private System.Windows.Forms.TextBox textBox2;
-        private System.Windows.Forms.TextBox tB;
+        private System.Windows.Forms.TextBox tB_WD;
+        private System.Windows.Forms.TextBox tB_fStep;
+        private System.Windows.Forms.TextBox tB_fRange;
+        private System.Windows.Forms.TextBox tB_Step;
+        private System.Windows.Forms.TextBox tB_Down;
+        private System.Windows.Forms.TextBox tB_Up;
         private System.Windows.Forms.Label label8;
         private System.Windows.Forms.Label label7;
         private System.Windows.Forms.Label label6;

+ 120 - 3
ManulDo/MainForm.cs

@@ -29,6 +29,14 @@ namespace WindowsFormsApp1
         //自动对焦函数
         public FocusParam m_focusParam;
 
+        enum WorkType
+        {
+            AutoFocus =  1,
+            AllThing = 2
+        };
+
+        WorkType m_work;
+
         #endregion
         #region 构造函数
         public MainForm()
@@ -45,6 +53,7 @@ namespace WindowsFormsApp1
             LogManager.InitManulLog();
 
             m_focusParam = new FocusParam();
+            m_work = new WorkType();
         }
         #endregion
         #region 测量线程
@@ -54,8 +63,16 @@ namespace WindowsFormsApp1
             m_Ms.InitMeas(m_MeasureFile);
             m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage); //注册事件
 
-            //自动测量的全过程
-            m_Ms.DoMeasure();
+            if (m_work == WorkType.AutoFocus)
+            {
+                //自动对焦
+            }
+            else
+            {
+                //自动测量的全过程
+                m_Ms.DoMeasure();
+            }
+            
             //定位
             //切割
             //分析位置
@@ -289,8 +306,108 @@ namespace WindowsFormsApp1
 
         private void button2_Click(object sender, EventArgs e)
         {
-           //保存自动对焦函数
+            if (tBImgPath.Text == "" ||
+               tB_Up.Text == "" ||
+               tB_Down.Text == "" ||
+               tB_Step.Text == "" ||
+               tB_fRange.Text == "" ||
+               tB_fStep.Text == "")
+            {
+                MessageBox.Show("请输入完整的参数");
+                return;
+            }
+            //保存自动对焦函数
+            m_focusParam.Path = tBImgPath.Text;
+            m_focusParam.UP = float.Parse(tB_Up.Text);
+            m_focusParam.Down = float.Parse(tB_Down.Text);
+            m_focusParam.Step = float.Parse(tB_Step.Text);
+            m_focusParam.Range = float.Parse(tB_fRange.Text);
+            m_focusParam.fStep = float.Parse(tB_fStep.Text);           
+        }
+
+        private void tB_TextChanged(object sender, EventArgs e)
+        {
+
+        }
+
+        //输入限制只能是数字
+        private void textBox_KeyPress(string text, object sender, KeyPressEventArgs e)
+        {
+
+            //允许输入数字、小数点、删除键和负号  
+            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
+            {
+                MessageBox.Show("请输入正确的数字");
+                text = "";
+                e.Handled = true;
+            }
+            if (e.KeyChar == (char)('-'))
+            {
+                if (text != "")
+                {
+                    MessageBox.Show("请输入正确的数字");
+                    text = "";
+                    e.Handled = true;
+                }
+            }
+            //小数点只能输入一次  
+            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
+            {
+                MessageBox.Show("请输入正确的数字");
+                text = "";
+                e.Handled = true;
+            }
+            //第一位不能为小数点  
+            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
+            {
+                MessageBox.Show("请输入正确的数字");
+                text = "";
+                e.Handled = true;
+            }
+            //第一位是0,第二位必须为小数点  
+            if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0")
+            {
+                MessageBox.Show("请输入正确的数字");
+                text = "";
+                e.Handled = true;
+            }
+            //第一位是负号,第二位不能为小数点  
+            if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
+            {
+                MessageBox.Show("请输入正确的数字");
+                text = "";
+                e.Handled = true;
+            }
+        }
+
+        private void tB_Up_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            textBox_KeyPress(tB_Up.Text, sender, e);
+        }
 
+        private void tB_Down_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            textBox_KeyPress(tB_Down.Text, sender, e);
+        }
+
+        private void tB_Step_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            textBox_KeyPress(tB_Step.Text, sender, e);
+        }
+
+        private void tB_fRange_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            textBox_KeyPress(tB_fRange.Text, sender, e);
+        }
+
+        private void tB_fStep_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            textBox_KeyPress(tB_fStep.Text, sender, e);
+        }
+
+        private void tbAutoFocus_Click(object sender, EventArgs e)
+        {
+            // 调用对焦线程
         }
     }
 }

+ 24 - 1
MeasureThread/Measure.cs

@@ -1625,11 +1625,34 @@ namespace MeasureThread
         }
 
         //自动聚焦
-        public bool AutoFocus(string a_strPath, out int a_nWd)
+        public bool AutoFocus(FocusParam a_param, out int a_nWd)
         {
             a_nWd = 0;
             a_nWd = (int)Math.Ceiling(iSEM.GetWorkingDistance() * 100000000 + 0.5);//获取当前的工作距离
 
+            if (a_param == null)
+            {
+                return false;
+            }
+
+            //1. 拍照
+            //1.1, 初拍照
+            //1.1.1, 根据参数计算拍照次数
+            //int n = 
+
+            //3.控制SEM拍照
+            String fileName4 = WorkingFolder + ImageName4;
+            if (!GetImage(ImageMode.SEM, fileName4))
+            {
+                return false;
+            }
+
+            //1.2, 选定细拍照的工作距离
+            //1.3, 细拍照
+
+            //2. 计算评价函数
+
+            //3. 3选2策略获取工作距离
             return true;
 
         }