mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-04 16:16:34 +08:00
offset修复一半
This commit is contained in:
@@ -29,7 +29,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
private bool drag;
|
||||
private void DragThumb_DragStarted(object sender, DragStartedEventArgs e)
|
||||
{
|
||||
GetDesignerCanvas(this)?.Focus();
|
||||
GetDesignerCanvas(this)?.Focus();
|
||||
|
||||
drag = false;
|
||||
SelectableDesignerItemViewModelBase designerItem = this.DataContext as SelectableDesignerItemViewModelBase;
|
||||
@@ -61,7 +61,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
|
||||
DiagramViewModel.DoCommandManager.BeginDo = true;
|
||||
foreach (DesignerItemViewModelBase item in designerItems.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
{
|
||||
item.SetOldValue(item.TopLeft, nameof(item.TopLeft));
|
||||
}
|
||||
|
||||
@@ -75,7 +75,11 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
|
||||
private void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e)
|
||||
{
|
||||
if (drag == false) return;
|
||||
if (drag == false)
|
||||
{
|
||||
DiagramViewModel.DoCommandManager.BeginDo = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (designerItems != null)
|
||||
{
|
||||
@@ -84,9 +88,9 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
item.SetCellAlignment();
|
||||
}
|
||||
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<PointBase, PointBase>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<PointBase, PointBase>(p.GetOldValue< PointBase >(nameof(p.TopLeft)), p.TopLeft));
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<PointBase, PointBase>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<PointBase, PointBase>(p.GetOldValue<PointBase>(nameof(p.TopLeft)), p.TopLeft));
|
||||
DiagramViewModel.DoCommandManager.BeginDo = false;
|
||||
DiagramViewModel.DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
@@ -110,23 +114,12 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
drag = true;
|
||||
if (designerItems != null)
|
||||
{
|
||||
double minLeft = double.MaxValue;
|
||||
double minTop = double.MaxValue;
|
||||
|
||||
foreach (DesignerItemViewModelBase item in designerItems.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
double left = item.Left;
|
||||
double top = item.Top;
|
||||
minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
|
||||
minTop = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
|
||||
|
||||
double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
|
||||
double deltaVertical = Math.Max(-minTop, e.VerticalChange);
|
||||
item.Left += deltaHorizontal;
|
||||
item.Top += deltaVertical;
|
||||
item.Left += e.HorizontalChange;
|
||||
item.Top += e.VerticalChange;
|
||||
}
|
||||
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,10 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
}
|
||||
|
||||
private List<SelectableDesignerItemViewModelBase> designerItems;
|
||||
IDiagramViewModel diagarmViewModel;
|
||||
|
||||
private void ResizeThumb_DragStarted(object sender, DragStartedEventArgs e)
|
||||
{
|
||||
DesignerItemViewModelBase designerItem = this.DataContext as DesignerItemViewModelBase;
|
||||
diagarmViewModel = designerItem.Root;
|
||||
if (designerItem != null && designerItem.IsSelected)
|
||||
{
|
||||
designerItems = designerItem.Root.SelectedItems.ToList();
|
||||
@@ -55,14 +53,10 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
{
|
||||
if (designerItems != null)
|
||||
{
|
||||
foreach (DesignerItemViewModelBase item in designerItems.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<SizeBase, SizeBase>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<SizeBase, SizeBase>(p.GetOldValue<SizeBase>(nameof(p.Size)), p.Size));
|
||||
|
||||
DiagramViewModel.DoCommandManager.BeginDo = false;
|
||||
DiagramViewModel.DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
@@ -101,13 +95,13 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
case VerticalAlignment.Bottom:
|
||||
dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
|
||||
scale = (item.ItemHeight - dragDeltaVertical) / item.ItemHeight;
|
||||
DragBottom(scale, item, diagarmViewModel.SelectionService);
|
||||
DragBottom(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
case VerticalAlignment.Top:
|
||||
double top = item.Top;
|
||||
dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
|
||||
scale = (item.ItemHeight - dragDeltaVertical) / item.ItemHeight;
|
||||
DragTop(scale, item, diagarmViewModel.SelectionService);
|
||||
DragTop(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -119,12 +113,12 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
double left = item.Left;
|
||||
dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
|
||||
scale = (item.ItemWidth - dragDeltaHorizontal) / item.ItemWidth;
|
||||
DragLeft(scale, item, diagarmViewModel.SelectionService);
|
||||
DragLeft(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
case HorizontalAlignment.Right:
|
||||
dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
|
||||
scale = (item.ItemWidth - dragDeltaHorizontal) / item.ItemWidth;
|
||||
DragRight(scale, item, diagarmViewModel.SelectionService);
|
||||
DragRight(scale, item, DiagramViewModel.SelectionService);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -75,11 +75,6 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
|
||||
if (this.designerItems != null)
|
||||
{
|
||||
foreach (DesignerItemViewModelBase item in designerItems.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Dictionary<DesignerItemViewModelBase, Tuple<double, double>> infos =
|
||||
designerItems.OfType<DesignerItemViewModelBase>().ToDictionary(p => p,
|
||||
p => new Tuple<double, double>(p.GetOldValue<double>(nameof(p.Angle)), p.Angle));
|
||||
|
||||
@@ -66,9 +66,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
UnDoActionStack = new Stack<Command>();
|
||||
}
|
||||
|
||||
private bool _beginDo;
|
||||
public bool BeginDo
|
||||
{
|
||||
get;set;
|
||||
get
|
||||
{
|
||||
return _beginDo;
|
||||
}
|
||||
set
|
||||
{
|
||||
_beginDo = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _undoing;
|
||||
@@ -76,7 +84,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (BeginDo == true)
|
||||
return;
|
||||
if (_undoing == true)
|
||||
if (_undoing == true)
|
||||
return;
|
||||
try
|
||||
{
|
||||
@@ -111,7 +119,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (!CanUnDo)
|
||||
return;
|
||||
|
||||
if (_undoing == true)
|
||||
if (_undoing == true)
|
||||
return;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -102,13 +102,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = true;
|
||||
var size = MeasureOverride(mindNode);
|
||||
ArrangeOverride(mindNode);
|
||||
|
||||
mindNode.Root.BringToFrontCommand.Execute(mindNode.Root.Items.OfType<DesignerItemViewModelBase>());
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,9 +144,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.DesiredSize.Width / 2 - child.ItemWidth / 2 + child.Offset.X;
|
||||
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(left + child.DesiredSize.Width / 2 - child.ItemWidth / 2, top + child.Spacing.Height);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
|
||||
left += child.DesiredSize.Width;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -159,18 +161,20 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
mindNode.Offset = new PointBase();//修正后归0
|
||||
}
|
||||
else
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X;
|
||||
double top = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
double left = mindNode.DesiredMiddlePosition.X;
|
||||
double top = mindNode.DesiredMiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Offset.X;
|
||||
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(left, top + child.Spacing.Height);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
top += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = true;
|
||||
|
||||
switch (mindNode.NodeLevel)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
public ConnectionViewModel GetOrSetConnectionViewModel(MindNode source, MindNode sink, ConnectionViewModel connector = null)
|
||||
@@ -129,13 +129,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = true;
|
||||
var size = MeasureOverride(mindNode);
|
||||
ArrangeOverride(mindNode);
|
||||
|
||||
mindNode.Root.BringToFrontCommand.Execute(mindNode.Root.Items.OfType<DesignerItemViewModelBase>());
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||
@@ -184,9 +184,10 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
foreach (var child in tops)
|
||||
{
|
||||
child.Left = topleft + child.Spacing.Width + child.Offset.X;
|
||||
child.Top = toptop - child.ItemHeight - child.Spacing.Height + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(topleft + child.Spacing.Width, toptop - child.ItemHeight - child.Spacing.Height);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
topleft += child.DesiredSize.Width;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -207,9 +208,10 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
foreach (var child in bottoms)
|
||||
{
|
||||
child.Left = bottomleft + child.Spacing.Width + child.Offset.X;
|
||||
child.Top = bottomtop + child.Spacing.Height + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(bottomleft + child.Spacing.Width, bottomtop + child.Spacing.Height);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
bottomleft += child.DesiredSize.Width;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -222,21 +224,23 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
mindNode.Offset = new PointBase();//修正后归0
|
||||
}
|
||||
else if (mindNode.NodeLevel == 1)
|
||||
{
|
||||
if (mindNode.ConnectorOrientation == ConnectorOrientation.BottomLeft)
|
||||
{
|
||||
double x0 = mindNode.Left;
|
||||
double y0 = mindNode.Top + mindNode.ItemHeight;
|
||||
double x0 = mindNode.DesiredPosition.X;
|
||||
double y0 = mindNode.DesiredPosition.Y + mindNode.ItemHeight;
|
||||
double h = mindNode.ItemHeight + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = x0 + (h + child.DesiredSize.Height - child.ItemHeight / 2 - child.Spacing.Height) + child.Offset.X;
|
||||
child.Top = y0 - (h + child.DesiredSize.Height - child.Spacing.Height) + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(x0 + (h + child.DesiredSize.Height - child.ItemHeight / 2 - child.Spacing.Height), y0 - (h + child.DesiredSize.Height - child.Spacing.Height));
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
h += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -250,16 +254,17 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
double x0 = mindNode.Left;
|
||||
double y0 = mindNode.Top;
|
||||
double x0 = mindNode.DesiredPosition.X;
|
||||
double y0 = mindNode.DesiredPosition.Y;
|
||||
double h = mindNode.ItemHeight + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = x0 + (h + child.DesiredSize.Height - child.ItemHeight / 2 - child.Spacing.Height) + child.Offset.X;
|
||||
child.Top = y0 + (h + child.DesiredSize.Height - child.ItemHeight - child.Spacing.Height) + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(x0 + (h + child.DesiredSize.Height - child.ItemHeight / 2 - child.Spacing.Height), y0 + (h + child.DesiredSize.Height - child.ItemHeight - child.Spacing.Height));
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
h += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -274,17 +279,18 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mindNode.GetLevel2Node().ConnectorOrientation == ConnectorOrientation.BottomLeft)
|
||||
if (mindNode.GetLevel1Node().ConnectorOrientation == ConnectorOrientation.BottomLeft)
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X;
|
||||
double top = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
double left = mindNode.DesiredMiddlePosition.X;
|
||||
double top = mindNode.DesiredMiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Offset.X;
|
||||
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(left, top + child.Spacing.Height);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
top += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -298,15 +304,16 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X;
|
||||
double bottom = mindNode.MiddlePosition.Y - mindNode.ItemHeight / 2 - mindNode.Spacing.Height;
|
||||
double left = mindNode.DesiredMiddlePosition.X;
|
||||
double bottom = mindNode.DesiredMiddlePosition.Y - mindNode.ItemHeight / 2 - mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Offset.X;
|
||||
child.Top = bottom - child.Spacing.Height - child.ItemHeight + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(left, bottom - child.Spacing.Height - child.ItemHeight);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
bottom -= child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
|
||||
@@ -101,13 +101,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = true;
|
||||
var size = MeasureOverride(mindNode);
|
||||
ArrangeOverride(mindNode);
|
||||
|
||||
mindNode.Root.BringToFrontCommand.Execute(mindNode.Root.Items.OfType<DesignerItemViewModelBase>());
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||
@@ -126,15 +126,21 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
|
||||
public void ArrangeOverride(MindNode mindNode)
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||
double top = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
if (mindNode.NodeLevel == 0)
|
||||
{
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
}
|
||||
|
||||
double left = mindNode.DesiredMiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||
double top = mindNode.DesiredMiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Spacing.Width + child.Offset.X;
|
||||
child.Top = top + child.DesiredSize.Height / 2 - child.ItemHeight / 2 + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(left + child.Spacing.Width, top + child.DesiredSize.Height / 2 - child.ItemHeight / 2);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
top += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -144,8 +150,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
connector?.SetSinkPort(child.LeftConnector);
|
||||
connector?.SetVisible(child.Visible);
|
||||
}
|
||||
}
|
||||
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
if (mindNode.NodeLevel == 0)
|
||||
{
|
||||
mindNode.Offset = new PointBase();//修正后归0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,13 +103,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = true;
|
||||
var size = MeasureOverride(mindNode);
|
||||
ArrangeOverride(mindNode);
|
||||
|
||||
mindNode.Root.BringToFrontCommand.Execute(mindNode.Root.Items.OfType<DesignerItemViewModelBase>());
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||
@@ -150,9 +150,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
double lefttop = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, rights.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
foreach (var child in rights)
|
||||
{
|
||||
child.Left = left + child.Spacing.Width + child.Offset.X - child.RootNode.Offset.X;
|
||||
child.Top = lefttop + child.DesiredSize.Height / 2 - child.ItemHeight / 2 + child.Offset.Y - child.RootNode.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);
|
||||
|
||||
child.DesiredPosition = new PointBase(left + child.Spacing.Width, lefttop + child.DesiredSize.Height / 2 - child.ItemHeight / 2);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
lefttop += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -168,9 +170,10 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
double righttop = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, lefts.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
foreach (var child in lefts)
|
||||
{
|
||||
child.Left = right - child.Spacing.Width - child.ItemWidth + child.Offset.X - child.RootNode.Offset.X;
|
||||
child.Top = righttop + child.DesiredSize.Height / 2 - child.ItemHeight / 2 + child.Offset.Y - child.RootNode.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);
|
||||
child.DesiredPosition = new PointBase(right - child.Spacing.Width - child.ItemWidth, righttop + child.DesiredSize.Height / 2 - child.ItemHeight / 2);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
righttop += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -182,22 +185,23 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
//mindNode.Offset = new PointBase();
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
mindNode.Offset = new PointBase();//修正后归0
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mindNode.GetLevel2Node().ConnectorOrientation == ConnectorOrientation.Left)
|
||||
if (mindNode.GetLevel1Node().ConnectorOrientation == ConnectorOrientation.Left)
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||
double top = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
double left = mindNode.DesiredMiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||
double top = mindNode.DesiredMiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Spacing.Width + child.Offset.X - child.RootNode.Offset.X;
|
||||
child.Top = top + child.DesiredSize.Height / 2 - child.ItemHeight / 2 + child.Offset.Y - child.RootNode.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);
|
||||
child.DesiredPosition = new PointBase(left + child.Spacing.Width, top + child.DesiredSize.Height / 2 - child.ItemHeight / 2);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
top += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -211,15 +215,16 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
double right = mindNode.MiddlePosition.X - mindNode.ItemWidth / 2 - mindNode.Spacing.Width;
|
||||
double top = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
double right = mindNode.DesiredMiddlePosition.X - mindNode.ItemWidth / 2 - mindNode.Spacing.Width;
|
||||
double top = mindNode.DesiredMiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.SumOrDefault(p => p.DesiredSize.Height)) / 2;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = right - child.Spacing.Width - child.ItemWidth + child.Offset.X - child.RootNode.Offset.X;
|
||||
child.Top = top + child.DesiredSize.Height / 2 - child.ItemHeight / 2 + child.Offset.Y - child.RootNode.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);
|
||||
child.DesiredPosition = new PointBase(right - child.Spacing.Width - child.ItemWidth, top + child.DesiredSize.Height / 2 - child.ItemHeight / 2);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
top += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
|
||||
@@ -103,13 +103,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = true;
|
||||
var size = MeasureOverride(mindNode);
|
||||
ArrangeOverride(mindNode);
|
||||
|
||||
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
mindNode.GetLevel0Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||
@@ -128,15 +128,21 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
|
||||
public void ArrangeOverride(MindNode mindNode)
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X - Math.Max(mindNode.DesiredSize.Width, mindNode.Children.SumOrDefault(p => p.DesiredSize.Width)) / 2;
|
||||
double top = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
if (mindNode.NodeLevel == 0)
|
||||
{
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
}
|
||||
|
||||
double left = mindNode.DesiredMiddlePosition.X - Math.Max(mindNode.DesiredSize.Width, mindNode.Children.SumOrDefault(p => p.DesiredSize.Width)) / 2;
|
||||
double top = mindNode.DesiredMiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.DesiredSize.Width / 2 - child.ItemWidth / 2 + child.Offset.X;
|
||||
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||
child.Offset = new PointBase(child.Offset.X - child.RootNode.Offset.X, child.Offset.Y - child.RootNode.Offset.Y);//按根节点修正Offset
|
||||
child.DesiredPosition = new PointBase(left + child.DesiredSize.Width / 2 - child.ItemWidth / 2, top + child.Spacing.Height);
|
||||
child.Left = child.DesiredPosition.X + child.Offset.X;
|
||||
child.Top = child.DesiredPosition.Y + child.Offset.Y;
|
||||
left += child.DesiredSize.Width;
|
||||
|
||||
ArrangeOverride(child);
|
||||
@@ -151,7 +157,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
|
||||
if (mindNode.NodeLevel == 0)
|
||||
{
|
||||
mindNode.DesiredPosition = mindNode.Position;
|
||||
mindNode.Offset = new PointBase();//修正后归0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetLevel1Node();
|
||||
return GetLevel0Node();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,11 +242,19 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
get; set;
|
||||
}
|
||||
|
||||
public PointBase? DesiredPosition
|
||||
public PointBase DesiredPosition
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public PointBase DesiredMiddlePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return new PointBase(this.DesiredPosition.X + ItemWidth / 2, this.DesiredPosition.Y + ItemHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public PointBase Offset
|
||||
{
|
||||
get; set;
|
||||
@@ -463,6 +471,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
}
|
||||
this.Parent = parent;
|
||||
this.ParentId = parent?.Id ?? Guid.Empty;
|
||||
this.Offset = parent?.Offset ?? new PointBase();
|
||||
this.InitLayout(true);//因为节点的层级不同的样式,所以需要Parent确定后才能初始化
|
||||
this.InitConnectLayout();
|
||||
|
||||
@@ -520,7 +529,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
#endregion
|
||||
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (GetLevel1Node()?.LayoutUpdating == true) return;
|
||||
if (GetLevel0Node()?.LayoutUpdating == true) return;
|
||||
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
@@ -529,6 +538,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
|
||||
{
|
||||
UpdateOffsetX((double)valuePropertyChangedEventArgs.OldValue, (double)valuePropertyChangedEventArgs.NewValue);
|
||||
Console.WriteLine((sender as MindNode).Text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -615,7 +625,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
IsSelected = selected;
|
||||
}
|
||||
#region 布局相关
|
||||
public MindNode GetLevel1Node()
|
||||
public MindNode GetLevel0Node()
|
||||
{
|
||||
var node = this;
|
||||
while (node.Parent is MindNode mindNode)
|
||||
@@ -625,7 +635,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
return node;
|
||||
}
|
||||
|
||||
public MindNode GetLevel2Node()
|
||||
public MindNode GetLevel1Node()
|
||||
{
|
||||
var node = this;
|
||||
while (node.Parent is MindNode mindNode && mindNode.NodeLevel == 1)
|
||||
@@ -673,7 +683,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
|
||||
public void LayoutUpdated()
|
||||
{
|
||||
MindLayout?.LayoutUpdated(GetLevel1Node());
|
||||
MindLayout?.LayoutUpdated(GetLevel0Node());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user