画线调整

This commit is contained in:
艾竹
2023-01-16 22:38:58 +08:00
parent 718d8c01e9
commit f8a0b29d5f
2 changed files with 20 additions and 22 deletions

View File

@@ -9,20 +9,18 @@ namespace AIStudio.Wpf.DiagramDesigner
public static double SourceMarkerAdjustement(PointBase[] route, double markerWidth)
{
var angleInRadians = Math.Atan2(route[1].Y - route[0].Y, route[1].X - route[0].X) + Math.PI;
//不需要留出箭头的位置
//var xChange = markerWidth * Math.Cos(angleInRadians);
//var yChange = markerWidth * Math.Sin(angleInRadians);
//route[0] = new PointBase(route[0].X - xChange, route[0].Y - yChange);
var xChange = markerWidth * Math.Cos(angleInRadians);
var yChange = markerWidth * Math.Sin(angleInRadians);
route[0] = new PointBase(route[0].X - xChange, route[0].Y - yChange);
return angleInRadians * 180 / Math.PI;
}
public static double TargetMarkerAdjustement(PointBase[] route, double markerWidth)
{
var angleInRadians = Math.Atan2(route[route.Length - 1].Y - route[route.Length - 2].Y, route[route.Length - 1].X - route[route.Length - 2].X);
//不需要留出箭头的位置
//var xChange = markerWidth * Math.Cos(angleInRadians);
//var yChange = markerWidth * Math.Sin(angleInRadians);
//route[route.Length - 1] = new PointBase(route[route.Length - 1].X - xChange, route[route.Length - 1].Y - yChange);
var xChange = markerWidth * Math.Cos(angleInRadians);
var yChange = markerWidth * Math.Sin(angleInRadians);
route[route.Length - 1] = new PointBase(route[route.Length - 1].X - xChange, route[route.Length - 1].Y - yChange);
return angleInRadians * 180 / Math.PI;
}

View File

@@ -37,6 +37,14 @@ 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);
}
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
{
this.ColorViewModel.RightArrowPathStyle = ArrowPathStyle.None;
}
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();
@@ -47,16 +55,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.SourceConnectorInfo = sourceConnectorInfo;
this.SinkConnectorInfo = sinkConnectorInfo;
DeleteConnectionCommand = new SimpleCommand(DeleteConnection);
AddVertexCommand = new SimpleCommand(AddVertex);
if (Parent != null && Parent.ColorViewModel != null)
{
this.ColorViewModel = CopyHelper.Mapper(Parent.ColorViewModel);
}
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
{
this.ColorViewModel.RightArrowPathStyle = ArrowPathStyle.None;
}
AddVertexCommand = new SimpleCommand(AddVertex);
}
public override SelectableDesignerItemBase ToXmlObject()
@@ -352,12 +351,13 @@ 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 = PathGeneratorResult.SourceMarkerPosition;
EndPoint = PathGeneratorResult.TargetMarkerPosition;
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);
StartAngle = PathGeneratorResult.SourceMarkerAngle;
EndAngle = PathGeneratorResult.TargetMarkerAngle;
}