mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-07 02:00:50 +08:00
连线完成
This commit is contained in:
@@ -37,6 +37,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
private void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Parent = sourceConnectorInfo.DataItem.Parent;
|
||||
|
||||
if (Parent != null && Parent.ColorViewModel != null)
|
||||
{
|
||||
this.ColorViewModel = CopyHelper.Mapper(Parent.ColorViewModel);
|
||||
@@ -45,6 +46,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
this.ColorViewModel.RightArrowPathStyle = ArrowPathStyle.None;
|
||||
}
|
||||
ColorViewModel.PropertyChanged += ColorViewModel_PropertyChanged;
|
||||
|
||||
var routetype = GlobalType.AllTypes.Where(p => typeof(IRouter).IsAssignableFrom(p)).FirstOrDefault(p => p.Name == RouterMode);
|
||||
Router = routetype != null ? (System.Activator.CreateInstance(routetype) as IRouter) : new RouterNormal();
|
||||
@@ -55,7 +57,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.SourceConnectorInfo = sourceConnectorInfo;
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
DeleteConnectionCommand = new SimpleCommand(DeleteConnection);
|
||||
AddVertexCommand = new SimpleCommand(AddVertex);
|
||||
AddVertexCommand = new SimpleCommand(AddVertex);
|
||||
}
|
||||
|
||||
private void ColorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(ColorViewModel.LeftArrowPathStyle) ||
|
||||
e.PropertyName == nameof(ColorViewModel.LeftArrowSizeStyle) ||
|
||||
e.PropertyName == nameof(ColorViewModel.RightArrowPathStyle) ||
|
||||
e.PropertyName == nameof(ColorViewModel.RightArrowSizeStyle))
|
||||
{
|
||||
UpdatePathGeneratorResult();
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectableDesignerItemBase ToXmlObject()
|
||||
@@ -200,7 +213,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
RectangleBase oldarea = _area;
|
||||
if (SetProperty(ref _area, value))
|
||||
{
|
||||
UpdateConnectionPoints();
|
||||
UpdatePathGeneratorResult();
|
||||
OutTextItemLocation(oldarea, value);
|
||||
}
|
||||
}
|
||||
@@ -343,7 +356,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Area = new RectangleBase(SourceA, SourceB);
|
||||
}
|
||||
|
||||
private void UpdateConnectionPoints()
|
||||
private void UpdatePathGeneratorResult()
|
||||
{
|
||||
if (SourceConnectorInfo == null || SinkConnectorInfo == null)
|
||||
return;
|
||||
@@ -351,17 +364,77 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var route = Router.Get(Parent, this);
|
||||
|
||||
(var source, var target) = FindConnectionPoints(route);
|
||||
if (source == null || target == null)
|
||||
return;
|
||||
if (source == null || target == null)
|
||||
return;
|
||||
|
||||
PathGeneratorResult = PathGenerator.Get(Parent, this, route, source.Value, target.Value);
|
||||
|
||||
StartPoint = new PointBase(source.Value.X - Area.Left, source.Value.Y - Area.Top);
|
||||
EndPoint = new PointBase(target.Value.X - Area.Left, target.Value.Y - Area.Top);
|
||||
|
||||
//修正旋转
|
||||
switch (SourceConnectorInfo.Orientation)
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X, PathGeneratorResult.SourceMarkerPosition.Y - ColorViewModel.LeftArrowSize / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - ColorViewModel.LeftArrowSize / 2, PathGeneratorResult.SourceMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - ColorViewModel.LeftArrowSize, PathGeneratorResult.SourceMarkerPosition.Y - ColorViewModel.LeftArrowSize / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - ColorViewModel.LeftArrowSize / 2, PathGeneratorResult.SourceMarkerPosition.Y - ColorViewModel.LeftArrowSize);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//修正旋转
|
||||
switch (SinkConnectorInfo.Orientation)
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X, PathGeneratorResult.TargetMarkerPosition.Y - ColorViewModel.RightArrowSize / 2);
|
||||
break; }
|
||||
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - ColorViewModel.RightArrowSize / 2, PathGeneratorResult.TargetMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - ColorViewModel.RightArrowSize, PathGeneratorResult.TargetMarkerPosition.Y - ColorViewModel.RightArrowSize / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - ColorViewModel.RightArrowSize / 2, PathGeneratorResult.TargetMarkerPosition.Y - ColorViewModel.RightArrowSize);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
EndPoint = PathGeneratorResult.TargetMarkerPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartAngle = PathGeneratorResult.SourceMarkerAngle;
|
||||
EndAngle = PathGeneratorResult.TargetMarkerAngle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
@@ -415,7 +488,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
MouseButtonEventArgs mosueArg = ((EventToCommandArgs)parameter).EventArgs as MouseButtonEventArgs;
|
||||
var position = mosueArg.GetPosition(((EventToCommandArgs)parameter).Sender as IInputElement);
|
||||
|
||||
|
||||
ConnectionPoints.Add(new ConnectorPoint(position.X, position.Y));
|
||||
|
||||
if (!((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control))
|
||||
|
||||
Reference in New Issue
Block a user