箭头分离到独立的model中,方便自定义path

This commit is contained in:
艾竹
2023-01-26 18:27:17 +08:00
parent f11a4170d8
commit 9bb6c6d321
42 changed files with 993 additions and 299 deletions

View File

@@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Animations\" />
<Folder Include="Views\Algorithms\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
{
class LabelsViewModel : BaseViewModel
{
public LabelsViewModel()
{
Title = "Link Labels";
Info = "Labels help you show more information through out a link. You can specify a distance or an offset." +
"The content of the labels is still limited because of Blazor's poor SVG support.";
_service.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 50 };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 50 };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
ConnectionViewModel connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.AddLabel("Content");
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 160, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 160, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.AddLabel("0.25", 0.3);
connector1.AddLabel("0.75", 0.7);
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 270, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 270, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.AddLabel("50", 50);
connector1.AddLabel("-50", -50);
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 380, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 380, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.AddLabel("(0,-20)", 50, new Point(0, -20));
connector1.AddLabel("(0,20)", -50, new Point(0, 20));
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
{
class MarkersViewModel : BaseViewModel
{
public MarkersViewModel()
{
Title = "Link Markers";
Info = "Markers are SVG Paths that you can put at the beginning or at the end of your links.";
_service.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 50, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 50, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
ConnectionViewModel connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.ShapeViewModel.SourceMarker = LinkMarker.Arrow;
connector1.ShapeViewModel.SinkMarker = LinkMarker.Arrow;
connector1.AddLabel("Arrow");
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 160, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 160, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.ShapeViewModel.SourceMarker = LinkMarker.Circle;
connector1.ShapeViewModel.SinkMarker = LinkMarker.Circle;
connector1.AddLabel("Circle");
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 270, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
node2 = new DefaultDesignerItemViewModel() { Left = 400, Top = 270, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector);
connector1.ShapeViewModel.SourceMarker = LinkMarker.Square;
connector1.ShapeViewModel.SinkMarker = LinkMarker.Square;
connector1.AddLabel("Square");
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using AIStudio.Wpf.DiagramDesigner.Algorithms;
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
{
class ReconnectLinksToClosestPortsViewModel : BaseViewModel
{
public ReconnectLinksToClosestPortsViewModel()
{
Title = "Reconnect links";
Info = "An example of reconnecting links to the closest ports.";
_service.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 50, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel() { Left = 300, Top = 300, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel() { Left = 300, Top = 50, Text = "3" };
DiagramViewModel.DirectAddItemCommand.Execute(node3);
ConnectionViewModel connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector, DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
ConnectionViewModel connector2 = new ConnectionViewModel(node2.RightConnector, node3.RightConnector, DrawMode.ConnectingLineStraight, RouterMode.RouterOrthogonal);
DiagramViewModel.DirectAddItemCommand.Execute(connector2);
ReconnectLinksCommand = new SimpleCommand(ReconnectLinks);
}
public SimpleCommand ReconnectLinksCommand
{
get; private set;
}
protected void ReconnectLinks(object para) => DiagramViewModel.ReconnectLinksToClosestPorts();
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
{
class ZoomViewModel : BaseViewModel
{
public ZoomViewModel()
{
Title = "Zoom";
Info = "Drag the upper-right scroll bar to make the canvas larger and smaller.";
_service.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 50, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel() { Left = 300, Top = 300, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel() { Left = 300, Top = 50, Text = "3" };
DiagramViewModel.DirectAddItemCommand.Execute(node3);
ConnectionViewModel connector1 = new ConnectionViewModel(node1.RightConnector, node2.LeftConnector, DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
ConnectionViewModel connector2 = new ConnectionViewModel(node2.RightConnector, node3.RightConnector, DrawMode.ConnectingLineStraight, RouterMode.RouterOrthogonal);
DiagramViewModel.DirectAddItemCommand.Execute(connector2);
}
}
}

View File

@@ -0,0 +1,17 @@
<UserControl x:Class="AIStudio.Wpf.DiagramDesigner.Demo.Views.ReconnectLinksToClosestPortsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram"
xmlns:controls="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- Diagram Control -->
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Command="{Binding ReconnectLinksCommand}" HorizontalAlignment="Left" VerticalAlignment="Top">Reconnect links</Button>
<controls:TitleControl/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AIStudio.Wpf.DiagramDesigner.Demo.Views
{
/// <summary>
/// ReconnectLinksToClosestPortsView.xaml 的交互逻辑
/// </summary>
public partial class ReconnectLinksToClosestPortsView : UserControl
{
public ReconnectLinksToClosestPortsView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,16 @@
<UserControl x:Class="AIStudio.Wpf.DiagramDesigner.Demo.Views.LabelsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram"
xmlns:controls="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- Diagram Control -->
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<controls:TitleControl/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AIStudio.Wpf.DiagramDesigner.Demo.Views
{
/// <summary>
/// LabelsView.xaml 的交互逻辑
/// </summary>
public partial class LabelsView : UserControl
{
public LabelsView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,16 @@
<UserControl x:Class="AIStudio.Wpf.DiagramDesigner.Demo.Views.MarkersView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram"
xmlns:controls="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- Diagram Control -->
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<controls:TitleControl/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AIStudio.Wpf.DiagramDesigner.Demo.Views
{
/// <summary>
/// MarkersView.xaml 的交互逻辑
/// </summary>
public partial class MarkersView : UserControl
{
public MarkersView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,29 @@
<UserControl x:Class="AIStudio.Wpf.DiagramDesigner.Demo.Views.ZoomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram"
xmlns:controls="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- Diagram Control -->
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Slider x:Name="zoomSlider"
Minimum="0.5"
Value="{Binding DiagramViewModel.ZoomValue}"
Maximum="2.0"
IsDirectionReversed="False"
IsSnapToTickEnabled="True"
TickFrequency="0.1"
SmallChange="0.1"
LargeChange="0.1"
Width="200"
HorizontalAlignment="Right"
VerticalAlignment="Top"/>
<controls:TitleControl/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AIStudio.Wpf.DiagramDesigner.Demo.Views
{
/// <summary>
/// ZoomView.xaml 的交互逻辑
/// </summary>
public partial class ZoomView : UserControl
{
public ZoomView()
{
InitializeComponent();
}
}
}