diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml index 72e6083..a26c554 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml +++ b/AIStudio.Wpf.DiagramDesigner/Controls/BlockItemsControl.xaml @@ -12,7 +12,10 @@ - + diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs index 7fd1698..f297fe4 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Container/BlockItemsContainerInfo.cs @@ -136,7 +136,13 @@ namespace AIStudio.Wpf.DiagramDesigner { var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0); - return 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()); + //foreach(var child in Children) + //{ + // var bound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, child.GetItemWidth(), child.GetItemHeight()); + //} + + return containBound; } public BlockDesignerItemViewModel DataItem diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModelHelper.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModelHelper.cs index 3c4d48b..d6812de 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModelHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BlockViewModel/BlockDesignerItemViewModelHelper.cs @@ -8,142 +8,6 @@ namespace AIStudio.Wpf.DiagramDesigner { public static class BlockDesignerItemViewModelHelper { - /// - /// type=0最近且没有依附;=1 - /// - /// - /// - /// - public static Tuple FindNearPortToAttachTo(this IDiagramViewModel diagramViewModel, BlockDesignerItemViewModel blockDesignerItemViewModel, bool isExist) - { - if (blockDesignerItemViewModel == null) - return new Tuple(null, null); - - List items; - if (isExist == false) - { - items = diagramViewModel.Items.OfType(). - Where(p => p != blockDesignerItemViewModel && p != blockDesignerItemViewModel.Parent && p != blockDesignerItemViewModel.Next) - .ToList(); - - } - else - { - items = diagramViewModel.Items.OfType(). - Where(p => p != blockDesignerItemViewModel) - .ToList(); - } - - FullyCreatedConnectorInfo parent = null; - FullyCreatedConnectorInfo next = null; - - foreach (var port in items.SelectMany(n => n.Connectors)) - { - foreach (var port2 in blockDesignerItemViewModel.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) < diagramViewModel.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) < diagramViewModel.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(parent, next); - } - - public static BlockItemsContainerInfo FindNearContainerToAttachTo(this IDiagramViewModel diagramViewModel, BlockDesignerItemViewModel blockDesignerItemViewModel) - { - if (blockDesignerItemViewModel == null) - return null; - - List items; - - items = diagramViewModel.Items.OfType(). - Where(p => p != blockDesignerItemViewModel) - .ToList(); - - foreach (var port in items.SelectMany(n => n.Containers)) - { - if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交 - { - var innerport = port.GetAllContainers(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault(); - if (innerport != null) - { - innerport.DataItem.ShowConnectors = true; - if (innerport.CanAttachTo(blockDesignerItemViewModel) == true) - { - innerport.BeAttachTo = true; - } - else - { - innerport.DisableAttachTo = true; - } - return innerport; - } - else - { - port.DataItem.ShowConnectors = true; - if (port.CanAttachTo(blockDesignerItemViewModel) == true) - { - port.BeAttachTo = true; - } - else - { - port.DisableAttachTo = true; - } - return port; - } - } - } - - return null; - } - /// /// type=0最近且没有依附;=1 /// @@ -252,18 +116,26 @@ namespace AIStudio.Wpf.DiagramDesigner items = diagramViewModel.Items.OfType().Where(p => !blockDesignerItemTempLink.Items.Contains(p)).ToList(); - foreach (var port in items.SelectMany(n => n.Containers)) + foreach (var container in items.SelectMany(n => n.Containers)) { - if (port.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())) //如果两个位置相交 + if (container.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())) //如果两个位置相交 { - var innerport = port.GetAllContainers(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault(); + var innerport = container.GetAllContainers(container.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault(); if (innerport != null) { innerport.DataItem.ShowConnectors = true; if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true) { - innerport.BeAttachTo = true; - return innerport; + if (innerport.OnlyOneChild) + { + innerport.BeAttachTo = true; + return innerport; + } + else + { + innerport.BeAttachTo = true; + return innerport; + } } //else //{ @@ -274,11 +146,11 @@ namespace AIStudio.Wpf.DiagramDesigner } else { - port.DataItem.ShowConnectors = true; - if (port.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true) + container.DataItem.ShowConnectors = true; + if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true) { - port.BeAttachTo = true; - return port; + container.BeAttachTo = true; + return container; } //else //{