mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-05-02 05:51:28 +08:00
部分连接线完成,另外待连接点红色区域显示。
This commit is contained in:
@@ -464,7 +464,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else if (partialConnection.IsFullConnection)//自动连接模式
|
||||
{
|
||||
partialConnection.RaiseFullConnection();
|
||||
_viewModel.ClearNearPort();
|
||||
}
|
||||
else if (_service.DrawModeViewModel.LineDrawModeSelected)
|
||||
{
|
||||
|
||||
@@ -34,6 +34,12 @@
|
||||
<Setter TargetName="innter" Property="Fill" Value="#f73438" />
|
||||
<Setter TargetName="innter" Property="Stroke" Value="#f73438" />
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding BeAttachTo}" Value="True">
|
||||
<Setter TargetName="outer" Property="Margin" Value="-6" />
|
||||
<Setter TargetName="outer" Property="Fill" Value="#f73438" />
|
||||
<Setter TargetName="innter" Property="Fill" Value="#f73438" />
|
||||
<Setter TargetName="innter" Property="Stroke" Value="#f73438" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
|
||||
@@ -462,27 +462,22 @@
|
||||
<DataTemplate.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Value="True" Binding="{Binding IsSelected}"/>
|
||||
<Condition Value="{x:Static sys:Guid.Empty}" Binding="{Binding ParentId}"/>
|
||||
<Condition Binding="{Binding IsSelected}" Value="True" />
|
||||
<Condition Binding="{Binding ParentId}" Value="{x:Static sys:Guid.Empty}" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Value="True" Binding="{Binding IsSelected}"/>
|
||||
<Condition Value="True" Binding="{Binding AlwayForResized}"/>
|
||||
<Condition Binding="{Binding IsSelected}" Value="True" />
|
||||
<Condition Binding="{Binding AlwayForResized}" Value="True" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
|
||||
</MultiDataTrigger>
|
||||
<Trigger Property="IsMouseOver"
|
||||
Value="true">
|
||||
<Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
|
||||
</Trigger>
|
||||
<DataTrigger Value="0"
|
||||
Binding="{Binding Connectors.Count}">
|
||||
<DataTrigger Binding="{Binding Connectors.Count}" Value="0">
|
||||
<Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Value="True" Binding="{Binding IsInnerConnector}">
|
||||
<DataTrigger Binding="{Binding IsInnerConnector}" Value="True">
|
||||
<Setter TargetName="PART_ConnectorDecorator" Property="Template" Value="{StaticResource InnerConnectorDecoratorTemplate}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
@@ -521,13 +516,13 @@
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<Grid x:Name="selectedGrid">
|
||||
<Grid x:Name="selectedGrid" IsHitTestVisible="{Binding IsHitTestVisible}">
|
||||
<Grid.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding EditCommand}" CommandParameter="{Binding }" />
|
||||
</Grid.InputBindings>
|
||||
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<ContextMenu x:Name="PART_ContextMenu">
|
||||
<MenuItem Header="删除" Command="{Binding DeleteConnectionCommand}" CommandParameter="{Binding}"/>
|
||||
<MenuItem Header="添加文本" Command="{Binding AddLabelCommand}" CommandParameter="{Binding}"/>
|
||||
<MenuItem Header="插入点(按住ctrl可一直插入)" IsCheckable="True" IsChecked="{Binding ShouldInsertAnchor}" IsEnabled="{Binding IsReadOnly,Converter={dd:InvertBoolConverter}}" />
|
||||
@@ -599,19 +594,14 @@
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Value="True"
|
||||
Binding="{Binding IsSelected}">
|
||||
<Setter TargetName="PART_VerticesContainer"
|
||||
Property="Visibility"
|
||||
Value="Visible"/>
|
||||
<DataTrigger Binding="{Binding IsSelected}" Value="True">
|
||||
<Setter TargetName="PART_VerticesContainer" Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
|
||||
<DataTrigger Value="True"
|
||||
Binding="{Binding ShouldInsertAnchor}">
|
||||
<Setter TargetName="PART_VerticesContainer"
|
||||
Property="Visibility"
|
||||
Value="Visible"/>
|
||||
<DataTrigger Binding="{Binding ShouldInsertAnchor}" Value="True">
|
||||
<Setter TargetName="PART_VerticesContainer" Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
@@ -681,8 +671,8 @@
|
||||
<DataTemplate.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Value="True" Binding="{Binding IsSelected}"/>
|
||||
<Condition Value="{x:Static sys:Guid.Empty}" Binding="{Binding ParentId}"/>
|
||||
<Condition Binding="{Binding IsSelected}" Value="True" />
|
||||
<Condition Binding="{Binding ParentId}" Value="{x:Static sys:Guid.Empty}" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
|
||||
</MultiDataTrigger>
|
||||
|
||||
@@ -448,12 +448,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RaiseFullConnection()
|
||||
{
|
||||
RaisePropertyChanged(nameof(IsFullConnection));
|
||||
}
|
||||
|
||||
public double SmoothMargin { get; set; } = 125;
|
||||
public double SmoothAutoSlope { get; set; } = 1;
|
||||
public double OrthogonalShapeMargin { get; set; } = 10;
|
||||
@@ -585,13 +579,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else if(connectorVertexModel.ConnectorVertexType == ConnectorVertexType.Start)
|
||||
{
|
||||
var nearPort = Root.FindNearPortToAttachTo(this, ConnectorVertexType.Start);
|
||||
SetSourcePort(new PartCreatedConnectorInfo(connectorVertexModel.Position.X, connectorVertexModel.Position.Y));
|
||||
this.ZIndex = -1;
|
||||
}
|
||||
else if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.End)
|
||||
{
|
||||
var nearPort = Root.FindNearPortToAttachTo(this, ConnectorVertexType.End);
|
||||
SetSinkPort(new PartCreatedConnectorInfo(connectorVertexModel.Position.X, connectorVertexModel.Position.Y));
|
||||
this.ZIndex = -1;
|
||||
}
|
||||
break;
|
||||
case nameof(ConnectorPointModel.DragStart):
|
||||
@@ -599,7 +593,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.Start)
|
||||
{
|
||||
var nearPort = Root.FindNearPortToAttachTo(this, ConnectorVertexType.Start);
|
||||
var nearPort = Root?.FindNearPortToAttachTo(this, ConnectorVertexType.Start);
|
||||
if (nearPort != null)
|
||||
{
|
||||
SetSourcePort(nearPort);
|
||||
@@ -607,12 +601,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.End)
|
||||
{
|
||||
var nearPort = Root.FindNearPortToAttachTo(this, ConnectorVertexType.End);
|
||||
var nearPort = Root?.FindNearPortToAttachTo(this, ConnectorVertexType.End);
|
||||
if (nearPort != null)
|
||||
{
|
||||
SetSinkPort(nearPort);
|
||||
}
|
||||
}
|
||||
Root?.ClearNearPort();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -895,7 +890,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public double GetSourceMarkerWidth()
|
||||
{
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -904,7 +899,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public double GetSourceMarkerHeight()
|
||||
{
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -913,7 +908,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public double GetSinkMarkerWidth()
|
||||
{
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -922,7 +917,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public double GetSinkMarkerHeight()
|
||||
{
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -145,6 +145,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _beAttachTo;
|
||||
public bool BeAttachTo
|
||||
{
|
||||
get
|
||||
{
|
||||
return _beAttachTo;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _beAttachTo, value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool CanAttachTo(ConnectorInfoBase port)
|
||||
=> port != this && !port.IsReadOnly;
|
||||
#endregion
|
||||
|
||||
@@ -170,11 +170,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPosition(PointBase position)
|
||||
{
|
||||
X = position.X;
|
||||
Y = position.Y;
|
||||
}
|
||||
|
||||
private bool _dragStart;
|
||||
public bool DragStart
|
||||
@@ -189,6 +184,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPosition(PointBase position)
|
||||
{
|
||||
X = position.X;
|
||||
Y = position.Y;
|
||||
}
|
||||
|
||||
|
||||
public static ConnectorPointModel operator -(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
return new ConnectorPointModel(a.X - b.X, a.Y - b.Y);
|
||||
|
||||
@@ -39,10 +39,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
} = 50;
|
||||
public double HittingRadius
|
||||
{
|
||||
get; set;
|
||||
} = 20;
|
||||
}
|
||||
|
||||
public class ShortcutOption
|
||||
|
||||
@@ -3357,19 +3357,28 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection == null)
|
||||
return null;
|
||||
|
||||
ClearNearPort();
|
||||
foreach (var port in Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (connectorVertexType == ConnectorVertexType.Start)
|
||||
{
|
||||
if (partialConnection.SourceConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.HittingRadius &&
|
||||
if (partialConnection.SourceConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius &&
|
||||
partialConnection.SinkConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
}
|
||||
else if (connectorVertexType == ConnectorVertexType.End)
|
||||
{
|
||||
if (partialConnection.SinkConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.HittingRadius &&
|
||||
if (partialConnection.SinkConnectorInfo.Position.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius &&
|
||||
partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3381,15 +3390,25 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection == null)
|
||||
return null;
|
||||
|
||||
ClearNearPort();
|
||||
foreach (var port in Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (partialConnection.OnGoingPosition.DistanceTo(port.Position) < DiagramOption.SnappingOption.SnappingRadius &&
|
||||
partialConnection.SourceConnectorInfoFully?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ClearNearPort()
|
||||
{
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true).ToList().ForEach(p => p.BeAttachTo = false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +408,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
#region 公共方法
|
||||
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection, ConnectorVertexType connectorVertexType);
|
||||
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection);
|
||||
void ClearNearPort();
|
||||
#endregion
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user