实现了多画布下,节点的复制粘贴功能

This commit is contained in:
fengjiayi
2025-05-27 18:32:40 +08:00
parent 7ad6041be6
commit 7848af0363
53 changed files with 1187 additions and 499 deletions

View File

@@ -12,9 +12,15 @@ using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using System.Windows.Documents;
using System.Threading;
using Serein.Workbench.Services;
using Serein.Workbench.Tool;
namespace Serein.Workbench.Node.View
{
/// <summary>
/// 控制带的拓展方法
/// </summary>
internal static class MyUIFunc
{
public static Pen CreateAndFreezePen()
@@ -31,10 +37,11 @@ namespace Serein.Workbench.Node.View
}
}
/// <summary>
/// 入参控件
/// </summary>
public class ParamsArgControl: Shape
{
public ParamsArgControl()
{
this.MouseDown += ParamsArg_OnMouseDown; // 增加或删除
@@ -159,8 +166,10 @@ namespace Serein.Workbench.Node.View
public abstract class JunctionControlBase : Shape
{
private readonly FlowNodeService flowNodeService;
protected JunctionControlBase()
{
flowNodeService = App.GetService<FlowNodeService>();
this.Width = 25;
this.Height = 20;
this.MouseDown += JunctionControlBase_MouseDown;
@@ -229,7 +238,7 @@ namespace Serein.Workbench.Node.View
{
if(_isMouseOver != value)
{
GlobalJunctionData.MyGlobalConnectingData.CurrentJunction = this;
flowNodeService.ConnectingData.CurrentJunction = this;
_isMouseOver = value;
InvalidateVisual();
}
@@ -252,22 +261,22 @@ namespace Serein.Workbench.Node.View
/// <returns></returns>
protected Brush GetBackgrounp()
{
var myData = GlobalJunctionData.MyGlobalConnectingData;
if(!myData.IsCreateing)
var cd = flowNodeService.ConnectingData;
if(!cd.IsCreateing)
{
return Brushes.Transparent;
}
if (IsMouseOver)
{
if (myData.IsCanConnected)
if (cd.IsCanConnected)
{
if (myData.Type == JunctionOfConnectionType.Invoke)
if (cd.Type == JunctionOfConnectionType.Invoke)
{
return myData.ConnectionInvokeType.ToLineColor();
return cd.ConnectionInvokeType.ToLineColor();
}
else
{
return myData.ConnectionArgSourceType.ToLineColor();
return cd.ConnectionArgSourceType.ToLineColor();
}
}
else
@@ -320,15 +329,15 @@ namespace Serein.Workbench.Node.View
{
if (e.LeftButton == MouseButtonState.Pressed)
{
var canvas = MainWindow.GetParentOfType<Canvas>(this);
var canvas = WpfFuncTool.GetParentOfType<Canvas>(this);
if (canvas != null)
{
var myData = GlobalJunctionData.MyGlobalConnectingData;
myData.Reset();
myData.IsCreateing = true; // 表示开始连接
myData.StartJunction = this;
myData.CurrentJunction = this;
myData.StartPoint = this.TranslatePoint(new Point(this.Width / 2, this.Height / 2), canvas);
var cd = flowNodeService.ConnectingData;
cd.Reset();
cd.IsCreateing = true; // 表示开始连接
cd.StartJunction = this;
cd.CurrentJunction = this;
cd.StartPoint = this.TranslatePoint(new Point(this.Width / 2, this.Height / 2), canvas);
var junctionOfConnectionType = this.JunctionType.ToConnectyionType();
ConnectionLineShape bezierLine; // 类别
@@ -346,13 +355,13 @@ namespace Serein.Workbench.Node.View
return;
}
bezierLine = new ConnectionLineShape(LineType.Bezier,
myData.StartPoint,
myData.StartPoint,
cd.StartPoint,
cd.StartPoint,
brushColor,
isTop: true); // 绘制临时的线
Mouse.OverrideCursor = Cursors.Cross; // 设置鼠标为正在创建连线
myData.MyLine = new MyLine(canvas, bezierLine);
cd.MyLine = new MyLine(canvas, bezierLine);
}
}
e.Handled = true;

View File

@@ -123,7 +123,7 @@ namespace Serein.Workbench.Node.View
}
/// <summary>
/// 重置
/// 重置连线状态
/// </summary>
public void Reset()
{
@@ -139,7 +139,7 @@ namespace Serein.Workbench.Node.View
}
public static class GlobalJunctionData
public static class GlobalJunctionData1
{
//private static ConnectingData? myGlobalData;
//private static object _lockObj = new object();

View File

@@ -1,6 +1,7 @@
using Serein.Library;
using Serein.Library.Api;
using Serein.Workbench.Extension;
using Serein.Workbench.Tool;
using System;
using System.Net;
using System.Windows;
@@ -224,8 +225,8 @@ namespace Serein.Workbench.Node.View
private void ConfigureLineContextMenu()
{
var contextMenu = new ContextMenu();
contextMenu.Items.Add(MainWindow.CreateMenuItem("删除连线", (s, e) => Remote()));
contextMenu.Items.Add(MainWindow.CreateMenuItem("于父节点调用顺序中置顶", (s, e) => Topping()));
contextMenu.Items.Add(WpfFuncTool.CreateMenuItem("删除连线", (s, e) => Remote()));
contextMenu.Items.Add(WpfFuncTool.CreateMenuItem("于父节点调用顺序中置顶", (s, e) => Topping()));
BezierLine.ContextMenu = contextMenu;
}

View File

@@ -140,26 +140,26 @@ namespace Serein.Workbench.Node.View
return;
}
MoveNodeData moveNodeData = new MoveNodeData
{
//MoveNodeData moveNodeData = new MoveNodeData
//{
NodeControlType = nodeType switch
{
NodeType.Action => NodeControlType.Action,
NodeType.Flipflop => NodeControlType.Flipflop,
NodeType.UI => NodeControlType.UI,
_ => NodeControlType.None,
},
MethodDetailsInfo = mdInfo,
};
if(moveNodeData.NodeControlType == NodeControlType.None)
{
return;
}
// NodeControlType = nodeType switch
// {
// NodeType.Action => NodeControlType.Action,
// NodeType.Flipflop => NodeControlType.Flipflop,
// NodeType.UI => NodeControlType.UI,
// _ => NodeControlType.None,
// },
// MethodDetailsInfo = mdInfo,
//};
//if(moveNodeData.NodeControlType == NodeControlType.None)
//{
// return;
//}
// 创建一个 DataObject 用于拖拽操作,并设置拖拽效果
DataObject dragData = new DataObject(MouseNodeType.CreateDllNodeInCanvas, moveNodeData);
DragDrop.DoDragDrop(typeText, dragData, DragDropEffects.Move);
//// 创建一个 DataObject 用于拖拽操作,并设置拖拽效果
//DataObject dragData = new DataObject(MouseNodeType.CreateDllNodeInCanvas, moveNodeData);
//DragDrop.DoDragDrop(typeText, dragData, DragDropEffects.Move);
}
}
}