diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 93 |
1 files changed, 80 insertions, 13 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 4a16be957..f455faa9e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -56,6 +56,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private ObservablesContext _activeJobDbContext; private SpeechSynthesizer _speech; private SoundPlayer _soundPlayer; + private SoundPlayer _soundPlayerErr; #region Properties @@ -629,6 +630,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _speech = new SpeechSynthesizer(); _soundPlayer = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Developer.bip.wav")); + _soundPlayerErr = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Developer.error.wav")); _speech.SelectVoice(_speech.GetInstalledVoices().LastOrDefault(x => x.VoiceInfo.Gender == VoiceGender.Female).VoiceInfo.Name); //Initialize Commands... @@ -644,7 +646,7 @@ namespace Tango.MachineStudio.Developer.ViewModels RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null); SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null); DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null); - StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning && MachineOperator != null); + StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null); @@ -671,6 +673,25 @@ namespace Tango.MachineStudio.Developer.ViewModels private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine) { MachineOperator = machine; + + if (MachineOperator != null) + { + MachineOperator.MachineEventsStateProvider.EventsChanged -= MachineEventsStateProvider_EventsChanged; + MachineOperator.MachineEventsStateProvider.EventsChanged += MachineEventsStateProvider_EventsChanged; + + MachineOperator.MachineEventsStateProvider.NewEvents -= MachineEventsStateProvider_NewEvents; + MachineOperator.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; + } + } + + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable<MachinesEvent> events) + { + HandleNewHardwareEvents(events); + } + + private void MachineEventsStateProvider_EventsChanged(object sender, IEnumerable<MachinesEvent> changedEvents) + { + InvokeUI(StartJobCommand.RaiseCanExecuteChanged); } /// <summary> @@ -714,6 +735,42 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion + #region Hardware Events + + private void HandleNewHardwareEvents(IEnumerable<MachinesEvent> events) + { + if (IsJobRunning) + { + SpeakError(events.Last().EventType.Name); + + if (events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.AbortRunningJob))) + { + if (_jobHandler != null) + { + InvokeUI(StopJob); + } + } + } + } + + #endregion + + #region Sound + + private void SpeakInfo(String text) + { + _soundPlayer.Play(); + _speech.SpeakAsync(text); + } + + private void SpeakError(String text) + { + _soundPlayerErr.Play(); + _speech.SpeakAsync(text); + } + + #endregion + #region Properties Changes /// <summary> @@ -895,12 +952,14 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> private void SetJobFailed() { - LogManager.Log("Setting job failed state..."); - IsJobRunning = false; - IsJobFailed = true; + if (IsJobRunning) + { + LogManager.Log("Setting job failed state..."); + IsJobRunning = false; + IsJobFailed = true; - _soundPlayer.Play(); - _speech.SpeakAsync("Job Failed!"); + SpeakError("Job Failed!"); + } } /// <summary> @@ -911,8 +970,7 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Setting job completed state..."); IsJobRunning = false; IsJobCompleted = true; - _soundPlayer.Play(); - _speech.SpeakAsync("Job Completed!"); + SpeakInfo("Job Completed!"); } /// <summary> @@ -955,11 +1013,20 @@ namespace Tango.MachineStudio.Developer.ViewModels _jobHandler.StatusReceived += (x, status) => { - RunningJobRemainingTime = _runningJobEstimatedDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - RunningJobProgress = status.Progress; + if (IsJobRunning) + { + + RunningJobRemainingTime = _runningJobEstimatedDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + RunningJobProgress = status.Progress; + } foreach (var segment in RunningJobSegments) { + if (!IsJobRunning) + { + break; + } + var previousSegmentsWithThis = RunningJobSegments.Where(s => RunningJobSegments.IndexOf(s) <= RunningJobSegments.IndexOf(segment)).ToList(); var segmentsDuration = TimeSpan.FromSeconds(previousSegmentsWithThis.Sum(s => s.Length) / (SelectedProcessParametersTable.DyeingSpeed / 100d)); var segmentDuration = TimeSpan.FromSeconds(segment.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); @@ -973,15 +1040,14 @@ namespace Tango.MachineStudio.Developer.ViewModels if (!segment.Started) { segment.Started = true; - _soundPlayer.Play(); if (segment.ID != -1) { - _speech.SpeakAsync(String.Format("Segment {0} Started.", segment.SegmentIndex)); + SpeakInfo(String.Format("Segment {0} Started.", segment.SegmentIndex)); } else { - _speech.SpeakAsync(String.Format("Inter Segment Started.")); + SpeakInfo(String.Format("Inter Segment Started.")); } } } @@ -1052,6 +1118,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { new BrushStop() { + ColorSpace = ColorSpaces.Single(x => x.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()), Color = Colors.White, } }, |
