mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-05-03 22:01:27 +08:00
破坏性更新,移除了Core/Framework(对应的上下文类移动到了Library)
This commit is contained in:
@@ -74,7 +74,8 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
UIContextOperation? uIContextOperation = null;
|
||||
uIContextOperation = new UIContextOperation(getSyncContext); // 封装一个调用UI线程的工具类
|
||||
FlowEnvironmentDecorator flowEnvironmentDecorator = new FlowEnvironmentDecorator(uIContextOperation);
|
||||
var flowEnvironmentDecorator = new FlowEnvironmentDecorator();
|
||||
flowEnvironmentDecorator.SetUIContextOperation(uIContextOperation);
|
||||
collection.AddSingleton<UIContextOperation>(uIContextOperation); // 注册UI线程操作上下文
|
||||
collection.AddSingleton<IFlowEnvironment>(flowEnvironmentDecorator); // 注册运行环境
|
||||
collection.AddSingleton<IFlowEnvironmentEvent>(flowEnvironmentDecorator); // 注册运行环境事件
|
||||
|
||||
@@ -4,7 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Serein.Library;
|
||||
using Serein.Workbench.Avalonia.Api;
|
||||
using Serein.Workbench.Avalonia.Custom.Node.Views;
|
||||
using Serein.Workbench.Avalonia.Custom.Views;
|
||||
using Serein.Workbench.Avalonia.Model;
|
||||
using Serein.Workbench.Avalonia.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -30,11 +30,7 @@ namespace Serein.Workbench.Avalonia.Custom.Node.ViewModels
|
||||
|
||||
public NodeModelBase NodeModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录与该节点控件有关的所有连接
|
||||
/// </summary>
|
||||
private readonly List<NodeConnectionLineView> connectionControls = new List<NodeConnectionLineView>();
|
||||
|
||||
|
||||
//public NodeControlViewModelBase ViewModel { get; set; }
|
||||
|
||||
|
||||
@@ -42,48 +38,6 @@ namespace Serein.Workbench.Avalonia.Custom.Node.ViewModels
|
||||
public void SetNodeModel(NodeModelBase nodeModel) => this.NodeModel = nodeModel;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加与该节点有关的连接后,记录下来
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
public void AddCnnection(NodeConnectionLineView connection)
|
||||
{
|
||||
connectionControls.Add(connection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除了连接之后,还需要从节点中的记录移除
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
public void RemoveConnection(NodeConnectionLineView connection)
|
||||
{
|
||||
connectionControls.Remove(connection);
|
||||
//connection.Remote();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除所有连接
|
||||
/// </summary>
|
||||
public void RemoveAllConection()
|
||||
{
|
||||
foreach (var connection in this.connectionControls)
|
||||
{
|
||||
//connection.Remote();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新与该节点有关的数据
|
||||
/// </summary>
|
||||
public void UpdateLocationConnections()
|
||||
{
|
||||
foreach (var connection in this.connectionControls)
|
||||
{
|
||||
//connection.RefreshLine(); // 主动更新连线位置
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置绑定:
|
||||
/// Canvas.X and Y : 画布位置
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
<!--调用控制点,方法名称,下一个方法调用控制点-->
|
||||
<Grid x:Name="HeaderGrid" Grid.Row="0" ColumnDefinitions="auto,*,auto" VerticalAlignment="Center">
|
||||
<cv:NodeJunctionView Grid.Column="0" JunctionType="Execute" MyNode="{Binding NodeMoel}" Width="30" Height="15" Margin="4,0,2,0" />
|
||||
<cv:NodeJunctionView x:Name="ExecuteJunctionControl" Grid.Column="0" JunctionType="Execute" MyNode="{Binding NodeMoel}" Width="30" Height="15" Margin="4,0,2,0" />
|
||||
<StackPanel Grid.Column="1" Grid.RowSpan="2" >
|
||||
<TextBlock Text="{Binding NodeMoel.DisplayName}" FontSize="17" HorizontalAlignment="Center">
|
||||
<ToolTip.Tip>
|
||||
@@ -31,7 +31,7 @@
|
||||
</ToolTip.Tip>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
<cv:NodeJunctionView Grid.Column="2" JunctionType="NextStep" MyNode="{Binding NodeMoel}" Width="30" Height="15" Margin="2,0,8,0"/>
|
||||
<cv:NodeJunctionView x:Name="NextStepJunctionControl" Grid.Column="2" JunctionType="NextStep" MyNode="{Binding NodeMoel}" Width="30" Height="15" Margin="2,0,8,0"/>
|
||||
</Grid>
|
||||
|
||||
<!--入参信息-->
|
||||
|
||||
@@ -5,10 +5,11 @@ using Serein.Library;
|
||||
using Serein.NodeFlow.Model;
|
||||
using Serein.Workbench.Avalonia.Api;
|
||||
using Serein.Workbench.Avalonia.Custom.Node.ViewModels;
|
||||
using Serein.Workbench.Avalonia.Custom.Views;
|
||||
|
||||
namespace Serein.Workbench.Avalonia.Custom.Node.Views;
|
||||
|
||||
public partial class ActionNodeView : NodeControlBase
|
||||
public partial class ActionNodeView : NodeControlBase, INodeJunction
|
||||
{
|
||||
private ActionNodeViewModel _vm;
|
||||
|
||||
@@ -20,4 +21,11 @@ public partial class ActionNodeView : NodeControlBase
|
||||
//DataContext = _vm;
|
||||
}
|
||||
|
||||
public NodeJunctionView ExecuteJunction => this.ExecuteJunctionControl;
|
||||
|
||||
public NodeJunctionView NextStepJunction => this.NextStepJunctionControl;
|
||||
|
||||
public NodeJunctionView[] ArgDataJunction => throw new System.NotImplementedException();
|
||||
|
||||
public NodeJunctionView ReturnDataJunction => throw new System.NotImplementedException();
|
||||
}
|
||||
@@ -14,13 +14,62 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Workbench.Avalonia.Custom.Node.Views
|
||||
{
|
||||
public class NodeControlBase : UserControl
|
||||
public abstract class NodeControlBase : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 记录与该节点控件有关的所有连接
|
||||
/// </summary>
|
||||
private readonly List<NodeConnectionLineControl> connectionControls = new List<NodeConnectionLineControl>();
|
||||
|
||||
protected NodeControlBase()
|
||||
{
|
||||
this.Background = Brushes.Transparent;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加与该节点有关的连接后,记录下来
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
public void AddConnection(NodeConnectionLineControl connection)
|
||||
{
|
||||
connectionControls.Add(connection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除了连接之后,还需要从节点中的记录移除
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
public void RemoveConnection(NodeConnectionLineControl connection)
|
||||
{
|
||||
connectionControls.Remove(connection);
|
||||
connection.Remove();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除所有连接
|
||||
/// </summary>
|
||||
public void RemoveAllConection()
|
||||
{
|
||||
foreach (var connection in this.connectionControls)
|
||||
{
|
||||
connection.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新与该节点有关的数据
|
||||
/// </summary>
|
||||
public void UpdateLocationConnections()
|
||||
{
|
||||
foreach (var connection in this.connectionControls)
|
||||
{
|
||||
connection.RefreshLineDsiplay(); // 主动更新连线位置
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 放置在某个节点容器中
|
||||
/// </summary>
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
//visualPen.Freeze(); // Freeze以提高性能
|
||||
|
||||
linkSize = 4; // 整线条粗细
|
||||
int zIndex = 999999;
|
||||
int zIndex = -999999;
|
||||
|
||||
this.ZIndex = zIndex;
|
||||
//Panel.SetZIndex(this, zIndex); // 置底
|
||||
@@ -111,6 +111,15 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
this.leftPoint = left;
|
||||
InvalidateVisual(); // 触发重绘
|
||||
}
|
||||
/// <summary>
|
||||
/// 刷新颜色
|
||||
/// </summary>
|
||||
/// <param name="brush"></param>
|
||||
public void UpdateColor(Brush brush )
|
||||
{
|
||||
visualPen = new Pen(brush, 3.0); // 默认可视化Pen
|
||||
InvalidateVisual(); // 触发重绘
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控件重绘事件
|
||||
|
||||
@@ -9,6 +9,7 @@ using Newtonsoft.Json.Linq;
|
||||
using Serein.Library;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.Workbench.Avalonia.Api;
|
||||
using Serein.Workbench.Avalonia.Custom.Node.Views;
|
||||
using Serein.Workbench.Avalonia.Custom.ViewModels;
|
||||
using Serein.Workbench.Avalonia.Extension;
|
||||
using Serein.Workbench.Avalonia.Services;
|
||||
@@ -51,7 +52,7 @@ public partial class NodeContainerView : UserControl
|
||||
/// <summary>
|
||||
/// 当前选取的控件
|
||||
/// </summary>
|
||||
private readonly List<Control> selectNodeControls = [];
|
||||
private readonly List<NodeControlBase> selectNodeControls = [];
|
||||
|
||||
/// <summary>
|
||||
/// 记录开始拖动节点控件时的鼠标位置
|
||||
@@ -98,7 +99,7 @@ public partial class NodeContainerView : UserControl
|
||||
{
|
||||
IsCanvasDragging = false;
|
||||
IsControlDragging = false;
|
||||
nodeOperationService.ConnectingData.Reset();
|
||||
nodeOperationService.ConnectingManage.Reset();
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
@@ -192,7 +193,7 @@ public partial class NodeContainerView : UserControl
|
||||
private void NodeContainerView_PointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
// 是否正在连接
|
||||
var myData = nodeOperationService.ConnectingData;
|
||||
var myData = nodeOperationService.ConnectingManage;
|
||||
if (myData.IsCreateing)
|
||||
{
|
||||
var isPass = e.JudgePointer(sender, PointerType.Mouse, p => p.IsLeftButtonPressed);
|
||||
@@ -318,7 +319,7 @@ public partial class NodeContainerView : UserControl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控件的鼠标左键按下事件,启动拖动操作。
|
||||
/// 控件的鼠标右键按下事件,启动拖动操作。
|
||||
/// </summary>
|
||||
private void Block_MouseLeftButtonDown(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
@@ -328,10 +329,11 @@ public partial class NodeContainerView : UserControl
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender is Control nodeControl)
|
||||
if (sender is NodeControlBase nodeControl)
|
||||
{
|
||||
IsControlDragging = true;
|
||||
startControlDragPoint = GetPositionOfCanvas(e); // 记录鼠标按下时的位置
|
||||
|
||||
e.Handled = true; // 防止事件传播影响其他控件
|
||||
}
|
||||
|
||||
@@ -343,7 +345,7 @@ public partial class NodeContainerView : UserControl
|
||||
private void Block_MouseMove(object? sender, PointerEventArgs e)
|
||||
{
|
||||
|
||||
if (sender is not Control nodeControl)
|
||||
if (sender is not NodeControlBase nodeControl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -365,6 +367,7 @@ public partial class NodeContainerView : UserControl
|
||||
double newLeft = Canvas.GetLeft(nodeControl) + deltaX; // 新的左边距
|
||||
double newTop = Canvas.GetTop(nodeControl) + deltaY; // 新的上边距
|
||||
DragControl(nodeControl, newLeft, newTop);
|
||||
nodeControl.UpdateLocationConnections();
|
||||
}
|
||||
// 批量移动
|
||||
else
|
||||
@@ -401,10 +404,10 @@ public partial class NodeContainerView : UserControl
|
||||
}
|
||||
|
||||
// 更新节点之间线的连接位置
|
||||
//foreach (var nodeControl in selectNodeControls)
|
||||
//{
|
||||
// //nodeControl.UpdateLocationConnections();
|
||||
//}
|
||||
foreach (var item in selectNodeControls)
|
||||
{
|
||||
item.UpdateLocationConnections();
|
||||
}
|
||||
}
|
||||
startControlDragPoint = currentPosition; // 更新起始点位置
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Serein.Library.Api;
|
||||
using Serein.Workbench.Avalonia.Api;
|
||||
using Serein.Workbench.Avalonia.Extension;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Color = Avalonia.Media.Color;
|
||||
using Point = Avalonia.Point;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class NodeJunctionView : TemplatedControl
|
||||
|
||||
private void NodeJunctionView_PointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
if (!nodeOperationService.ConnectingData.IsCreateing)
|
||||
if (!nodeOperationService.ConnectingManage.IsCreateing)
|
||||
return;
|
||||
if (nodeOperationService.MainCanvas is not InputElement inputElement)
|
||||
return;
|
||||
@@ -87,7 +88,7 @@ public class NodeJunctionView : TemplatedControl
|
||||
}
|
||||
else
|
||||
{
|
||||
var oldNj = nodeOperationService.ConnectingData.CurrentJunction;
|
||||
var oldNj = nodeOperationService.ConnectingManage.CurrentJunction;
|
||||
if (oldNj is not null)
|
||||
{
|
||||
oldNj.IsPreviewing = false;
|
||||
@@ -98,7 +99,7 @@ public class NodeJunctionView : TemplatedControl
|
||||
|
||||
private void RefreshDisplay(NodeJunctionView junctionView)
|
||||
{
|
||||
var oldNj = nodeOperationService.ConnectingData.CurrentJunction;
|
||||
var oldNj = nodeOperationService.ConnectingManage.CurrentJunction;
|
||||
if (oldNj is not null )
|
||||
{
|
||||
if (junctionView.Equals(oldNj))
|
||||
@@ -108,11 +109,11 @@ public class NodeJunctionView : TemplatedControl
|
||||
oldNj.IsPreviewing = false;
|
||||
oldNj.InvalidateVisual();
|
||||
}
|
||||
nodeOperationService.ConnectingData.CurrentJunction = junctionView;
|
||||
if (!this.Equals(junctionView))
|
||||
nodeOperationService.ConnectingManage.CurrentJunction = junctionView;
|
||||
if (!this.Equals(junctionView) && nodeOperationService.ConnectingManage.IsCanConnected())
|
||||
{
|
||||
|
||||
nodeOperationService.ConnectingData.TempLine?.ToEnd(junctionView);
|
||||
Debug.WriteLine("ok");
|
||||
nodeOperationService.ConnectingManage.TempLine?.ToEnd(junctionView);
|
||||
}
|
||||
junctionView.IsPreviewing = true;
|
||||
junctionView.InvalidateVisual();
|
||||
@@ -132,12 +133,12 @@ public class NodeJunctionView : TemplatedControl
|
||||
private void NodeJunctionView_PointerReleased(object? sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
CheckJunvtion();
|
||||
nodeOperationService.ConnectingData.Reset();
|
||||
nodeOperationService.ConnectingManage.Reset();
|
||||
}
|
||||
|
||||
private void CheckJunvtion()
|
||||
{
|
||||
var myData = nodeOperationService.ConnectingData;
|
||||
var myData = nodeOperationService.ConnectingManage;
|
||||
if(myData.StartJunction is null || myData.CurrentJunction is null)
|
||||
{
|
||||
return;
|
||||
@@ -246,7 +247,7 @@ public class NodeJunctionView : TemplatedControl
|
||||
/// <returns></returns>
|
||||
protected IBrush GetBackgrounp()
|
||||
{
|
||||
var myData = nodeOperationService.ConnectingData;
|
||||
var myData = nodeOperationService.ConnectingManage;
|
||||
if (IsPreviewing == false || !myData.IsCreateing )
|
||||
{
|
||||
return new SolidColorBrush(Color.Parse("#76ABEE"));
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Serein.Workbench.Avalonia.DataTemplates
|
||||
textBlock.FontSize = 12;
|
||||
return textBlock;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public bool Match(object data)
|
||||
@@ -57,7 +57,7 @@ namespace Serein.Workbench.Avalonia.DataTemplates
|
||||
}
|
||||
var dragData = new DataObject(); // 设置需要传递的数据
|
||||
dragData.Set(DataFormats.Text, mdInfo.ToJsonText());
|
||||
_ = DragDrop.DoDragDrop(e, dragData, DragDropEffects.Copy);
|
||||
_ = DragDrop.DoDragDrop(e, dragData, DragDropEffects.Copy);
|
||||
//var result = await DragDrop.DoDragDrop(e, dragData, DragDropEffects.Copy);
|
||||
//Debug.WriteLine("DoDrag :" + result);
|
||||
//switch (result)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Threading;
|
||||
using Serein.Library;
|
||||
using Serein.Workbench.Avalonia.Api;
|
||||
using Serein.Workbench.Avalonia.Custom.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,12 +16,13 @@ namespace Serein.Workbench.Avalonia.Model
|
||||
/// <summary>
|
||||
/// 节点之间连接线的相关控制方法
|
||||
/// </summary>
|
||||
public class ConnectingData
|
||||
internal class ConnectingManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否正在创建连线
|
||||
/// </summary>
|
||||
public bool IsCreateing { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 起始控制点
|
||||
/// </summary>
|
||||
@@ -29,14 +31,11 @@ namespace Serein.Workbench.Avalonia.Model
|
||||
/// 当前的控制点
|
||||
/// </summary>
|
||||
public NodeJunctionView? CurrentJunction { get; set; }
|
||||
/// <summary>
|
||||
/// 开始坐标
|
||||
/// </summary>
|
||||
public Point StartPoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 线条样式
|
||||
/// </summary>
|
||||
public NodeConnectionLineView? TempLine { get; set; }
|
||||
public NodeConnectionLineControl? TempLine { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 线条类别(方法调用)
|
||||
@@ -51,7 +50,10 @@ namespace Serein.Workbench.Avalonia.Model
|
||||
/// 判断当前连接类型
|
||||
/// </summary>
|
||||
public JunctionOfConnectionType? Type => StartJunction?.JunctionType.ToConnectyionType();
|
||||
|
||||
|
||||
private readonly INodeOperationService nodeOperationService1;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否允许连接
|
||||
@@ -105,6 +107,10 @@ namespace Serein.Workbench.Avalonia.Model
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置
|
||||
/// </summary>
|
||||
@@ -5,6 +5,7 @@ using Avalonia.Media;
|
||||
using Avalonia.VisualTree;
|
||||
using Serein.Library;
|
||||
using Serein.Script.Node;
|
||||
using Serein.Workbench.Avalonia.Custom.Views;
|
||||
using Serein.Workbench.Avalonia.Extension;
|
||||
using Serein.Workbench.Avalonia.Services;
|
||||
using System;
|
||||
@@ -18,12 +19,12 @@ using System.Threading.Tasks;
|
||||
using Color = Avalonia.Media.Color;
|
||||
using Point = Avalonia.Point;
|
||||
|
||||
namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
namespace Serein.Workbench.Avalonia.Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class NodeConnectionLineView
|
||||
|
||||
public class NodeConnectionLineControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 线条类别(方法调用)
|
||||
@@ -53,13 +54,37 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
/// </summary>
|
||||
public ConnectionLineShape? ConnectionLineShape { get; private set; }
|
||||
|
||||
public NodeConnectionLineView(Canvas canvas,
|
||||
private NodeJunctionView StartNodeJunctionView;
|
||||
|
||||
public NodeConnectionLineControl(Canvas canvas,
|
||||
NodeJunctionView? leftNodeJunctionView,
|
||||
NodeJunctionView? rightNodeJunctionView)
|
||||
{
|
||||
this.Canvas = canvas;
|
||||
this.LeftNodeJunctionView = leftNodeJunctionView;
|
||||
this.RightNodeJunctionView = rightNodeJunctionView;
|
||||
if (leftNodeJunctionView is null && rightNodeJunctionView is null)
|
||||
{
|
||||
throw new Exception("不能都为空");
|
||||
}
|
||||
|
||||
Canvas = canvas;
|
||||
LeftNodeJunctionView = leftNodeJunctionView;
|
||||
RightNodeJunctionView = rightNodeJunctionView;
|
||||
|
||||
if (leftNodeJunctionView is null && rightNodeJunctionView is not null)
|
||||
{
|
||||
StartNodeJunctionView = rightNodeJunctionView;
|
||||
}
|
||||
else if(leftNodeJunctionView is not null && rightNodeJunctionView is null)
|
||||
{
|
||||
StartNodeJunctionView = leftNodeJunctionView;
|
||||
}
|
||||
else if (leftNodeJunctionView is not null && rightNodeJunctionView is not null)
|
||||
{
|
||||
LeftNodeJunctionView = leftNodeJunctionView;
|
||||
RightNodeJunctionView = rightNodeJunctionView;
|
||||
RefreshLineDsiplay();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,35 +93,52 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
/// <param name="endNodeJunctionView"></param>
|
||||
public void ToEnd(NodeJunctionView endNodeJunctionView)
|
||||
{
|
||||
if((endNodeJunctionView.JunctionType == JunctionType.NextStep
|
||||
|| endNodeJunctionView.JunctionType == JunctionType.ReturnData)
|
||||
&& RightNodeJunctionView is not null
|
||||
/*&& LeftNodeJunctionView is null*/
|
||||
/*&& !LeftNodeJunctionView.Equals(endNodeJunctionView)*/)
|
||||
var @bool = endNodeJunctionView.JunctionType == JunctionType.Execute || endNodeJunctionView.JunctionType == JunctionType.ArgData;
|
||||
(LeftNodeJunctionView, RightNodeJunctionView) = @bool? (StartNodeJunctionView, endNodeJunctionView) : (endNodeJunctionView, StartNodeJunctionView);
|
||||
RefreshLineDsiplay();
|
||||
return;
|
||||
|
||||
/*if(StartNodeJunctionView.JunctionType == JunctionType.NextStep
|
||||
&& endNodeJunctionView.JunctionType == JunctionType.Execute
|
||||
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
||||
{
|
||||
LeftNodeJunctionView = endNodeJunctionView;
|
||||
LeftNodeJunctionView = StartNodeJunctionView;
|
||||
RightNodeJunctionView = endNodeJunctionView;
|
||||
RefreshLineDsiplay();
|
||||
return;
|
||||
}
|
||||
else if ((endNodeJunctionView.JunctionType == JunctionType.Execute
|
||||
|| endNodeJunctionView.JunctionType == JunctionType.ArgData)
|
||||
&& LeftNodeJunctionView is not null
|
||||
/*&& RightNodeJunctionView is null*/
|
||||
/*&& !RightNodeJunctionView.Equals(endNodeJunctionView)*/)
|
||||
|
||||
if (StartNodeJunctionView.JunctionType == JunctionType.ReturnData
|
||||
&& endNodeJunctionView.JunctionType == JunctionType.ArgData
|
||||
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
||||
{
|
||||
LeftNodeJunctionView = StartNodeJunctionView;
|
||||
RightNodeJunctionView = endNodeJunctionView;
|
||||
RefreshLineDsiplay();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
if (StartNodeJunctionView.JunctionType == JunctionType.Execute
|
||||
&& endNodeJunctionView.JunctionType == JunctionType.NextStep
|
||||
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
||||
{
|
||||
LeftNodeJunctionView = endNodeJunctionView;
|
||||
RightNodeJunctionView = StartNodeJunctionView;
|
||||
RefreshLineDsiplay();
|
||||
return;
|
||||
}
|
||||
|
||||
if (StartNodeJunctionView.JunctionType == JunctionType.ArgData
|
||||
&& endNodeJunctionView.JunctionType == JunctionType.ReturnData
|
||||
&& StartNodeJunctionView.MyNode?.Equals(endNodeJunctionView.MyNode) == false)
|
||||
{
|
||||
LeftNodeJunctionView = endNodeJunctionView;
|
||||
RightNodeJunctionView = StartNodeJunctionView;
|
||||
RefreshLineDsiplay();
|
||||
return;
|
||||
}*/
|
||||
|
||||
//var leftPoint = GetPoint(LeftNodeJunctionView);
|
||||
//var rightPoint = GetPoint(RightNodeJunctionView);
|
||||
//var brush = GetBackgrounp();
|
||||
//ConnectionLineShape.UpdatePoint(leftPoint, rightPoint);
|
||||
//CreateLineShape(startPoint, endPoint, brush);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,7 +146,7 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
/// </summary>
|
||||
public void RefreshLineDsiplay()
|
||||
{
|
||||
if(LeftNodeJunctionView is null || RightNodeJunctionView is null)
|
||||
if (LeftNodeJunctionView is null || RightNodeJunctionView is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -112,30 +154,35 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
var rightPoint = GetPoint(RightNodeJunctionView);
|
||||
if (ConnectionLineShape is null)
|
||||
{
|
||||
Debug.WriteLine("创建");
|
||||
CreateLineShape(leftPoint, rightPoint, GetBackgrounp());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("刷新");
|
||||
var brush = GetBackgrounp();
|
||||
ConnectionLineShape.UpdatePoint( leftPoint, rightPoint, brush);
|
||||
ConnectionLineShape.UpdatePoint(leftPoint, rightPoint, brush);
|
||||
}
|
||||
}
|
||||
|
||||
//public void UpdateColor()
|
||||
//{
|
||||
// var brush = GetBackgrounp();
|
||||
// ConnectionLineShape?.UpdateColor(brush);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新临时线的显示
|
||||
/// </summary>
|
||||
public void RefreshRightPointOfTempLineDsiplay(Point rightPoint)
|
||||
{
|
||||
if(ConnectionLineShape is not null)
|
||||
if (ConnectionLineShape is not null)
|
||||
{
|
||||
|
||||
RightNodeJunctionView = null;
|
||||
var brush = GetBackgrounp();
|
||||
ConnectionLineShape.UpdateRightPoint(rightPoint, brush);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (LeftNodeJunctionView is not null)
|
||||
{
|
||||
var leftPoint = GetPoint(LeftNodeJunctionView);
|
||||
@@ -143,18 +190,20 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
CreateLineShape(leftPoint, rightPoint, brush);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新临时线的显示
|
||||
/// </summary>
|
||||
public void RefreshLeftPointOfTempLineDsiplay(Point leftPoint)
|
||||
{
|
||||
if(ConnectionLineShape is not null)
|
||||
if (ConnectionLineShape is not null)
|
||||
{
|
||||
var brush = GetBackgrounp();
|
||||
LeftNodeJunctionView = null;
|
||||
ConnectionLineShape.UpdateLeftPoints(leftPoint, brush);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (RightNodeJunctionView is not null)
|
||||
{
|
||||
var rightPoint = GetPoint(RightNodeJunctionView);
|
||||
@@ -163,56 +212,6 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static Point defaultPoint = new Point(0, 0);
|
||||
int count;
|
||||
private Point GetPoint(NodeJunctionView nodeJunctionView)
|
||||
{
|
||||
|
||||
var junctionSize = nodeJunctionView.GetTransformedBounds()!.Value.Bounds.Size;
|
||||
Point junctionPoint;
|
||||
if (nodeJunctionView.JunctionType == JunctionType.ArgData || nodeJunctionView.JunctionType == JunctionType.Execute)
|
||||
{
|
||||
junctionPoint = new Point(junctionSize.Width / 2 - 11, junctionSize.Height / 2); // 选择左侧
|
||||
}
|
||||
else
|
||||
{
|
||||
junctionPoint = new Point(junctionSize.Width / 2 + 11, junctionSize.Height / 2); // 选择右侧
|
||||
}
|
||||
if (nodeJunctionView.TranslatePoint(junctionPoint, Canvas) is Point point)
|
||||
{
|
||||
//myData.StartPoint = point;
|
||||
return point;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultPoint;
|
||||
}
|
||||
|
||||
//var point = nodeJunctionView.TranslatePoint(defaultPoint , Canvas);
|
||||
//if(point is null)
|
||||
//{
|
||||
// return defaultPoint;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return point.Value;
|
||||
// }
|
||||
}
|
||||
|
||||
private void CreateLineShape(Point leftPoint, Point rightPoint, Brush brush)
|
||||
{
|
||||
ConnectionLineShape = new ConnectionLineShape(leftPoint, rightPoint, brush);
|
||||
Canvas.Children.Add(ConnectionLineShape);
|
||||
}
|
||||
|
||||
private JunctionOfConnectionType GetConnectionType()
|
||||
{
|
||||
return LeftNodeJunctionView.JunctionType.ToConnectyionType();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取背景颜色
|
||||
/// </summary>
|
||||
@@ -220,7 +219,7 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
public Brush GetBackgrounp()
|
||||
{
|
||||
|
||||
if(LeftNodeJunctionView is null || RightNodeJunctionView is null)
|
||||
if (LeftNodeJunctionView is null || RightNodeJunctionView is null)
|
||||
{
|
||||
return new SolidColorBrush(Color.Parse("#FF0000")); // 没有终点
|
||||
}
|
||||
@@ -231,16 +230,19 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
return new SolidColorBrush(Color.Parse("#FF0000"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (GetConnectionType() == JunctionOfConnectionType.Invoke)
|
||||
{
|
||||
return ConnectionInvokeType.ToLineColor(); // 调用
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else if (GetConnectionType() == JunctionOfConnectionType.Arg)
|
||||
{
|
||||
return ConnectionArgSourceType.ToLineColor(); // 参数
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return new SolidColorBrush(Color.Parse("#FF0000"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCanConnected()
|
||||
@@ -269,11 +271,69 @@ namespace Serein.Workbench.Avalonia.Custom.Views
|
||||
/// </summary>
|
||||
public void Remove()
|
||||
{
|
||||
if(ConnectionLineShape is null)
|
||||
if (ConnectionLineShape is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Canvas.Children.Remove(ConnectionLineShape);
|
||||
}
|
||||
|
||||
|
||||
private static Point defaultPoint = new Point(0, 0);
|
||||
int count;
|
||||
private Point GetPoint(NodeJunctionView nodeJunctionView)
|
||||
{
|
||||
|
||||
var junctionSize = nodeJunctionView.GetTransformedBounds()!.Value.Bounds.Size;
|
||||
Point junctionPoint;
|
||||
if (nodeJunctionView.JunctionType == JunctionType.ArgData || nodeJunctionView.JunctionType == JunctionType.Execute)
|
||||
{
|
||||
junctionPoint = new Point(junctionSize.Width / 2 - 11, junctionSize.Height / 2); // 选择左侧
|
||||
}
|
||||
else
|
||||
{
|
||||
junctionPoint = new Point(junctionSize.Width / 2 + 11, junctionSize.Height / 2); // 选择右侧
|
||||
}
|
||||
if (nodeJunctionView.TranslatePoint(junctionPoint, Canvas) is Point point)
|
||||
{
|
||||
//myData.StartPoint = point;
|
||||
return point;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultPoint;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateLineShape(Point leftPoint, Point rightPoint, Brush brush)
|
||||
{
|
||||
ConnectionLineShape = new ConnectionLineShape(leftPoint, rightPoint, brush);
|
||||
Canvas.Children.Add(ConnectionLineShape);
|
||||
}
|
||||
|
||||
private JunctionOfConnectionType GetConnectionType()
|
||||
{
|
||||
if(LeftNodeJunctionView is null)
|
||||
{
|
||||
if(RightNodeJunctionView is null)
|
||||
{
|
||||
|
||||
return JunctionOfConnectionType.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return RightNodeJunctionView.JunctionType.ToConnectyionType();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return LeftNodeJunctionView.JunctionType.ToConnectyionType();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace Serein.Workbench.Avalonia.Api
|
||||
/// <summary>
|
||||
/// 连接数据
|
||||
/// </summary>
|
||||
ConnectingData ConnectingData { get; }
|
||||
ConnectingManage ConnectingManage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 主画布
|
||||
@@ -116,7 +116,6 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
feefService.OnNodeCreate += FeefService_OnNodeCreate; // 订阅运行环境创建节点事件
|
||||
feefService.OnNodeConnectChange += FeefService_OnNodeConnectChange; // 订阅运行环境连接了节点事件
|
||||
NodeMVVMManagement.RegisterUI(NodeControlType.Action, typeof(ActionNodeView), typeof(ActionNodeViewModel)); // 注册动作节点
|
||||
|
||||
// 手动加载项目
|
||||
_ = Task.Run(async delegate
|
||||
{
|
||||
@@ -128,13 +127,11 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
var projectDfilePath = System.IO.Path.GetDirectoryName(filePath)!;
|
||||
flowEnvironment.LoadProject(new FlowEnvInfo { Project = projectData }, projectDfilePath);
|
||||
}, CancellationToken.None);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 接口属性
|
||||
public ConnectingData ConnectingData { get; private set; } = new ConnectingData();
|
||||
public ConnectingManage ConnectingManage { get; private set; } = new ConnectingManage();
|
||||
public Canvas MainCanvas { get; set; }
|
||||
|
||||
#endregion
|
||||
@@ -149,7 +146,7 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
/// <summary>
|
||||
/// 存储所有连接
|
||||
/// </summary>
|
||||
private List<NodeConnectionLineView> Connections { get; } = [];
|
||||
private List<NodeConnectionLineControl> Connections { get; } = [];
|
||||
|
||||
|
||||
|
||||
@@ -227,7 +224,6 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void FeefService_OnNodeConnectChange(NodeConnectChangeEventArgs eventArgs)
|
||||
{
|
||||
#if false
|
||||
string fromNodeGuid = eventArgs.FromNodeGuid;
|
||||
string toNodeGuid = eventArgs.ToNodeGuid;
|
||||
if (!TryGetControl(fromNodeGuid, out var fromNodeControl)
|
||||
@@ -236,6 +232,7 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (eventArgs.JunctionOfConnectionType == JunctionOfConnectionType.Invoke)
|
||||
{
|
||||
ConnectionInvokeType connectionType = eventArgs.ConnectionInvokeType;
|
||||
@@ -251,16 +248,20 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
var startJunction = IFormJunction.NextStepJunction;
|
||||
var endJunction = IToJunction.ExecuteJunction;
|
||||
|
||||
startJunction.TransformToVisual(MainCanvas);
|
||||
NodeConnectionLineControl nodeConnectionLineControl = new NodeConnectionLineControl(MainCanvas, startJunction, endJunction);
|
||||
|
||||
// 添加连接
|
||||
var shape = new ConnectionLineShape(
|
||||
FlowChartCanvas,
|
||||
connectionType,
|
||||
startJunction,
|
||||
endJunction
|
||||
);
|
||||
NodeConnectionLine nodeConnectionLine = new NodeConnectionLine(MainCanvas, shape);
|
||||
//startJunction.TransformToVisual(MainCanvas);
|
||||
|
||||
//// 添加连接
|
||||
//var shape = new ConnectionLineShape(
|
||||
// FlowChartCanvas,
|
||||
// connectionType,
|
||||
// startJunction,
|
||||
// endJunction
|
||||
//);
|
||||
|
||||
|
||||
//NodeConnectionLine nodeConnectionLine = new NodeConnectionLine(MainCanvas, shape);
|
||||
|
||||
//if (toNodeControl is FlipflopNodeControl flipflopControl
|
||||
// && flipflopControl?.ViewModel?.NodeModel is NodeModelBase nodeModel) // 某个节点连接到了触发器,尝试从全局触发器视图中移除该触发器
|
||||
@@ -268,15 +269,15 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
// NodeTreeViewer.RemoveGlobalFlipFlop(nodeModel); // 从全局触发器树树视图中移除
|
||||
//}
|
||||
|
||||
Connections.Add(nodeConnectionLine);
|
||||
fromNodeControl.AddCnnection(shape);
|
||||
toNodeControl.AddCnnection(shape);
|
||||
Connections.Add(nodeConnectionLineControl);
|
||||
fromNodeControl.AddConnection(nodeConnectionLineControl);
|
||||
toNodeControl.AddConnection(nodeConnectionLineControl);
|
||||
}
|
||||
#endregion
|
||||
#if false
|
||||
|
||||
|
||||
#region 移除连接
|
||||
else if (eventArgs.ChangeType == NodeConnectChangeEventArgs.ConnectChangeType.Remove) // 移除连接
|
||||
/* else if (eventArgs.ChangeType == NodeConnectChangeEventArgs.ConnectChangeType.Remove) // 移除连接
|
||||
{
|
||||
// 需要移除连接
|
||||
var removeConnections = Connections.Where(c =>
|
||||
@@ -297,16 +298,16 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
JudgmentFlipFlopNode(control); // 连接关系变更时判断
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
#endregion
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
else
|
||||
/*else
|
||||
{
|
||||
#if false
|
||||
ConnectionArgSourceType connectionArgSourceType = eventArgs.ConnectionArgSourceType;
|
||||
|
||||
ConnectionArgSourceType connectionArgSourceType = eventArgs.ConnectionArgSourceType;
|
||||
#region 创建/删除节点之间的参数传递关系
|
||||
#region 创建连接
|
||||
if (eventArgs.ChangeType == NodeConnectChangeEventArgs.ConnectChangeType.Create) // 添加连接
|
||||
@@ -383,9 +384,9 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
} */
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -490,18 +491,18 @@ namespace Serein.Workbench.Avalonia.Services
|
||||
{
|
||||
if (MainCanvas is not null)
|
||||
{
|
||||
ConnectingData.Reset();
|
||||
ConnectingData.IsCreateing = true; // 表示开始连接
|
||||
ConnectingData.StartJunction = startJunction;
|
||||
ConnectingData.CurrentJunction = startJunction;
|
||||
ConnectingManage.Reset();
|
||||
ConnectingManage.IsCreateing = true; // 表示开始连接
|
||||
ConnectingManage.StartJunction = startJunction;
|
||||
ConnectingManage.CurrentJunction = startJunction;
|
||||
if(startJunction.JunctionType == JunctionType.NextStep || startJunction.JunctionType == JunctionType.ReturnData)
|
||||
{
|
||||
|
||||
ConnectingData.TempLine = new NodeConnectionLineView(MainCanvas, startJunction, null);
|
||||
ConnectingManage.TempLine = new NodeConnectionLineControl(MainCanvas, startJunction, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectingData.TempLine = new NodeConnectionLineView(MainCanvas,null ,startJunction);
|
||||
ConnectingManage.TempLine = new NodeConnectionLineControl(MainCanvas,null ,startJunction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user