| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 | 
							- /**
 
-  *
 
-  * @author    seagle
 
-  * @date      2024-7-22
 
-  * @Description 脚本中的自定义函数
 
-  */
 
- using MECF.Framework.UI.Core.Control;
 
- using MECF.Framework.UI.Core.ExtendedControls;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Reflection;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using System.Windows;
 
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
 
- using System.Windows.Input;
 
- using System.Xml.Linq;
 
- using Aitex.Core.UI.Control;
 
- using MECF.Framework.UI.Core.DxfScript;
 
- using MECF.Framework.Common.OperationCenter;
 
- using Aitex.Core.Common.DeviceData;
 
- using MECF.Framework.Common;
 
- using static MECF.Framework.UI.Core.DxfScript.Express;
 
- namespace MECF.Framework.UI.Core.DxfScript
 
- {
 
-     public partial class Express
 
-     {
 
-         private UserFunction GetFunAddr(string name)
 
-         {
 
-             if (name.Equals("Debug")) return Debug;
 
-             else if (name.Equals("InitVariable")) return InitVariable;
 
-             else if (name.Equals("ValveTouchUp")) return ValveTouchUp;
 
-             else if (name.Equals("MfcTouchUp")) return MfcTouchUp;
 
-             else if (name.Equals("SwichValue")) return SwichValue;
 
-             else throw new Exception("Function not found:" + name);
 
-         }
 
-         /**  脚本函数名:InitVariable
 
-          *   功能:       初始化脚本变量,仅用于开发环境
 
-          *   参数:   
 
-          *               变量名:string
 
-          *               表达式,表达式的结算结果的类型作为变量的类型,并把值赋给变量
 
-          * 
 
-          *   返回值:   无意义
 
-          */
 
-         private void InitVariable(ExpressNode curr, bool OnlyCheckDataType = false)
 
-         {
 
-             if (!OnlyCheckDataType)
 
-             {
 
-                 if (curr.FirstChild == null)
 
-                 {
 
-                     throw new Exception("No arguments in InitVariable");
 
-                 }
 
-                 else
 
-                 {
 
-                     if (curr.FirstChild.NodeType != KeywordType.KW_OPERATOR_COMMA)
 
-                     {
 
-                         throw new Exception("Not enouch arguments in InitVariable");
 
-                     }
 
-                     if (curr.FirstChild.FirstChild == null)
 
-                     {
 
-                         throw new Exception("No variable name in InitVariable");
 
-                     }
 
-                     if (curr.FirstChild.FirstChild.NextBrother == null)
 
-                     {
 
-                         throw new Exception("No variable type and value in InitVariable");
 
-                     }
 
-                     ComputeNode(curr.FirstChild.FirstChild, false);
 
-                     string varName = curr.FirstChild.FirstChild.Var.StringValue;
 
-                     ComputeNode(curr.FirstChild.FirstChild.NextBrother, false);
 
-                     Variable var = curr.FirstChild.FirstChild.NextBrother.Var;
 
-                     VariableDataType dataType = curr.FirstChild.FirstChild.NextBrother.Var.DataType;
 
-                     Variable newVar = new Variable(varName, dataType);
 
-                     newVar.CopyFrom(var);
 
-                     if (!ScriptVariables.fakeVariables.ContainsKey(varName))
 
-                     {
 
-                         ScriptVariables.fakeVariables.Add(varName, newVar);
 
-                     }
 
-                     else
 
-                     {
 
-                         ScriptVariables.fakeVariables[varName] = newVar;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         /**  脚本函数名:Debug
 
-          *   功能:       打印并返回表达式的值
 
-          *   参数:   
 
-          *              表达式
 
-          *   返回值:   表达式的值
 
-          */
 
-         private void Debug(ExpressNode curr, bool OnlyCheckDataType = false)
 
-         {
 
-             if (!OnlyCheckDataType)
 
-             {
 
-                 if (curr.FirstChild == null)
 
-                 {
 
-                     MessageBox.Show("No arguments", "Debug", MessageBoxButton.OK);
 
-                 }
 
-                 else
 
-                 {
 
-                     ComputeNode(curr.FirstChild, false);
 
-                     string result = null;
 
-                     switch (curr.FirstChild.Var.DataType)
 
-                     {
 
-                         case VariableDataType.BOOL:
 
-                             result = curr.FirstChild.Var.BoolValue.ToString();
 
-                             break;
 
-                         case VariableDataType.DOUBLE:
 
-                             result = curr.FirstChild.Var.DoubleValue.ToString();
 
-                             break;
 
-                         case VariableDataType.STRING:
 
-                             result = curr.FirstChild.Var.StringValue;
 
-                             break;
 
-                         default:
 
-                             result = "Unknown type";
 
-                             break;
 
-                     }
 
-                     MessageBox.Show(result, "Debug", MessageBoxButton.OK);
 
-                     curr.Var.CopyFrom(curr.FirstChild.Var, false);
 
-                 }
 
-             }
 
-         }
 
-         /**  脚本函数名:AIValveTouchUp
 
-           *   功能:       设置阀的开关
 
-           *              表达式
 
-           *   返回值:   表达式的值
 
-         */
 
-         private void ValveTouchUp(ExpressNode curr, bool OnlyCheckDataType = false)
 
-         {
 
-             if (OnlyCheckDataType) return;
 
-             var shape = (GasAITValve)GasMapProvider.GasMap.SelectedShape;
 
-             Dictionary<string, object> param = new Dictionary<string, object>()
 
-             {
 
-                 {"shape", shape},
 
-             };
 
-             UserFunctionsEvents.RaiseEvent("ValveTouchUp", param);
 
-         }
 
-         /**  脚本函数名:MfcTouchUp
 
-          *   功能:       设置mfc值
 
-          *              表达式
 
-          *   返回值:   表达式的值
 
-        */
 
-         private void MfcTouchUp(ExpressNode curr, bool OnlyCheckDataType = false)
 
-         {
 
-             if (OnlyCheckDataType) return;
 
-             var shape = (GasAnalogControl4Jet)GasMapProvider.GasMap.SelectedShape;
 
-          
 
-             Dictionary<string, object> param = new Dictionary<string, object>()
 
-             {
 
-                 {"shape", shape},
 
-             };
 
-             //0:devicename, 1:operation, 2:args
 
-             UserFunctionsEvents.RaiseEvent("MfcFlowTouchUp", param);
 
-         }
 
-         private void SwichValue(ExpressNode curr, bool OnlyCheckDataType = false)
 
-         {
 
-             if (OnlyCheckDataType) return;
 
-             var parameters = GetParameter(curr);
 
-             var name = parameters[0].StringValue;
 
-             var showType = (int)parameters[1].DoubleValue;
 
-             var shape = (GasButton)GasMapProvider.GasMap.SelectedShape;
 
-             Dictionary<string, object> param = new Dictionary<string, object>()
 
-             {
 
-                 {"name",name },
 
-                 {"shape",shape },
 
-                 {"showType",showType },
 
-             };
 
-             UserFunctionsEvents.RaiseEvent("SwichValue", param);
 
-         }
 
-         public enum ShowType
 
-         {
 
-             None = 10,
 
-             Confirm = 20,
 
-             Dialog = 30
 
-         }
 
-         #region 私有方法
 
-         private GasBaseShape GetGasBaseShapeById(string id)
 
-         {
 
-             return GasMapProvider.GasMap.FindShapeById(int.Parse(id));
 
-         }
 
-         private List<Variable> GetParameter(ExpressNode node)
 
-         {
 
-             return ParseVariables(node);
 
-         }
 
-         public List<Variable> ParseVariables(ExpressNode root)
 
-         {
 
-             List<Variable> variables = new List<Variable>();
 
-             ParseNode(root, variables);
 
-             return variables;
 
-         }
 
-         private void ParseNode(ExpressNode node, List<Variable> variables)
 
-         {
 
-             if (node == null) return;
 
-             // 如果当前节点是变量,将其添加到列表中
 
-             if (node.NodeType == KeywordType.KW_VARIABLE && node.Var != null)
 
-             {
 
-                 variables.Add(node.Var);
 
-             }
 
-             // 递归解析子节点
 
-             if (node.FirstChild != null)
 
-             {
 
-                 ParseNode(node.FirstChild, variables);
 
-             }
 
-             // 递归解析兄弟节点
 
-             if (node.NextBrother != null)
 
-             {
 
-                 ParseNode(node.NextBrother, variables);
 
-             }
 
-         }
 
-         #endregion
 
-     }
 
- }
 
 
  |