diff --git a/Workbench/Extension/LineExtension.cs b/Workbench/Extension/LineExtension.cs
deleted file mode 100644
index ce0eb42..0000000
--- a/Workbench/Extension/LineExtension.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using Serein.Library;
-using Serein.Workbench.Node.View;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Media;
-
-namespace Serein.Workbench.Extension
-{
- ///
- /// 线条颜色
- ///
- public static class LineExtension
- {
- ///
- /// 根据连接类型指定颜色
- ///
- ///
- ///
- ///
- public static SolidColorBrush ToLineColor(this ConnectionInvokeType currentConnectionType)
- {
- return currentConnectionType switch
- {
- ConnectionInvokeType.IsSucceed => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#04FC10")), // 04FC10 & 027E08
- ConnectionInvokeType.IsFail => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F18905")),
- ConnectionInvokeType.IsError => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FE1343")),
- ConnectionInvokeType.Upstream => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4A82E4")),
- ConnectionInvokeType.None => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#56CEF6")),
- _ => throw new Exception(),
- };
- }
- ///
- /// 根据连接类型指定颜色
- ///
- ///
- ///
- ///
- public static SolidColorBrush ToLineColor(this ConnectionArgSourceType connection)
- {
- return connection switch
- {
- ConnectionArgSourceType.GetPreviousNodeData => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#56CEF6")), // 04FC10 & 027E08
- ConnectionArgSourceType.GetOtherNodeData => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#56CEF6")),
- ConnectionArgSourceType.GetOtherNodeDataOfInvoke => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#B06BBB")),
- _ => throw new Exception(),
- };
- }
-
- }
-}
diff --git a/Workbench/Extension/MyExtension.cs b/Workbench/Extension/MyExtension.cs
deleted file mode 100644
index 0bacb12..0000000
--- a/Workbench/Extension/MyExtension.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-
-namespace Serein.Workbench.Extension
-{
- public static class PointExtension
- {
- public static Point Add(this Point a, Point b)
- {
- return new Point(a.X + b.X, a.Y + b.Y);
- }
-
- public static Point Sub(this Point a, Point b)
- {
- return new Point(a.X - b.X, a.Y - b.Y);
- }
-
- public static Vector ToVector(this Point me)
- {
- return new Vector(me.X, me.Y);
- }
- }
- public static class VectorExtension
- {
- public static double DotProduct(this Vector a, Vector b)
- {
- return a.X * b.X + a.Y * b.Y;
- }
-
- public static Vector NormalizeTo(this Vector v)
- {
- var temp = v;
- temp.Normalize();
-
- return temp;
- }
- }
-}
diff --git a/Workbench/Node/INodeContainerControl.cs b/Workbench/Node/INodeContainerControl.cs
deleted file mode 100644
index 4c01eff..0000000
--- a/Workbench/Node/INodeContainerControl.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Serein.Workbench.Node.View;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Serein.Workbench.Node
-{
-
- ///
- /// 约束具有容器功能的节点控件应该有什么方法
- ///
- public interface INodeContainerControl
- {
- ///
- /// 放置一个节点
- ///
- ///
- bool PlaceNode(NodeControlBase nodeControl);
-
- ///
- /// 取出一个节点
- ///
- ///
- bool TakeOutNode(NodeControlBase nodeControl);
-
- ///
- /// 取出所有节点(用于删除容器)
- ///
- void TakeOutAll();
- }
-}
diff --git a/Workbench/Node/INodeJunction.cs b/Workbench/Node/INodeJunction.cs
deleted file mode 100644
index ae74d0d..0000000
--- a/Workbench/Node/INodeJunction.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using Serein.Workbench.Node.View;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-
-namespace Serein.Workbench.Node
-{
-
-
-
- ///
- /// 约束一个节点应该有哪些控制点
- ///
- public interface INodeJunction
- {
- ///
- /// 方法执行入口控制点
- ///
- JunctionControlBase ExecuteJunction { get; }
- ///
- /// 执行完成后下一个要执行的方法控制点
- ///
- JunctionControlBase NextStepJunction { get; }
-
- ///
- /// 参数节点控制点
- ///
- JunctionControlBase[] ArgDataJunction { get; }
- ///
- /// 返回值控制点
- ///
- JunctionControlBase ReturnDataJunction { get; }
-
- ///
- /// 获取目标参数控制点,用于防止wpf释放资源导致找不到目标节点,返回-1,-1的坐标
- ///
- ///
- ///
- JunctionControlBase GetJunctionOfArgData(int index)
- {
- var arr = ArgDataJunction;
- if (index >= arr.Length)
- {
- return null;
- }
- return arr[index];
- }
- }
-}
diff --git a/Workbench/Node/Junction/ConnectionLineShape.cs b/Workbench/Node/Junction/ConnectionLineShape.cs
deleted file mode 100644
index 122adaf..0000000
--- a/Workbench/Node/Junction/ConnectionLineShape.cs
+++ /dev/null
@@ -1,234 +0,0 @@
-using Serein.Library;
-using Serein.Workbench.Extension;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
-using System.Windows.Shapes;
-
-namespace Serein.Workbench.Node.View
-{
- ///
- /// 连接线的类型
- ///
- public enum LineType
- {
- ///
- /// 贝塞尔曲线
- ///
- Bezier,
- ///
- /// 半圆线
- ///
- Semicircle,
- }
-
-
-
- ///
- /// 贝塞尔曲线
- ///
- public class ConnectionLineShape : Shape
- {
- private readonly double strokeThickness;
-
- private readonly LineType lineType;
-
- ///
- /// 确定起始坐标和目标坐标、外光样式的曲线
- ///
- /// 线条类型
- /// 起始坐标
- /// 结束坐标
- /// 颜色
- /// 是否为虚线
- public ConnectionLineShape(LineType lineType,
- Point start,
- Point end,
- Brush brush,
- bool isDotted = false,
- bool isTop = false)
- {
- this.lineType = lineType;
- this.brush = brush;
- startPoint = start;
- endPoint = end;
- this.strokeThickness = 4;
- InitElementPoint(isDotted, isTop);
- InvalidateVisual(); // 触发重绘
- }
-
-
- public void InitElementPoint(bool isDotted , bool isTop = false)
- {
- hitVisiblePen = new Pen(Brushes.Transparent, 1.0); // 初始化碰撞检测线
- hitVisiblePen.Freeze(); // Freeze以提高性能
- visualPen = new Pen(brush, 3.0); // 默认可视化Pen
- opacity = 1.0d;
- if (isDotted)
- {
- opacity = 0.42d;
- visualPen.DashStyle = DashStyles.Dash; // 选择虚线样式
- }
- visualPen.Freeze(); // Freeze以提高性能
-
- linkSize = 4; // 整线条粗细
- int zIndex = -999999;
- if (isTop)
- {
- zIndex *= -1;
- }
- Panel.SetZIndex(this, zIndex); // 置底
- }
-
- ///
- /// 更新线条落点位置
- ///
- ///
- ///
- public void UpdatePoints(Point start, Point end)
- {
- startPoint = start;
- endPoint = end;
- InvalidateVisual(); // 触发重绘
- }
-
- ///
- /// 更新线条落点位置
- ///
- ///
- public void UpdateEndPoints(Point point)
- {
- endPoint = point;
- InvalidateVisual(); // 触发重绘
- }
- ///
- /// 更新线条落点位置
- ///
- ///
- public void UpdateStartPoints(Point point)
- {
- startPoint = point;
- InvalidateVisual(); // 触发重绘
- }
-
- ///
- /// 控件重绘事件
- ///
- ///
- protected override void OnRender(DrawingContext drawingContext)
- {
- // 刷新线条显示位置
- switch (this.lineType)
- {
- case LineType.Bezier:
- DrawBezierCurve(drawingContext, startPoint, endPoint);
- break;
- case LineType.Semicircle:
- DrawSemicircleCurve(drawingContext, startPoint, endPoint);
- break;
- default:
- break;
- }
-
- }
- #region 重绘
-
- private readonly StreamGeometry streamGeometry = new StreamGeometry();
- private Point rightCenterOfStartLocation; // 目标节点选择左侧边缘中心
- private Point leftCenterOfEndLocation; // 起始节点选择右侧边缘中心
- private Pen hitVisiblePen; // 初始化碰撞检测线
- private Pen visualPen; // 默认可视化Pen
- private Point startPoint; // 连接线的起始节点
- private Point endPoint; // 连接线的终点
- private Brush brush; // 线条颜色
- private double opacity; // 透明度
-
- double linkSize; // 根据缩放比例调整线条粗细
- protected override Geometry DefiningGeometry => streamGeometry;
-
- public void UpdateLineColor(Brush brush)
- {
- visualPen = new Pen(brush, 3.0); // 默认可视化Pen
- InvalidateVisual(); // 触发重绘
- }
-
-
- private Point c0, c1; // 用于计算贝塞尔曲线控制点逻辑
- private Vector axis = new Vector(1, 0);
- private Vector startToEnd;
- private void DrawBezierCurve(DrawingContext drawingContext,
- Point start,
- Point end)
- {
- // 控制点的计算逻辑
- double power = 140; // 控制贝塞尔曲线的“拉伸”强度
- drawingContext.PushOpacity(opacity);
- // 计算轴向向量与起点到终点的向量
- //var axis = new Vector(1, 0);
- startToEnd = (end.ToVector() - start.ToVector()).NormalizeTo();
-
- // 计算拉伸程度k,拉伸与水平夹角正相关
- var k = 1 - Math.Pow(Math.Max(0, axis.DotProduct(startToEnd)), 10.0);
-
- // 如果起点x大于终点x,增加额外的偏移量,避免重叠
- var bias = start.X > end.X ? Math.Abs(start.X - end.X) * 0.25 : 0;
-
- // 控制点的实际计算
- c0 = new Point(+(power + bias) * k + start.X, start.Y);
- c1 = new Point(-(power + bias) * k + end.X, end.Y);
-
- // 准备StreamGeometry以用于绘制曲线
- streamGeometry.Clear();
- using (var context = streamGeometry.Open())
- {
- context.BeginFigure(start, true, false); // 曲线起点
- context.BezierTo(c0, c1, end, true, false); // 画贝塞尔曲线
- }
- drawingContext.DrawGeometry(null, visualPen, streamGeometry);
-
- }
-
-
-
- private void DrawSemicircleCurve(DrawingContext drawingContext, Point start, Point end)
- {
- // 计算中心点和半径
- // 计算圆心和半径
- double x = 35;
- // 创建一个弧线路径
- streamGeometry.Clear();
- using (var context = streamGeometry.Open())
- {
- // 开始绘制
- context.BeginFigure(start, false, false);
-
- // 生成弧线
- context.ArcTo(
- end, // 结束点
- new Size(x, x), // 椭圆的半径
- 0, // 椭圆的旋转角度
- false, // 是否大弧
- SweepDirection.Counterclockwise, // 方向
- true, // 是否连接到起始点
- true // 是否使用高质量渲染
- );
-
- // 结束绘制
- context.LineTo(start, false, false); // 连接到起始点(可选)
- }
-
- // 绘制弧线
- drawingContext.DrawGeometry(null, visualPen, streamGeometry);
-
- }
- #endregion
- }
-
-
-}
diff --git a/Workbench/Node/Junction/JunctionControlBase.cs b/Workbench/Node/Junction/JunctionControlBase.cs
deleted file mode 100644
index 5ce870c..0000000
--- a/Workbench/Node/Junction/JunctionControlBase.cs
+++ /dev/null
@@ -1,378 +0,0 @@
-using Serein.Library;
-using Serein.Library.Utils;
-using System;
-using System.Net;
-using System.Reflection;
-using System.Windows;
-using Serein.Workbench.Extension;
-using System.Windows.Controls;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Shapes;
-using System.Windows.Media.Media3D;
-using System.Windows.Documents;
-using System.Threading;
-
-namespace Serein.Workbench.Node.View
-{
- internal static class MyUIFunc
- {
- public static Pen CreateAndFreezePen()
- {
- // 创建Pen
- Pen pen = new Pen(Brushes.Black, 1);
-
- // 冻结Pen
- if (pen.CanFreeze)
- {
- pen.Freeze();
- }
- return pen;
- }
- }
-
- public class ParamsArgControl: Shape
- {
-
-
- public ParamsArgControl()
- {
- this.MouseDown += ParamsArg_OnMouseDown; // 增加或删除
- this.MouseMove += ParamsArgControl_MouseMove;
- this.MouseLeave += ParamsArgControl_MouseLeave;
- AddOrRemoveParamsTask = AddAsync;
- }
-
-
-
- protected readonly StreamGeometry StreamGeometry = new StreamGeometry();
- protected override Geometry DefiningGeometry => StreamGeometry;
-
-
- #region 控件属性,所在的节点
- public static readonly DependencyProperty NodeProperty =
- DependencyProperty.Register(nameof(MyNode), typeof(NodeModelBase), typeof(ParamsArgControl), new PropertyMetadata(default(NodeModelBase)));
- //public NodeModelBase NodeModel;
-
- ///
- /// 所在的节点
- ///
- public NodeModelBase MyNode
- {
- get { return (NodeModelBase)GetValue(NodeProperty); }
- set { SetValue(NodeProperty, value); }
- }
- #endregion
-
- #region 控件属性,连接器类型
- public static readonly DependencyProperty ArgIndexProperty =
- DependencyProperty.Register(nameof(ArgIndex), typeof(int), typeof(ParamsArgControl), new PropertyMetadata(default(int)));
-
- ///
- /// 参数的索引
- ///
- public int ArgIndex
- {
- get { return (int)GetValue(ArgIndexProperty); }
- set { SetValue(ArgIndexProperty, value.ToString()); }
- }
- #endregion
-
-
- ///
- /// 控件重绘事件
- ///
- ///
- protected override void OnRender(DrawingContext drawingContext)
- {
- Brush brush = isMouseOver ? Brushes.Red : Brushes.Green;
- double height = ActualHeight;
- // 定义圆形的大小和位置
- double connectorSize = 10; // 连接器的大小
- double circleCenterX = 8; // 圆心 X 坐标
- double circleCenterY = height / 2; // 圆心 Y 坐标
- var circlePoint = new Point(circleCenterX, circleCenterY);
-
- // 圆形部分
- var ellipse = new EllipseGeometry(circlePoint, connectorSize / 2, connectorSize / 2);
-
- drawingContext.DrawGeometry(brush, MyUIFunc.CreateAndFreezePen(), ellipse);
- }
-
-
- private bool isMouseOver; // 鼠标悬停状态
-
- private Func AddOrRemoveParamsTask; // 增加或删除参数
-
- public async void ParamsArg_OnMouseDown(object sender, MouseButtonEventArgs e)
- {
- await AddOrRemoveParamsTask.Invoke();
- }
-
- private void ParamsArgControl_MouseMove(object sender, MouseEventArgs e)
- {
- isMouseOver = true;
- if (cancellationTokenSource.IsCancellationRequested) {
- cancellationTokenSource = new CancellationTokenSource();
- Task.Run(async () =>
- {
- await Task.Delay(380);
-
- }, cancellationTokenSource.Token).ContinueWith((t) =>
- {
- // 如果焦点仍在控件上时,则改变点击事件
- if (isMouseOver)
- {
- AddOrRemoveParamsTask = RemoveAsync;
- this.Dispatcher.Invoke(InvalidateVisual);// 触发一次重绘
-
- }
- });
- }
-
- }
- private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
-
-
- private void ParamsArgControl_MouseLeave(object sender, MouseEventArgs e)
- {
- isMouseOver = false;
- AddOrRemoveParamsTask = AddAsync; // 鼠标焦点离开时恢复点击事件
- cancellationTokenSource?.Cancel();
- this.Dispatcher.Invoke(InvalidateVisual);// 触发一次重绘
-
- }
-
-
- private async Task AddAsync()
- {
- await this.MyNode.Env.ChangeParameter(MyNode.Guid, true, ArgIndex);
- }
- private async Task RemoveAsync()
- {
- await this.MyNode.Env.ChangeParameter(MyNode.Guid, false, ArgIndex);
- }
-
- }
-
-
-
- public abstract class JunctionControlBase : Shape
- {
- protected JunctionControlBase()
- {
- this.Width = 25;
- this.Height = 20;
- this.MouseDown += JunctionControlBase_MouseDown;
- this.MouseMove += JunctionControlBase_MouseMove;
- this.MouseLeave += JunctionControlBase_MouseLeave; ;
- }
-
-
- #region 控件属性,所在的节点
- public static readonly DependencyProperty NodeProperty =
- DependencyProperty.Register(nameof(MyNode), typeof(NodeModelBase), typeof(JunctionControlBase), new PropertyMetadata(default(NodeModelBase)));
- //public NodeModelBase NodeModel;
-
- ///
- /// 所在的节点
- ///
- public NodeModelBase MyNode
- {
- get { return (NodeModelBase)GetValue(NodeProperty); }
- set { SetValue(NodeProperty, value); }
- }
- #endregion
-
- #region 控件属性,连接器类型
- public static readonly DependencyProperty JunctionTypeProperty =
- DependencyProperty.Register(nameof(JunctionType), typeof(string), typeof(JunctionControlBase), new PropertyMetadata(default(string)));
-
- ///
- /// 控制点类型
- ///
- public JunctionType JunctionType
- {
- get { return EnumHelper.ConvertEnum(GetValue(JunctionTypeProperty).ToString()); }
- set { SetValue(JunctionTypeProperty, value.ToString()); }
- }
- #endregion
-
- protected readonly StreamGeometry StreamGeometry = new StreamGeometry();
- protected override Geometry DefiningGeometry => StreamGeometry;
-
- ///
- /// 重绘方法
- ///
- ///
- public abstract void Render(DrawingContext drawingContext);
- ///
- /// 中心点
- ///
- public abstract Point MyCenterPoint { get; }
-
-
-
- ///
- /// 禁止连接
- ///
- private bool IsConnectionDisable;
-
- ///
- /// 处理鼠标悬停状态
- ///
- private bool _isMouseOver;
- public bool IsMouseOver
- {
- get => _isMouseOver;
- set
- {
- if(_isMouseOver != value)
- {
- GlobalJunctionData.MyGlobalConnectingData.CurrentJunction = this;
- _isMouseOver = value;
- InvalidateVisual();
- }
-
- }
- }
-
- ///
- /// 控件重绘事件
- ///
- ///
- protected override void OnRender(DrawingContext drawingContext)
- {
- Render(drawingContext);
- }
-
- ///
- /// 获取背景颜色
- ///
- ///
- protected Brush GetBackgrounp()
- {
- var myData = GlobalJunctionData.MyGlobalConnectingData;
- if(!myData.IsCreateing)
- {
- return Brushes.Transparent;
- }
- if (IsMouseOver)
- {
- if (myData.IsCanConnected)
- {
- if (myData.Type == JunctionOfConnectionType.Invoke)
- {
- return myData.ConnectionInvokeType.ToLineColor();
- }
- else
- {
- return myData.ConnectionArgSourceType.ToLineColor();
- }
- }
- else
- {
- return Brushes.Red;
- }
- }
- else
- {
- return Brushes.Transparent;
- }
- }
-
- private object lockObj = new object();
-
- ///
- /// 控件获得鼠标焦点事件
- ///
- ///
- ///
- private void JunctionControlBase_MouseMove(object sender, MouseEventArgs e)
- {
- //if (!GlobalJunctionData.MyGlobalConnectingData.IsCreateing) return;
-
- //if (IsMouseOver) return;
- IsMouseOver = true;
-
- //this.InvalidateVisual();
- }
-
- ///
- /// 控件失去鼠标焦点事件
- ///
- ///
- ///
- private void JunctionControlBase_MouseLeave(object sender, MouseEventArgs e)
- {
- IsMouseOver = false;
- e.Handled = true;
-
- }
-
-
- ///
- /// 在碰撞点上按下鼠标控件开始进行移动
- ///
- ///
- ///
- protected void JunctionControlBase_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- var canvas = MainWindow.GetParentOfType