节点导入完成

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

@@ -45,6 +45,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
get;
}
ICommand ExportCommand
{
get;
}
ICommand ImportCommand
{
get;
}
ICommand SelectBrotherCommand
{
get;

View File

@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.Mind.Controls;
using AIStudio.Wpf.Mind.Helpers;
using AIStudio.Wpf.Mind.Models;
@@ -160,6 +160,24 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private ICommand _exportCommand;
public ICommand ExportCommand
{
get
{
return this._exportCommand ?? (this._exportCommand = new SimpleCommand(MindExecuteEnable, ExecuteExportCommand));
}
}
private ICommand _importCommand;
public ICommand ImportCommand
{
get
{
return this._importCommand ?? (this._importCommand = new SimpleCommand(MindExecuteEnable, ExecuteImportCommand));
}
}
private ICommand _selectBrotherCommand;
public ICommand SelectBrotherCommand
{
@@ -354,7 +372,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
AddRootItem();
}
ResetChildren(RootItems);
RootItems?.ForEach(p => p.LayoutUpdated());
RootItems?.ForEach(p => p.UpdatedLayout());
base.Init();
}
@@ -378,7 +396,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
item.Offset = new DiagramDesigner.Geometrys.PointBase();
}
RootItems?.ForEach(p => p.LayoutUpdated());
RootItems?.ForEach(p => p.UpdatedLayout());
}
private void ResetChildren(IEnumerable<MindNode> parents)
@@ -393,7 +411,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
item.Parent = parent;
item.InitLayout(false);
item.InitConnectLayout();
item.InitConnectionLayout();
}
ResetChildren(parent.Children);
}
@@ -483,7 +501,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
newitems.Add(newitem);
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
},
() => {
foreach (var item in newitems)
@@ -491,7 +509,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
item.RemoveFrom();
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
});
}
@@ -529,7 +547,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
newitems.Add(newitem);
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
},
() => {
foreach (var item in items)
@@ -545,7 +563,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
item.AddTo(parent.ParentNode, index);
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
});
}
@@ -580,16 +598,16 @@ namespace AIStudio.Wpf.Mind.ViewModels
newitems.Add(newitem);
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
},
() => {
foreach (var item in newitems)
{
item.RemoveFrom();
item.LayoutUpdated();
item.UpdatedLayout();
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
});
}
@@ -644,6 +662,78 @@ namespace AIStudio.Wpf.Mind.ViewModels
});
}
private void ExecuteExportCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
var output = node.GetChildrenText(true);
var window = new NodeDTSWindow("导出节点", output);
window.ShowDialog();
}
}
private void ExecuteImportCommand(object parameter)
{
if (parameter is MindNode node)
{
}
else
{
node = SelectedItem as MindNode;
}
if (node != null)
{
var window = new NodeDTSWindow("导入节点", "");
if (window.ShowDialog() == true)
{
List<MindNode> newitems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
var content = window.ContentString;
var lines = content.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
MindNode lastnode = node;
foreach (var line in lines)
{
int level = Regex.Matches(line, "\t").Count + node.NodeLevel + 1;
string text = line.Replace("\t", "");
var newitem = new MindNode(this) { Text = text };
while (lastnode.NodeLevel != level - 1)
{
lastnode = lastnode.ParentNode;
}
if (lastnode == null)
{
continue;
}
newitem.AddTo(lastnode, isSelected: false);
lastnode = newitem;
newitems.Add(newitem);
}
node.UpdatedLayout();
},
() => {
foreach (var item in newitems)
{
item.RemoveFrom();
}
node.UpdatedLayout();
});
}
}
}
private void MoveBack(List<MindNode> items)
{
foreach (var item in items)
@@ -660,7 +750,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
item.AddTo(parent, index + 1);
}
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
}
private void MoveForward(List<MindNode> items)
@@ -679,7 +769,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
item.AddTo(parent, index - 1);
}
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
}
protected override bool Delete(object parameter)
@@ -731,7 +821,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
base.Delete(others);
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
},
() => {
if (others.Any())
@@ -748,7 +838,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.LayoutUpdated());
items.Select(p => p.RootNode).Distinct().ToList().ForEach(p => p.UpdatedLayout());
});
return true;
}
@@ -776,7 +866,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
ResetChildren(parents);
parents.ForEach(p => p.LayoutUpdated());
parents.ForEach(p => p.UpdatedLayout());
}
#endregion
@@ -997,14 +1087,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
() => {
roots.ForEach(p => p.MindType = mindType);
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectLayout(); });
roots.ForEach(p => p.LayoutUpdated());
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
roots.ForEach(p => p.MindType = oldMindType);
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectLayout(); });
roots.ForEach(p => p.LayoutUpdated());
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
});
}
}
@@ -1033,7 +1123,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
MindTheme = mindTheme;
roots.ForEach(p => p.MindTheme = MindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.LayoutUpdated());
roots.ForEach(p => p.UpdatedLayout());
},
() => {
var mindThemeModel = MindThemeHelper.GetTheme(oldmindTheme);
@@ -1048,7 +1138,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
MindTheme = oldmindTheme;
roots.ForEach(p => p.MindTheme = MindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.LayoutUpdated());
roots.ForEach(p => p.UpdatedLayout());
});
}
}
@@ -1177,7 +1267,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
rootitem.Left = left.Value;
rootitem.Top = top.Value;
rootitem.Offset = offset;
rootitem?.LayoutUpdated();
rootitem?.UpdatedLayout();
FitViewModel = new FitViewModel() { BoundingRect = rootitem.GetBounds() };
}

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
}