mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 00:37:19 +08:00
连接点显示
This commit is contained in:
@@ -37,11 +37,37 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return DiagramServicesProvider.Instance.Provider;
|
||||
}
|
||||
}
|
||||
private ConnectionViewModel partialConnection;
|
||||
private List<Connector> connectorsHit = new List<Connector>();
|
||||
private ConnectionViewModel partialConnection;
|
||||
|
||||
private Point? rubberbandSelectionStartPoint = null;
|
||||
|
||||
private Connector sourceConnector;
|
||||
public Connector SourceConnector
|
||||
{
|
||||
get
|
||||
{
|
||||
return sourceConnector;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (sourceConnector != value)
|
||||
{
|
||||
sourceConnector = value;
|
||||
|
||||
FullyCreatedConnectorInfo 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));
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(partialConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Connector sinkConnector;
|
||||
|
||||
private DrawMode DrawMode
|
||||
{
|
||||
get
|
||||
@@ -100,7 +126,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region GridCellSize
|
||||
|
||||
public static readonly DependencyProperty GridCellSizeProperty =
|
||||
@@ -293,32 +319,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Connector sourceConnector;
|
||||
public Connector SourceConnector
|
||||
{
|
||||
get
|
||||
{
|
||||
return sourceConnector;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (sourceConnector != value)
|
||||
{
|
||||
sourceConnector = value;
|
||||
connectorsHit.Add(sourceConnector);
|
||||
|
||||
FullyCreatedConnectorInfo 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));
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(partialConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
@@ -376,6 +376,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var point = CursorPointManager.GetCursorPosition();
|
||||
_viewModel.CurrentColor = ColorPickerManager.GetColor(point.X, point.Y);
|
||||
|
||||
//移动
|
||||
if (_service.DrawModeViewModel.CursorMode == CursorMode.Move)
|
||||
{
|
||||
_viewModel.SelectedItems.OfType<DesignerItemViewModelBase>().ToList().ForEach(p => {
|
||||
@@ -390,7 +391,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
partialConnection.SinkConnectorInfo = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
HitTesting(currentPoint);
|
||||
sinkConnector = HitTesting(currentPoint);
|
||||
|
||||
if (EnableSnapping)
|
||||
{
|
||||
@@ -405,7 +406,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
else
|
||||
{
|
||||
// if mouse button is not pressed we have no drag operation, ...
|
||||
if (e.LeftButton != MouseButtonState.Pressed && _service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
rubberbandSelectionStartPoint = null;
|
||||
|
||||
// ... but if mouse button is pressed and start
|
||||
@@ -439,9 +440,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (sourceConnector != null)
|
||||
{
|
||||
FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
|
||||
if (connectorsHit.Count() == 2)
|
||||
if (sinkConnector != null)
|
||||
{
|
||||
Connector sinkConnector = connectorsHit.Last();
|
||||
|
||||
FullyCreatedConnectorInfo sinkDataItem = sinkConnector.Info;
|
||||
|
||||
int indexOfLastTempConnection = sinkDataItem.DataItem.Root.Items.Count - 1;
|
||||
@@ -459,13 +460,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
int indexOfLastTempConnection = sourceDataItem.DataItem.Root.Items.Count - 1;
|
||||
sourceDataItem.DataItem.Root.Remove(
|
||||
sourceDataItem.DataItem.Root.Items[indexOfLastTempConnection]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
connectorsHit = new List<Connector>();
|
||||
sourceConnector = null;
|
||||
sinkConnector = null;
|
||||
|
||||
if (_service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
|
||||
{
|
||||
@@ -526,7 +525,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return size;
|
||||
}
|
||||
|
||||
private void HitTesting(Point hitPoint)
|
||||
private Connector HitTesting(Point hitPoint)
|
||||
{
|
||||
DependencyObject hitObject = this.InputHitTest(hitPoint) as DependencyObject;
|
||||
while (hitObject != null &&
|
||||
@@ -534,11 +533,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (hitObject is Connector connector)
|
||||
{
|
||||
if (!connectorsHit.Contains(hitObject as Connector))
|
||||
connectorsHit.Add(hitObject as Connector);
|
||||
return connector;
|
||||
}
|
||||
hitObject = VisualTreeHelper.GetParent(hitObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnDrop(DragEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user