FrmAOISetting.cs 5.3 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
// COM 组件接口
using System.Runtime.InteropServices;
using URSoldering.Common;

namespace URSoldering.Client
{
    public partial class FrmAOISetting : FrmBase
    {
        FrmDebugMenu frmMean = null;
        public FrmAOISetting(FrmDebugMenu frmMean)
        {
            this.frmMean = frmMean;
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cmbPro.SelectedIndex = 0;
            //位置配置到文件中
            string appPath = Application.StartupPath;
            string strFilePathName = ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
            string filePath = appPath + strFilePathName;
            if (File.Exists(filePath))
            {
                axCKVisionCtrl1.LoadConfigure(filePath);
            }
            else
            {
                LogUtil.error("未找到文件:" + strFilePathName);
            }
        }

        private void LOAD_FILE_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openfileDlg = new OpenFileDialog();

                openfileDlg.Filter = "vscf files (*.vscf)|*.vscf";
                openfileDlg.FilterIndex = 1;
                openfileDlg.RestoreDirectory = true;

                if (openfileDlg.ShowDialog() == DialogResult.OK)
                {
                    string strFilePathName = openfileDlg.FileName.ToString();
                    axCKVisionCtrl1.LoadConfigure(strFilePathName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
            }

        }

        private void SAVE_FILE_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog savefileDlg = new SaveFileDialog();

                savefileDlg.Filter = "ckcf files (*.vscf)|*.vscf";
                savefileDlg.FilterIndex = 1;
                savefileDlg.RestoreDirectory = true;

                if (savefileDlg.ShowDialog() == DialogResult.OK)
                {
                    string FilePathName = savefileDlg.FileName.ToString();
                    bool isSave = axCKVisionCtrl1.SaveConfigure(FilePathName);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not save file to the disk. Original error: " + ex.Message);
            }

        }

        private void EDIT_PROC_Click(object sender, EventArgs e)
        {
            try
            {
                axCKVisionCtrl1.ShowEditor( "编辑流程", 0 );
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not edit proc. Original error: " + ex.Message);
            }
        }

        private void EXECUTE_Click(object sender, EventArgs e)
        {
            try
            {
                int index = cmbPro.SelectedIndex;
                axCKVisionCtrl1.Execute(index);
                axCKVisionCtrl1.Redraw();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not extcute proc. Original error: " + ex.Message);
            }
        }

        private void GET_DATA_Click(object sender, EventArgs e)
        {
            string strToolName = textBox1.Text;
            int idTool = axCKVisionCtrl1.GetTool(strToolName);   

            int DataId = Convert.ToInt32(textBox2.Text);

            double value = 0.0;
            object objValue = new VariantWrapper(value);

            if (axCKVisionCtrl1.GetValue(idTool, DataId, 0, ref objValue) == true)
            {
                textBox3.Text = objValue.ToString().Substring(0,6);
            }
            else
            {
                MessageBox.Show("获取数据失败! ");
            }
 
        }

        private void ZOOM_IN_Click(object sender, EventArgs e)
        {
            axCKVisionCtrl1.ZoomView(0);
            axCKVisionCtrl1.Redraw();
        }

        private void ZOOM_OUT_Click(object sender, EventArgs e)
        {
            axCKVisionCtrl1.ZoomView(1);
            axCKVisionCtrl1.Redraw();
        }

        private void ZOOM_FIT_Click(object sender, EventArgs e)
        {
            axCKVisionCtrl1.ZoomView(2);
            axCKVisionCtrl1.Redraw();
        }

        private void ZOOM_1X1_Click(object sender, EventArgs e)
        {
            axCKVisionCtrl1.ZoomView(3);
            axCKVisionCtrl1.Redraw();
        }

        private void TOOL_Property_Click(object sender, EventArgs e)
        {
            string strToolName = textBox1.Text;
            int idTool = axCKVisionCtrl1.GetTool(strToolName);
            axCKVisionCtrl1.ShowProperty(idTool );
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            axCKVisionCtrl1.UnloadConfigure();
            frmMean.Visible = true;
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
         
    }
}