mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-05-04 06:51:28 +08:00
调试中
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@ namespace AIStudio.Wpf.Flowchart
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private MindType _mindType = Mind.MindType.Directory;
|
private MindType _mindType = Mind.MindType.Organizational;
|
||||||
public MindType MindType
|
public MindType MindType
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -55,8 +55,10 @@ namespace AIStudio.Wpf.Flowchart
|
|||||||
base.Init();
|
base.Init();
|
||||||
|
|
||||||
MindNode level1node = new MindNode(DiagramViewModel, Mind.NodeLevel.Level1, MindType) { Text = "思维导图" };
|
MindNode level1node = new MindNode(DiagramViewModel, Mind.NodeLevel.Level1, MindType) { Text = "思维导图" };
|
||||||
|
level1node.Left = 220;
|
||||||
|
level1node.Top = 15;
|
||||||
DiagramViewModel.DirectAddItemCommand.Execute(level1node);
|
DiagramViewModel.DirectAddItemCommand.Execute(level1node);
|
||||||
DiagramViewModel.CenterMoveCommand.Execute(level1node);
|
//DiagramViewModel.CenterMoveCommand.Execute(level1node);
|
||||||
|
|
||||||
MindNode level2node1_1 = new MindNode(DiagramViewModel, Mind.NodeLevel.Level2, MindType) { Text = "分支主题1" };
|
MindNode level2node1_1 = new MindNode(DiagramViewModel, Mind.NodeLevel.Level2, MindType) { Text = "分支主题1" };
|
||||||
level1node.AddChild(level2node1_1);
|
level1node.AddChild(level2node1_1);
|
||||||
|
|||||||
@@ -71,6 +71,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 属性
|
#region 属性
|
||||||
|
|
||||||
|
public FullyCreatedConnectorInfo FirstConnector
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return connectors?.FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public FullyCreatedConnectorInfo TopConnector
|
public FullyCreatedConnectorInfo TopConnector
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||||
mindNode.FontViewModel.FontColor = Colors.White;
|
mindNode.FontViewModel.FontColor = Colors.White;
|
||||||
mindNode.FontViewModel.FontSize = 15;
|
mindNode.FontViewModel.FontSize = 15;
|
||||||
mindNode.Spacing = new SizeBase(50, 15);
|
|
||||||
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||||
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||||
|
|
||||||
@@ -80,14 +79,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
{
|
{
|
||||||
if (mindNode == null) return;
|
if (mindNode == null) return;
|
||||||
|
|
||||||
mindNode.LayoutUpdating = true;
|
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||||
var size = MeasureOverride(mindNode);
|
var size = MeasureOverride(mindNode);
|
||||||
ArrangeOverride(mindNode);
|
ArrangeOverride(mindNode);
|
||||||
|
|
||||||
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
||||||
mindNode.Root?.ReconnectLinksToClosestPorts();
|
|
||||||
|
|
||||||
mindNode.LayoutUpdating = false;
|
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,13 +102,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||||
sizewithSpacing = new SizeBase(sizewithSpacing.Width * 0.5 + childrensizes.Max(p => p.Width), sizewithSpacing.Height + childrensizes.Sum(p => p.Height));
|
sizewithSpacing = new SizeBase(Math.Max(sizewithSpacing.Width, sizewithSpacing.Width * 0.5 + childrensizes.Max(p => p.Width)), sizewithSpacing.Height + childrensizes.Sum(p => p.Height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
||||||
mindNode.Visible = isExpanded;
|
mindNode.Visible = isExpanded;
|
||||||
var connectors = mindNode.Root?.Items.OfType<ConnectionViewModel>().Where(p => p.SinkConnectorInfoFully?.DataItem == mindNode).ToList();
|
|
||||||
connectors?.ForEach(p => p.Visible = mindNode.Visible);
|
|
||||||
|
|
||||||
return mindNode.DesiredSize;
|
return mindNode.DesiredSize;
|
||||||
}
|
}
|
||||||
@@ -131,6 +127,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
left += child.DesiredSize.Width;
|
left += child.DesiredSize.Width;
|
||||||
|
|
||||||
ArrangeOverride(child);
|
ArrangeOverride(child);
|
||||||
|
|
||||||
|
var connect = mindNode.Root?.Items.OfType<ConnectionViewModel>().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child);
|
||||||
|
connect?.SetSourcePort(mindNode.FirstConnector);
|
||||||
|
connect?.SetSinkPort(child.TopConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,6 +149,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
top += child.DesiredSize.Height;
|
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.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,14 +80,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
{
|
{
|
||||||
if (mindNode == null) return;
|
if (mindNode == null) return;
|
||||||
|
|
||||||
mindNode.LayoutUpdating = true;
|
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||||
var size = MeasureOverride(mindNode);
|
var size = MeasureOverride(mindNode);
|
||||||
ArrangeOverride(mindNode);
|
ArrangeOverride(mindNode);
|
||||||
|
|
||||||
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
||||||
mindNode.Root?.ReconnectLinksToClosestPorts();
|
|
||||||
|
|
||||||
mindNode.LayoutUpdating = false;
|
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||||
@@ -100,8 +99,6 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
}
|
}
|
||||||
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
||||||
mindNode.Visible = isExpanded;
|
mindNode.Visible = isExpanded;
|
||||||
var connectors = mindNode.Root?.Items.OfType<ConnectionViewModel>().Where(p => p.SinkConnectorInfoFully?.DataItem == mindNode).ToList();
|
|
||||||
connectors?.ForEach(p => p.Visible = mindNode.Visible);
|
|
||||||
|
|
||||||
return mindNode.DesiredSize;
|
return mindNode.DesiredSize;
|
||||||
}
|
}
|
||||||
@@ -120,6 +117,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
top += child.DesiredSize.Height;
|
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.RightConnector ?? mindNode.FirstConnector);
|
||||||
|
connect?.SetSinkPort(child.LeftConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,14 +81,13 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
{
|
{
|
||||||
if (mindNode == null) return;
|
if (mindNode == null) return;
|
||||||
|
|
||||||
mindNode.LayoutUpdating = true;
|
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||||
var size = MeasureOverride(mindNode);
|
var size = MeasureOverride(mindNode);
|
||||||
ArrangeOverride(mindNode);
|
ArrangeOverride(mindNode);
|
||||||
|
|
||||||
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
||||||
mindNode.Root?.ReconnectLinksToClosestPorts();
|
|
||||||
|
|
||||||
mindNode.LayoutUpdating = false;
|
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||||
@@ -99,11 +98,10 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
if (mindNode.NodeLevel == NodeLevel.Level1)
|
if (mindNode.NodeLevel == NodeLevel.Level1)
|
||||||
{
|
{
|
||||||
var rights = mindNode.Children.Where((p, index) => index % 2 == 0).ToList();
|
var rights = mindNode.Children.Where((p, index) => index % 2 == 0).ToList();
|
||||||
rights.ForEach(p => p.IsRightLayout = true);
|
rights.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.Left);
|
||||||
var rightsizes = rights.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
var rightsizes = rights.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||||
|
|
||||||
var lefts = mindNode.Children.Where((p, index) => index % 2 == 1).ToList();
|
var lefts = mindNode.Children.Where((p, index) => index % 2 == 1).ToList();
|
||||||
lefts.ForEach(p => p.IsRightLayout = false);
|
lefts.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.Right);
|
||||||
var leftsizes = lefts.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
var leftsizes = lefts.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||||
sizewithSpacing = new SizeBase(sizewithSpacing.Width + rightsizes.Max(p => p.Width) + +leftsizes.Max(p => p.Width), Math.Max(sizewithSpacing.Height, Math.Max(rightsizes.Sum(p => p.Height), leftsizes.Sum(p => p.Height))));
|
sizewithSpacing = new SizeBase(sizewithSpacing.Width + rightsizes.Max(p => p.Width) + +leftsizes.Max(p => p.Width), Math.Max(sizewithSpacing.Height, Math.Max(rightsizes.Sum(p => p.Height), leftsizes.Sum(p => p.Height))));
|
||||||
}
|
}
|
||||||
@@ -115,8 +113,6 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
}
|
}
|
||||||
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
||||||
mindNode.Visible = isExpanded;
|
mindNode.Visible = isExpanded;
|
||||||
var connectors = mindNode.Root?.Items.OfType<ConnectionViewModel>().Where(p => p.SinkConnectorInfoFully?.DataItem == mindNode).ToList();
|
|
||||||
connectors?.ForEach(p => p.Visible = mindNode.Visible);
|
|
||||||
|
|
||||||
return mindNode.DesiredSize;
|
return mindNode.DesiredSize;
|
||||||
}
|
}
|
||||||
@@ -127,7 +123,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
{
|
{
|
||||||
if (mindNode.Children?.Count > 0)
|
if (mindNode.Children?.Count > 0)
|
||||||
{
|
{
|
||||||
var rights = mindNode.Children.Where(p => p.IsRightLayout == true).ToList();
|
var rights = mindNode.Children.Where(p => p.ConnectorOrientation == ConnectorOrientation.Left).ToList();
|
||||||
double left = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
double left = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||||
double lefttop = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, rights.Sum(p => p.DesiredSize.Height)) / 2;
|
double lefttop = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, rights.Sum(p => p.DesiredSize.Height)) / 2;
|
||||||
foreach (var child in rights)
|
foreach (var child in rights)
|
||||||
@@ -138,9 +134,14 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
lefttop += child.DesiredSize.Height;
|
lefttop += 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.FirstConnector);
|
||||||
|
connect?.SetSinkPort(child.LeftConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lefts = mindNode.Children.Where(p => p.IsRightLayout == false).ToList();
|
var lefts = mindNode.Children.Where(p => p.ConnectorOrientation == ConnectorOrientation.Right).ToList();
|
||||||
double right = mindNode.MiddlePosition.X - mindNode.ItemWidth / 2 - mindNode.Spacing.Width;
|
double right = mindNode.MiddlePosition.X - mindNode.ItemWidth / 2 - mindNode.Spacing.Width;
|
||||||
double righttop = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, lefts.Sum(p => p.DesiredSize.Height)) / 2;
|
double righttop = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, lefts.Sum(p => p.DesiredSize.Height)) / 2;
|
||||||
foreach (var child in lefts)
|
foreach (var child in lefts)
|
||||||
@@ -151,12 +152,17 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
righttop += child.DesiredSize.Height;
|
righttop += 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.FirstConnector);
|
||||||
|
connect?.SetSinkPort(child.RightConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mindNode.GetLevel2Node().IsRightLayout)
|
if (mindNode.GetLevel2Node().ConnectorOrientation == ConnectorOrientation.Left)
|
||||||
{
|
{
|
||||||
double left = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
double left = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width;
|
||||||
double top = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.Sum(p => p.DesiredSize.Height)) / 2;
|
double top = mindNode.MiddlePosition.Y - Math.Min(mindNode.DesiredSize.Height, mindNode.Children.Sum(p => p.DesiredSize.Height)) / 2;
|
||||||
@@ -170,6 +176,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
top += child.DesiredSize.Height;
|
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.RightConnector);
|
||||||
|
connect?.SetSinkPort(child.LeftConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,6 +198,11 @@ namespace AIStudio.Wpf.Mind.Helpers
|
|||||||
top += child.DesiredSize.Height;
|
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.LeftConnector);
|
||||||
|
connect?.SetSinkPort(child.RightConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
131
AIStudio.Wpf.Mind/Helpers/OrganizationalLayout.cs
Normal file
131
AIStudio.Wpf.Mind/Helpers/OrganizationalLayout.cs
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using AIStudio.Wpf.DiagramDesigner;
|
||||||
|
using AIStudio.Wpf.DiagramDesigner.Algorithms;
|
||||||
|
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||||
|
using AIStudio.Wpf.Mind.ViewModels;
|
||||||
|
|
||||||
|
namespace AIStudio.Wpf.Mind.Helpers
|
||||||
|
{
|
||||||
|
public class OrganizationalLayout : IMindLayout
|
||||||
|
{
|
||||||
|
public void Appearance(MindNode mindNode)
|
||||||
|
{
|
||||||
|
switch (mindNode.NodeLevel)
|
||||||
|
{
|
||||||
|
case NodeLevel.Level1:
|
||||||
|
{
|
||||||
|
mindNode.ItemWidth = 110;
|
||||||
|
mindNode.ItemHeight = 40;
|
||||||
|
mindNode.ClearConnectors();
|
||||||
|
|
||||||
|
var port = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.5, YRatio = 1 };
|
||||||
|
mindNode.AddConnector(port);
|
||||||
|
|
||||||
|
mindNode.IsInnerConnector = true;
|
||||||
|
|
||||||
|
mindNode.ColorViewModel.FillColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||||
|
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||||
|
mindNode.FontViewModel.FontColor = Colors.White;
|
||||||
|
mindNode.FontViewModel.FontSize = 15;
|
||||||
|
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||||
|
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NodeLevel.Level2:
|
||||||
|
{
|
||||||
|
mindNode.ItemWidth = 80;
|
||||||
|
mindNode.ItemHeight = 25;
|
||||||
|
mindNode.ClearConnectors();
|
||||||
|
var port1 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Top, true) { XRatio = 0.5, YRatio = 0 };
|
||||||
|
mindNode.AddConnector(port1);
|
||||||
|
var port2 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.5, YRatio = 1 };
|
||||||
|
mindNode.AddConnector(port2);
|
||||||
|
|
||||||
|
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.ConnectorOrientation = ConnectorOrientation.Top;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NodeLevel.Level3:
|
||||||
|
{
|
||||||
|
mindNode.ItemWidth = 80;
|
||||||
|
mindNode.ItemHeight = 25;
|
||||||
|
mindNode.ClearConnectors();
|
||||||
|
|
||||||
|
var port1 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Top, true) { XRatio = 0.5, YRatio = 0 };
|
||||||
|
mindNode.AddConnector(port1);
|
||||||
|
var port2 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.5, YRatio = 1 };
|
||||||
|
mindNode.AddConnector(port2);
|
||||||
|
|
||||||
|
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);
|
||||||
|
mindNode.ConnectorOrientation = ConnectorOrientation.Top;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutUpdated(MindNode mindNode)
|
||||||
|
{
|
||||||
|
if (mindNode == null) return;
|
||||||
|
|
||||||
|
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||||
|
var size = MeasureOverride(mindNode);
|
||||||
|
ArrangeOverride(mindNode);
|
||||||
|
|
||||||
|
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
||||||
|
|
||||||
|
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||||
|
{
|
||||||
|
var sizewithSpacing = mindNode.SizeWithSpacing;
|
||||||
|
if (mindNode.Children?.Count > 0)
|
||||||
|
{
|
||||||
|
var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray();
|
||||||
|
sizewithSpacing = new SizeBase(Math.Max(sizewithSpacing.Width, childrensizes.Sum(p => p.Width)), sizewithSpacing.Height + childrensizes.Max(p => p.Height));
|
||||||
|
}
|
||||||
|
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
||||||
|
mindNode.Visible = isExpanded;
|
||||||
|
|
||||||
|
return mindNode.DesiredSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ArrangeOverride(MindNode mindNode)
|
||||||
|
{
|
||||||
|
double left = mindNode.MiddlePosition.X - Math.Max(mindNode.DesiredSize.Width, mindNode.Children.Sum(p => p.DesiredSize.Width)) / 2;
|
||||||
|
double top = mindNode.MiddlePosition.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 + child.Spacing.Width + child.Offset.X;
|
||||||
|
child.Top = top + child.Spacing.Height + child.Offset.Y;
|
||||||
|
child.DesiredPosition = child.Position;
|
||||||
|
left += child.DesiredSize.Width;
|
||||||
|
|
||||||
|
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.TopConnector);
|
||||||
|
connect.Visible = child.Visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,10 +91,15 @@
|
|||||||
<ToggleButton x:Name="toggle" IsChecked="{Binding IsExpanded}" Style="{StaticResource ExpandCollapseToggleStyle}" HorizontalAlignment="Left" Margin="-15,0,0,0" Visibility="{Binding Children.Count,Converter={StaticResource IntToVisibilityConverter}}"/>
|
<ToggleButton x:Name="toggle" IsChecked="{Binding IsExpanded}" Style="{StaticResource ExpandCollapseToggleStyle}" HorizontalAlignment="Left" Margin="-15,0,0,0" Visibility="{Binding Children.Count,Converter={StaticResource IntToVisibilityConverter}}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<ControlTemplate.Triggers>
|
<ControlTemplate.Triggers>
|
||||||
<DataTrigger Binding="{Binding IsRightLayout}" Value="false">
|
<DataTrigger Binding="{Binding ConnectorOrientation}" Value="Right">
|
||||||
<Setter TargetName="toggle" Property="HorizontalAlignment" Value="Right"/>
|
<Setter TargetName="toggle" Property="HorizontalAlignment" Value="Right"/>
|
||||||
<Setter TargetName="toggle" Property="Margin" Value="0,0,-15,0"/>
|
<Setter TargetName="toggle" Property="Margin" Value="0,0,-15,0"/>
|
||||||
</DataTrigger>
|
</DataTrigger>
|
||||||
|
<DataTrigger Binding="{Binding ConnectorOrientation}" Value="Top">
|
||||||
|
<Setter TargetName="toggle" Property="HorizontalAlignment" Value="Center"/>
|
||||||
|
<Setter TargetName="toggle" Property="VerticalAlignment" Value="Top"/>
|
||||||
|
<Setter TargetName="toggle" Property="Margin" Value="0,-15,0,0"/>
|
||||||
|
</DataTrigger>
|
||||||
</ControlTemplate.Triggers>
|
</ControlTemplate.Triggers>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|
||||||
@@ -125,10 +130,15 @@
|
|||||||
<ToggleButton x:Name="toggle" IsChecked="{Binding IsExpanded}" Style="{StaticResource ExpandCollapseToggleStyle}" HorizontalAlignment="Left" Margin="-15,0,0,0" Visibility="{Binding Children.Count,Converter={StaticResource IntToVisibilityConverter}}"/>
|
<ToggleButton x:Name="toggle" IsChecked="{Binding IsExpanded}" Style="{StaticResource ExpandCollapseToggleStyle}" HorizontalAlignment="Left" Margin="-15,0,0,0" Visibility="{Binding Children.Count,Converter={StaticResource IntToVisibilityConverter}}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<ControlTemplate.Triggers>
|
<ControlTemplate.Triggers>
|
||||||
<DataTrigger Binding="{Binding IsRightLayout}" Value="false">
|
<DataTrigger Binding="{Binding ConnectorOrientation}" Value="Right">
|
||||||
<Setter TargetName="toggle" Property="HorizontalAlignment" Value="Right"/>
|
<Setter TargetName="toggle" Property="HorizontalAlignment" Value="Right"/>
|
||||||
<Setter TargetName="toggle" Property="Margin" Value="0,0,-15,0"/>
|
<Setter TargetName="toggle" Property="Margin" Value="0,0,-15,0"/>
|
||||||
</DataTrigger>
|
</DataTrigger>
|
||||||
|
<DataTrigger Binding="{Binding ConnectorOrientation}" Value="Top">
|
||||||
|
<Setter TargetName="toggle" Property="HorizontalAlignment" Value="Center"/>
|
||||||
|
<Setter TargetName="toggle" Property="VerticalAlignment" Value="Top"/>
|
||||||
|
<Setter TargetName="toggle" Property="Margin" Value="0,-15,0,0"/>
|
||||||
|
</DataTrigger>
|
||||||
</ControlTemplate.Triggers>
|
</ControlTemplate.Triggers>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|
||||||
|
|||||||
@@ -185,16 +185,16 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _isRightLayout = true;
|
private ConnectorOrientation _connectorOrientation = ConnectorOrientation.Left;
|
||||||
public bool IsRightLayout
|
public ConnectorOrientation ConnectorOrientation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _isRightLayout;
|
return _connectorOrientation;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetProperty(ref _isRightLayout, value);
|
SetProperty(ref _connectorOrientation, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,9 +356,9 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (NodeLevel == NodeLevel.Level1)
|
if (NodeLevel == NodeLevel.Level1)
|
||||||
node = new MindNode(Root, NodeLevel.Level2) { Text = "分支主题" };
|
node = new MindNode(Root, NodeLevel.Level2, this.MindType) { Text = "分支主题" };
|
||||||
else
|
else
|
||||||
node = new MindNode(Root, NodeLevel.Level3) { Text = "分支主题" };
|
node = new MindNode(Root, NodeLevel.Level3, this.MindType) { Text = "分支主题" };
|
||||||
}
|
}
|
||||||
AddChild(node);
|
AddChild(node);
|
||||||
|
|
||||||
@@ -379,9 +379,9 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (NodeLevel == NodeLevel.Level2)
|
else if (NodeLevel == NodeLevel.Level2)
|
||||||
node = new MindNode(Root, NodeLevel.Level2) { Text = "分支主题" };
|
node = new MindNode(Root, NodeLevel.Level2, this.MindType) { Text = "分支主题" };
|
||||||
else
|
else
|
||||||
node = new MindNode(Root, NodeLevel.Level3) { Text = "分支主题" };
|
node = new MindNode(Root, NodeLevel.Level3, this.MindType) { Text = "分支主题" };
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.RemoveChild(this);
|
parent.RemoveChild(this);
|
||||||
@@ -408,9 +408,9 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (NodeLevel == NodeLevel.Level2)
|
else if (NodeLevel == NodeLevel.Level2)
|
||||||
node = new MindNode(Root, NodeLevel.Level2) { Text = "分支主题" };
|
node = new MindNode(Root, NodeLevel.Level2, this.MindType) { Text = "分支主题" };
|
||||||
else
|
else
|
||||||
node = new MindNode(Root, NodeLevel.Level3) { Text = "分支主题" };
|
node = new MindNode(Root, NodeLevel.Level3, this.MindType) { Text = "分支主题" };
|
||||||
}
|
}
|
||||||
int index = parent.Children.IndexOf(this);
|
int index = parent.Children.IndexOf(this);
|
||||||
parent.AddChild(node, index + 1);
|
parent.AddChild(node, index + 1);
|
||||||
@@ -482,6 +482,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
switch (MindType)
|
switch (MindType)
|
||||||
{
|
{
|
||||||
case MindType.Directory:
|
case MindType.Directory:
|
||||||
|
case MindType.Organizational:
|
||||||
drawMode = DrawMode.ConnectingLineStraight;
|
drawMode = DrawMode.ConnectingLineStraight;
|
||||||
routerMode = AIStudio.Wpf.DiagramDesigner.RouterMode.RouterOrthogonal;
|
routerMode = AIStudio.Wpf.DiagramDesigner.RouterMode.RouterOrthogonal;
|
||||||
break;
|
break;
|
||||||
@@ -527,6 +528,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
|
|
||||||
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (GetLevel1Node()?.LayoutUpdating == true) return;
|
||||||
|
|
||||||
switch (e.PropertyName)
|
switch (e.PropertyName)
|
||||||
{
|
{
|
||||||
case nameof(IsExpanded):
|
case nameof(IsExpanded):
|
||||||
@@ -539,17 +542,17 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
case nameof(NodeLevel):
|
case nameof(NodeLevel):
|
||||||
MindLayout?.Appearance(this);
|
MindLayout?.Appearance(this);
|
||||||
break;
|
break;
|
||||||
case nameof(MindType):
|
//case nameof(MindType):
|
||||||
if (NodeLevel == NodeLevel.Level1)
|
// if (NodeLevel == NodeLevel.Level1)
|
||||||
{
|
// {
|
||||||
MindLayout?.Appearance(this);
|
// MindLayout?.Appearance(this);
|
||||||
LayoutUpdated();
|
// LayoutUpdated();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
GetLevel1Node().MindType = MindType;
|
// GetLevel1Node().MindType = MindType;
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
case nameof(Left):
|
case nameof(Left):
|
||||||
{
|
{
|
||||||
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
|
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
|
||||||
@@ -608,15 +611,11 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
|||||||
|
|
||||||
protected void UpdateOffsetX(double oldvalue, double newvalue)
|
protected void UpdateOffsetX(double oldvalue, double newvalue)
|
||||||
{
|
{
|
||||||
if (GetLevel1Node()?.LayoutUpdating == true) return;
|
|
||||||
|
|
||||||
Offset += new VectorBase(newvalue - oldvalue, 0);
|
Offset += new VectorBase(newvalue - oldvalue, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateOffsetY(double oldvalue, double newvalue)
|
protected void UpdateOffsetY(double oldvalue, double newvalue)
|
||||||
{
|
{
|
||||||
if (GetLevel1Node()?.LayoutUpdating == true) return;
|
|
||||||
|
|
||||||
Offset += new VectorBase(0, newvalue - oldvalue);
|
Offset += new VectorBase(0, newvalue - oldvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user