From e6848e641770688df3a6259a552466f5223af707 Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Mon, 5 Aug 2024 20:32:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DynamicFlow/NodeModel/SingleExpOpNode.cs | 4 +- WorkBench/App.xaml.cs | 16 ++- WorkBench/MainWindow.xaml.cs | 113 ++++++++++++------ .../Node/View/ConditionNodeControl.xaml.cs | 12 +- WorkBench/Node/View/ExpOpNodeControl.xaml.cs | 11 +- WorkBench/SereinOutputFileData.cs | 4 +- 6 files changed, 100 insertions(+), 60 deletions(-) diff --git a/Library/DynamicFlow/NodeModel/SingleExpOpNode.cs b/Library/DynamicFlow/NodeModel/SingleExpOpNode.cs index 1866502..6cc3ac6 100644 --- a/Library/DynamicFlow/NodeModel/SingleExpOpNode.cs +++ b/Library/DynamicFlow/NodeModel/SingleExpOpNode.cs @@ -12,7 +12,9 @@ namespace Serein.DynamicFlow.NodeModel /// public class SingleExpOpNode : NodeBase { - + /// + /// 表达式 + /// public string Expression { get; set; } diff --git a/WorkBench/App.xaml.cs b/WorkBench/App.xaml.cs index bf10fa6..19ae216 100644 --- a/WorkBench/App.xaml.cs +++ b/WorkBench/App.xaml.cs @@ -157,15 +157,13 @@ namespace Serein.WorkBench Shutdown(); // 关闭应用程序 } } - else if(1 == 11) - { - string filePath = - @"D:\Project\C#\DynamicControl\DynamicControl\DynamicDemo\bin\Debug\net8.0-windows7.0\project 233.dnf"; - //@"D:\Project\C#\DynamicControl\DynamicControl\DynamicDemo\bin\Debug\net8.0-windows7.0\demo project\node project.dnf"; - string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容 - FData = JsonConvert.DeserializeObject(content); - App.FileDataPath = System.IO.Path.GetDirectoryName(filePath); - } + //else if(1 == 1) + //{ + // string filePath =@"F:\临时\project\project.dnf"; + // string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容 + // FData = JsonConvert.DeserializeObject(content); + // App.FileDataPath = System.IO.Path.GetDirectoryName(filePath); + //} } } diff --git a/WorkBench/MainWindow.xaml.cs b/WorkBench/MainWindow.xaml.cs index ecd191f..cc94ffb 100644 --- a/WorkBench/MainWindow.xaml.cs +++ b/WorkBench/MainWindow.xaml.cs @@ -20,6 +20,7 @@ using System.Windows.Media.Animation; using System.Windows.Shapes; using static Serein.WorkBench.Connection; using DynamicDemo.Node; +using Npgsql.Logging; namespace Serein.WorkBench { @@ -451,18 +452,20 @@ namespace Serein.WorkBench /// private NodeControlBase CreateNodeControl(NodeInfo nodeInfo) { - if (!DllMethodDetails.TryGetValue(nodeInfo.name, out var md)) + MethodDetails md = null; + if (!string.IsNullOrWhiteSpace(nodeInfo.name)) { - WriteLog($"目标节点不存在方法信息: {nodeInfo.name}\r\n"); - - return null; - + DllMethodDetails.TryGetValue(nodeInfo.name, out md); } + NodeControlBase control = nodeInfo.type switch { $"{NodeSpaceName}.{nameof(SingleActionNode)}" => CreateNodeControl(md), - $"{NodeSpaceName}.{nameof(SingleConditionNode)}" => CreateNodeControl(md), $"{NodeSpaceName}.{nameof(SingleFlipflopNode)}" => CreateNodeControl(md), + + $"{NodeSpaceName}.{nameof(SingleConditionNode)}" => CreateNodeControl(), // 条件表达式控件 + $"{NodeSpaceName}.{nameof(SingleExpOpNode)}" => CreateNodeControl(), // 操作表达式控件 + $"{NodeSpaceName}.{nameof(CompositeActionNode)}" => CreateNodeControl(), $"{NodeSpaceName}.{nameof(CompositeConditionNode)}" => CreateNodeControl(), _ => throw new NotImplementedException($"非预期的节点类型{nodeInfo.type}"), @@ -480,14 +483,30 @@ namespace Serein.WorkBench var node = control.Node; if (node != null) { + node.Guid = nodeInfo.guid; for (int i = 0; i < nodeInfo.parameterData.Length; i++) { Parameterdata? pd = nodeInfo.parameterData[i]; - node.MethodDetails.ExplicitDatas[i].IsExplicitData = pd.state; - node.MethodDetails.ExplicitDatas[i].DataValue = pd.value; + if (control is ConditionNodeControl conditionNodeControl) + { + conditionNodeControl.ViewModel.IsCustomData = pd.state; + conditionNodeControl.ViewModel.CustomData = pd.value; + conditionNodeControl.ViewModel.Expression = pd.expression; + } + else if (control is ExpOpNodeControl expOpNodeControl) + { + expOpNodeControl.ViewModel.Expression = pd.expression; + } + else + { + node.MethodDetails.ExplicitDatas[i].IsExplicitData = pd.state; + node.MethodDetails.ExplicitDatas[i].DataValue = pd.value; + } } } - + + + return control;// DNF文件加载时创建 @@ -516,6 +535,7 @@ namespace Serein.WorkBench throw new Exception("无法创建节点控件"); } + nodeBase.Guid = Guid.NewGuid().ToString(); if (methodDetails != null) @@ -1798,49 +1818,72 @@ namespace Serein.WorkBench { try { - // 保存节点 - var nodeObjs = nodeControls.Select(item => + // 生成节点信息 + var nodeInfos = nodeControls.Select(item => { var node = item.Node; Point positionRelativeToParent = item.TranslatePoint(new Point(0, 0), FlowChartCanvas); - var trueNodes = item.Node.TrueBranch.Select(item => item.Guid).ToArray(); - var falseNodes = item.Node.FalseBranch.Select(item => item.Guid).ToArray(); + var trueNodes = item.Node.TrueBranch.Select(item => item.Guid); // 真分支 + var falseNodes = item.Node.FalseBranch.Select(item => item.Guid);// 加分制 - IEnumerable? parameterData = []; - if (node?.MethodDetails?.ExplicitDatas is not null) + // 常规节点的参数信息 + List parameterData = []; + if (node?.MethodDetails?.ExplicitDatas is not null + && (node.MethodDetails.MethodDynamicType == DynamicNodeType.Action + || node.MethodDetails.MethodDynamicType == DynamicNodeType.Flipflop)) { - parameterData = node?.MethodDetails.ExplicitDatas.Select(it => { - - if (it != null) + parameterData = node.MethodDetails + .ExplicitDatas + .Where(it => it is not null) + .Select(it => new Parameterdata + { + state = it.IsExplicitData, + value = it.DataValue + }) + .ToList(); + } + else if (node is SingleExpOpNode expOpNode) + { + parameterData.Add(new Parameterdata + { + state = true, + expression = expOpNode.Expression, + }); + } + else if (node is SingleConditionNode conditionNode) + { + parameterData.Add(new Parameterdata + { + state = conditionNode.IsCustomData, + expression = conditionNode.Expression, + value = conditionNode.CustomData switch { - return new - { - state = it.IsExplicitData, - value = it.DataValue, - }; - } - else - { - return null; + Type when conditionNode.CustomData.GetType() == typeof(int) + && conditionNode.CustomData.GetType() == typeof(double) + && conditionNode.CustomData.GetType() == typeof(float) + => ((double)conditionNode.CustomData).ToString(), + Type when conditionNode.CustomData.GetType() == typeof(bool) => ((bool)conditionNode.CustomData).ToString(), + _ => conditionNode.CustomData?.ToString()!, } }); } + - return new + return new NodeInfo { guid = node.Guid, name = node.MethodDetails?.MethodName, label = node.DisplayName ?? "", type = node.GetType().ToString(), - position = new + position = new Position { - x = positionRelativeToParent.X, - y = positionRelativeToParent.Y, + x = (float)positionRelativeToParent.X, + y = (float)positionRelativeToParent.Y, }, - trueNodes = trueNodes, - falseNodes = falseNodes, - parameterData = parameterData, + trueNodes = trueNodes.ToArray(), + falseNodes = falseNodes.ToArray(), + parameterData = parameterData.ToArray(), }; }).ToList(); @@ -1962,7 +2005,7 @@ namespace Serein.WorkBench }, ["library"] = JArray.FromObject(dlls), ["startNode"] = flowStartBlock == null ? "" : flowStartBlock.Node.Guid, - ["nodes"] = JArray.FromObject(nodeObjs), + ["nodes"] = JArray.FromObject(nodeInfos), ["regions"] = JArray.FromObject(regionObjs), }; // WriteLog(keyValuePairs.ToString()); diff --git a/WorkBench/Node/View/ConditionNodeControl.xaml.cs b/WorkBench/Node/View/ConditionNodeControl.xaml.cs index 37332e9..ffab6a8 100644 --- a/WorkBench/Node/View/ConditionNodeControl.xaml.cs +++ b/WorkBench/Node/View/ConditionNodeControl.xaml.cs @@ -14,21 +14,21 @@ namespace Serein.WorkBench.Node.View /// public partial class ConditionNodeControl : NodeControlBase { - private readonly ConditionNodeControlViewModel viewModel; + public ConditionNodeControlViewModel ViewModel { get; } public ConditionNodeControl() : base() { - - viewModel = new (new ()); - DataContext = viewModel; + + ViewModel = new (new ()); + DataContext = ViewModel; InitializeComponent(); } public ConditionNodeControl(SingleConditionNode node) : base(node) { Node = node; - viewModel = new ConditionNodeControlViewModel(node); - DataContext = viewModel; + ViewModel = new ConditionNodeControlViewModel(node); + DataContext = ViewModel; InitializeComponent(); } diff --git a/WorkBench/Node/View/ExpOpNodeControl.xaml.cs b/WorkBench/Node/View/ExpOpNodeControl.xaml.cs index d8009f7..9b06841 100644 --- a/WorkBench/Node/View/ExpOpNodeControl.xaml.cs +++ b/WorkBench/Node/View/ExpOpNodeControl.xaml.cs @@ -22,20 +22,19 @@ namespace Serein.WorkBench.Node.View /// public partial class ExpOpNodeControl : NodeControlBase { - private readonly ExpOpNodeViewModel viewModel; - + public ExpOpNodeViewModel ViewModel { get; } public ExpOpNodeControl() { - viewModel = new (new()); - DataContext = viewModel; + ViewModel = new (new()); + DataContext = ViewModel; InitializeComponent(); } public ExpOpNodeControl(SingleExpOpNode node):base(node) { Node = node; - viewModel = new(node); - DataContext = viewModel; + ViewModel = new(node); + DataContext = ViewModel; InitializeComponent(); } diff --git a/WorkBench/SereinOutputFileData.cs b/WorkBench/SereinOutputFileData.cs index 7335816..4b9660f 100644 --- a/WorkBench/SereinOutputFileData.cs +++ b/WorkBench/SereinOutputFileData.cs @@ -156,6 +156,7 @@ namespace Serein.WorkBench public bool state { get; set; } public string value { get; set; } + public string expression { get; set; } } @@ -175,10 +176,7 @@ namespace Serein.WorkBench /// public class Region { - public string guid { get; set; } - - public NodeInfo[] childNodes { get; set; } }