部分连接线拖拽完成

This commit is contained in:
艾竹
2023-05-03 09:59:46 +08:00
parent 6de36f2473
commit 1536e5018d
33 changed files with 997 additions and 158 deletions

View File

@@ -37,7 +37,7 @@ namespace AIStudio.Wpf.DiagramDesigner
return DiagramServicesProvider.Instance.Provider;
}
}
private ConnectionViewModel partialConnection;
private ConnectionViewModel partialConnection;
private Point? rubberbandSelectionStartPoint = null;
@@ -54,11 +54,14 @@ namespace AIStudio.Wpf.DiagramDesigner
{
sourceConnector = value;
FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
ConnectorInfoBase sourceDataItem = sourceConnector.Info;
//Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
//Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
// rectangleBounds.Bottom + (rectangleBounds.Height / 2));
Point point = sourceDataItem.MiddlePosition;
Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
_viewModel.Add(partialConnection);
@@ -127,7 +130,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
}
#region GridCellSize
public static readonly DependencyProperty GridCellSizeProperty =
@@ -350,13 +353,24 @@ namespace AIStudio.Wpf.DiagramDesigner
{
// in case that this click is the start for a
// drag operation we cache the start point
rubberbandSelectionStartPoint = e.GetPosition(this);
Point currentPoint = e.GetPosition(this);
rubberbandSelectionStartPoint = currentPoint;
if (!(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
{
_viewModel.ClearSelectedItems();
}
if (_service.DrawModeViewModel.LineDrawModeSelected)//画线模式,可以不命中实体
{
if (SourceConnector == null)
{
//新建一个Part连接点
SourceConnector = new Connector() { Content = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y) };
}
}
e.Handled = true;
}
}
@@ -365,8 +379,8 @@ namespace AIStudio.Wpf.DiagramDesigner
protected override void OnMouseMove(MouseEventArgs e)
{
var focusedElement = Keyboard.FocusedElement;
Debug.WriteLine("focusedElement" + focusedElement?.ToString());
//var focusedElement = Keyboard.FocusedElement;
//Debug.WriteLine("focusedElement" + focusedElement?.ToString());
base.OnMouseMove(e);
@@ -440,32 +454,36 @@ namespace AIStudio.Wpf.DiagramDesigner
if (sourceConnector != null)
{
FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
ConnectorInfoBase sourceDataItem = sourceConnector.Info;
if (sinkConnector != null)
{
ConnectorInfoBase sinkDataItem = sinkConnector.Info;
FullyCreatedConnectorInfo sinkDataItem = sinkConnector.Info;
int indexOfLastTempConnection = sinkDataItem.DataItem.Root.Items.Count - 1;
sinkDataItem.DataItem.Root.Remove(
sinkDataItem.DataItem.Root.Items[indexOfLastTempConnection]);
sinkDataItem.DataItem.Root.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode));
_viewModel.Remove(partialConnection);
_viewModel.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode));
}
else if (partialConnection.IsFullConnection)//自动连接模式
{
partialConnection.RaiseFullConnection();
}
else if (_service.DrawModeViewModel.LineDrawModeSelected)
{
Point currentPoint = e.GetPosition(this);
ConnectorInfoBase sinkDataItem = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
_viewModel.Remove(partialConnection);
_viewModel.AddItemCommand.Execute(new ConnectionViewModel(_viewModel, sourceDataItem, sinkDataItem, DrawMode, RouterMode));
}
else
{
//Need to remove last item as we did not finish drawing the path
int indexOfLastTempConnection = sourceDataItem.DataItem.Root.Items.Count - 1;
sourceDataItem.DataItem.Root.Remove(
sourceDataItem.DataItem.Root.Items[indexOfLastTempConnection]);
_viewModel.Remove(partialConnection);
}
}
sourceConnector = null;
sinkConnector = null;
partialConnection = null;
if (_service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
{
@@ -534,7 +552,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (hitObject is Connector connector)
{
return connector;
return connector;
}
hitObject = VisualTreeHelper.GetParent(hitObject);
}
@@ -622,7 +640,7 @@ namespace AIStudio.Wpf.DiagramDesigner
foreach (var port in _viewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
{
if (partialConnection.OnGoingPosition.DistanceTo(port.Position) < SnappingRadius &&
partialConnection.SourceConnectorInfo.CanAttachTo(port))
partialConnection.SourceConnectorInfoFully?.CanAttachTo(port) == true)
return port;
}