mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-14 21:26:35 +08:00
部分连接线拖拽完成
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
@@ -44,10 +45,14 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
designerItems.AddRange(designerItem.Root.SelectionService.GetGroupMembers(groupable).OfType<SelectableDesignerItemViewModelBase>());
|
||||
}
|
||||
|
||||
//拖动连线,把连接者也一起移动
|
||||
if (designerItem is ConnectionViewModel connector)
|
||||
{
|
||||
designerItems.Add(connector.SourceConnectorInfo.DataItem);
|
||||
if (connector.IsFullConnection)
|
||||
if (connector.SourceConnectorInfoFully != null)
|
||||
{
|
||||
designerItems.Add(connector.SourceConnectorInfoFully.DataItem);
|
||||
}
|
||||
if (connector.SinkConnectorInfoFully != null)
|
||||
{
|
||||
designerItems.Add(connector.SinkConnectorInfoFully.DataItem);
|
||||
}
|
||||
@@ -66,6 +71,13 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
item.SetOldValue(item.TopLeft, nameof(item.TopLeft));
|
||||
}
|
||||
|
||||
//部分连接点可以移动
|
||||
foreach (ConnectionViewModel item in designerItems.OfType<ConnectionViewModel>())
|
||||
{
|
||||
item.SourceConnectorInfoPart?.SetOldValue(item.SourceConnectorInfoPart.Position, nameof(item.SourceConnectorInfoPart.Position));
|
||||
item.SinkConnectorInfoPart?.SetOldValue(item.SinkConnectorInfoPart.Position, nameof(item.SinkConnectorInfoPart.Position));
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
else
|
||||
@@ -76,10 +88,10 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
|
||||
private void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e)
|
||||
{
|
||||
if (drag == false)
|
||||
if (drag == false)
|
||||
{
|
||||
Interlocked.Decrement(ref DiagramViewModel.DoCommandManager.BeginDo);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
if (designerItems != null)
|
||||
@@ -92,6 +104,16 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<PointBase, PointBase>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<PointBase, PointBase>(p.GetOldValue<PointBase>(nameof(p.TopLeft)), p.TopLeft));
|
||||
|
||||
//部分连接点可以移动
|
||||
Dictionary<ConnectionViewModel, Tuple<Tuple<PointBase?, PointBase?>, Tuple<PointBase?, PointBase?>>> conncetorinfos =
|
||||
designerItems.OfType<ConnectionViewModel>().ToDictionary(p => p,
|
||||
p => new Tuple<Tuple<PointBase?, PointBase?>, Tuple<PointBase?, PointBase?>>(
|
||||
new Tuple<PointBase?, PointBase?>(p.SourceConnectorInfoPart?.GetOldValue<PointBase>(nameof(p.SourceConnectorInfoPart.Position)),
|
||||
p.SinkConnectorInfoPart?.GetOldValue<PointBase>(nameof(p.SinkConnectorInfoPart.Position))),
|
||||
new Tuple<PointBase?, PointBase?>(p.SourceConnectorInfoPart?.Position,
|
||||
p.SinkConnectorInfoPart?.Position)));
|
||||
|
||||
Interlocked.Decrement(ref DiagramViewModel.DoCommandManager.BeginDo);
|
||||
DiagramViewModel.DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
@@ -99,12 +121,20 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
{
|
||||
info.Key.TopLeft = info.Value.Item2;
|
||||
}
|
||||
foreach (var info in conncetorinfos)
|
||||
{
|
||||
info.Key.SetPartPostion(info.Value.Item2.Item1, info.Value.Item2.Item2);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
foreach (var info in infos)
|
||||
{
|
||||
info.Key.TopLeft = info.Value.Item1;
|
||||
}
|
||||
foreach (var info in conncetorinfos)
|
||||
{
|
||||
info.Key.SetPartPostion(info.Value.Item1.Item1, info.Value.Item1.Item2);
|
||||
}
|
||||
});
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -121,6 +151,22 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
item.Top += e.VerticalChange;
|
||||
}
|
||||
|
||||
//部分连接点可以移动
|
||||
foreach (ConnectionViewModel item in designerItems.OfType<ConnectionViewModel>())
|
||||
{
|
||||
PointBase? sourcePoint = null;
|
||||
PointBase? sinkPoint = null;
|
||||
if (item.SourceConnectorInfoPart != null)
|
||||
{
|
||||
sourcePoint = new PointBase(item.SourceConnectorInfoPart.Position.X + e.HorizontalChange, item.SourceConnectorInfoPart.Position.Y + e.VerticalChange);
|
||||
}
|
||||
if (item.SinkConnectorInfoPart != null)
|
||||
{
|
||||
sinkPoint = new PointBase(item.SinkConnectorInfoPart.Position.X + e.HorizontalChange, item.SinkConnectorInfoPart.Position.Y + e.VerticalChange);
|
||||
}
|
||||
item.SetPartPostion(sourcePoint, sinkPoint);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user