diff --git a/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Utils.cs b/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Utils.cs index 88e1955..46982d0 100644 --- a/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Utils.cs +++ b/AIStudio.Wpf.DiagramDesigner/PathGenerators/PathGenerators.Utils.cs @@ -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; } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectorViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectorViewModel.cs index 29d9fec..53c24c7 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectorViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectorViewModel.cs @@ -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; }