Exemple #1
0
        private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is GrblViewModel)
            {
                switch (e.PropertyName)
                {
                case nameof(GrblViewModel.GrblState):
                    GrblStateChanged((sender as GrblViewModel).GrblState);
                    break;

                case nameof(GrblViewModel.MDI):
                    SendCommand((sender as GrblViewModel).MDI);
                    break;

                case nameof(GrblViewModel.IsMPGActive):
                    grblState.MPG = (sender as GrblViewModel).IsMPGActive == true;
                    (sender as GrblViewModel).Poller.SetState(grblState.MPG ? 0 : AppConfig.Settings.Base.PollInterval);
                    streamingHandler.Call(grblState.MPG ? StreamingState.Disabled : StreamingState.Idle, false);
                    break;

                case nameof(GrblViewModel.Signals):
                    if (isActive)
                    {
                        var signals = (sender as GrblViewModel).Signals.Value;
                        if (JobPending && signals.HasFlag(Signals.CycleStart) && !signals.HasFlag(Signals.Hold) && !cycleStartSignal)
                        {
                            CycleStart();
                        }
                        holdSignal       = signals.HasFlag(Signals.Hold);
                        cycleStartSignal = signals.HasFlag(Signals.CycleStart);
                    }
                    break;

                case nameof(GrblViewModel.ProgramEnd):
                    if (!GCode.File.IsLoaded)
                    {
                        streamingHandler.Call(model.IsSDCardJob ? StreamingState.JobFinished : StreamingState.NoFile, model.IsSDCardJob);
                    }
                    else if (JobTimer.IsRunning && !job.Complete)
                    {
                        streamingHandler.Call(StreamingState.JobFinished, true);
                    }
                    if (!model.IsParserStateLive)
                    {
                        SendCommand(GrblConstants.CMD_GETPARSERSTATE);
                    }
                    break;

                case nameof(GrblViewModel.FileName):
                {
                    job.IsSDFile = false;
                    if (string.IsNullOrEmpty((sender as GrblViewModel).FileName))
                    {
                        job.NextRow = null;
                    }
                    else
                    {
                        job.ToolChangeLine = -1;
                        job.CurrLine       = job.PendingLine = job.ACKPending = model.BlockExecuting = 0;
                        job.PgmEndLine     = GCode.File.Blocks - 1;
                        if ((sender as GrblViewModel).IsPhysicalFileLoaded)
                        {
                            if (GCode.File.ToolChanges > 0)
                            {
                                if (!GrblSettings.HasSetting(grblHALSetting.ToolChangeMode))
                                {
                                    MessageBox.Show(string.Format((string)FindResource("JobToolChanges"), GCode.File.ToolChanges), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning);
                                }
                                else if (GrblSettings.GetInteger(grblHALSetting.ToolChangeMode) > 0 && !model.IsTloReferenceSet)
                                {
                                    MessageBox.Show(string.Format((string)FindResource("JobToolReference"), GCode.File.ToolChanges), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning);
                                }
                            }
                            if (GCode.File.HasGoPredefinedPosition && (sender as GrblViewModel).IsGrblHAL && (sender as GrblViewModel).HomedState != HomedState.Homed)
                            {
                                MessageBox.Show((string)FindResource("JobG28G30"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                            streamingHandler.Call(GCode.File.IsLoaded ? StreamingState.Idle : StreamingState.NoFile, false);
                        }
                    }
                    break;
                }

                case nameof(GrblViewModel.GrblReset):
                {
                    JobTimer.Stop();
                    streamingHandler.Call(StreamingState.Stop, true);
                }
                break;
                }
            }
        }