GrooveComputerVM.cs 1.71 KB
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HHECS.RobotTool.Dto;
using HHECS.RobotTool.Service;
using MessageBox = HandyControl.Controls.MessageBox;

namespace HHECS.RobotTool.ViewModel
{
    internal partial class GrooveComputerVM : ObservableObject
    {
        [ObservableProperty]
        private RobotInputParameter inputParameter = new RobotInputParameter();

        [ObservableProperty]
        private RobotOutputParameter outputParameter = new RobotOutputParameter();

        [ObservableProperty]
        private List<RobotTechnology> technologies = new List<RobotTechnology>();

        private readonly GrooveService _grooveService;
        public GrooveComputerVM(GrooveService grooveService)
        {
            _grooveService = grooveService;
            Reset();
        }

        [RelayCommand]
        private void Computer()
        {
            var result = _grooveService.GetComputedData(InputParameter);
            if (!result.Success)
            {
                MessageBox.Error($"数据计算出现异常:{result.Msg}");
                return;
            }
            (OutputParameter, Technologies) = result.Data;
        }

        [RelayCommand]
        private void Reset()
        {
            InputParameter = new RobotInputParameter
            {
                GrooveWidth = 37,
                GrooveDepth = 30,
                WeldingWire = 1.2,
                ReservedGap = 0,
                BluntEdgeSize = 2,
                WeldLength = 1000,
                WeldWidth = 1.5,
                WeldHeight = 2
            };
            OutputParameter = new RobotOutputParameter();
            Technologies = new List<RobotTechnology>();
        }
    }
}