88 lines
3.0 KiB
C#
88 lines
3.0 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.View;
|
|
using ILSOS_PrismaticGun.Process;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using WeldingCommon;
|
|
using WeldingCommon.Views;
|
|
|
|
namespace ILSOS_PrismaticGun.Views.Main
|
|
{
|
|
public class UCWorkStateViewModel : NotifyPropertyChangedBase
|
|
{
|
|
private IAuroraEnvironment _Aurora;
|
|
private eStage _targetStage;
|
|
private PalletInfo palletInfo;
|
|
private ISequence targetSequence;
|
|
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
|
|
public Dictionary<ePalletState, BlinkModel> WorkingStates { get; set; } = new Dictionary<ePalletState, BlinkModel>();
|
|
|
|
public UCWorkStateViewModel(IAuroraEnvironment aurora, eStage stage)
|
|
{
|
|
this._Aurora = aurora;
|
|
this._targetStage = stage;
|
|
|
|
if (_targetStage is eStage.A) {
|
|
palletInfo = ProcessManager.Instance.PalletInStageA;
|
|
targetSequence = _Aurora.SequenceEntry[SequenceIds.SeqAutoRunPrismaticGunStageA];
|
|
} else {
|
|
palletInfo = ProcessManager.Instance.PalletInStageB;
|
|
targetSequence = _Aurora.SequenceEntry[SequenceIds.SeqAutoRunPrismaticGunStageB];
|
|
}
|
|
|
|
for (ePalletState i = ePalletState.NotEntered; i < ePalletState.UnloadingComp + 1; i++) {
|
|
WorkingStates.Add(i,
|
|
new BlinkModel() {
|
|
Position = Enum.GetName(typeof(ePalletState), i)
|
|
});
|
|
}
|
|
|
|
InitWorkingState(palletInfo.palletState);
|
|
palletInfo.PropertyChanged += PalletInfo_PropertyChanged;
|
|
targetSequence.RunStateChanged += OnRunStateChanged;
|
|
}
|
|
|
|
private void PalletInfo_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
{
|
|
if (e.PropertyName == nameof(PalletInfo.palletState)) {
|
|
Application.Current.Dispatcher.InvokeAsync(() => {
|
|
InitWorkingState(palletInfo.palletState);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void InitWorkingState(ePalletState workingState)
|
|
{
|
|
foreach (var item in WorkingStates) {
|
|
if (item.Key != workingState) {
|
|
item.Value.IsActivated = false;
|
|
item.Value.IsRunning = false;
|
|
} else {
|
|
item.Value.IsActivated = true;
|
|
item.Value.IsRunning = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnRunStateChanged(object sender, (string sequenceId, SequenceRunState state) e)
|
|
{
|
|
Application.Current.Dispatcher.InvokeAsync(() => {
|
|
if (e.state != SequenceRunState.Running) {
|
|
foreach (var item in WorkingStates) {
|
|
item.Value.IsActivated = false;
|
|
item.Value.IsRunning = false;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|