mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
@@ -1449,7 +1449,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return items;
|
||||
}
|
||||
|
||||
protected virtual void ExecuteDeleteCommand(object parameter)
|
||||
protected void ExecuteDeleteCommand(object parameter)
|
||||
{
|
||||
var items = Delete(parameter, false);
|
||||
if (items.Any())
|
||||
@@ -1580,11 +1580,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
double mid = selectedItems.Select(p => p.Top + p.GetItemHeight() / 2).Average();
|
||||
double mid = selectedItems.Select(p => p.Top + p.ItemHeight / 2).Average();
|
||||
|
||||
foreach (DesignerItemViewModelBase item in selectedItems)
|
||||
{
|
||||
item.Top = mid - item.GetItemHeight() / 2;
|
||||
item.Top = mid - item.ItemHeight / 2;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -1618,11 +1618,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
double top = selectedItems.OrderBy(p => p.Top + p.GetItemHeight()).Select(p => p.Top + p.GetItemHeight()).LastOrDefault();
|
||||
double top = selectedItems.OrderBy(p => p.Top + p.ItemHeight).Select(p => p.Top + p.ItemHeight).LastOrDefault();
|
||||
|
||||
foreach (DesignerItemViewModelBase item in selectedItems)
|
||||
{
|
||||
item.Top = top - item.GetItemHeight();
|
||||
item.Top = top - item.ItemHeight;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -1694,11 +1694,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
double mid = selectedItems.Select(p => p.Left + p.GetItemWidth() / 2).Average();
|
||||
double mid = selectedItems.Select(p => p.Left + p.ItemWidth / 2).Average();
|
||||
|
||||
foreach (DesignerItemViewModelBase item in selectedItems)
|
||||
{
|
||||
item.Left = mid - item.GetItemWidth() / 2;
|
||||
item.Left = mid - item.ItemWidth / 2;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -1732,11 +1732,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
double right = selectedItems.OrderBy(p => p.Left + p.GetItemWidth()).Select(p => p.Left + p.GetItemWidth()).LastOrDefault();
|
||||
double right = selectedItems.OrderBy(p => p.Left + p.ItemWidth).Select(p => p.Left + p.ItemWidth).LastOrDefault();
|
||||
|
||||
foreach (DesignerItemViewModelBase item in selectedItems)
|
||||
{
|
||||
item.Left = right - item.GetItemWidth();
|
||||
item.Left = right - item.ItemWidth;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -1975,8 +1975,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
foreach (DesignerItemViewModelBase item in selectedItems)
|
||||
{
|
||||
left = Math.Min(left, item.Left);
|
||||
right = Math.Max(right, item.Left + item.GetItemWidth());
|
||||
sumWidth += item.GetItemWidth();
|
||||
right = Math.Max(right, item.Left + item.ItemWidth);
|
||||
sumWidth += item.ItemWidth;
|
||||
}
|
||||
|
||||
double distance = Math.Max(0, (right - left - sumWidth) / (selectedItems.Count() - 1));
|
||||
@@ -1989,7 +1989,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
di.Left += delta;
|
||||
}
|
||||
offset = offset + item.GetItemWidth() + distance;
|
||||
offset = offset + item.ItemWidth + distance;
|
||||
}
|
||||
|
||||
},
|
||||
@@ -2030,8 +2030,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
foreach (DesignerItemViewModelBase item in selectedItems)
|
||||
{
|
||||
top = Math.Min(top, item.Top);
|
||||
bottom = Math.Max(bottom, item.Top + item.GetItemHeight());
|
||||
sumHeight += item.GetItemHeight();
|
||||
bottom = Math.Max(bottom, item.Top + item.ItemHeight);
|
||||
sumHeight += item.ItemHeight;
|
||||
}
|
||||
|
||||
double distance = Math.Max(0, (bottom - top - sumHeight) / (selectedItems.Count() - 1));
|
||||
@@ -2044,7 +2044,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
di.Top += +delta;
|
||||
}
|
||||
offset = offset + item.GetItemHeight() + distance;
|
||||
offset = offset + item.ItemHeight + distance;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -2264,8 +2264,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
() => {
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
item.ItemWidth = selectedItems.FirstOrDefault().GetItemWidth();
|
||||
item.ItemHeight = selectedItems.FirstOrDefault().GetItemHeight();
|
||||
item.ItemWidth = selectedItems.FirstOrDefault().ItemWidth;
|
||||
item.ItemHeight = selectedItems.FirstOrDefault().ItemHeight;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -2295,13 +2295,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (selectedItems.Count > 1)
|
||||
{
|
||||
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.GetItemWidth());
|
||||
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.ItemWidth);
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
item.ItemWidth = selectedItems.FirstOrDefault().GetItemWidth();
|
||||
item.ItemWidth = selectedItems.FirstOrDefault().ItemWidth;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -2331,13 +2331,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (selectedItems.Count > 1)
|
||||
{
|
||||
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.GetItemHeight());
|
||||
Dictionary<DesignerItemViewModelBase, double> infos = selectedItems.ToDictionary(p => p, p => p.ItemHeight);
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
item.ItemHeight = selectedItems.FirstOrDefault().GetItemHeight();
|
||||
item.ItemHeight = selectedItems.FirstOrDefault().ItemHeight;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -3145,37 +3145,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
}
|
||||
|
||||
public ItemsContainerInfo FindNearContainerToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel)
|
||||
{
|
||||
if (blockDesignerItemViewModel == null)
|
||||
return null;
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().
|
||||
Where(p => p != blockDesignerItemViewModel)
|
||||
.ToList();
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Contains))
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port.CanAttachTo(blockDesignerItemViewModel) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ClearNearPort()
|
||||
{
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
@@ -3183,91 +3152,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ClearNearContain()
|
||||
{
|
||||
Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.Contains).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Block拖拽预览-拖拽完成
|
||||
public void PreviewNearBlock(List<BlockDesignerItemViewModel> blocks)
|
||||
{
|
||||
if (blocks.Any())
|
||||
{
|
||||
ClearNearPort();
|
||||
ClearNearContain();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
{
|
||||
var contain = FindNearContainerToAttachTo(item);
|
||||
if (contain != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
FindNearPortToAttachTo(item, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void FinishNearBlock(List<BlockDesignerItemViewModel> blocks)
|
||||
{
|
||||
if (blocks.Any())
|
||||
{
|
||||
ClearNearPort();
|
||||
ClearNearContain();
|
||||
foreach (BlockDesignerItemViewModel item in blocks)
|
||||
{
|
||||
var contain = FindNearContainerToAttachTo(item);
|
||||
if (contain != null)
|
||||
{
|
||||
(contain.DataItem as BlockDesignerItemViewModel).AddChild(item);
|
||||
contain.BeAttachTo = false;
|
||||
contain.DisableAttachTo = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
var portTuple = FindNearPortToAttachTo(item, true);
|
||||
var portParent = portTuple.Item1;
|
||||
var portNext = portTuple.Item2;
|
||||
|
||||
if (portParent != null)
|
||||
{
|
||||
(portParent.DataItem as BlockDesignerItemViewModel).AddNext(item);
|
||||
portParent.BeAttachTo = false;
|
||||
portParent.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Parent != null)
|
||||
{
|
||||
(item.Parent as BlockDesignerItemViewModel).RemoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
if (portNext != null)
|
||||
{
|
||||
item.AddNext(portNext.DataItem as BlockDesignerItemViewModel);
|
||||
portNext.BeAttachTo = false;
|
||||
portNext.DisableAttachTo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Next != null)
|
||||
{
|
||||
item.RemoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user