GalvanometerControl.cs 5.3 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;

namespace UserFromControl
{
    public partial class GalvanometerControl : UserControl
    {
        public GalvanometerControl()
        {
            InitializeComponent();
        }
        public string GroupName
        {
            get { return group.Text; }
            set
            {
                group.Text = value;
            }
        }

        private void btnShowPoint_Click(object sender, EventArgs e)
        {
            ShowCurrPoint();
        }
        public void ShowCurrPoint()
        {
            this.Cursor = Cursors.WaitCursor;
            int x = FormUtil.GetIntValue(txtAreaX);
            int y = FormUtil.GetIntValue(txtAreaY);
            int px = FormUtil.GetIntValue(txtX);
            int py = FormUtil.GetIntValue(txtY);
            int pointType = cmbType.SelectedIndex + 1;
            int pointLenth = FormUtil.GetIntValue(txtSize);
            int pointLight = FormUtil.GetIntValue(txtLight);
            //如果亮度和大小超过范围,直接用默认值
            if (pointLenth < 0 || pointLenth > 255)
            {
                pointLenth = 1;
                txtSize.Text = pointLenth.ToString();
            }
            if (pointLight < 0 || pointLight > 255)
            {
                pointLight = 10;
                txtLight.Text = pointLight.ToString();
            }
            GalvanometerPoint p = new GalvanometerPoint(px, py, x, y, pointType, pointLenth, pointLight);
            GalvanometerManager.ShowPoint(TSAVBean.Gal_Port, TSAVBean.Gal_Addr, p);
            this.Cursor = Cursors.Default;
        }
        private void btnUp_Click(object sender, EventArgs e)
        {
            int x = FormUtil.GetIntValue(txtX);
            int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.XAxis_Change));
            txtX.Text = (x - stepValue).ToString();
            ShowCurrPoint();
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            int y = FormUtil.GetIntValue(txtY);
            int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.YAxis_Change));
            txtY.Text = (y + stepValue).ToString();
            ShowCurrPoint();
        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            int y = FormUtil.GetIntValue(txtY);
            int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.YAxis_Change));
            txtY.Text = (y - stepValue).ToString();
            ShowCurrPoint();
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            int x = FormUtil.GetIntValue(txtX);
            int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.XAxis_Change));
            txtX.Text = (x + stepValue).ToString();
            ShowCurrPoint();
        }


        private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            int size = FormUtil.GetIntValue(txtSize);
            if (cmbType.SelectedIndex.Equals(0) && size > 10)
            {
                txtSize.Text = "1";
            }
            else
            {
                if (size < 15)
                    txtSize.Text = "15";
            }
        }

        public double XValue
        {
            set
            {
                txtX.Text = ((int)value).ToString();
            }
            get
            {
                return FormUtil.GetIntValue(txtX);
            }
        }
         
        public double YValue
        {
            set
            {
                txtY.Text = ((int)value).ToString();
            }
            get
            {
                return FormUtil.GetIntValue(txtY);
            }
        }
        public int PointType
        {
            set
            {
                cmbType.SelectedIndex = ((int)value)-1;
            }
            get
            {
                return cmbType.SelectedIndex+1;
            }
        }
        public int PointSize
        {
            set
            {
                txtSize.Text = ((int)value).ToString();
            }
            get
            {
                return FormUtil.GetIntValue(txtSize);
            }
        }
        public void UpdateStatus()
        {
            txtX.Text = GalvanometerManager.GetLastPoint().X.ToString();
            txtY.Text = GalvanometerManager.GetLastPoint().Y.ToString();
        }
        private List<double> vallue = new List<double>() { 0.5, 1, 2, 5, 10, 20, 50 };

        private double GetStepValue()
        {
            int index = cmbStep.SelectedIndex;
            TSAVBean.LastStepIndex = index;
            if (vallue.Count > index)
            {
                return vallue[index];
            }
            return 10;
        }
        private void GalvanometerControl_Load(object sender, EventArgs e)
        {
            cmbStep.SelectedIndex =TSAVBean.LastStepIndex;
            if (cmbType.SelectedIndex < 0)
            {
                cmbType.SelectedIndex = 0;
            }
        }
         
    }
}