AxisControl.cs 4.6 KB
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class AxisControl : UserControl
    {
        StoreMachine Machine;
        public AxisControl(StoreMachine machine)
        {
            Machine = machine;
            
            InitializeComponent();
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
            configControl1.Machine = machine;
            crc.LanguageProcess(this);
        }

        private void Crc_LanguageChangeEvent(object sender, EventArgs e)
        {
            RobotManage_LoadFinishEvent(true, "");
            crc.LanguageProcess(this);
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((EventHandler)delegate
                {
                    RobotManage_LoadFinishEvent(state, msg);
                });
                return;
            }

            if (!state)
                return;
            axisMoveControl1.LoadData(AxisBean.List[Machine.MachineSide]);
            configControl1.Config = Machine.Config;
            LogUtil.info("伺服面板加载完成.");

        }

        private void AxisControl_Load(object sender, EventArgs e)
        {
            var sizelist = Machine.StorePosition.Values.Distinct(new ACStorePositionComparer());
            var ll = sizelist.Select(a => { return new Position(a.BagWidth, a.BagHigh); }).ToList();
            ll.AddRange(FixtureConfig.FixtureConfigList.Select(a => { return new Position(a.Width, a.Height); }).ToArray());
            var aa=ll.Distinct(new PositionComparer());
            cb_sizelist.Items.AddRange(aa.ToArray());
            if (cb_sizelist.Items.Count > 0)
                cb_sizelist.SelectedIndex = 0;
        }

        private void btn_comptest_Click(object sender, EventArgs e)
        {
            Position p = cb_sizelist.SelectedItem as Position;
            var BagHigh = p.Height;
            if (FixtureConfig.GetFixtureHeight(p.Width, p.Height, out int actualheight))
                BagHigh = actualheight;

            var Comp_PL = Machine.Config.Comp_P2 - Machine.Config.Comp_PoToMM * (BagHigh - 70);
            Comp_PL = Comp_PL < 0 ? 0 : Comp_PL;
            Machine.Comp_Axis.AbsMove(null, Comp_PL, Machine.Config.Comp_P1_speed);
        }
        public class Position {
            public int Width;
            public int Height;
            public Position(int width, int height)
            {
                Width = width;
                Height = height;
            }            
            public override string ToString()
            {
                return $"{Width}x{Height}";
            }
        }
        public class ACStorePositionComparer : IEqualityComparer<ACStorePosition>
        {
            public bool Equals(ACStorePosition x, ACStorePosition y)
            {
                if (x == null && y == null)
                    return true;
                else if (x == null || y == null)
                    return false;
                return $"{x.BagHigh}x{x.BagWidth}" == $"{y.BagHigh}x{y.BagWidth}";
            }

            public int GetHashCode(ACStorePosition obj)
            {
                return base.GetHashCode();
            }
        }
        public class PositionComparer : IEqualityComparer<Position>
        {
            public bool Equals(Position x, Position y)
            {
                if (x == null && y == null)
                    return true;
                else if (x == null || y == null)
                    return false;
                return $"{x.Height}x{x.Width}" == $"{y.Height}x{y.Width}";
            }

            public int GetHashCode(Position obj)
            {
                return base.GetHashCode();
            }
        }
        private void cb_sizelist_SelectedIndexChanged(object sender, EventArgs e)
        {
            Position p = cb_sizelist.SelectedItem as Position;
            var BagHigh = p.Height;
            if (FixtureConfig.GetFixtureHeight(p.Width, p.Height, out int actualheight))
                BagHigh = actualheight;

            lbl_acheight.Text = crc.GetString("AxisControl_panel1_groupBox1_lbl_acheight_Text","设置高度") + ":" + BagHigh + "mm";
        }
    }
}