mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-06 01:30:52 +08:00
画线优化基本完成
This commit is contained in:
@@ -14,7 +14,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public ConnectorViewModel(IDiagramViewModel parent, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode drawMode, RouterMode routerMode)
|
||||
{
|
||||
Parent = parent;
|
||||
PathMode = drawMode.ToString().Replace("ConnectingLine","");
|
||||
PathMode = drawMode.ToString();
|
||||
RouterMode = routerMode.ToString();
|
||||
Init(sourceConnectorInfo, sinkConnectorInfo);
|
||||
}
|
||||
@@ -26,9 +26,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Init(sourceConnectorInfo, sinkConnectorInfo);
|
||||
}
|
||||
|
||||
public ConnectorViewModel(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode drawMode, RouterMode routerMode) :this(null, sourceConnectorInfo, sinkConnectorInfo, drawMode, routerMode)
|
||||
public ConnectorViewModel(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode drawMode, RouterMode routerMode) : this(null, sourceConnectorInfo, sinkConnectorInfo, drawMode, routerMode)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
@@ -36,10 +36,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.Parent = sourceConnectorInfo.DataItem.Parent;
|
||||
|
||||
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 NormalRouter();
|
||||
Router = routetype != null ? (System.Activator.CreateInstance(routetype) as IRouter) : new RouterNormal();
|
||||
|
||||
var pathGeneratortype = GlobalType.AllTypes.Where(p => typeof(IPathGenerator).IsAssignableFrom(p)).FirstOrDefault(p => p.Name == PathMode);
|
||||
PathGenerator = pathGeneratortype != null ? (System.Activator.CreateInstance(pathGeneratortype) as IPathGenerator) : new SmoothPathGenerator();
|
||||
PathGenerator = pathGeneratortype != null ? (System.Activator.CreateInstance(pathGeneratortype) as IPathGenerator) : new ConnectingLineSmooth();
|
||||
|
||||
this.SourceConnectorInfo = sourceConnectorInfo;
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
@@ -72,7 +72,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public override Type ToXmlType()
|
||||
{
|
||||
return typeof(ConnectionItem);
|
||||
}
|
||||
}
|
||||
|
||||
private PointBase _sourceA;
|
||||
public PointBase SourceA
|
||||
@@ -249,7 +249,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SourceB = _sinkConnectorInfo.Location;
|
||||
if (_sinkConnectorInfo is FullyCreatedConnectorInfo)
|
||||
{
|
||||
{
|
||||
(((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem as INotifyPropertyChanged).PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
}
|
||||
}
|
||||
@@ -297,18 +297,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void UpdateConnectionPoints()
|
||||
{
|
||||
//ConnectionPoints = PathFinder.UpdateConnectionPoints(Parent, SourceA, SourceB, SourceConnectorInfo, SinkConnectorInfo);
|
||||
//StartPoint = ConnectionPoints.First();
|
||||
//EndPoint = ConnectionPoints.Last();
|
||||
if (SourceConnectorInfo == null || SinkConnectorInfo == null)
|
||||
return;
|
||||
|
||||
var route = Router.Get(Parent, this);
|
||||
|
||||
|
||||
(var source, var target) = FindConnectionPoints(route);
|
||||
if (source == null || target == null)
|
||||
return;
|
||||
|
||||
PathGeneratorResult = PathGenerator.Get(Parent, this, route, source.Value, target.Value);
|
||||
}
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition ?? new PointBase();
|
||||
EndPoint = PathGeneratorResult.TargetMarkerPosition ?? new PointBase();
|
||||
}
|
||||
|
||||
private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
@@ -338,7 +339,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCommand DeleteConnectionCommand
|
||||
{
|
||||
@@ -369,14 +370,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
TextDesignerItemViewModel textitem = new TextDesignerItemViewModel();
|
||||
textitem.ItemWidth = Double.NaN;
|
||||
textitem.ItemHeight = double.NaN;
|
||||
if (diagramVM.DiagramType == DiagramType.FlowChart)
|
||||
{
|
||||
var mid = (int)(ConnectionPoints.Count / 2);
|
||||
var p = BoundaryPathFinder.SegmentMiddlePoint(ConnectionPoints[mid - 1], ConnectionPoints[mid]);
|
||||
textitem.Left = this.Area.Left + p.X + 2;
|
||||
textitem.Top = this.Area.Top + p.Y - 15;
|
||||
}
|
||||
else
|
||||
//if (this.PathMode == DrawMode.ConnectingLineBoundary.ToString())
|
||||
//{
|
||||
// var mid = (int)(ConnectionPoints.Count / 2);
|
||||
// var p = PathGenerators.SegmentMiddlePoint(ConnectionPoints[mid - 1], ConnectionPoints[mid]);
|
||||
// textitem.Left = this.Area.Left + p.X + 2;
|
||||
// textitem.Top = this.Area.Top + p.Y - 15;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
textitem.Left = this.Area.Left + this.Area.Width / 2 - 16;
|
||||
textitem.Top = this.Area.Top + this.Area.Height / 2 - 5;
|
||||
|
||||
Reference in New Issue
Block a user