mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -98,9 +98,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
_sourceItemsContainer = value;
|
||||
if (_sourceItemsContainer != null)
|
||||
{
|
||||
BlockItemsContainerInfo sourceDataItem = _sourceItemsContainer.Info;
|
||||
BlockItemsContainerInfo sourceContainerInfo = _sourceItemsContainer.Info;
|
||||
|
||||
sourceDataItem.DataItem.RemoveChild(_sourceItemsContainer.DragObject);
|
||||
sourceContainerInfo.DataItem.RemoveChild(_sourceItemsContainer.DragObject, sourceContainerInfo);
|
||||
|
||||
EnterMove();
|
||||
}
|
||||
|
||||
@@ -164,17 +164,18 @@
|
||||
dd:WidthAndHeightProps.BoundActualHeight="{Binding ActualItemHeight,Mode=OneWayToSource}">
|
||||
<Rectangle x:Name="innter"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
/>
|
||||
StrokeThickness="0"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding BeAttachTo}" Value="True">
|
||||
<Setter TargetName="innter" Property="Margin" Value="-1" />
|
||||
<Setter TargetName="innter" Property="StrokeThickness" Value="1" />
|
||||
<Setter TargetName="innter" Property="Stroke" Value="#f73438" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DisableAttachTo}" Value="True">
|
||||
<Setter TargetName="innter" Property="Margin" Value="-1" />
|
||||
<Setter TargetName="innter" Property="StrokeThickness" Value="1" />
|
||||
<Setter TargetName="innter" Property="Stroke" Value="Gray" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
|
||||
@@ -146,12 +146,12 @@
|
||||
</Control.Style>
|
||||
</Control>
|
||||
</Grid>
|
||||
<dd:BlockItemsContainer x:Name="contain"
|
||||
<dd:BlockItemsContainer x:Name="container"
|
||||
Margin="20"
|
||||
ParentPanel="{Binding ElementName=grid}"
|
||||
GetOffSetFunc="{Binding FirstContain.GetOffSetFunc,Mode=OneWayToSource}"
|
||||
Border="{Binding FirstContain}">
|
||||
<dd:BlockItemsControl x:Name="items" ItemsSource="{Binding FirstContain.Children}">
|
||||
GetOffSetFunc="{Binding FirstContainer.GetOffSetFunc,Mode=OneWayToSource}"
|
||||
Border="{Binding FirstContainer}">
|
||||
<dd:BlockItemsControl x:Name="items" ItemsSource="{Binding FirstContainer.Children}">
|
||||
|
||||
</dd:BlockItemsControl>
|
||||
</dd:BlockItemsContainer>
|
||||
@@ -161,8 +161,8 @@
|
||||
<DataTrigger Binding="{Binding IsSelected}" Value="true">
|
||||
<Setter TargetName="left" Property="Background" Value="#3399FF"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding FirstContain}" Value="{x:Null}">
|
||||
<Setter TargetName="contain" Property="Visibility" Value="Collapsed"/>
|
||||
<DataTrigger Binding="{Binding FirstContainer}" Value="{x:Null}">
|
||||
<Setter TargetName="container" Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
@@ -44,6 +44,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ColorViewModel.FillColor.Color = Colors.Transparent;
|
||||
}
|
||||
|
||||
public new BlockDesignerItemViewModel DataItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as BlockDesignerItemViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanAttachTo(ConnectorInfoBase port)
|
||||
{
|
||||
|
||||
@@ -134,16 +134,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<BlockDesignerItemViewModel> _children = new ObservableCollection<BlockDesignerItemViewModel>();
|
||||
public ObservableCollection<BlockDesignerItemViewModel> Children
|
||||
{
|
||||
get; set;
|
||||
} = new ObservableCollection<BlockDesignerItemViewModel>();
|
||||
get
|
||||
{
|
||||
return _children;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _children, value);
|
||||
}
|
||||
}
|
||||
|
||||
public List<BlockItemsContainerInfo> ChildrenContain
|
||||
{
|
||||
get
|
||||
{
|
||||
return Children?.SelectMany(p => p.Contains)?.ToList();
|
||||
return Children?.SelectMany(p => p.Containers)?.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,13 +159,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataItem.ParentContain == null)
|
||||
if (DataItem.ParentContainer == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DataItem.ParentContain.ContainLevel + 1;
|
||||
return DataItem.ParentContainer.ContainLevel + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,8 +209,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool CanAttachTo(DesignerItemViewModelBase item)
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && item is BlockDesignerItemViewModel;
|
||||
public virtual bool CanAttachTo(BlockDesignerItemViewModel item)
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && item.CanContainTo;
|
||||
#endregion
|
||||
|
||||
public double GetItemWidth()
|
||||
@@ -217,13 +225,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void AddChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
child.ParentContain = this;
|
||||
child.ParentContainer = this;
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
public void RemoveChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
child.ParentContain = null;
|
||||
child.ParentContainer = null;
|
||||
Children.Remove(child);
|
||||
}
|
||||
|
||||
@@ -238,12 +246,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
foreach (var item in children)
|
||||
{
|
||||
if (item.Contains != null)
|
||||
if (item.Containers != null)
|
||||
{
|
||||
foreach (var contain in item.Contains)
|
||||
foreach (var container in item.Containers)
|
||||
{
|
||||
itemsContainers.Add(contain);
|
||||
itemsContainers.AddRange(contain.GetAllContain(contain.Children, false));
|
||||
itemsContainers.Add(container);
|
||||
itemsContainers.AddRange(container.GetAllContain(container.Children, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Reactive.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Xml.Serialization;
|
||||
@@ -1567,7 +1568,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void ExecutedRemoveNextCommand(object parameter)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ExecutedAddChildCommand(object parameter)
|
||||
@@ -3216,7 +3217,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Where(p => p != blockDesignerItemViewModel)
|
||||
.ToList();
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Contains))
|
||||
foreach (var port in items.SelectMany(n => n.Containers))
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
@@ -3253,6 +3254,144 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// type=0最近且没有依附;=1
|
||||
/// </summary>
|
||||
/// <param name="blockDesignerItemViewModel"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemTempLink blockDesignerItemTempLink, bool isExist)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
if (isExist == false)
|
||||
{
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
}
|
||||
|
||||
FullyCreatedConnectorInfo parent = null;
|
||||
FullyCreatedConnectorInfo next = null;
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Connectors).OfType<BlockConnectorInfo>())
|
||||
{
|
||||
//已经被连接的不允许在顶部吸附了
|
||||
if ((port.Orientation == ConnectorOrientation.Top || port.Orientation == ConnectorOrientation.Left) && port.DataItem.Prev != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var port2 in blockDesignerItemTempLink.Connectors)
|
||||
{
|
||||
//parent
|
||||
if (parent == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Right && port2.Orientation == ConnectorOrientation.Left)
|
||||
|| (port.Orientation == ConnectorOrientation.Bottom && port2.Orientation == ConnectorOrientation.Top))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
parent = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//next
|
||||
if (next == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Left && port2.Orientation == ConnectorOrientation.Right)
|
||||
|| (port.Orientation == ConnectorOrientation.Top && port2.Orientation == ConnectorOrientation.Bottom))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
next = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemTempLink blockDesignerItemTempLink)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
return null;
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Containers))
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
innerport.BeAttachTo = true;
|
||||
return innerport;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// innerport.DisableAttachTo = true;
|
||||
// return null;
|
||||
//}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
return port;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// port.DisableAttachTo = true;
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ClearNearPort()
|
||||
{
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
@@ -3260,8 +3399,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ClearNearContain()
|
||||
@@ -3281,10 +3418,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
ClearNearPort();
|
||||
ClearNearContain();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
var contain = FindNearContainerToAttachTo(item);
|
||||
if (contain != null)
|
||||
var container = FindNearContainerToAttachTo(item);
|
||||
if (container != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -3301,14 +3439,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
ClearNearPort();
|
||||
ClearNearContain();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
var contain = FindNearContainerToAttachTo(item);
|
||||
if (contain != null)
|
||||
var container = FindNearContainerToAttachTo(item);
|
||||
if (container != null)
|
||||
{
|
||||
(contain.DataItem as BlockDesignerItemViewModel).AddChild(item);
|
||||
contain.BeAttachTo = false;
|
||||
contain.DisableAttachTo = false;
|
||||
(container.DataItem as BlockDesignerItemViewModel).AddChild(item.Items.FirstOrDefault(), container);//待完善
|
||||
container.BeAttachTo = false;
|
||||
container.DisableAttachTo = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3318,35 +3458,35 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (portParent != null)
|
||||
{
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item);
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item.Items.FirstOrDefault());
|
||||
portParent.BeAttachTo = false;
|
||||
portParent.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Parent != null)
|
||||
if (item.Items.FirstOrDefault().Parent != null)
|
||||
{
|
||||
(item.Parent as BlockDesignerItemViewModel).RemoveNext();
|
||||
(item.Items.FirstOrDefault().Parent as BlockDesignerItemViewModel).RemoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
if (portNext != null)
|
||||
{
|
||||
item.AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
item.Items.LastOrDefault().AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
portNext.BeAttachTo = false;
|
||||
portNext.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Next != null)
|
||||
if (item.Items.LastOrDefault().Next != null)
|
||||
{
|
||||
item.RemoveNext();
|
||||
item.Items.LastOrDefault().RemoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -29,32 +29,40 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Contains.Add(new BlockItemsContainerInfo(this.Root, this));
|
||||
Containers.Add(new BlockItemsContainerInfo(this.Root, this));
|
||||
}
|
||||
|
||||
public override void AddChild(BlockDesignerItemViewModel child)
|
||||
public override void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
var oldchildren = FirstContain.Children.FirstOrDefault();
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
var oldchildren = container.Children.FirstOrDefault();
|
||||
if (oldchildren != null)
|
||||
{
|
||||
this.RemoveChild(oldchildren);
|
||||
this.RemoveChild(oldchildren, container);
|
||||
}
|
||||
|
||||
Root.Items.Remove(child);
|
||||
FirstContain.AddChild(child);
|
||||
container.AddChild(child);
|
||||
|
||||
base.AddChild(child);
|
||||
base.AddChild(child, container);
|
||||
}
|
||||
|
||||
public override void RemoveChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
public override void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Add(child);
|
||||
FirstContain.RemoveChild(child);
|
||||
container.RemoveChild(child);
|
||||
|
||||
this.RemoveFromSelection();
|
||||
child.AddToSelection(true, false);
|
||||
|
||||
base.RemoveChild(child);
|
||||
base.RemoveChild(child, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,23 +29,31 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Contains.Add(new BlockItemsContainerInfo(this.Root, this));
|
||||
Containers.Add(new BlockItemsContainerInfo(this.Root, this));
|
||||
}
|
||||
|
||||
public override void AddChild(BlockDesignerItemViewModel child)
|
||||
public override void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Remove(child);
|
||||
FirstContain.Children.Add(child);
|
||||
container.Children.Add(child);
|
||||
|
||||
base.AddChild(child);
|
||||
base.AddChild(child, container);
|
||||
}
|
||||
|
||||
public override void RemoveChild(BlockDesignerItemViewModel child)
|
||||
public override void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Add(child);
|
||||
FirstContain.Children.Remove(child);
|
||||
container.Children.Remove(child);
|
||||
|
||||
base.RemoveChild(child);
|
||||
base.RemoveChild(child, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockDesignerItemTempLink
|
||||
{
|
||||
List<BlockDesignerItemViewModel> Items
|
||||
public List<BlockDesignerItemViewModel> Items
|
||||
{
|
||||
get;set;
|
||||
get; set;
|
||||
} = new List<BlockDesignerItemViewModel>();
|
||||
|
||||
//public static List<BlockDesignerItemTempLink> Build(List<BlockDesignerItemViewModel> blocks)
|
||||
//{
|
||||
// List<BlockDesignerItemTempLink> links = new List<BlockDesignerItemTempLink>(){
|
||||
// new BlockDesignerItemTempLink() };
|
||||
public RectangleBase GetBounds(bool includePorts = false)
|
||||
{
|
||||
return Items.FirstOrDefault().GetBounds();
|
||||
}
|
||||
|
||||
// foreach(var )
|
||||
//}
|
||||
public List<FullyCreatedConnectorInfo> Connectors
|
||||
{
|
||||
get
|
||||
{
|
||||
List<FullyCreatedConnectorInfo> connectors = new List<FullyCreatedConnectorInfo>();
|
||||
if (Items.FirstOrDefault().TopConnector != null)
|
||||
{
|
||||
connectors.Add(Items.FirstOrDefault().TopConnector);
|
||||
}
|
||||
if (Items.FirstOrDefault().LeftConnector != null)
|
||||
{
|
||||
connectors.Add(Items.FirstOrDefault().LeftConnector);
|
||||
}
|
||||
if (Items.LastOrDefault().BottomConnector != null)
|
||||
{
|
||||
connectors.Add(Items.LastOrDefault().BottomConnector);
|
||||
}
|
||||
if (Items.LastOrDefault().RightConnector != null)
|
||||
{
|
||||
connectors.Add(Items.LastOrDefault().RightConnector);
|
||||
}
|
||||
return connectors;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<BlockDesignerItemTempLink> Build(List<BlockDesignerItemViewModel> blocks)
|
||||
{
|
||||
List<BlockDesignerItemTempLink> links = new List<BlockDesignerItemTempLink>();
|
||||
foreach (var block in blocks.OrderBy(p => p.BlockLevel).ToList())
|
||||
{
|
||||
bool success = false;
|
||||
foreach (var link in links)
|
||||
{
|
||||
if (link.Items.LastOrDefault() == block.Prev)
|
||||
{
|
||||
link.Items.Add(block);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if (success == false)
|
||||
{
|
||||
BlockDesignerItemTempLink link = new BlockDesignerItemTempLink();
|
||||
link.Items.Add(block);
|
||||
links.Add(link);
|
||||
}
|
||||
}
|
||||
return links;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
AlignNext(next);
|
||||
return;
|
||||
}
|
||||
var oldnext = this.Next;
|
||||
RemoveNext();
|
||||
|
||||
next.Left = this.Left;
|
||||
@@ -54,6 +55,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
next.AlignNext(next.Next);
|
||||
}
|
||||
if (oldnext != null)
|
||||
{
|
||||
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
||||
await Task.Delay(10);
|
||||
GetLast().AddNext(oldnext);
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void AlignNext(BlockDesignerItemViewModel next)
|
||||
@@ -97,7 +106,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
IsSelected = selected;
|
||||
}
|
||||
|
||||
public virtual void AddChild(BlockDesignerItemViewModel child)
|
||||
public virtual void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
child.RemoveFromSelection();
|
||||
this.GetRootContainItem.AddToSelection(true, true);
|
||||
@@ -108,7 +117,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}));
|
||||
}
|
||||
|
||||
public virtual void RemoveChild(BlockDesignerItemViewModel child)
|
||||
public virtual void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
this.RemoveFromSelection();
|
||||
|
||||
@@ -120,6 +129,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}));
|
||||
}
|
||||
|
||||
public int BlockLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Prev == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Prev.BlockLevel + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel Prev
|
||||
{
|
||||
get
|
||||
@@ -133,24 +157,45 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo ParentContain
|
||||
public bool CanContainTo
|
||||
{
|
||||
get; set;
|
||||
} = true;
|
||||
|
||||
public BlockItemsContainerInfo ParentContainer
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ObservableCollection<BlockItemsContainerInfo> Contains
|
||||
public ObservableCollection<BlockItemsContainerInfo> Containers
|
||||
{
|
||||
get; set;
|
||||
} = new ObservableCollection<BlockItemsContainerInfo>();
|
||||
|
||||
public BlockItemsContainerInfo FirstContain
|
||||
public BlockItemsContainerInfo FirstContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return Contains?.FirstOrDefault();
|
||||
return Containers?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo SecondContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return Containers?.Skip(1)?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo ThirdContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return Containers?.Skip(2)?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel GetFirst()
|
||||
{
|
||||
var parent = this.Next;
|
||||
@@ -179,20 +224,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public List<BlockItemsContainerInfo> GetAllContain()
|
||||
{
|
||||
return Contains.SelectMany(p => p.GetAllContain(p.Children, true)).ToList();
|
||||
return Containers.SelectMany(p => p.GetAllContain(p.Children, true)).ToList();
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel GetRootContainItem
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ParentContain == null)
|
||||
if (ParentContainer == null)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ParentContain.DataItem.GetRootContainItem;
|
||||
return ParentContainer.DataItem.GetRootContainItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,8 +365,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
#region 公共方法
|
||||
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection, ConnectorVertexType connectorVertexType);
|
||||
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection);
|
||||
Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel, bool isExist);
|
||||
BlockItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel);
|
||||
Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemTempLink blockDesignerItemViewModel, bool isExist);
|
||||
BlockItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemTempLink blockDesignerItemViewModel);
|
||||
void ClearNearPort();
|
||||
void ClearNearContain();
|
||||
void PreviewNearBlock(List<BlockDesignerItemViewModel> blocks);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<!-- Project properties -->
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net461;netcoreapp3.1;net5.0-windows;net6.0-windows</TargetFrameworks>
|
||||
<TargetFrameworks>net461;net5.0-windows;net6.0-windows</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
|
||||
Reference in New Issue
Block a user