mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-12 12:16:37 +08:00
连线完成
This commit is contained in:
@@ -1139,14 +1139,14 @@
|
||||
Format="0 pt" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="箭头样式" Margin="5"/>
|
||||
<TextBlock Text="箭头样式" Margin="5"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Fluent:ComboBox Size="Small" Width="140" Margin="5" IsEditable="False" helper:EnumHelper.Enum="{x:Type dd:ArrowPathStyle}" SelectedItem="{Binding ColorViewModel.LeftArrowPathStyle}">
|
||||
<Fluent:ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DockPanel>
|
||||
<Grid>
|
||||
<Line X1="0" Y1="0" X2="100" Y2="0" Stroke="Black" StrokeThickness="1" VerticalAlignment="Center" />
|
||||
<Line X1="0" Y1="0" X2="100" Y2="0" Stroke="Black" Margin="5,0,0,0" StrokeThickness="1" VerticalAlignment="Center" />
|
||||
<Path
|
||||
Data="{Binding .,Converter={StaticResource ArrowPathConverter}}"
|
||||
HorizontalAlignment="Left"
|
||||
@@ -1167,12 +1167,13 @@
|
||||
</DataTemplate>
|
||||
</Fluent:ComboBox.ItemTemplate>
|
||||
</Fluent:ComboBox>
|
||||
|
||||
<Fluent:ComboBox Size="Small" Width="140" Margin="5" IsEditable="False" helper:EnumHelper.Enum="{x:Type dd:ArrowPathStyle}" SelectedItem="{Binding ColorViewModel.RightArrowPathStyle}">
|
||||
<Fluent:ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DockPanel>
|
||||
<Grid>
|
||||
<Line X1="0" Y1="0" X2="100" Y2="0" Stroke="Black" StrokeThickness="1" VerticalAlignment="Center" />
|
||||
<Line X1="0" Y1="0" X2="100" Y2="0" Stroke="Black" Margin="0,0,5,0" StrokeThickness="1" VerticalAlignment="Center" />
|
||||
<Path
|
||||
Data="{Binding .,Converter={StaticResource ArrowPathConverter}}"
|
||||
HorizontalAlignment="Right"
|
||||
@@ -1182,7 +1183,7 @@
|
||||
Stroke="Black"
|
||||
Fill="Black"
|
||||
VerticalAlignment="Center"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
</Path>
|
||||
</Grid>
|
||||
<TextBlock DockPanel.Dock="Right" Margin="2,0" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplatedParent.(ItemsControl.AlternationIndex),Converter={StaticResource NumberConverter}}"></TextBlock>
|
||||
@@ -1190,6 +1191,8 @@
|
||||
</DataTemplate>
|
||||
</Fluent:ComboBox.ItemTemplate>
|
||||
</Fluent:ComboBox>
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -559,20 +559,19 @@
|
||||
Data="{Binding ColorViewModel.RightArrowPathStyle,Converter={StaticResource ArrowPathConverter}}"
|
||||
Visibility="{Binding Path=IsFullConnection, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
|
||||
Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
HorizontalAlignment="Left"
|
||||
Height="{Binding ColorViewModel.RightArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Width="{Binding ColorViewModel.RightArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Canvas.Left="{Binding EndPoint.X}"
|
||||
Canvas.Top="{Binding EndPoint.Y}"
|
||||
Stretch="Fill"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
VerticalAlignment="Top"
|
||||
Stretch="Fill"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform x:Name="rightrot" Angle="{Binding EndAngle}"/>
|
||||
<TransformGroup>
|
||||
<RotateTransform x:Name="rightrot" Angle="{Binding EndAngle}"/>
|
||||
<TranslateTransform X="{Binding EndPoint.X}" Y="{Binding EndPoint.Y}"/>
|
||||
</TransformGroup>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
|
||||
</Path>
|
||||
|
||||
<Path x:Name="leftarrow"
|
||||
Data="{Binding ColorViewModel.LeftArrowPathStyle,Converter={StaticResource ArrowPathConverter}}"
|
||||
Visibility="{Binding Path=IsFullConnection, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
|
||||
@@ -588,6 +587,7 @@
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform x:Name="leftrot" Angle="{Binding StartAngle}"/>
|
||||
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Canvas>
|
||||
@@ -662,60 +662,12 @@
|
||||
Value="Visible"/>
|
||||
</DataTrigger>
|
||||
|
||||
<!--右箭头-->
|
||||
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
|
||||
Value="Left">
|
||||
<Setter TargetName="rightarrow"
|
||||
Property="Margin"
|
||||
Value="-10,-5,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
|
||||
Value="Top">
|
||||
<Setter TargetName="rightarrow"
|
||||
Property="Margin"
|
||||
Value="-5,-10,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
|
||||
Value="Right">
|
||||
<Setter TargetName="rightarrow"
|
||||
Property="Margin"
|
||||
Value="0,-5,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
|
||||
Value="Bottom">
|
||||
<Setter TargetName="rightarrow"
|
||||
Property="Margin"
|
||||
Value="-5,0,0,0" />
|
||||
</DataTrigger>
|
||||
<!--右箭头-->
|
||||
<DataTrigger Binding="{Binding Path=ColorViewModel.RightArrowPathStyle}" Value="None">
|
||||
<Setter TargetName="rightarrow" Property="Visibility" Value="Hidden"/>
|
||||
</DataTrigger>
|
||||
|
||||
<!--左箭头-->
|
||||
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
|
||||
Value="Left">
|
||||
<Setter TargetName="leftarrow"
|
||||
Property="Margin"
|
||||
Value="-10,-5,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
|
||||
Value="Top">
|
||||
<Setter TargetName="leftarrow"
|
||||
Property="Margin"
|
||||
Value="-5,-10,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
|
||||
Value="Right">
|
||||
<Setter TargetName="leftarrow"
|
||||
Property="Margin"
|
||||
Value="0,-5,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
|
||||
Value="Bottom">
|
||||
<Setter TargetName="leftarrow"
|
||||
Property="Margin"
|
||||
Value="-5,0,0,0" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Path=ColorViewModel.LeftArrowPathStyle}" Value="None">
|
||||
<Setter TargetName="leftarrow" Property="Visibility" Value="Hidden"/>
|
||||
</DataTrigger>
|
||||
|
||||
@@ -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