This commit is contained in:
艾竹
2023-06-27 22:57:08 +08:00
parent 6995fe1476
commit d2e00c6149
8 changed files with 70 additions and 73 deletions

View File

@@ -158,7 +158,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (Math.Sqrt(Math.Pow(FirstPoint.Value.X - currentPoint.X, 2) + Math.Pow(FirstPoint.Value.Y - currentPoint.Y, 2)) > 5) if (Math.Sqrt(Math.Pow(FirstPoint.Value.X - currentPoint.X, 2) + Math.Pow(FirstPoint.Value.Y - currentPoint.Y, 2)) > 5)
{ {
FirstPoint = null; FirstPoint = null;
if (Info?.Children?.Count > 0) if (Info?.Children.Count > 0)
{ {
var borders = VisualHelper.FindVisualChildren<BlockGrid>(this); var borders = VisualHelper.FindVisualChildren<BlockGrid>(this);
foreach (var border in borders) foreach (var border in borders)

View File

@@ -77,7 +77,5 @@ namespace AIStudio.Wpf.DiagramDesigner
newY = (newY - connector.DataItem.MiddlePosition.Y) * connector.DataItem.ScaleY + connector.DataItem.MiddlePosition.Y; newY = (newY - connector.DataItem.MiddlePosition.Y) * connector.DataItem.ScaleY + connector.DataItem.MiddlePosition.Y;
return new PointBase(newX, newY); return new PointBase(newX, newY);
} }
} }
} }

View File

@@ -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) public override bool CanAttachTo(ConnectorInfoBase port)
{ {
if (port is BlockConnectorInfo blockConnectorInfo) if (port is BlockConnectorInfo blockConnectorInfo)

View File

@@ -137,27 +137,18 @@ namespace AIStudio.Wpf.DiagramDesigner
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0); var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
var containBound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight()); 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; 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 public BlockDesignerItemViewModel DataItem
{ {
@@ -184,7 +175,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
get 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; return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
} }
public void AddChild(BlockDesignerItemViewModel child) public void InsertChild(BlockDesignerItemViewModel child, int index)
{ {
child.ParentContainer = this; child.ParentContainer = this;
Children.Add(child); Children.Insert(index, child);
} }
public void RemoveChild(BlockDesignerItemViewModel child) public void RemoveChild(BlockDesignerItemViewModel child)

View File

@@ -106,7 +106,7 @@ namespace AIStudio.Wpf.DiagramDesigner
IsSelected = selected; IsSelected = selected;
} }
public virtual void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container) public virtual void InsertChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container, int index)
{ {
if (container == null) if (container == null)
{ {
@@ -122,7 +122,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
Root.Items.Remove(child); Root.Items.Remove(child);
container.AddChild(child); container.InsertChild(child, index);
child.RemoveFromSelection(); child.RemoveFromSelection();
this.GetRootContainItem.AddToSelection(true, true); this.GetRootContainItem.AddToSelection(true, true);

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
namespace AIStudio.Wpf.DiagramDesigner namespace AIStudio.Wpf.DiagramDesigner
{ {
@@ -14,20 +15,20 @@ namespace AIStudio.Wpf.DiagramDesigner
/// <param name="blockDesignerItemViewModel"></param> /// <param name="blockDesignerItemViewModel"></param>
/// <param name="type"></param> /// <param name="type"></param>
/// <returns></returns> /// <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) if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null); return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
List<BlockDesignerItemViewModel> items; List<BlockDesignerItemViewModel> items = diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList();
if (isExist == false)
{ return diagramViewModel.FindNearPortToAttachTo(items, blockDesignerItemTempLink);
items = diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList(); }
}
else public static Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(this IDiagramViewModel diagramViewModel, List<BlockDesignerItemViewModel> items, BlockDesignerItemTempLink blockDesignerItemTempLink)
{ {
items = diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList(); if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
} return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
FullyCreatedConnectorInfo parent = null; FullyCreatedConnectorInfo parent = null;
FullyCreatedConnectorInfo next = null; FullyCreatedConnectorInfo next = null;
@@ -100,10 +101,14 @@ namespace AIStudio.Wpf.DiagramDesigner
public static void ClearNearContain(this IDiagramViewModel diagramViewModel) 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 => { .ForEach(p => {
p.DisableAttachTo = false; p.DisableAttachTo = false;
p.BeAttachTo = 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 else
{ {
var childrenbounds = container.GetChildrenBounds(); diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
innerport.BeAttachTo = true;
return innerport; return innerport;
} }
} }
@@ -151,8 +154,16 @@ namespace AIStudio.Wpf.DiagramDesigner
container.DataItem.ShowConnectors = true; container.DataItem.ShowConnectors = true;
if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true) if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
{ {
container.BeAttachTo = true; if (container.OnlyOneChild || container.Children.Count == 0)
return container; {
container.BeAttachTo = true;
return container;
}
else
{
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
return container;
}
} }
//else //else
//{ //{
@@ -184,7 +195,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
continue; continue;
} }
diagramViewModel.FindNearPortToAttachTo(item, false); diagramViewModel.FindNearPortToAttachTo(item);
} }
} }
} }
@@ -207,13 +218,28 @@ namespace AIStudio.Wpf.DiagramDesigner
var container = diagramViewModel.FindNearContainerToAttachTo(item); var container = diagramViewModel.FindNearContainerToAttachTo(item);
if (container != null) 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.BeAttachTo = false;
container.DisableAttachTo = 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; continue;
} }
var portTuple = diagramViewModel.FindNearPortToAttachTo(item, true); var portTuple = diagramViewModel.FindNearPortToAttachTo(item);
var portParent = portTuple.Item1; var portParent = portTuple.Item1;
var portNext = portTuple.Item2; var portNext = portTuple.Item2;

View File

@@ -33,12 +33,12 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
private ICommand _addChildCommand; private ICommand _insertChildCommand;
public ICommand AddChildCommand public ICommand InsertChildCommand
{ {
get 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) if (parameter is BlockContainerPara blockContainerPara)
{ {
DoCommandManager.DoNewCommand(this.ToString(), 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); blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
@@ -98,12 +98,13 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
if (parameter is BlockContainerPara blockContainerPara) if (parameter is BlockContainerPara blockContainerPara)
{ {
int index = blockContainerPara.Container.Children.IndexOf(blockContainerPara.Child);
DoCommandManager.DoNewCommand(this.ToString(), DoCommandManager.DoNewCommand(this.ToString(),
() => { () => {
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container); 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; get; set;
} }
public int Index
{
get;set;
}
} }
} }

View File

@@ -19,7 +19,7 @@ namespace AIStudio.Wpf.DiagramDesigner
get; get;
} }
ICommand AddChildCommand ICommand InsertChildCommand
{ {
get; get;
} }