2026-01-26 14:51:28 +09:00

118 lines
4.1 KiB
C#

using Aurora;
using Aurora.Api;
using Aurora.View;
using AuroraUIComponent.Sequence;
using AuroraUIComponent.UserControls.SequenceDrawer;
using CoreUnit.Scanner.UserControl.ScannerCanvas;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using VisionCommon;
using WeldingCommon.Recipes;
using WeldingCommon.Sequences;
using static WeldingCommon.Views.UCScannerObjectTeachingViewModel;
namespace WeldingCommon.Views
{
public class UCCommonAutoRunViewModel : NotifyPropertyChangedBase
{
private readonly Logger Log = new Logger("UCCommonAutoRunViewModel");
public delegate void ExternalRecipeUpdate(Logger log, IAuroraEnvironment aurora);
public static ExternalRecipeUpdate RecipeUpdate;
public ICommand CMD_VisibleChanged { get; }
private readonly IAuroraEnvironment _Aurora;
public UCWorkPosViewModel WorkPosViewModel { get; }
private UCSequenceDiagram _ContentDiagram;
public UCSequenceDiagram ContentDiagram { get => _ContentDiagram; set => SetProperty(ref _ContentDiagram, value); }
public event Action RecipeChange;
public UCCommonAutoRunViewModel(IAuroraEnvironment aurora, string sequenceId, ExternalRecipeUpdate externalRecipeUpdate)
{
_Aurora = aurora;
WorkPosViewModel = new UCWorkPosViewModel(aurora, sequenceId);
ContentDiagram = new UCSequenceDiagram();
ContentDiagram.SequenceID = sequenceId;
//ContentDiagram.DiagramType = eDiagramType.Layered;
ContentDiagram.DiagramType = eDiagramType.Tree;
ContentDiagram.LineType = eLineType.Straight;
ContentDiagram.ShowSubSequence = false;
ContentDiagram.SetVisibleKeys(new List<string>());
RecipeUpdate = externalRecipeUpdate;
_Aurora.EventObservable.AsObservable(CommonEventIds.EVENT_AUTO_RUN_START_REQUEST)
.ObserveOnDispatcher()
.Subscribe(x => OnAutoRunStartRequest());
_Aurora.EventObservable.AsObservable(CommonEventIds.EVENT_AUTO_RUN_STOP_REQUEST)
.ObserveOnDispatcher()
.Subscribe(x => OnAutoRunStopRequest());
//_Aurora.EventObservable.AsObservable(CommonEventIds.EVENT_AUTO_RUN_START_REQUEST)
// .ObserveOn(Application.Current.Dispatcher)
// .Subscribe(OnAutoRunStartRequest);
//_EventObservable.AsObservable(CommonEventIds.EVENT_AUTO_RUN_STOP_REQUEST)
// .ObserveOn(Application.Current.Dispatcher)
// .Subscribe(OnAutoRunStopRequest);
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
}
private void VisibleChanged(object obj)
{
//Thread.Sleep(100);
}
public void OnAutorunRecipeChange()
{
//현재 Activated된 Recipe를 화면에 표시한다.
WeldingRecipeManager.OnActiveReloaded();
WeldingRecipeManager.UpdateAutoRunWeldingPage();
RecipeChange?.Invoke();
}
private void OnAutoRunStartRequest()
{
//현재 Activated된 Recipe를 화면에 표시한다.
WeldingRecipeManager.OnSaveRecipeForEditing();
WeldingRecipeManager.OnActiveReloaded();
if (RecipeUpdate != null) {
RecipeUpdate(Log, _Aurora);
} else {
//Log.W("Check Machine Type");
Log.W("Check OnAutoRunStartRequest and need function!!");
}
// RunState 가 idle 일 경우만 실행됨
_Aurora.EventPublisher.Publish(new EventMessage("CommonAutoRunViewModel", CommonEventIds.EVENT_SEQ_AUTO_RUN_START));
}
private void OnAutoRunStopRequest()
{
// RunState 가 start 일 경우만 멈춤을 실행
_Aurora.EventPublisher.Publish(new EventMessage("CommonAutoRunViewModel", CommonEventIds.EVENT_SEQ_AUTO_RUN_STOP));
}
}
}