mind继续

This commit is contained in:
艾竹
2023-02-20 23:01:26 +08:00
parent 58c18db12f
commit 71ed33f881
5 changed files with 247 additions and 46 deletions

View File

@@ -52,7 +52,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
private void LevelInit(bool init = false)
{
{
switch (NodeLevel)
{
case NodeLevel.Level1:
@@ -60,8 +60,23 @@ namespace AIStudio.Wpf.Mind.ViewModels
ItemWidth = 110;
ItemHeight = 40;
this.ClearConnectors();
var port = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.None, true) { XRatio = 0.5, YRatio = 0.5 };
this.AddConnector(port);
switch (MindType)
{
case MindType.Mind:
case MindType.Logical:
{
var port = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.None, true) { XRatio = 0.5, YRatio = 0.5 };
this.AddConnector(port);
break;
}
case MindType.Directory:
{
var port = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Bottom, true) { XRatio = 0.5, YRatio = 1 };
this.AddConnector(port);
break;
}
}
IsInnerConnector = true;
ColorViewModel.FillColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
@@ -79,10 +94,26 @@ namespace AIStudio.Wpf.Mind.ViewModels
ItemWidth = 80;
ItemHeight = 25;
this.ClearConnectors();
var port1 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Left, true) { XRatio = 0, YRatio = 0.5 };
this.AddConnector(port1);
var port2 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Right, true) { XRatio = 1, YRatio = 0.5 };
this.AddConnector(port2);
switch (MindType)
{
case MindType.Mind:
case MindType.Logical:
{
var port1 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Left, true) { XRatio = 0, YRatio = 0.5 };
this.AddConnector(port1);
var port2 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Right, true) { XRatio = 1, YRatio = 0.5 };
this.AddConnector(port2);
break;
}
case MindType.Directory:
{
var port1 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Top, true) { XRatio = 0.5, YRatio = 0 };
this.AddConnector(port1);
var port2 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Bottom, true) { XRatio = 0.25, YRatio = 1 };
this.AddConnector(port2);
break;
}
}
IsInnerConnector = true;
ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
@@ -95,12 +126,29 @@ namespace AIStudio.Wpf.Mind.ViewModels
ItemWidth = 80;
ItemHeight = 25;
this.ClearConnectors();
var port1 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Left, true) { XRatio = 0, YRatio = 1 };
this.AddConnector(port1);
var port2 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Right, true) { XRatio = 1, YRatio = 1 };
this.AddConnector(port2);
IsInnerConnector = true;
switch (MindType)
{
case MindType.Mind:
case MindType.Logical:
{
var port1 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Left, true) { XRatio = 0, YRatio = 1 };
this.AddConnector(port1);
var port2 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Right, true) { XRatio = 1, YRatio = 1 };
this.AddConnector(port2);
break;
}
case MindType.Directory:
{
var port1 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Left, true) { XRatio = 0, YRatio = 0.5 };
this.AddConnector(port1);
var port2 = new FullyCreatedConnectorInfo(Root, this, ConnectorOrientation.Bottom, true) { XRatio = 0.25, YRatio = 1 };
this.AddConnector(port2);
break;
}
}
IsInnerConnector = true;
ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
@@ -155,17 +203,26 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
SetProperty(ref _isExpanded, value);
}
}
}
public SizeBase Spacing
{
get; set;
} = new SizeBase(15, 15);
public List<MindNode> Children
private ObservableCollection<MindNode> _children = new ObservableCollection<MindNode>();
public ObservableCollection<MindNode> Children
{
get; set;
} = new List<MindNode>();
get
{
return _children;
}
set
{
SetProperty(ref _children, value);
}
}
public SizeBase SizeWithSpacing
{
@@ -190,7 +247,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
get; set;
}
private MindType _mindType;
private MindType _mindType = MindType.Directory;
public MindType MindType
{
get
@@ -203,9 +260,20 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private bool _layoutUpdating;
private bool _isRightLayout = true;
public bool IsRightLayout
{
get
{
return _isRightLayout;
}
set
{
SetProperty(ref _isRightLayout, value);
}
}
private bool _layoutUpdating;
#endregion
#region
@@ -274,8 +342,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private List<string> _tags;
public List<string> Tags
private ObservableCollection<string> _tags;
public ObservableCollection<string> Tags
{
get
{
@@ -481,7 +549,18 @@ namespace AIStudio.Wpf.Mind.ViewModels
item.Parent = this;
Root?.DirectAddItemCommand.Execute(item);
ConnectionViewModel connector = new ConnectionViewModel(Root, this.Connectors.FirstOrDefault(), item.Connectors.FirstOrDefault());
DrawMode drawMode = DrawMode.ConnectingLineSmooth;
RouterMode routerMode = AIStudio.Wpf.DiagramDesigner.RouterMode.RouterNormal;
switch (MindType)
{
case MindType.Directory:
drawMode = DrawMode.ConnectingLineStraight;
routerMode = AIStudio.Wpf.DiagramDesigner.RouterMode.RouterOrthogonal;
break;
}
ConnectionViewModel connector = new ConnectionViewModel(Root, this.Connectors.FirstOrDefault(), item.Connectors.FirstOrDefault(), drawMode, routerMode);
connector.ColorViewModel.LineColor = this.ColorViewModel.LineColor;
connector.SmoothMargin = 20;
connector.SmoothAutoSlope = 0.2;
@@ -526,7 +605,15 @@ namespace AIStudio.Wpf.Mind.ViewModels
case nameof(ItemWidth):
case nameof(ItemHeight):
case nameof(MindType):
GetLevel1Node()?.LayoutUpdated();
if (NodeLevel == NodeLevel.Level1)
{
LevelInit();
LayoutUpdated();
}
else
{
GetLevel1Node().MindType = MindType;
}
break;
case nameof(NodeLevel):
LevelInit();
@@ -620,7 +707,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
protected SizeBase MeasureOverride(bool isExpanded = true)
{
switch (MindType)
switch (GetLevel1Node()?.MindType)
{
case MindType.Mind:
{
@@ -630,11 +717,11 @@ namespace AIStudio.Wpf.Mind.ViewModels
if (NodeLevel == NodeLevel.Level1)
{
var rights = Children.Where((p, index) => index % 2 == 0).ToList();
rights.ForEach(p => p._isRightLayout = true);
rights.ForEach(p => p.IsRightLayout = true);
var rightsizes = rights.Select(p => p.MeasureOverride(IsExpanded && isExpanded)).ToArray();
var lefts = Children.Where((p, index) => index % 2 == 1).ToList();
lefts.ForEach(p => p._isRightLayout = false);
lefts.ForEach(p => p.IsRightLayout = false);
var leftsizes = lefts.Select(p => p.MeasureOverride(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))));
}
@@ -664,6 +751,28 @@ namespace AIStudio.Wpf.Mind.ViewModels
connectors?.ForEach(p => p.Visible = Visible);
break;
}
case MindType.Directory:
{
var sizewithSpacing = SizeWithSpacing;
if (Children?.Count > 0)
{
if (NodeLevel == NodeLevel.Level1)
{
var childrensizes = Children.Select(p => p.MeasureOverride(IsExpanded && isExpanded)).ToArray();
sizewithSpacing = new SizeBase(Math.Max(sizewithSpacing.Width, childrensizes.Sum(p => p.Width)), sizewithSpacing.Height + childrensizes.Max(p => p.Height));
}
else
{
var childrensizes = Children.Select(p => p.MeasureOverride(IsExpanded && isExpanded)).ToArray();
sizewithSpacing = new SizeBase(sizewithSpacing.Width * 0.5 + childrensizes.Max(p => p.Width), sizewithSpacing.Height + childrensizes.Sum(p => p.Height));
}
}
DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
Visible = isExpanded;
var connectors = Root?.Items.OfType<ConnectionViewModel>().Where(p => p.SinkConnectorInfoFully?.DataItem == this).ToList();
connectors?.ForEach(p => p.Visible = Visible);
break;
}
default:
{
var sizewithSpacing = SizeWithSpacing;
@@ -684,7 +793,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
protected void ArrangeOverride()
{
switch (MindType)
switch (GetLevel1Node()?.MindType)
{
case MindType.Mind:
{
@@ -692,7 +801,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
if (Children?.Count > 0)
{
var rights = Children.Where(p => p._isRightLayout == true).ToList();
var rights = Children.Where(p => p.IsRightLayout == true).ToList();
double left = MiddlePosition.X + ItemWidth / 2 + Spacing.Width;
double lefttop = MiddlePosition.Y - Math.Min(DesiredSize.Height, rights.Sum(p => p.DesiredSize.Height)) / 2;
foreach (var child in rights)
@@ -705,12 +814,12 @@ namespace AIStudio.Wpf.Mind.ViewModels
child.ArrangeOverride();
}
var lefts = Children.Where(p => p._isRightLayout == false).ToList();
var lefts = Children.Where(p => p.IsRightLayout == false).ToList();
double right = MiddlePosition.X - ItemWidth / 2 - Spacing.Width;
double righttop = MiddlePosition.Y - Math.Min(DesiredSize.Height, lefts.Sum(p => p.DesiredSize.Height)) / 2;
double righttop = MiddlePosition.Y - Math.Min(DesiredSize.Height, lefts.Sum(p => p.DesiredSize.Height)) / 2;
foreach (var child in lefts)
{
child.Left = right - child.Spacing.Width - child.ItemWidth + child.Offset.X ;
child.Left = right - child.Spacing.Width - child.ItemWidth + child.Offset.X;
child.Top = righttop + child.DesiredSize.Height / 2 - child.ItemHeight / 2 + child.Offset.Y;
child.DesiredPosition = child.Position;
righttop += child.DesiredSize.Height;
@@ -721,7 +830,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
else
{
if (GetLevel2Node()._isRightLayout)
if (GetLevel2Node().IsRightLayout)
{
double left = MiddlePosition.X + ItemWidth / 2 + Spacing.Width;
double top = MiddlePosition.Y - Math.Min(DesiredSize.Height, Children.Sum(p => p.DesiredSize.Height)) / 2;
@@ -776,6 +885,44 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
break;
}
case MindType.Directory:
{
if (NodeLevel == NodeLevel.Level1)
{
double left = MiddlePosition.X - Math.Max(DesiredSize.Width, Children.Sum(p => p.DesiredSize.Width)) / 2;
double top = MiddlePosition.Y + ItemHeight / 2 + Spacing.Height;
if (Children?.Count > 0)
{
foreach (var child in Children)
{
child.Left = left + child.Spacing.Width + child.Offset.X;
child.Top = top + child.Spacing.Height + child.Offset.Y;
child.DesiredPosition = child.Position;
left += child.DesiredSize.Width;
child.ArrangeOverride();
}
}
}
else
{
double left = MiddlePosition.X;
double top = MiddlePosition.Y + ItemHeight / 2 + Spacing.Height;
if (Children?.Count > 0)
{
foreach (var child in Children)
{
child.Left = left + child.Offset.X;
child.Top = top + child.Spacing.Height + child.Offset.Y;
child.DesiredPosition = child.Position;
top += child.DesiredSize.Height;
child.ArrangeOverride();
}
}
}
break;
}
default:
{
break;