mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
修改了保存方法,可以正常使用
This commit is contained in:
@@ -12,7 +12,9 @@ namespace Serein.DynamicFlow.NodeModel
|
||||
/// </summary>
|
||||
public class SingleExpOpNode : NodeBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 表达式
|
||||
/// </summary>
|
||||
public string Expression { get; set; }
|
||||
|
||||
|
||||
|
||||
@@ -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<SereinOutputFileData>(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<SereinOutputFileData>(content);
|
||||
// App.FileDataPath = System.IO.Path.GetDirectoryName(filePath);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// <returns></returns>
|
||||
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<SingleActionNode, ActionNodeControl>(md),
|
||||
$"{NodeSpaceName}.{nameof(SingleConditionNode)}" => CreateNodeControl<SingleConditionNode, ConditionNodeControl>(md),
|
||||
$"{NodeSpaceName}.{nameof(SingleFlipflopNode)}" => CreateNodeControl<SingleFlipflopNode, FlipflopNodeControl>(md),
|
||||
|
||||
$"{NodeSpaceName}.{nameof(SingleConditionNode)}" => CreateNodeControl<SingleConditionNode, ConditionNodeControl>(), // 条件表达式控件
|
||||
$"{NodeSpaceName}.{nameof(SingleExpOpNode)}" => CreateNodeControl<SingleExpOpNode, ExpOpNodeControl>(), // 操作表达式控件
|
||||
|
||||
$"{NodeSpaceName}.{nameof(CompositeActionNode)}" => CreateNodeControl<CompositeActionNode, ActionRegionControl>(),
|
||||
$"{NodeSpaceName}.{nameof(CompositeConditionNode)}" => CreateNodeControl<CompositeConditionNode, ConditionRegionControl>(),
|
||||
_ => 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<object?>? parameterData = [];
|
||||
if (node?.MethodDetails?.ExplicitDatas is not null)
|
||||
// 常规节点的参数信息
|
||||
List<Parameterdata> 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());
|
||||
|
||||
@@ -14,21 +14,21 @@ namespace Serein.WorkBench.Node.View
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,20 +22,19 @@ namespace Serein.WorkBench.Node.View
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public class Region
|
||||
{
|
||||
|
||||
public string guid { get; set; }
|
||||
|
||||
|
||||
public NodeInfo[] childNodes { get; set; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user