节点导入完成

This commit is contained in:
艾竹
2023-04-02 21:47:55 +08:00
parent 0701f25519
commit 7835b422ff
20 changed files with 765 additions and 119 deletions

View File

@@ -2,27 +2,22 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Linq;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Algorithms;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.DiagramDesigner.Helpers;
using AIStudio.Wpf.DiagramDesigner.Models;
using AIStudio.Wpf.DiagramModels;
using AIStudio.Wpf.DiagramModels.ViewModels;
using AIStudio.Wpf.Mind.Models;
using AIStudio.Wpf.Mind.Controls;
using AIStudio.Wpf.Mind.Helpers;
using AIStudio.Wpf.Mind.Models;
namespace AIStudio.Wpf.Mind.ViewModels
{
public class MindNode : DiagramItemViewModel
@@ -85,6 +80,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
DeleteCommand = (Root as IMindDiagramViewModel)?.DeleteCommand;
MoveForwardCommand = (Root as IMindDiagramViewModel)?.MoveForwardCommand;
MoveBackCommand = (Root as IMindDiagramViewModel)?.MoveBackCommand;
ExportCommand = (Root as IMindDiagramViewModel)?.ExportCommand;
ImportCommand = (Root as IMindDiagramViewModel)?.ImportCommand;
BuildMenuOptions();
Tags = new ObservableCollection<string>();
}
@@ -105,6 +102,27 @@ namespace AIStudio.Wpf.Mind.ViewModels
this.PropertyChanged += this.Item_PropertyChanged;
}
public void InitConnectionLayout()
{
var connector = Root?.Items.OfType<ConnectionViewModel>().Where(p => p.IsFullConnection).FirstOrDefault(p => p.SinkConnectorInfoFully.DataItem == this);
if (connector != null)
{
MindLayout?.GetOrSetConnectionViewModel(connector.SourceConnectorInfo.DataItem as MindNode, connector.SinkConnectorInfoFully.DataItem as MindNode, connector);
}
else if (ParentNode != null)
{
connector = MindLayout?.GetOrSetConnectionViewModel(ParentNode, this, null);
Root?.Add(new SelectableDesignerItemViewModelBase[] { connector });
connector.ZIndex = -1;
connector.IsSelected = false;
}
}
public void UpdatedLayout()
{
MindLayout?.UpdatedLayout(GetLevel0Node());
}
public void ThemeChange()
{
MindThemeHelper.ThemeChange(this, MindTheme);
@@ -144,6 +162,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
}
#region
private MindType _mindType = MindType.Mind;
public MindType MindType
@@ -428,6 +447,16 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
get; private set;
}
public ICommand ExportCommand
{
get; private set;
}
public ICommand ImportCommand
{
get; private set;
}
#endregion
#region
@@ -464,6 +493,16 @@ namespace AIStudio.Wpf.Mind.ViewModels
menuItem.Command = DeleteCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "导出节点";
menuItem.Command = ExportCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
menuItem = new CinchMenuItem();
menuItem.Text = "导入节点";
menuItem.Command = ImportCommand;
menuItem.CommandParameter = this;
menuOptions.Add(menuItem);
}
#endregion
@@ -483,7 +522,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
this.ParentId = parent?.Id ?? Guid.Empty;
this.Offset = parent?.Offset ?? new PointBase();
this.InitLayout(true);//因为节点的层级不同的样式所以需要Parent确定后才能初始化
this.InitConnectLayout();
this.InitConnectionLayout();
Root?.Add(this);
@@ -508,35 +547,10 @@ namespace AIStudio.Wpf.Mind.ViewModels
Root?.Remove(this);
Root?.Remove(connectors);
//if (removeall)
//{
// if (this.Children?.Count > 0)
// {
// foreach (var child in this.Children.ToList())
// {
// child.RemoveFrom(removeall);
// }
// }
//}
}
public void InitConnectLayout()
{
var connector = Root?.Items.OfType<ConnectionViewModel>().Where(p => p.IsFullConnection).FirstOrDefault(p => p.SinkConnectorInfoFully.DataItem == this);
if (connector != null)
{
MindLayout?.GetOrSetConnectionViewModel(connector.SourceConnectorInfo.DataItem as MindNode, connector.SinkConnectorInfoFully.DataItem as MindNode, connector);
}
else if (ParentNode != null)
{
connector = MindLayout?.GetOrSetConnectionViewModel(ParentNode, this, null);
Root?.Add(new SelectableDesignerItemViewModelBase[] { connector });
connector.ZIndex = -1;
connector.IsSelected = false;
}
}
}
#endregion
#region
private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (GetLevel0Node()?.LayoutUpdating == true) return;
@@ -564,7 +578,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
case nameof(ItemWidth):
case nameof(ItemHeight):
{
LayoutUpdated();
UpdatedLayout();
break;
}
case nameof(NodeLevel):
@@ -583,33 +597,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private void SetItemWidthHeight()
{
double width = 0;
double height = 0;
width += GetTextDisplayWidthHelper.GetTextDisplayWidth(Text, new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch, FontViewModel.FontSize) + 30;
width += Rate == null ? 0 : 24;
width += Priority == null ? 0 : 24;
width += Remark == null ? 0 : 24;
width += LinkInfo == null ? 0 : 24;
var defaultTheme = MindThemeHelper.GetNodeDefaultTheme(this);
if (ImageInfo != null)
{
width = Math.Max(width, 160);
height = defaultTheme.ItemHeight / defaultTheme.FontSize * FontViewModel.FontSize + 135;
}
else
{
height = defaultTheme.ItemHeight / defaultTheme.FontSize * FontViewModel.FontSize;
}
ItemWidth = width;
ItemHeight = height;
}
protected override void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(FontViewModel.FontSize))
@@ -617,15 +604,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
SetItemWidthHeight();
}
}
#endregion
public override void AddToSelection(bool selected)
{
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
item.IsSelected = false;
Root.SelectedItems.Clear();
IsSelected = selected;
}
#region
public MindNode GetLevel0Node()
{
@@ -682,6 +662,26 @@ namespace AIStudio.Wpf.Mind.ViewModels
return mindnode;
}
public string GetChildrenText(bool self = false)
{
StringBuilder sb = new StringBuilder();
List<MindNode> mindnode = new List<MindNode>();
if (self)
{
sb.AppendLine(this.Text);
}
if (this.Children != null)
{
foreach (var child in this.Children)
{
sb.AppendLine($"{new String('\t', child.NodeLevel)}{child.Text}");
sb.Append(child.GetChildrenText());
}
}
return sb.ToString();
}
protected void UpdateOffsetX(double oldvalue, double newvalue)
{
Offset += new VectorBase(newvalue - oldvalue, 0);
@@ -692,11 +692,42 @@ namespace AIStudio.Wpf.Mind.ViewModels
Offset += new VectorBase(0, newvalue - oldvalue);
}
public void LayoutUpdated()
private void SetItemWidthHeight()
{
MindLayout?.LayoutUpdated(GetLevel0Node());
double width = 0;
double height = 0;
width += GetTextDisplayWidthHelper.GetTextDisplayWidth(Text, new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch, FontViewModel.FontSize) + 30;
width += Rate == null ? 0 : 24;
width += Priority == null ? 0 : 24;
width += Remark == null ? 0 : 24;
width += LinkInfo == null ? 0 : 24;
var defaultTheme = MindThemeHelper.GetNodeDefaultTheme(this);
if (ImageInfo != null)
{
width = Math.Max(width, 160);
height = defaultTheme.ItemHeight / defaultTheme.FontSize * FontViewModel.FontSize + 135;
}
else
{
height = defaultTheme.ItemHeight / defaultTheme.FontSize * FontViewModel.FontSize;
}
ItemWidth = width;
ItemHeight = height;
}
public override void AddToSelection(bool selected)
{
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
item.IsSelected = false;
Root.SelectedItems.Clear();
IsSelected = selected;
}
#endregion
}