| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.UI.Control;
- using Aitex.Core.UI.ControlDataContext;
- using Aitex.Core.UI.DeviceControl;
- using Aitex.Core.Util;
- using Caliburn.Micro.Core;
- using DocumentFormat.OpenXml.Drawing.Charts;
- using DocumentFormat.OpenXml.Office2019.Excel.RichData;
- using DocumentFormat.OpenXml.Wordprocessing;
- using FurnaceUI.Models;
- using MECF.Framework.Common;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
- using MECF.Framework.UI.Core.Control;
- using MECF.Framework.UI.Core.DxfScript;
- using MECF.Framework.UI.Core.DxfScript.Converter;
- using MECF.Framework.UI.Core.ExtendedControls;
- using OpenSEMI.ClientBase;
- using SciChart.Core.AttachedProperties;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Xml.Linq;
- using static MECF.Framework.UI.Core.DxfScript.Express;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
- namespace FurnaceUI.Views.Editors
- {
- public class RecipeGasXmlViewModel : FurnaceUIViewModelBase, IUserFunctions, IDisposable
- {
- private string _PM = $"{ModuleName.PM1.ToString()}.";
- private Dictionary<string, string> ConvertNameDict = new Dictionary<string, string>()
- {
- };
- public List<string> ChangeMfcValue = new List<string>();
- public Window WinOwner { get; set; }
- private string _selectedStepName;
- public string SelectedStepName
- {
- get
- {
- return _selectedStepName;
- }
- set
- {
- _selectedStepName = value;
- NotifyOfPropertyChange("SelectedStepName");
- }
- }
- private Step _step;
- public Step SelectedStep
- {
- get => _step;
- set
- {
- _step = value;
- NotifyOfPropertyChange("SelectedStep");
- }
- }
- public delegate void ChangedStepHandler(Step step);
- public event ChangedStepHandler ChangedStepEvent;
- public RecipeDataBase CurrentRecipe { get; set; }
- private GasPanelStateType _selectedGasStateType = GasPanelStateType.Recipe;
- public GasPanelStateType SelectedGasStateType
- {
- get
- {
- return _selectedGasStateType;
- }
- set
- {
- _selectedGasStateType = value;
- NotifyOfPropertyChange(nameof(SelectedGasStateType));
- }
- }
- private bool _isUsePREVBtn = false;
- public bool IsUsePREVBtn
- {
- get => _isUsePREVBtn;
- set
- {
- _isUsePREVBtn = value;
- NotifyOfPropertyChange("IsUsePREVBtn");
- }
- }
- private bool _isUseNEXTBtn = false;
- public bool IsUseNEXTBtn
- {
- get => _isUseNEXTBtn;
- set
- {
- _isUseNEXTBtn = value;
- NotifyOfPropertyChange("IsUseNEXTBtn");
- }
- }
- public RecipeGasXmlViewModel()
- {
- UserFunctionsEvents.ClearAll();
- UserFunctionsEvents.RegisterEvent<Dictionary<string, object>>("SwichValue", SwichValue);
- UserFunctionsEvents.RegisterEvent<Dictionary<string, object>>("MfcFlowTouchUp", MfcFlowTouchUp);
- UserFunctionsEvents.RegisterEvent<Dictionary<string, object>>("ValveTouchUp", ValveTouchUp);
- }
- protected override void OnViewLoaded(object view)
- {
- base.OnViewLoaded(view);
- GetIoValveBtn();
- SetValveVirtualFeedbackValue();
- SwitchKey(false);
- SetPREVAndNEXTBtn();
- }
- /// <summary>
- /// DevicePM中有些IoValve命名存在问题,没有表明是btn类型,故需要转化下。
- /// </summary>
- private void GetIoValveBtn()
- {
- ConvertNameDict.Clear();
- var valueSetsName = SelectedStep.ValveSets.Where(a => a.Name.StartsWith("ValveAV")).Select(a => $"{_PM}{a.Name}Btn").ToList();
- var valuveDatas = QueryDataClient.Instance.Service.PollData(valueSetsName);
- foreach (var item in valuveDatas)
- {
- var valveItem = SelectedStep.ValveSets.Where(a => $"{_PM}{a.Name}Btn" == item.Key).FirstOrDefault().Name;
- ConvertNameDict.Add(valveItem, item.Value.ToString());
- }
- }
- protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
- {
- base.InvokeAfterUpdateProperty(data);
- GasMapProvider.GasMap.ModifyDrag();
- }
- /// <summary>
- /// 切换Key
- /// </summary>
- /// <param name="isMonitor"></param>
- public void SwitchKey(bool isMonitor = true)
- {
- ScriptVariables.IsFetchRT = isMonitor;
- foreach (var item in GasMapProvider.GasMap.Valves)
- {
- var realKey = $"{ModuleName.PM1.ToString()}.{item.Name}.Feedback";
- item.Key = isMonitor ? realKey : $"{realKey.Replace(_PM, "")}";
- }
- foreach (var item in GasMapProvider.GasMap.Buttons)
- {
- bool isExextue = item.BoolCondition != null;
- var realKey = $"{ModuleName.PM1}.{item.InnerText.Text}Enable";
- if (isExextue)
- {
- item.BoolCondition.Execute();
- realKey = item.BoolCondition.ReadBoolValue().Item1;
- }
- item.DataKey = isMonitor ? realKey : $"{realKey.Replace(_PM, "")}";
- }
- foreach (var item in GasMapProvider.GasMap.Analogs)
- {
- item.Brush = GasMapProvider.InitMFCColor;
- if (ChangeMfcValue.Contains(item.Name) && !isMonitor)
- {
- item.Brush = GasMapProvider.ChangeMFCColor;
- }
- var realKey = $"{ModuleName.PM1}.{item.Name}.Feedback";
- item.ValueKey = isMonitor ? realKey : $"{realKey.Replace(_PM, "")}";
- }
- foreach (var item in GasMapProvider.GasMap.Circles)
- {
- bool isExextue = item.ClickCondition == null && item.BoolCondition != null && item.StringCondition == null;
- if (isExextue)
- {
- item.BoolCondition.Execute();
- item.Key = item.BoolCondition.ReadBoolValue().Item1;
- continue;
- }
- }
- }
- /// <summary>
- /// 初始化虚拟值
- /// </summary>
- public void SetValveVirtualFeedbackValue()
- {
- var str = $"{ModuleName.PM1.ToString()}.";
- ChangeMfcValue.Clear();
- Dictionary<string, object> btnNameKeyValues = new Dictionary<string, object>();
- foreach (var item in SelectedStep.ValveSets)
- {
- var itemName = item.Name;
- if (ConvertNameDict.ContainsKey(item.Name))
- {
- itemName = ConvertNameDict[item.Name];
- }
- if (itemName.StartsWith("ValveAV"))
- {
- var temporaryKey = $"{itemName}.Feedback";
- var realKey = $"{ModuleName.PM1}.{temporaryKey}";
- if (!btnNameKeyValues.Keys.Contains(temporaryKey))
- {
- btnNameKeyValues.Add(temporaryKey, item.Value);
- }
- }
- else
- {
- var temporaryKey = $"{itemName}Enable";
- var realKey = $"{ModuleName.PM1}.{temporaryKey}";
- if (!btnNameKeyValues.Keys.Contains(temporaryKey))
- {
- btnNameKeyValues.Add(temporaryKey, item.Value);
- }
- }
- }
- foreach (var item in SelectedStep.MFCSets)
- {
- var temporaryKey = $"{item.ControlName}.Feedback";
- var realKey = $"{ModuleName.PM1}.{temporaryKey}";
- var recipeValue = double.Parse(item.SetValue.Value);
- if (recipeValue > 0)
- {
- ChangeMfcValue.Add(item.ControlName);
- }
- btnNameKeyValues.Add(temporaryKey, recipeValue);
- temporaryKey = $"{item.ControlName}.Scal";
- realKey = $"{ModuleName.PM1}.{temporaryKey}";
- if (ScriptVariables.ContainsVariable(realKey))
- {
- var newvalue = ScriptVariables.GetDoubleByName(realKey);
- if (btnNameKeyValues.ContainsKey(realKey))
- {
- btnNameKeyValues[realKey] = newvalue;
- }
- else
- {
- btnNameKeyValues.Add(realKey, newvalue);
- }
- }
- temporaryKey = $"{item.ControlName}.Unit";
- realKey = $"{ModuleName.PM1}.{temporaryKey}";
- btnNameKeyValues.Add(temporaryKey, item.Unit);
- if (ScriptVariables.ContainsVariable(realKey))
- {
- var newvalue = ScriptVariables.GetStringByName(realKey);
- if (btnNameKeyValues.ContainsKey(realKey))
- {
- btnNameKeyValues[realKey] = newvalue;
- }
- else
- {
- btnNameKeyValues.Add(realKey, newvalue);
- }
- }
- }
- ScriptVariables.InitializeDefaultSubscriptions(btnNameKeyValues);
- }
- /// <summary>
- /// btn点击事件
- /// </summary>
- /// <param name="parameter"></param>
- public void SwichValue(Dictionary<string, object> parameter)
- {
- if (SelectedGasStateType == GasPanelStateType.Monitor) return;
- var setCmd = (string)parameter["name"];
- var showType = (ShowType)parameter["showType"];
- var shape = (GasButton)parameter["shape"];
- ScriptVariables.IsFetchRT = false;
- bool setValue = false;
- var status = ScriptVariables.GetBoolByName(shape.DataKey);
- setValue = !status;
- ScriptVariables.SetBoolByName(shape.DataKey, setValue);
- setCmd = ConvertNameDict.ContainsValue(setCmd) ? ConvertNameDict.FirstOrDefault(x => x.Value == setCmd).Key : setCmd;
- SelectedStep.ValveSets.FirstOrDefault(x => x.Name == setCmd).SetValue(setValue);
- if (!string.IsNullOrEmpty(setCmd))
- {
- SetValveFollow(setCmd, setValue);
- }
- }
- /// <summary>
- /// 阀点击事件
- /// </summary>
- /// <param name="parameter"></param>
- public void ValveTouchUp(Dictionary<string, object> parameter)
- {
- var shape = (GasAITValve)parameter["shape"];
- var name = shape.Name;
- if (SelectedGasStateType == GasPanelStateType.Monitor) return;
- var status = ScriptVariables.GetBoolByName(shape.Key);
- var newStatus = !status;
- ScriptVariables.SetBoolByName(shape.Key, newStatus);
- InvokeClient.Instance.Service.DoOperation($"{_PM}{name}.{AITValveOperation.GVVirtualTurnValve}", newStatus);
- var obj = new object[] { name, AITValveOperation.GVVirtualTurnValve, newStatus };
- SetValveCommand(obj);
- }
- [Subscription("PM1.MFC1.DeviceData")]
- public AITMfcData MFC1Data { get; set; }
- /// <summary>
- /// MFC点击事件
- /// </summary>
- /// <param name="parameter"></param>
- public void MfcFlowTouchUp(Dictionary<string, object> parameter)
- {
- var shape = (GasAnalogControl4Jet)parameter["shape"];
- var name = shape.Name;
- if (SelectedGasStateType == GasPanelStateType.Monitor || shape.IsMfm) return;
- var setPoint = ScriptVariables.GetVariableByName(shape.ValueKey).DoubleValue;
- var maxValue = ScriptVariables.GetVariableByName(shape.MaxValueKey).DoubleValue;
- var unit = ScriptVariables.GetVariableByName(shape.UnitKey).StringValue;
- InputDialogBox dialogBox = new InputDialogBox
- {
- TagName = "Number",
- CommandDelegate = Execute,
- DeviceName = shape.Name,
- SetPoint = setPoint,
- MaxValue = maxValue,
- Unit = unit,
- };
- dialogBox.SetPoint = Math.Round(setPoint * 100.0, 1);
- dialogBox.Owner = WinOwner;
- dialogBox.Topmost = false;
- dialogBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
- if ((bool)dialogBox.ShowDialog())
- {
- if (!string.IsNullOrEmpty(dialogBox.InputText))
- {
- var newValue = double.Parse(dialogBox.InputText);
- ScriptVariables.SetDoubleByName(shape.ValueKey, newValue);
- shape.Brush = GasMapProvider.ChangeMFCColor;
- var obj = new object[] { $"{_PM}{shape.Name}", AITMfcOperation.GVMfcVirtualTurnValve, newValue };
- PerformCmdSetMfcFlow(obj);
- //if (SelectedGasStateType == GasPanelStateType.Manual)
- //{
- // obj = new object[] { $"{_PM}{shape.Name}", AITMfcOperation.GVMfcValve, newValue };
- // PerformCmdSetMfcFlow(obj);
- //}
- }
- }
- dialogBox.Close();
- dialogBox.Dispose();
- }
- private void Execute(double value, double? ramp)
- {
- }
- /// <summary>
- /// 下一步/上一步
- /// </summary>
- /// <param name="cmd"></param>
- public void StepClick(string cmd)
- {
- bool isChangedStep = false;
- if (SelectedStep == null)
- {
- return;
- }
- switch (cmd)
- {
- case "PREV":
- SelectedStep = CurrentRecipe.Steps.Where(x => x.StepNo == SelectedStep.StepNo - 1).FirstOrDefault();
- isChangedStep = true;
- break;
- case "NEXT":
- SelectedStep = CurrentRecipe.Steps.Where(x => x.StepNo == SelectedStep.StepNo + 1).FirstOrDefault();
- isChangedStep = true;
- break;
- default:
- break;
- }
- if (isChangedStep && SelectedStep != null)
- {
- SelectedStepName = $"{SelectedStep.StepNo}:{SelectedStep.Name}";
- SetChangedStep(SelectedStep);
- SetValveVirtualFeedbackValue();
- }
- SetPREVAndNEXTBtn();
- }
- private void SetPREVAndNEXTBtn()
- {
- if (SelectedStep != null && CurrentRecipe != null)
- {
- if (CurrentRecipe.Steps.Count == 0)
- {
- IsUsePREVBtn = false;
- IsUseNEXTBtn = false;
- }
- else
- {
- if (SelectedStep.StepNo > CurrentRecipe.Steps[0].StepNo)
- {
- IsUsePREVBtn = true;
- }
- else
- {
- IsUsePREVBtn = false;
- }
- if (SelectedStep.StepNo < CurrentRecipe.Steps[CurrentRecipe.Steps.Count - 1].StepNo)
- {
- IsUseNEXTBtn = true;
- }
- else
- {
- IsUseNEXTBtn = false;
- }
- }
- }
- }
- public void SetChangedStep(Step step)
- {
- if (ChangedStepEvent != null)
- {
- ChangedStepEvent(step);
- }
- }
- public void SelectedGasStateTypeCmd(string cmd)
- {
- switch (cmd)
- {
- case "Manual":
- SelectedGasStateType = GasPanelStateType.Manual;
- break;
- case "Monitor":
- SelectedGasStateType = GasPanelStateType.Monitor;
- break;
- case "Recipe":
- SelectedGasStateType = GasPanelStateType.Recipe;
- break;
- default:
- break;
- }
- SwitchKey(SelectedGasStateType == GasPanelStateType.Monitor);
- }
- public void SetValveCommand(object param)
- {
- object[] args = (object[])param;
- if (args.Length == 3)
- if (SelectedStep != null && SelectedStep.ValveSets.Count > 0 && SelectedStep.ValveSets.FirstOrDefault(x => x.Name == (string)args[0]) != null)
- {
- SelectedStep.ValveSets.FirstOrDefault(x => x.Name == (string)args[0]).SetValue((bool)args[2]);
- //InvokeClient.Instance.Service.DoOperation($"{args[0]}.{args[1]}", args[2]);
- // SetValveFollow((string)args[0], (bool)args[2]);
- }
- //SetCursorPos(0, 0);
- }
- private void PerformCmdSetMfcFlow(object param)
- {
- object[] args = (object[])param; //0:devicename, 1:operation, 2:args
- if (args.Length == 3)
- {
- InvokeClient.Instance.Service.DoOperation($"{args[0]}.{args[1]}", args[2]);
- if (SelectedStep != null)
- {
- var mfc = SelectedStep.MFCSets.FirstOrDefault(x => x.ControlName == ((string)args[0]).Replace("PM1.", ""));
- if (mfc != null)
- {
- mfc.SetValue.SetValue(args[2].ToString());
- }
- }
- }
- // SetCursorPos(0, 0);
- }
- private void PerformCmdSetMfmFlow(object param)
- {
- object[] args = (object[])param; //0:devicename, 1:operation, 2:args
- if (args.Length == 3)
- {
- InvokeClient.Instance.Service.DoOperation($"PM1.{args[0]}.{args[1]}", args[2]);
- }
- // SetCursorPos(0, 0);
- }
- public void TempSetSave()
- {
- foreach (var mfcitem in SelectedStep.MFCSets)
- {
- var replaceStr = mfcitem.ControlName;
- var property = this.GetType().GetProperties().Where(x => x.Name == replaceStr).FirstOrDefault();
- if (property == null) continue;
- object value = property.GetValue(this, null);
- if (value != null)
- {
- mfcitem.SetValue.Value = ((AnalogDeviceDataItem)value).VirtualFeedBack.ToString();
- }
- }
- ((Window)GetView()).DialogResult = true;
- }
- public void TempSetCancel()
- {
- ((Window)GetView()).DialogResult = false;
- }
- private bool disposed = false;
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this); // 防止垃圾回收器再次调用析构函数
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposed)
- {
- if (disposing)
- {
- this.OnDeactivate(true);
- // 释放托管资源
- }
- // 释放非托管资源
- disposed = true;
- }
- }
- private void SwichValueBtn(string name, GasButton btn)
- {
- var dialog = new SwitchValueDialog { };
- var status = ScriptVariables.GetBoolByName(btn.DataKey);
- dialog.IsOpen = status;
- dialog.Owner = WinOwner;
- dialog.Topmost = true;
- dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
- dialog.DeviceName = $"Swich {name}";
- dialog.ShowDialog();
- if ((bool)dialog.IsSave)
- {
- string setCmd = name.Replace("Enable", "");
- ScriptVariables.SetBoolByName(btn.DataKey, dialog.IsOpen);
- SelectedStep.ValveSets.FirstOrDefault(x => x.Name == setCmd).Value = dialog.IsOpen;
- if (!string.IsNullOrEmpty(setCmd))
- {
- SetValveFollow(setCmd, dialog.IsOpen);
- }
- }
- }
- private void SetHeaterBtn(string name, GasButton btn)
- {
- ScriptVariables.IsFetchRT = false;
- string setCmd = "";
- bool setValue = false;
- var status = ScriptVariables.GetBoolByName(btn.DataKey);
- setCmd = name.Replace("Enable", "");
- setValue = !status;
- ScriptVariables.SetBoolByName(btn.DataKey, setValue);
- SelectedStep.ValveSets.FirstOrDefault(x => x.Name == setCmd).SetValue(setValue);
- if (!string.IsNullOrEmpty(setCmd))
- {
- SetValveFollow(setCmd, setValue);
- }
- }
- private void SelectPumpBtn(string name, GasButton btn)
- {
- ScriptVariables.IsFetchRT = false;
- var isConfirm = DialogBox.Confirm($"Are you sure change {name} status?");
- if (isConfirm)
- {
- string setCmd = "";
- bool setValue = false;
- //if (name == "DP1Enable")
- //{
- // name = "DPEnable";
- // btn.DataKey = name;
- //}
- var status = ScriptVariables.GetBoolByName(btn.DataKey);
- setCmd = name.Replace("Enable", "");
- setValue = !status;
- ScriptVariables.SetBoolByName(btn.DataKey, setValue);
- SelectedStep.ValveSets.FirstOrDefault(x => x.Name.ToUpper() == setCmd.ToUpper()).SetValue(setValue);
- if (!string.IsNullOrEmpty(setCmd))
- {
- SetValveFollow(setCmd, setValue);
- }
- }
- }
- private void SetValveFollow(string controlName, bool value)
- {
- int firstIndex = CurrentRecipe.Steps.IndexOf(SelectedStep);
- if (firstIndex < CurrentRecipe.Steps.Count)
- {
- for (int i = firstIndex + 1; i < CurrentRecipe.Steps.Count; i++)
- {
- if (!CurrentRecipe.Steps[i].ValveIsSaved)
- {
- break;
- }
- else
- {
- CurrentRecipe.Steps[i].ValveSets.FirstOrDefault(x => x.Name == controlName).Value = value;
- }
- }
- }
- }
- }
- }
|