Kyungshin-Welder/WeldingComponents/WeldingCommon/Views/Motion/UCSingleAxisPositionViewModel.cs
2026-01-26 14:51:28 +09:00

129 lines
4.1 KiB
C#

using Aurora;
using Aurora.Api.Devices;
using Aurora.Api.Manager;
using Aurora.View;
using AuroraUIComponent.UserControls;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
namespace WeldingCommon.Views
{
internal class UCSingleAxisPositionViewModel : NotifyPropertyChangedBase
{
private readonly IDeviceManager _DeviceManager;
private readonly DispatcherTimer _MonitorTimer;
#region Binding Properties
private List<string> _MotorIDList;
public List<string> MotorIDList { get => _MotorIDList; set => SetProperty(ref _MotorIDList, value); }
private string _SelectedMotorID;
public string SelectedMotorID { get => _SelectedMotorID; set => SetProperty(ref _SelectedMotorID, value); }
private MotorStatusTableView _UCMotorStatusTable;
public MotorStatusTableView UCMotorStatusTable { get => _UCMotorStatusTable; set => SetProperty(ref _UCMotorStatusTable, value); }
#endregion
#region EventCommands
public ICommand CMD_VisibleChanged { get; }
public ICommand CMD_IncreaseComboMotorID { get; }
public ICommand CMD_DecreaseComboMotorID { get; }
public ICommand CMD_MotorSave { get; }
#endregion
internal UCSingleAxisPositionViewModel(IAuroraEnvironment aurora)
{
_DeviceManager = aurora.DeviceManager;
#region Initialize Binding Properties
// Motor ID 를 List 에 넣기. devicemanager 에서 motor ID 를 받아오자.
// motor 가 define 되지 않았으니 테스트를 위해 임시로 몇개 넣어둔다.
MotorIDList = new List<string> { "Welding Y1", "Welding Z" };
SelectedMotorID = MotorIDList[0];
#endregion
#region DelegateCommands
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
CMD_IncreaseComboMotorID = new DelegateCommand(PerformCmdIncreaseComboMotorID);
CMD_DecreaseComboMotorID = new DelegateCommand(PerformCmdDecreaseComboMotorID);
CMD_MotorSave = new DelegateCommand(PerformCmdMotorSave);
#endregion
_MonitorTimer = new DispatcherTimer();
_MonitorTimer.Tick += OnMonitoring;
_MonitorTimer.Interval = TimeSpan.FromMilliseconds(100);
}
public void InitMotorStatusTableProperties()
{
// Init table list
}
private void VisibleChanged(object obj)
{
bool visible = (bool)obj;
if (visible) {
_MonitorTimer.Start();
} else {
_MonitorTimer.Stop();
}
}
private void OnMonitoring(object sender, EventArgs e)
{
try {
var motor = GetComboSelectedBaseMotor();
if (motor != null) {
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void PerformCmdIncreaseComboMotorID(object obj)
{
try {
int nIndex = MotorIDList.IndexOf(SelectedMotorID);
if (nIndex >= MotorIDList.Count - 1) {
nIndex = MotorIDList.Count;
} else {
nIndex++;
}
SelectedMotorID = MotorIDList[nIndex];
} catch {
}
}
private void PerformCmdDecreaseComboMotorID(object obj)
{
try {
int nIndex = MotorIDList.IndexOf(SelectedMotorID);
if (nIndex < 1) {
nIndex = 0;
} else {
nIndex--;
}
SelectedMotorID = MotorIDList[nIndex];
} catch {
}
}
private void PerformCmdMotorSave(object obj)
{
try {
// table 내용을 어떻게 처리할지 내용 파악할 것
} catch { }
}
private BaseMotor GetComboSelectedBaseMotor()
{
return _DeviceManager[SelectedMotorID] as BaseMotor;
}
}
}