diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/FlowchartViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/FlowchartViewModel.cs index b453e2f..94dd989 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/FlowchartViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/FlowchartViewModel.cs @@ -106,6 +106,7 @@ namespace AIStudio.Wpf.Flowchart FlowchartService.InitData(DiagramViewModel.Items.OfType().ToList(), DiagramViewModel.Items.OfType().ToList(), DiagramViewModel); } + public override void Dispose() { diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/MainWindowViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/MainWindowViewModel.cs index 605d051..0214b8f 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/MainWindowViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/MainWindowViewModel.cs @@ -790,6 +790,10 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels { flow = new SFCViewModel(filename, diagram); } + else if (diagram.DiagramType == DiagramType.Mind) + { + flow = new MindViewModel(filename, diagram); + } else { flow = new PageViewModel(filename, diagram); diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs index 665c037..8acd1a2 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs @@ -12,6 +12,7 @@ using System.Windows.Media; using AIStudio.Wpf.DiagramDesigner; using AIStudio.Wpf.Mind.ViewModels; using AIStudio.Wpf.Mind; +using AIStudio.Wpf.DiagramDesigner.Additionals; namespace AIStudio.Wpf.Flowchart { @@ -22,8 +23,11 @@ namespace AIStudio.Wpf.Flowchart } public MindViewModel(string filename, DiagramDocument diagramDocument) : base(filename, diagramDocument) - { - + { + foreach (var vm in DiagramViewModels) + { + vm.InitLayoutCommand.Execute(null); + } } protected override void InitDiagramViewModel() @@ -47,7 +51,7 @@ namespace AIStudio.Wpf.Flowchart { DiagramViewModels = new ObservableCollection() { - new MindDiagramViewModel(){Name= "页-1", DiagramType = DiagramType}, + GetDiagramViewModel("页-1", DiagramType), }; DiagramViewModel = DiagramViewModels.FirstOrDefault(); @@ -77,6 +81,10 @@ namespace AIStudio.Wpf.Flowchart level1node.LayoutUpdated(); } + protected override DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType) + { + return new MindDiagramViewModel() { Name = name ?? NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType }; + } public override void Dispose() { diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs index 6226992..338fdca 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/PageViewModel.cs @@ -57,7 +57,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels { DiagramViewModels = new ObservableCollection() { - new DiagramViewModel(){Name= "页-1", DiagramType = DiagramType}, + GetDiagramViewModel("页-1", DiagramType), }; DiagramViewModel = DiagramViewModels.FirstOrDefault(); @@ -241,9 +241,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels List viewModels = new List(); foreach (var diagramItem in diagramDocument.DiagramItems) { - var viewModel = new DiagramViewModel(); - viewModel.Name = diagramItem.Name; - viewModel.DiagramType = diagramItem.DiagramType; + var viewModel = GetDiagramViewModel(diagramItem.Name, diagramItem.DiagramType); viewModel.ShowGrid = diagramItem.ShowGrid; viewModel.PhysicalGridCellSize = diagramItem.PhysicalGridCellSize; viewModel.CellHorizontalAlignment = diagramItem.CellHorizontalAlignment; @@ -429,12 +427,17 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels { index = DiagramViewModels.Count; } - var page = new DiagramViewModel() { Name = NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = DiagramType }; + var page = GetDiagramViewModel(null, DiagramType); DiagramViewModels.Insert(index, page); DiagramViewModel = page; InitDiagramViewModel(); } + protected virtual DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType) + { + return new DiagramViewModel() { Name = name??NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType }; + } + public void AddCopyPageExecuted(object para) { if (DiagramViewModel != null) diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index 61078d6..87858f3 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -935,6 +935,24 @@ namespace AIStudio.Wpf.DiagramDesigner return this._redoCommand ?? (this._redoCommand = new SimpleCommand(Redo_Enabled, this.ExecutedRedoCommand)); } } + + private SimpleCommand _initLayoutCommand; + public SimpleCommand InitLayoutCommand + { + get + { + return this._initLayoutCommand ?? (this._initLayoutCommand = new SimpleCommand(ExecuteEnable, this.ExecutedInitLayoutCommand)); + } + } + + private SimpleCommand _resetLayoutCommand; + public SimpleCommand ResetLayoutCommand + { + get + { + return this._resetLayoutCommand ?? (this._resetLayoutCommand = new SimpleCommand(ExecuteEnable, this.ExecutedResetLayoutCommand)); + } + } #endregion public DoCommandManager DoCommandManager = new DoCommandManager(); @@ -1037,6 +1055,16 @@ namespace AIStudio.Wpf.DiagramDesigner #endregion + protected virtual void ExecutedInitLayoutCommand(object obj) + { + throw new NotImplementedException(); + } + + protected virtual void ExecutedResetLayoutCommand(object obj) + { + throw new NotImplementedException(); + } + private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.OldItems != null) diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs index 16733ed..5b7b21e 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/IDiagramViewModel.cs @@ -194,6 +194,15 @@ namespace AIStudio.Wpf.DiagramDesigner { get; } + SimpleCommand InitLayoutCommand + { + get; + } + + SimpleCommand ResetLayoutCommand + { + get; + } event DiagramEventHandler Event; diff --git a/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs b/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs index 845c8dc..8957b46 100644 --- a/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs +++ b/AIStudio.Wpf.Mind/ViewModels/IMindDiagramViewModel.cs @@ -59,11 +59,6 @@ namespace AIStudio.Wpf.Mind.ViewModels get; } - SimpleCommand ResetLayoutCommand - { - get; - } - SimpleCommand Expand2Level1Command { get; diff --git a/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs b/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs index 7049ae9..9e1dd87 100644 --- a/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs +++ b/AIStudio.Wpf.Mind/ViewModels/MindDiagramViewModel.cs @@ -106,15 +106,6 @@ namespace AIStudio.Wpf.Mind.ViewModels } } - private SimpleCommand _resetLayoutCommand; - public SimpleCommand ResetLayoutCommand - { - get - { - return this._resetLayoutCommand ?? (this._resetLayoutCommand = new SimpleCommand(MindExecuteEnable, this.ExecutedResetLayoutCommand)); - } - } - private SimpleCommand _expand2Level1Command; public SimpleCommand Expand2Level1Command { @@ -443,10 +434,6 @@ namespace AIStudio.Wpf.Mind.ViewModels } - private void ExecutedResetLayoutCommand(object obj) - { - throw new NotImplementedException(); - } private void ExecutedExpand2Level1Command(object obj) { @@ -478,6 +465,31 @@ namespace AIStudio.Wpf.Mind.ViewModels throw new NotImplementedException(); } #endregion + protected override void ExecutedInitLayoutCommand(object obj) + { + GetChildren(RootItem); + RootItem?.LayoutUpdated(); + } + protected override void ExecutedResetLayoutCommand(object obj) + { + foreach (var item in Items.OfType()) + { + item.Offset = new DiagramDesigner.Geometrys.PointBase(); + } + RootItem?.LayoutUpdated(); + } + + private void GetChildren(MindNode parent) + { + if (parent == null) + return; + + parent.Children = new System.Collections.ObjectModel.ObservableCollection(Items.OfType().Where(p => p.ParentId == parent.Id)); + foreach (var item in Items.OfType().Where(p => p.ParentId == parent.Id)) + { + GetChildren(item); + } + } } }