mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-03 15:46:36 +08:00
连接点显示
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -37,11 +37,37 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return DiagramServicesProvider.Instance.Provider;
|
||||
}
|
||||
}
|
||||
private ConnectionViewModel partialConnection;
|
||||
private List<Connector> connectorsHit = new List<Connector>();
|
||||
private ConnectionViewModel partialConnection;
|
||||
|
||||
private Point? rubberbandSelectionStartPoint = null;
|
||||
|
||||
private Connector sourceConnector;
|
||||
public Connector SourceConnector
|
||||
{
|
||||
get
|
||||
{
|
||||
return sourceConnector;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (sourceConnector != value)
|
||||
{
|
||||
sourceConnector = value;
|
||||
|
||||
FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
|
||||
|
||||
Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
|
||||
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(partialConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Connector sinkConnector;
|
||||
|
||||
private DrawMode DrawMode
|
||||
{
|
||||
get
|
||||
@@ -100,7 +126,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region GridCellSize
|
||||
|
||||
public static readonly DependencyProperty GridCellSizeProperty =
|
||||
@@ -293,32 +319,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Connector sourceConnector;
|
||||
public Connector SourceConnector
|
||||
{
|
||||
get
|
||||
{
|
||||
return sourceConnector;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (sourceConnector != value)
|
||||
{
|
||||
sourceConnector = value;
|
||||
connectorsHit.Add(sourceConnector);
|
||||
|
||||
FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
|
||||
|
||||
Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
|
||||
Point point = new Point(rectangleBounds.Left + (rectangleBounds.Width / 2),
|
||||
rectangleBounds.Bottom + (rectangleBounds.Height / 2));
|
||||
partialConnection = new ConnectionViewModel(_viewModel, sourceDataItem, new PartCreatedConnectorInfo(point.X, point.Y), DrawMode, RouterMode);
|
||||
|
||||
_viewModel.Add(partialConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
@@ -376,6 +376,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var point = CursorPointManager.GetCursorPosition();
|
||||
_viewModel.CurrentColor = ColorPickerManager.GetColor(point.X, point.Y);
|
||||
|
||||
//移动
|
||||
if (_service.DrawModeViewModel.CursorMode == CursorMode.Move)
|
||||
{
|
||||
_viewModel.SelectedItems.OfType<DesignerItemViewModelBase>().ToList().ForEach(p => {
|
||||
@@ -390,7 +391,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
partialConnection.SinkConnectorInfo = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y);
|
||||
HitTesting(currentPoint);
|
||||
sinkConnector = HitTesting(currentPoint);
|
||||
|
||||
if (EnableSnapping)
|
||||
{
|
||||
@@ -405,7 +406,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
else
|
||||
{
|
||||
// if mouse button is not pressed we have no drag operation, ...
|
||||
if (e.LeftButton != MouseButtonState.Pressed && _service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
rubberbandSelectionStartPoint = null;
|
||||
|
||||
// ... but if mouse button is pressed and start
|
||||
@@ -439,9 +440,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (sourceConnector != null)
|
||||
{
|
||||
FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
|
||||
if (connectorsHit.Count() == 2)
|
||||
if (sinkConnector != null)
|
||||
{
|
||||
Connector sinkConnector = connectorsHit.Last();
|
||||
|
||||
FullyCreatedConnectorInfo sinkDataItem = sinkConnector.Info;
|
||||
|
||||
int indexOfLastTempConnection = sinkDataItem.DataItem.Root.Items.Count - 1;
|
||||
@@ -459,13 +460,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
int indexOfLastTempConnection = sourceDataItem.DataItem.Root.Items.Count - 1;
|
||||
sourceDataItem.DataItem.Root.Remove(
|
||||
sourceDataItem.DataItem.Root.Items[indexOfLastTempConnection]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
connectorsHit = new List<Connector>();
|
||||
sourceConnector = null;
|
||||
sinkConnector = null;
|
||||
|
||||
if (_service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
|
||||
{
|
||||
@@ -526,7 +525,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return size;
|
||||
}
|
||||
|
||||
private void HitTesting(Point hitPoint)
|
||||
private Connector HitTesting(Point hitPoint)
|
||||
{
|
||||
DependencyObject hitObject = this.InputHitTest(hitPoint) as DependencyObject;
|
||||
while (hitObject != null &&
|
||||
@@ -534,11 +533,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (hitObject is Connector connector)
|
||||
{
|
||||
if (!connectorsHit.Contains(hitObject as Connector))
|
||||
connectorsHit.Add(hitObject as Connector);
|
||||
return connector;
|
||||
}
|
||||
hitObject = VisualTreeHelper.GetParent(hitObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnDrop(DragEventArgs e)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<dd:ConectorValueConverter x:Key="ConectorValueConverter"/>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:FullyCreatedConnectorInfo}">
|
||||
<Grid Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}">
|
||||
<Grid Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}" Cursor="Cross">
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding MenuOptions}" >
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
@@ -24,14 +24,22 @@
|
||||
</ContextMenu>
|
||||
</Grid.ContextMenu>
|
||||
<!-- transparent extra space makes connector easier to hit -->
|
||||
<Rectangle Fill="Transparent" Margin="-2" />
|
||||
<Rectangle Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
<Ellipse x:Name="outer" Fill="Transparent" Opacity="0.3" Margin="-3" />
|
||||
<Ellipse x:Name="innter" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" 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" />
|
||||
</Trigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:LogicalConnectorInfo}">
|
||||
<Grid >
|
||||
<Grid ToolTip="{Binding Name}" Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<Grid ToolTip="{Binding Name}" Width="{Binding ConnectorWidth}" Height="{Binding ConnectorHeight}" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="Cross">
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding MenuOptions}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
@@ -48,8 +56,8 @@
|
||||
</ContextMenu>
|
||||
</Grid.ContextMenu>
|
||||
<!-- transparent extra space makes connector easier to hit -->
|
||||
<Rectangle Fill="Transparent" Margin="-2" />
|
||||
<Rectangle Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
<Ellipse x:Name="outer" Fill="Transparent" Opacity="0.3" Margin="-3" />
|
||||
<Ellipse x:Name="innter" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
</Grid>
|
||||
|
||||
<Control x:Name="label">
|
||||
@@ -83,6 +91,12 @@
|
||||
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" 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" />
|
||||
</Trigger>
|
||||
<DataTrigger Value="Right" Binding="{Binding Orientation}">
|
||||
<Setter TargetName="label" Property="Template">
|
||||
<Setter.Value>
|
||||
|
||||
@@ -203,7 +203,6 @@
|
||||
<Grid Margin="{Binding ConnectorMargin}">
|
||||
<dd:Connector
|
||||
Content="{Binding LeftConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Left"
|
||||
VerticalAlignment="Center"
|
||||
@@ -211,7 +210,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding TopLeftConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="TopLeft"
|
||||
VerticalAlignment="Top"
|
||||
@@ -219,7 +217,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding TopConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Top"
|
||||
VerticalAlignment="Top"
|
||||
@@ -227,7 +224,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding TopRightConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="TopRight"
|
||||
VerticalAlignment="Top"
|
||||
@@ -235,7 +231,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding RightConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Right"
|
||||
VerticalAlignment="Center"
|
||||
@@ -243,7 +238,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding BottomRightConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="BottomRight"
|
||||
VerticalAlignment="Bottom"
|
||||
@@ -251,7 +245,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding BottomConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Bottom"
|
||||
VerticalAlignment="Bottom"
|
||||
@@ -259,7 +252,6 @@
|
||||
Visibility="{Binding Path=ShowConnectors, Converter={x:Static dd:BoolToVisibilityConverter.Instance}}" />
|
||||
<dd:Connector
|
||||
Content="{Binding BottomLeftConnector}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="BottomLeft"
|
||||
VerticalAlignment="Bottom"
|
||||
@@ -300,7 +292,6 @@
|
||||
<Grid>
|
||||
<dd:Connector
|
||||
Content="{Binding .}"
|
||||
Cursor="Cross"
|
||||
SnapsToDevicePixels="True"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
@@ -633,7 +624,7 @@
|
||||
<dd:ConnectorContainer x:Name="PART_ConnectorContainer" Visibility="Hidden" Style="{StaticResource GifImageConnectorContainer}" ItemsSource="{Binding Connectors}">
|
||||
<dd:ConnectorContainer.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<dd:Connector Content="{Binding .}" Cursor="Cross" SnapsToDevicePixels="True"/>
|
||||
<dd:Connector Content="{Binding .}" SnapsToDevicePixels="True"/>
|
||||
</DataTemplate>
|
||||
</dd:ConnectorContainer.ItemTemplate>
|
||||
</dd:ConnectorContainer>
|
||||
@@ -708,7 +699,7 @@
|
||||
<dd:ConnectorContainer.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<dd:Connector Content="{Binding .}" Cursor="Cross" SnapsToDevicePixels="True"/>
|
||||
<dd:Connector Content="{Binding .}" SnapsToDevicePixels="True"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</dd:ConnectorContainer.ItemTemplate>
|
||||
@@ -814,8 +805,7 @@
|
||||
<!-- PART_ConnectorDecorator -->
|
||||
<Grid Margin="-5"
|
||||
x:Name="PART_ConnectorDecorator">
|
||||
<dd:Connector Content="{Binding Connectors[0]}"
|
||||
Cursor="Cross"
|
||||
<dd:Connector Content="{Binding Connectors[0]}"
|
||||
SnapsToDevicePixels="True"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
@@ -13,31 +13,12 @@
|
||||
<dd:ArrowSizeConverter x:Key="ArrowSizeConverter"/>
|
||||
<dd:MathConverter x:Key="MathAddConverter" Operation="Add" />
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
|
||||
<Style x:Key="LineStyle" TargetType="Path">
|
||||
<Setter Property="Stroke" Value="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Value="True" Binding="{Binding IsSelected}">
|
||||
<Setter Property="Stroke" Value="Black"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="ArrowStyle" TargetType="Path">
|
||||
<!--<Setter Property="Stroke" Value="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"/>-->
|
||||
<Setter Property="Fill" Value="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Value="True" Binding="{Binding IsSelected}">
|
||||
<!--<Setter Property="Stroke" Value="Black"/>-->
|
||||
<Setter Property="Fill" Value="Black"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Canvas x:Name="rootCanvas">
|
||||
<Path x:Name="line" StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}"
|
||||
Style="{StaticResource LineStyle}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeLineJoin="Round"
|
||||
StrokeStartLineCap="Round"
|
||||
StrokeEndLineCap="Round">
|
||||
@@ -60,7 +41,7 @@
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
Style="{StaticResource ArrowStyle}">
|
||||
Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Path.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform Angle="{Binding EndAngle}"/>
|
||||
@@ -81,7 +62,7 @@
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
Style="{StaticResource ArrowStyle}">
|
||||
Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Path.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform Angle="{Binding StartAngle}"/>
|
||||
@@ -90,19 +71,35 @@
|
||||
</Path>
|
||||
</Grid>
|
||||
|
||||
<Rectangle Canvas.Left="{Binding StartPoint.X}"
|
||||
Canvas.Top="{Binding StartPoint.Y}"
|
||||
Fill="DarkRed"
|
||||
Width="{Binding SourceConnectorInfo.ConnectorWidth}"
|
||||
Height="{Binding SourceConnectorInfo.ConnectorHeight}"
|
||||
Visibility="{Binding IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<Grid Canvas.Left="{Binding StartPoint.X}"
|
||||
Canvas.Top="{Binding StartPoint.Y}"
|
||||
Width="{Binding SourceConnectorInfo.ConnectorWidth}"
|
||||
Height="{Binding SourceConnectorInfo.ConnectorHeight}"
|
||||
UseLayoutRounding="True"
|
||||
SnapsToDevicePixels="True"
|
||||
Visibility="{Binding IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Ellipse Stroke="DarkRed"
|
||||
StrokeThickness="1"
|
||||
Margin="-2.5"/>
|
||||
<Rectangle
|
||||
Fill="DarkRed"
|
||||
Margin="1"/>
|
||||
</Grid>
|
||||
|
||||
<Ellipse Canvas.Left="{Binding EndPoint.X}"
|
||||
Canvas.Top="{Binding EndPoint.Y}"
|
||||
Fill="DarkRed"
|
||||
Width="{Binding SinkConnectorInfo.ConnectorWidth}"
|
||||
Height="{Binding SinkConnectorInfo.ConnectorHeight}"
|
||||
Visibility="{Binding IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<Grid Canvas.Left="{Binding EndPoint.X}"
|
||||
Canvas.Top="{Binding EndPoint.Y}"
|
||||
Width="{Binding SinkConnectorInfo.ConnectorWidth}"
|
||||
Height="{Binding SinkConnectorInfo.ConnectorHeight}"
|
||||
UseLayoutRounding="True"
|
||||
SnapsToDevicePixels="True"
|
||||
Visibility="{Binding IsSelected,Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Ellipse Stroke="DarkRed"
|
||||
StrokeThickness="1"
|
||||
Margin="-2.5"/>
|
||||
<Ellipse
|
||||
Fill="DarkRed"
|
||||
Margin="1"/>
|
||||
</Grid>
|
||||
|
||||
<Path x:Name="ball"
|
||||
Stretch="Fill"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user