mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -53,29 +53,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataItem?.ParentContainer == null)
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this);//Todo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase MiddlePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanAttachTo(ConnectorInfoBase port)
|
||||
{
|
||||
if (port is BlockConnectorInfo blockConnectorInfo)
|
||||
|
||||
@@ -137,27 +137,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
|
||||
|
||||
var containBound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
|
||||
double height = 0;
|
||||
foreach (var child in Children)
|
||||
{
|
||||
child.Left = DataItem.Left + offset.X;
|
||||
child.Top = DataItem.Top + offset.Y + height;
|
||||
height += child.GetItemHeight();
|
||||
}
|
||||
|
||||
return containBound;
|
||||
}
|
||||
|
||||
public List<RectangleBase> GetChildrenBounds()
|
||||
{
|
||||
List<RectangleBase> bounds = new List<RectangleBase>();
|
||||
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
|
||||
|
||||
var containBound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
|
||||
double height = 0;
|
||||
foreach (var child in Children)
|
||||
{
|
||||
var bound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y + height, child.GetItemWidth(), child.GetItemHeight());
|
||||
bounds.Add(bound);
|
||||
|
||||
height += child.GetItemHeight();
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel DataItem
|
||||
{
|
||||
@@ -184,7 +175,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return Children?.SelectMany(p => p.Containers)?.ToList();
|
||||
return Children.SelectMany(p => p.Containers)?.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,10 +247,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
|
||||
}
|
||||
|
||||
public void AddChild(BlockDesignerItemViewModel child)
|
||||
public void InsertChild(BlockDesignerItemViewModel child, int index)
|
||||
{
|
||||
child.ParentContainer = this;
|
||||
Children.Add(child);
|
||||
Children.Insert(index, child);
|
||||
}
|
||||
|
||||
public void RemoveChild(BlockDesignerItemViewModel child)
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
IsSelected = selected;
|
||||
}
|
||||
|
||||
public virtual void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
public virtual void InsertChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container, int index)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
@@ -122,7 +122,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
Root.Items.Remove(child);
|
||||
container.AddChild(child);
|
||||
container.InsertChild(child, index);
|
||||
|
||||
child.RemoveFromSelection();
|
||||
this.GetRootContainItem.AddToSelection(true, true);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -14,20 +15,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
/// <param name="blockDesignerItemViewModel"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(this IDiagramViewModel diagramViewModel, BlockDesignerItemTempLink blockDesignerItemTempLink, bool isExist)
|
||||
public static Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(this IDiagramViewModel diagramViewModel, BlockDesignerItemTempLink blockDesignerItemTempLink)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
if (isExist == false)
|
||||
{
|
||||
items = diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
items = diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
}
|
||||
List<BlockDesignerItemViewModel> items = diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
|
||||
|
||||
return diagramViewModel.FindNearPortToAttachTo(items, blockDesignerItemTempLink);
|
||||
}
|
||||
|
||||
public static Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(this IDiagramViewModel diagramViewModel, List<BlockDesignerItemViewModel> items, BlockDesignerItemTempLink blockDesignerItemTempLink)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
|
||||
|
||||
FullyCreatedConnectorInfo parent = null;
|
||||
FullyCreatedConnectorInfo next = null;
|
||||
@@ -100,10 +101,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public static void ClearNearContain(this IDiagramViewModel diagramViewModel)
|
||||
{
|
||||
diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.GetAllContainers()).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.GetAllContainers()).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
p.Children.SelectMany(n => n.Connectors).Where(q => q.BeAttachTo == true || q.DisableAttachTo == true).ToList().ForEach(q => {
|
||||
q.DisableAttachTo = false;
|
||||
q.BeAttachTo = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -133,9 +138,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
var childrenbounds = container.GetChildrenBounds();
|
||||
|
||||
innerport.BeAttachTo = true;
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
return innerport;
|
||||
}
|
||||
}
|
||||
@@ -151,8 +154,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
container.DataItem.ShowConnectors = true;
|
||||
if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
container.BeAttachTo = true;
|
||||
return container;
|
||||
if (container.OnlyOneChild || container.Children.Count == 0)
|
||||
{
|
||||
container.BeAttachTo = true;
|
||||
return container;
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
@@ -184,7 +195,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
continue;
|
||||
}
|
||||
diagramViewModel.FindNearPortToAttachTo(item, false);
|
||||
diagramViewModel.FindNearPortToAttachTo(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,13 +218,28 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var container = diagramViewModel.FindNearContainerToAttachTo(item);
|
||||
if (container != null)
|
||||
{
|
||||
diagramViewModel.AddChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container });//待完善
|
||||
int index = 0;
|
||||
var child = container.Children.FirstOrDefault(p => p.Connectors.Any(q => q.BeAttachTo == true));
|
||||
if (child != null)
|
||||
{
|
||||
index = container.Children.IndexOf(child);
|
||||
if (child.RightConnector?.BeAttachTo == true || child.BottomConnector?.BeAttachTo == true)
|
||||
{
|
||||
index ++;
|
||||
}
|
||||
}
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });//待完善
|
||||
|
||||
container.BeAttachTo = false;
|
||||
container.DisableAttachTo = false;
|
||||
container.Children.SelectMany(n => n.Connectors).Where(q => q.BeAttachTo == true || q.DisableAttachTo == true).ToList().ForEach(q => {
|
||||
q.DisableAttachTo = false;
|
||||
q.BeAttachTo = false;
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
var portTuple = diagramViewModel.FindNearPortToAttachTo(item, true);
|
||||
var portTuple = diagramViewModel.FindNearPortToAttachTo(item);
|
||||
var portParent = portTuple.Item1;
|
||||
var portNext = portTuple.Item2;
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _addChildCommand;
|
||||
public ICommand AddChildCommand
|
||||
private ICommand _insertChildCommand;
|
||||
public ICommand InsertChildCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._addChildCommand ?? (this._addChildCommand = new SimpleCommand(ExecuteEnable, this.ExecutedAddChildCommand));
|
||||
return this._insertChildCommand ?? (this._insertChildCommand = new SimpleCommand(ExecuteEnable, this.ExecutedInsertChildCommand));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +81,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecutedAddChildCommand(object parameter)
|
||||
private void ExecutedInsertChildCommand(object parameter)
|
||||
{
|
||||
if (parameter is BlockContainerPara blockContainerPara)
|
||||
{
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
blockContainerPara.Item.AddChild(blockContainerPara.Child, blockContainerPara.Container);
|
||||
blockContainerPara.Item.InsertChild(blockContainerPara.Child, blockContainerPara.Container, blockContainerPara.Index);
|
||||
},
|
||||
() => {
|
||||
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
|
||||
@@ -98,12 +98,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (parameter is BlockContainerPara blockContainerPara)
|
||||
{
|
||||
int index = blockContainerPara.Container.Children.IndexOf(blockContainerPara.Child);
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
|
||||
},
|
||||
() => {
|
||||
blockContainerPara.Item.AddChild(blockContainerPara.Child, blockContainerPara.Container);
|
||||
blockContainerPara.Item.InsertChild(blockContainerPara.Child, blockContainerPara.Container, index);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -136,5 +137,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public int Index
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get;
|
||||
}
|
||||
|
||||
ICommand AddChildCommand
|
||||
ICommand InsertChildCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user