149 lines
4.8 KiB
C#
149 lines
4.8 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 UCSingleAxisJogViewModel : 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); }
|
|
|
|
public JogUnitPanel JogUnitPanel;
|
|
#endregion
|
|
|
|
#region EventCommands
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
public ICommand CMD_IncreaseComboMotorID { get; }
|
|
public ICommand CMD_DecreaseComboMotorID { get; }
|
|
public ICommand CMD_MinusJog { get; }
|
|
public ICommand CMD_PlusJog { get; }
|
|
public ICommand CMD_Stop { get; }
|
|
#endregion
|
|
|
|
internal UCSingleAxisJogViewModel(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_MinusJog = new DelegateCommand(PerformCmdMotorJog);
|
|
CMD_PlusJog = new DelegateCommand(PerformCmdMotorJog);
|
|
CMD_Stop = new DelegateCommand(PerformCmdMotorStop);
|
|
#endregion
|
|
|
|
|
|
_MonitorTimer = new DispatcherTimer();
|
|
_MonitorTimer.Tick += OnMonitoring;
|
|
_MonitorTimer.Interval = TimeSpan.FromMilliseconds(100);
|
|
|
|
}
|
|
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 PerformCmdMotorJog(object obj)
|
|
{
|
|
// +jog : true, -jog : false
|
|
int JogDirection = (bool)obj ? +1 : -1;
|
|
double JogVelocity = JogUnitPanel.JogVelocity;
|
|
|
|
try {
|
|
var motor = GetComboSelectedBaseMotor();
|
|
if (motor != null) {
|
|
motor.Jog(JogDirection, JogVelocity);
|
|
}
|
|
} catch { }
|
|
|
|
}
|
|
private void PerformCmdMotorStop(object obj)
|
|
{
|
|
try {
|
|
var motor = GetComboSelectedBaseMotor();
|
|
if (motor != null) {
|
|
motor.Stop();
|
|
}
|
|
} catch { }
|
|
|
|
}
|
|
|
|
private void VisibleChanged(object obj)
|
|
{
|
|
bool visible = (bool)obj;
|
|
if (visible) {
|
|
_MonitorTimer.Start();
|
|
} else {
|
|
_MonitorTimer.Stop();
|
|
}
|
|
}
|
|
private BaseMotor GetComboSelectedBaseMotor()
|
|
{
|
|
return _DeviceManager[SelectedMotorID] as BaseMotor;
|
|
}
|
|
|
|
public void InitJogUnitPanelProperties()
|
|
{
|
|
if (JogUnitPanel == null)
|
|
return;
|
|
|
|
#region Initialize JogUnitPanel
|
|
JogUnitPanel.LowVelocity = 0.1;
|
|
JogUnitPanel.MidVelocity = 1.0;
|
|
JogUnitPanel.HighVelocity = 5.0;
|
|
JogUnitPanel.JogStep = 1.0;
|
|
#endregion
|
|
}
|
|
}
|
|
}
|