mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-27 03:33:25 +08:00
Mind准备序列化,准备分离出model库
This commit is contained in:
@@ -70,27 +70,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
mindNode.AddConnector(port1);
|
||||
var port2 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.25, YRatio = 1 };
|
||||
mindNode.AddConnector(port2);
|
||||
var port3 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Top, true) { XRatio = 0.25, YRatio = 0 };
|
||||
mindNode.AddConnector(port3);
|
||||
|
||||
mindNode.IsInnerConnector = true;
|
||||
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||
mindNode.CornerRadius = new System.Windows.CornerRadius(0);
|
||||
mindNode.BorderThickness = new System.Windows.Thickness(0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
case NodeLevel.Level4:
|
||||
{
|
||||
mindNode.ItemWidth = 80;
|
||||
mindNode.ItemHeight = 25;
|
||||
mindNode.ClearConnectors();
|
||||
|
||||
var port1 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Left, true) { XRatio = 0, YRatio = 0.5 };
|
||||
mindNode.AddConnector(port1);
|
||||
var port2 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.25, YRatio = 1 };
|
||||
mindNode.AddConnector(port2);
|
||||
|
||||
mindNode.IsInnerConnector = true;
|
||||
mindNode.ColorViewModel.FillColor.Color = Colors.Transparent;
|
||||
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||
@@ -105,13 +89,23 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
|
||||
public ConnectionViewModel GetConnectionViewModel(MindNode source, MindNode sink)
|
||||
{
|
||||
DrawMode drawMode = DrawMode.ConnectingLineStraight;
|
||||
RouterMode routerMode = RouterMode.RouterNormal;
|
||||
DrawMode drawMode;
|
||||
RouterMode routerMode;
|
||||
if (source.NodeLevel == NodeLevel.Level1)
|
||||
{
|
||||
drawMode = DrawMode.ConnectingLineStraight;
|
||||
routerMode = RouterMode.RouterFishBone;
|
||||
}
|
||||
else if (source.NodeLevel == NodeLevel.Level2)
|
||||
{
|
||||
drawMode = DrawMode.ConnectingLineStraight;
|
||||
routerMode = RouterMode.RouterNormal;
|
||||
}
|
||||
else
|
||||
{
|
||||
drawMode = DrawMode.ConnectingLineStraight;
|
||||
routerMode = RouterMode.RouterOrthogonal;
|
||||
}
|
||||
|
||||
var connector = new ConnectionViewModel(source.Root, source.Connectors.FirstOrDefault(), sink.Connectors.FirstOrDefault(), drawMode, routerMode);
|
||||
connector.ColorViewModel.LineColor = source.ColorViewModel.LineColor;
|
||||
@@ -139,6 +133,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||
{
|
||||
var sizewithSpacing = mindNode.SizeWithSpacing;
|
||||
var bottomoffset = mindNode.Spacing.Width / 2;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
if (mindNode.NodeLevel == NodeLevel.Level1)
|
||||
@@ -149,15 +144,15 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
var bottoms = mindNode.Children.Where((p, index) => index % 2 == 1).ToList();
|
||||
bottoms.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.TopLeft);
|
||||
var bottomsizes = bottoms.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||
sizewithSpacing = new SizeBase(sizewithSpacing.Width + Math.Max(topsizes.Sum(p => p.Width), bottomsizes.Sum(p => p.Width)), sizewithSpacing.Height + topsizes.Max(p => p.Height) + bottomsizes.Max(p => p.Height));
|
||||
sizewithSpacing = new SizeBase(sizewithSpacing.Width + bottomoffset + Math.Max(topsizes.Sum(p => p.Width), bottomsizes.Sum(p => p.Width)), sizewithSpacing.Height + topsizes.Max(p => p.Height) + bottomsizes.Max(p => p.Height));
|
||||
}
|
||||
else if (mindNode.NodeLevel == NodeLevel.Level2)
|
||||
{
|
||||
var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||
var lastchildsize = childrensizes.LastOrDefault();
|
||||
sizewithSpacing = new SizeBase(sizewithSpacing.Height + childrensizes.Sum(p => p.Height) - lastchildsize.Height / 2 + lastchildsize.Width, sizewithSpacing.Height + childrensizes.Sum(p => p.Height));
|
||||
sizewithSpacing = new SizeBase(Math.Max(sizewithSpacing.Width, sizewithSpacing.Height + childrensizes.Sum(p => p.Height) - lastchildsize.Height / 2 + lastchildsize.Width), sizewithSpacing.Height + childrensizes.Sum(p => p.Height));
|
||||
}
|
||||
else if (mindNode.NodeLevel == NodeLevel.Level3 || mindNode.NodeLevel == NodeLevel.Level4)
|
||||
else if (mindNode.NodeLevel == NodeLevel.Level3)
|
||||
{
|
||||
var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||
sizewithSpacing = new SizeBase(Math.Max(sizewithSpacing.Width, sizewithSpacing.Width * 0.5 + childrensizes.Max(p => p.Width)), sizewithSpacing.Height + childrensizes.Sum(p => p.Height));
|
||||
@@ -195,8 +190,9 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
var bottomoffset = mindNode.Spacing.Width / 2;
|
||||
var bottoms = mindNode.Children.Where(p => p.ConnectorOrientation == ConnectorOrientation.TopLeft).ToList();
|
||||
double bottomleft = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||
double bottomleft = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width + bottomoffset;
|
||||
double bottomtop = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
|
||||
if (mindNode.Children?.Count > 0)
|
||||
@@ -266,25 +262,50 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mindNode.NodeLevel == NodeLevel.Level3 || mindNode.NodeLevel == NodeLevel.Level4)
|
||||
else if (mindNode.NodeLevel == NodeLevel.Level3)
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X;
|
||||
double top = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
if (mindNode.GetLevel2Node().ConnectorOrientation == ConnectorOrientation.BottomLeft)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
double left = mindNode.MiddlePosition.X;
|
||||
double top = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
child.Left = left + child.Offset.X;
|
||||
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||
child.DesiredPosition = child.Position;
|
||||
top += child.DesiredSize.Height;
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Offset.X;
|
||||
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||
child.DesiredPosition = child.Position;
|
||||
top += child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
ArrangeOverride(child);
|
||||
|
||||
var connect = mindNode.Root?.Items.OfType<ConnectionViewModel>().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child);
|
||||
connect?.SetSourcePort(mindNode.BottomConnector);
|
||||
connect?.SetSinkPort(child.LeftConnector);
|
||||
connect?.SetVisible(child.Visible);
|
||||
var connect = mindNode.Root?.Items.OfType<ConnectionViewModel>().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child);
|
||||
connect?.SetSourcePort(mindNode.BottomConnector);
|
||||
connect?.SetSinkPort(child.LeftConnector);
|
||||
connect?.SetVisible(child.Visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double left = mindNode.MiddlePosition.X;
|
||||
double bottom = mindNode.MiddlePosition.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.DesiredPosition = child.Position;
|
||||
bottom -= child.DesiredSize.Height;
|
||||
|
||||
ArrangeOverride(child);
|
||||
|
||||
var connect = mindNode.Root?.Items.OfType<ConnectionViewModel>().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child);
|
||||
connect?.SetSourcePort(mindNode.TopConnector);
|
||||
connect?.SetSinkPort(child.LeftConnector);
|
||||
connect?.SetVisible(child.Visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user