This commit is contained in:
艾竹
2023-03-24 22:32:42 +08:00
parent 5ff4376674
commit 8a2c742ec4
19 changed files with 776 additions and 648 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.Mind.Helpers;
@@ -38,11 +39,11 @@ namespace AIStudio.Wpf.Mind.ViewModels
SetProperty(ref _mindThemeModel, value);
}
}
public MindNode RootItem
public List<MindNode> RootItems
{
get
{
return Items.OfType<MindNode>().FirstOrDefault();
return Items.OfType<MindNode>().Where(p => p.NodeLevel == 0).ToList();
}
}
@@ -52,21 +53,30 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
return SelectedItem as MindNode;
}
}
}
#endregion
#region
private SimpleCommand _addParentCommand;
public SimpleCommand AddParentCommand
#region
private ICommand _addRootCommand;
public ICommand AddRootCommand
{
get
{
return this._addParentCommand ?? (this._addParentCommand = new SimpleCommand(MindLevelEnable, ExecuteAddParentCommand));
return this._addRootCommand ?? (this._addRootCommand = new SimpleCommand(ExecuteEnable, this.ExecuteAddRootCommand));
}
}
private SimpleCommand _addChildCommand;
public SimpleCommand AddChildCommand
private ICommand _addParentCommand;
public ICommand AddParentCommand
{
get
{
return this._addParentCommand ?? (this._addParentCommand = new SimpleCommand(MindLevelEnable, this.ExecuteAddParentCommand));
}
}
private ICommand _addChildCommand;
public ICommand AddChildCommand
{
get
{
@@ -74,8 +84,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _AddPearCommand;
public SimpleCommand AddPearCommand
private ICommand _AddPearCommand;
public ICommand AddPearCommand
{
get
{
@@ -83,8 +93,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _moveForwardCommand;
public SimpleCommand MoveForwardCommand
private ICommand _moveForwardCommand;
public ICommand MoveForwardCommand
{
get
{
@@ -92,8 +102,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _moveBackCommand;
public SimpleCommand MoveBackCommand
private ICommand _moveBackCommand;
public ICommand MoveBackCommand
{
get
{
@@ -101,8 +111,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _deleteCommand;
public override SimpleCommand DeleteCommand
private ICommand _deleteCommand;
public override ICommand DeleteCommand
{
get
{
@@ -110,8 +120,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _selectBrotherCommand;
public SimpleCommand SelectBrotherCommand
private ICommand _selectBrotherCommand;
public ICommand SelectBrotherCommand
{
get
{
@@ -119,8 +129,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _selectPearCommand;
public SimpleCommand SelectPearCommand
private ICommand _selectPearCommand;
public ICommand SelectPearCommand
{
get
{
@@ -128,8 +138,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _selectRouteCommand;
public SimpleCommand SelectRouteCommand
private ICommand _selectRouteCommand;
public ICommand SelectRouteCommand
{
get
{
@@ -137,8 +147,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _selectChildCommand;
public SimpleCommand SelectChildCommand
private ICommand _selectChildCommand;
public ICommand SelectChildCommand
{
get
{
@@ -146,8 +156,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _addLinkCommand;
public SimpleCommand AddLinkCommand
private ICommand _addLinkCommand;
public ICommand AddLinkCommand
{
get
{
@@ -155,8 +165,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _removeLinkCommand;
public SimpleCommand RemoveLinkCommand
private ICommand _removeLinkCommand;
public ICommand RemoveLinkCommand
{
get
{
@@ -164,8 +174,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _addImageCommand;
public SimpleCommand AddImageCommand
private ICommand _addImageCommand;
public ICommand AddImageCommand
{
get
{
@@ -173,8 +183,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _removeImageCommand;
public SimpleCommand RemoveImageCommand
private ICommand _removeImageCommand;
public ICommand RemoveImageCommand
{
get
{
@@ -182,8 +192,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _addRemarkCommand;
public SimpleCommand AddRemarkCommand
private ICommand _addRemarkCommand;
public ICommand AddRemarkCommand
{
get
{
@@ -191,8 +201,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _removeRemarkCommand;
public SimpleCommand RemoveRemarkCommand
private ICommand _removeRemarkCommand;
public ICommand RemoveRemarkCommand
{
get
{
@@ -200,8 +210,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _addPriorityCommand;
public SimpleCommand AddPriorityCommand
private ICommand _addPriorityCommand;
public ICommand AddPriorityCommand
{
get
{
@@ -209,8 +219,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _addRatioCommand;
public SimpleCommand AddRatioCommand
private ICommand _addRatioCommand;
public ICommand AddRatioCommand
{
get
{
@@ -218,8 +228,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _addTagCommand;
public SimpleCommand AddTagCommand
private ICommand _addTagCommand;
public ICommand AddTagCommand
{
get
{
@@ -227,8 +237,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _removeTagCommand;
public SimpleCommand RemoveTagCommand
private ICommand _removeTagCommand;
public ICommand RemoveTagCommand
{
get
{
@@ -236,8 +246,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _changeMindTypeCommand;
public SimpleCommand ChangeMindTypeCommand
private ICommand _changeMindTypeCommand;
public ICommand ChangeMindTypeCommand
{
get
{
@@ -245,8 +255,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _changeMindThemeCommand;
public SimpleCommand ChangeMindThemeCommand
private ICommand _changeMindThemeCommand;
public ICommand ChangeMindThemeCommand
{
get
{
@@ -254,8 +264,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _clearThemeCommand;
public SimpleCommand ClearThemeCommand
private ICommand _clearThemeCommand;
public ICommand ClearThemeCommand
{
get
{
@@ -263,8 +273,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _copyThemeCommand;
public SimpleCommand CopyThemeCommand
private ICommand _copyThemeCommand;
public ICommand CopyThemeCommand
{
get
{
@@ -272,8 +282,8 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _pasteThemeCommand;
public SimpleCommand PasteThemeCommand
private ICommand _pasteThemeCommand;
public ICommand PasteThemeCommand
{
get
{
@@ -281,16 +291,17 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private SimpleCommand _expand2LevelCommand;
public SimpleCommand Expand2LevelCommand
private ICommand _expand2LevelCommand;
public ICommand Expand2LevelCommand
{
get
{
return this._expand2LevelCommand ?? (this._expand2LevelCommand = new SimpleCommand(ExecuteEnable, this.ExecutedExpand2LevelCommand));
}
}
}
#endregion
#region ctor和初始化
public MindDiagramViewModel()
{
@@ -302,13 +313,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
InitRootItem();
}
ResetChildren(RootItem);
RootItem?.LayoutUpdated();
ResetChildren(RootItems);
RootItems?.ForEach(p => p.LayoutUpdated());
base.Init();
}
public void InitRootItem()
{
ClearSelectedItemsCommand.Execute(null);
MindNode level1node = new MindNode(this) { Root = this, Id = Guid.NewGuid(), Text = "思维导图" };
level1node.InitLayout(true);
Items.Add(level1node);
@@ -317,6 +329,61 @@ namespace AIStudio.Wpf.Mind.ViewModels
CenterMoveCommand.Execute(level1node);
}
protected override void ExecutedResetLayoutCommand(object obj)
{
foreach (var item in Items.OfType<MindNode>())
{
item.Offset = new DiagramDesigner.Geometrys.PointBase();
}
RootItems?.ForEach(p => p.LayoutUpdated());
}
private void ResetChildren(IEnumerable<MindNode> parents)
{
if (parents == null)
return;
foreach (var parent in parents)
{
parent.Children = new System.Collections.ObjectModel.ObservableCollection<MindNode>(Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id));
foreach (var item in Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id))
{
item.Parent = parent;
item.InitLayout(false);
item.InitConnectLayout();
}
ResetChildren(parent.Children);
}
}
private List<MindNode> GetParent(MindNode node)
{
List<MindNode> mindnode = new List<MindNode>();
while (node.ParentNode != null)
{
mindnode.Add(node.ParentNode);
node = node.ParentNode;
}
return mindnode;
}
private List<MindNode> GetChildren(MindNode parent)
{
List<MindNode> mindnode = new List<MindNode>();
if (parent.Children != null)
{
foreach (var child in parent.Children)
{
mindnode.Add(child);
mindnode.AddRange(GetChildren(child));
}
}
return mindnode;
}
#endregion
#region 使
public bool MindExecuteEnable(object para)
{
if (ExecuteEnable(para) == false) return false;
@@ -332,8 +399,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
return (SelectedItem as MindNode).NodeLevel != 0;
}
#endregion
#region ,
public void ExecuteAddRootCommand(object parameter)
{
InitRootItem();
}
#region
public void ExecuteAddChildCommand(object parameter)
{
List<MindNode> items = new List<MindNode>();
@@ -561,25 +634,30 @@ namespace AIStudio.Wpf.Mind.ViewModels
return false;
}
nodes = nodes.Except(new List<MindNode> { RootItem }).ToList();
if (nodes.Any())
{
Dictionary<MindNode, int> indexs = nodes.ToDictionary(p => p, p => p.ParentNode.Children.IndexOf(p));
Dictionary<MindNode, int> indexs = nodes.ToDictionary(p => p, p => p.ParentNode != null ? p.ParentNode.Children.IndexOf(p) : 0);
DoCommandManager.DoNewCommand(this.ToString(),
() => {
foreach (var node in nodes)
{
node.ParentNode.RemoveChild(node, true);
if (node.NodeLevel == 0)
{
DirectRemoveItemCommand.Execute(node);
}
else
{
node.ParentNode?.RemoveChild(node, true);
}
}
RootItem.LayoutUpdated();
RootItems.ForEach(p => p.LayoutUpdated());
},
() => {
foreach (var node in nodes)
{
node.ParentNode.AddChild(node, indexs[node]);
}
RootItem.LayoutUpdated();
RootItems.ForEach(p => p.LayoutUpdated());
});
return true;
}
@@ -588,20 +666,39 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
#endregion
#region ,
protected override void FixConnection(List<SelectableDesignerItemViewModelBase> items)
{
List<MindNode> parents = new List<MindNode>();
foreach (var item in items.OfType<MindNode>())
{
var parent = Items.OfType<MindNode>().FirstOrDefault(p => p.Id == item.ParentId);
if (parent != null)
{
parents.Add(parent);
}
else
{
parents.Add(item);
}
}
ResetChildren(parents);
}
#endregion
#region
private void ExecuteAddLinkCommand(object obj)
{
if (obj is object[] array && array.Length == 2)
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p =>
{
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
if (p.LinkInfo == null)
p.LinkInfo = new LinkInfo();
p.LinkInfo.Link = array[0]?.ToString();
p.LinkInfo.Text = array[1]?.ToString();
});
});
}
}
@@ -610,7 +707,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
SelectedItems.OfType<MindNode>().ToList().ForEach(p => {
if (p.LinkInfo != null)
{
p.LinkInfo.Link = null;
p.LinkInfo.Link = null;
p.LinkInfo.Text = null;
}
});
@@ -698,7 +795,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectLayout(); });
RootItem?.LayoutUpdated();
RootItems?.ForEach(p => p.LayoutUpdated());
}
}
@@ -716,7 +813,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
PageBackground = Colors.White;
}
Items.OfType<MindNode>().ToList().ForEach(item => { item.ThemeChange(); });
RootItem?.LayoutUpdated();
}
}
@@ -744,7 +840,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
node.ThemeChange();
}
RootItem.LayoutUpdated();
},
() => {
//ToDo
@@ -797,13 +892,12 @@ namespace AIStudio.Wpf.Mind.ViewModels
CopyHelper.CopyPropertyValue(_formatNode.ColorViewModel, node.ColorViewModel);
CopyHelper.CopyPropertyValue(_formatNode.FontViewModel, node.FontViewModel);
}
RootItem.LayoutUpdated();
},
() => {
//ToDo
});
}
}
}
@@ -812,10 +906,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
#region
protected override void ExecuteCenterMoveCommand(object parameter)
{
RootItem.Left = (PageSize.Width - RootItem.ItemWidth) / 2;
RootItem.Top = (PageSize.Height - RootItem.ItemHeight) / 2;
RootItem?.LayoutUpdated();
FitViewModel = new FitViewModel() { BoundingRect = RootItem.GetBounds() };
var rootitem = MindSelectedItem?.RootNode;
if (rootitem != null)
{
rootitem.Left = (PageSize.Width - rootitem.ItemWidth) / 2;
rootitem.Top = (PageSize.Height - rootitem.ItemHeight) / 2;
rootitem?.LayoutUpdated();
FitViewModel = new FitViewModel() { BoundingRect = rootitem.GetBounds() };
}
}
private void ExecutedExpand2LevelCommand(object obj)
@@ -914,55 +1012,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
#endregion
#region
protected override void ExecutedResetLayoutCommand(object obj)
{
foreach (var item in Items.OfType<MindNode>())
{
item.Offset = new DiagramDesigner.Geometrys.PointBase();
}
RootItem?.LayoutUpdated();
}
private void ResetChildren(MindNode parent)
{
if (parent == null)
return;
parent.Children = new System.Collections.ObjectModel.ObservableCollection<MindNode>(Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id));
foreach (var item in Items.OfType<MindNode>().Where(p => p.ParentId == parent.Id))
{
item.Parent = parent;
item.InitLayout(false);
item.InitConnectLayout();
ResetChildren(item);
}
}
private List<MindNode> GetParent(MindNode node)
{
List<MindNode> mindnode = new List<MindNode>();
while (node.ParentNode != null)
{
mindnode.Add(node.ParentNode);
node = node.ParentNode;
}
return mindnode;
}
private List<MindNode> GetChildren(MindNode parent)
{
List<MindNode> mindnode = new List<MindNode>();
if (parent.Children != null)
{
foreach (var child in parent.Children)
{
mindnode.Add(child);
mindnode.AddRange(GetChildren(child));
}
}
return mindnode;
}
#endregion
}
}