mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
连线优化1:开始和结束节点。
This commit is contained in:
@@ -62,6 +62,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(partialConnection);
|
||||
partialConnection.ZIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public static PointBase[] Normal(IDiagramViewModel _, ConnectionViewModel link)
|
||||
{
|
||||
return link.Vertices.Select(v => v.MiddlePosition).ToArray();
|
||||
return link.Vertices.Where(p => p.ConnectorVertexType == ConnectorVertexType.None).Select(v => v.MiddlePosition).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,12 +157,54 @@
|
||||
<ControlTemplate TargetType="{x:Type dd:PointConnector}">
|
||||
<Grid Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}">
|
||||
<!-- transparent extra space makes connector easier to hit -->
|
||||
<Ellipse Fill="Transparent" Margin="-2" />
|
||||
<Ellipse Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
<Ellipse Fill="Transparent" Margin="-3" />
|
||||
<Ellipse Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="1"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding ConnectorVertexType}" Value="Start">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type dd:PointConnector}">
|
||||
<Grid Width="{Binding ConnectorWidth}"
|
||||
Height="{Binding ConnectorHeight}"
|
||||
UseLayoutRounding="True"
|
||||
SnapsToDevicePixels="True">
|
||||
<Ellipse Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="1"
|
||||
Margin="-2.5"/>
|
||||
<Rectangle
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Margin="1"/>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding ConnectorVertexType}" Value="End">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type dd:PointConnector}">
|
||||
<Grid Width="{Binding ConnectorWidth}"
|
||||
Height="{Binding ConnectorHeight}"
|
||||
UseLayoutRounding="True"
|
||||
SnapsToDevicePixels="True">
|
||||
<Ellipse Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="1"
|
||||
Margin="-2.5"/>
|
||||
<Ellipse
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Margin="1"/>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="GifImageConnectorContainer" TargetType="{x:Type dd:ConnectorContainer}">
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
</Path>
|
||||
</Grid>
|
||||
|
||||
<Grid Canvas.Left="{Binding StartPoint.X}"
|
||||
<!--<Grid Canvas.Left="{Binding StartPoint.X}"
|
||||
Canvas.Top="{Binding StartPoint.Y}"
|
||||
Width="{Binding SourceConnectorInfo.ConnectorWidth}"
|
||||
Height="{Binding SourceConnectorInfo.ConnectorHeight}"
|
||||
@@ -99,7 +99,7 @@
|
||||
<Ellipse
|
||||
Fill="DarkRed"
|
||||
Margin="1"/>
|
||||
</Grid>
|
||||
</Grid>-->
|
||||
|
||||
<Path x:Name="ball"
|
||||
Stretch="Fill"
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
this.SourceConnectorInfo = sourceConnectorInfo;
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
|
||||
|
||||
DeleteConnectionCommand = new SimpleCommand(Command_Enable, DeleteConnection);
|
||||
AddVertexCommand = new SimpleCommand(Command_Enable, AddVertex);
|
||||
@@ -612,8 +613,37 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
StartAngle = PathGeneratorResult.SourceMarkerAngle;
|
||||
EndAngle = PathGeneratorResult.TargetMarkerAngle;
|
||||
StartPoint = new PointBase(source.Value.X - Area.Left - SourceConnectorInfo.ConnectorWidth / 2, source.Value.Y - Area.Top - SourceConnectorInfo.ConnectorHeight / 2) ;
|
||||
EndPoint = new PointBase(target.Value.X - Area.Left - SinkConnectorInfo.ConnectorWidth / 2 , target.Value.Y - Area.Top - SinkConnectorInfo.ConnectorHeight / 2 );
|
||||
//StartPoint = new PointBase(source.Value.X - Area.Left - SourceConnectorInfo.ConnectorWidth / 2, source.Value.Y - Area.Top - SourceConnectorInfo.ConnectorHeight / 2) ;
|
||||
//EndPoint = new PointBase(target.Value.X - Area.Left - SinkConnectorInfo.ConnectorWidth / 2 , target.Value.Y - Area.Top - SinkConnectorInfo.ConnectorHeight / 2 );
|
||||
|
||||
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);
|
||||
|
||||
var startVertice = Vertices.FirstOrDefault(p => p.ConnectorVertexType == ConnectorVertexType.Start);
|
||||
if (startVertice == null)
|
||||
{
|
||||
startVertice = new ConnectorVertexModel(this, StartPoint) { ConnectorVertexType = ConnectorVertexType.Start };
|
||||
startVertice.ColorViewModel.FillColor.Color = Colors.DarkRed;
|
||||
startVertice.ColorViewModel.LineColor.Color = Colors.DarkRed;
|
||||
Vertices.Add(startVertice);
|
||||
}
|
||||
else
|
||||
{
|
||||
startVertice.SetPosition(StartPoint);
|
||||
}
|
||||
|
||||
var endVertice = Vertices.FirstOrDefault(p => p.ConnectorVertexType == ConnectorVertexType.End);
|
||||
if (endVertice == null)
|
||||
{
|
||||
endVertice = new ConnectorVertexModel(this, EndPoint) { ConnectorVertexType = ConnectorVertexType.End };
|
||||
endVertice.ColorViewModel.FillColor.Color = Colors.DarkRed;
|
||||
endVertice.ColorViewModel.LineColor.Color = Colors.DarkRed;
|
||||
Vertices.Add(endVertice);
|
||||
}
|
||||
else
|
||||
{
|
||||
endVertice.SetPosition(EndPoint);
|
||||
}
|
||||
|
||||
var paths = Labels.Count > 0 ? PathGeneratorResult.Paths.Select(p => new SvgPath(p)).ToArray() : Array.Empty<SvgPath>();
|
||||
foreach (var label in Labels)
|
||||
@@ -821,6 +851,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
pointBase = new PointBase(pointBase.X - Area.Left, pointBase.Y - Area.Top);
|
||||
}
|
||||
var vertice = new ConnectorVertexModel(this, pointBase);
|
||||
vertice.ColorViewModel.LineColor.Color = Colors.Blue;
|
||||
vertice.PropertyChanged += new WeakINPCEventHandler(Item_PropertyChanged).Handler;
|
||||
Vertices.Add(vertice);
|
||||
UpdatePathGeneratorResult();
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ConnectorWidth = designer.ConnectorWidth;
|
||||
ConnectorHeight = designer.ConnectorHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中间X
|
||||
|
||||
@@ -51,6 +51,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
|
||||
public ConnectorVertexType ConnectorVertexType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ConnectionViewModel Connector
|
||||
{
|
||||
get
|
||||
@@ -82,5 +87,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPosition(PointBase position)
|
||||
{
|
||||
X = position.X;
|
||||
Y = position.Y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ConnectorVertexType
|
||||
{
|
||||
None,
|
||||
Start,
|
||||
End,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user