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

@@ -100,7 +100,7 @@ namespace AIStudio.Wpf.Flowchart
DiagramViewModel = DiagramViewModels.FirstOrDefault(); DiagramViewModel = DiagramViewModels.FirstOrDefault();
InitDiagramViewModel(); InitDiagramViewModel();
var level1node = MindDiagramViewModel.RootItem; var level1node = MindDiagramViewModel.RootItems.FirstOrDefault();
MindNode level2node1_1 = new MindNode(DiagramViewModel) { Text = "分支主题1" }; MindNode level2node1_1 = new MindNode(DiagramViewModel) { Text = "分支主题1" };
MindDiagramViewModel.AddChildCommand.Execute(new MindNode[] { level1node, level2node1_1 }); MindDiagramViewModel.AddChildCommand.Execute(new MindNode[] { level1node, level2node1_1 });

View File

@@ -144,13 +144,11 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
if (_diagramViewModel != null) if (_diagramViewModel != null)
{ {
_diagramViewModel.PropertyChanged -= DiagramViewModel_PropertyChanged; _diagramViewModel.PropertyChanged -= DiagramViewModel_PropertyChanged;
_diagramViewModel.OutAddVerify -= AddVerify;
} }
SetProperty(ref _diagramViewModel, value); SetProperty(ref _diagramViewModel, value);
if (_diagramViewModel != null) if (_diagramViewModel != null)
{ {
_diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged; _diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
_diagramViewModel.OutAddVerify += AddVerify;
} }
} }
} }

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Input;
namespace AIStudio.Wpf.DiagramDesigner namespace AIStudio.Wpf.DiagramDesigner
{ {
@@ -59,13 +60,13 @@ namespace AIStudio.Wpf.DiagramDesigner
public class CinchMenuItem public class CinchMenuItem
{ {
#region Public Properties #region Public Properties
public String Text { get; set; } public string Text { get; set; }
public String IconUrl { get; set; } public string IconUrl { get; set; }
public bool IsChecked { get; set; } public bool IsChecked { get; set; }
public bool IsCheckable { get; set; } public bool IsCheckable { get; set; }
public List<CinchMenuItem> Children { get; private set; } public List<CinchMenuItem> Children { get; private set; }
public Object CommandParameter { get; set; } public object CommandParameter { get; set; }
public SimpleCommand Command { get; set; } public ICommand Command { get; set; }
#endregion #endregion
#region Ctor #region Ctor

View File

@@ -27,14 +27,14 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
PathMode = drawMode.ToString(); PathMode = drawMode.ToString();
RouterMode = routerMode.ToString(); RouterMode = routerMode.ToString();
Init(sourceConnectorInfo, sinkConnectorInfo); Init(root, sourceConnectorInfo, sinkConnectorInfo);
} }
public ConnectionViewModel(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo, ConnectionItem designer) : base(root, designer) public ConnectionViewModel(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo, ConnectionItem designer) : base(root, designer)
{ {
PathMode = designer.PathMode; PathMode = designer.PathMode;
RouterMode = designer.RouterMode; RouterMode = designer.RouterMode;
Init(sourceConnectorInfo, sinkConnectorInfo); Init(root, sourceConnectorInfo, sinkConnectorInfo);
} }
public override SelectableItemBase GetSerializableObject() public override SelectableItemBase GetSerializableObject()
@@ -51,9 +51,9 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
protected virtual void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo) protected virtual void Init(IDiagramViewModel root, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
{ {
this.Root = sourceConnectorInfo.DataItem.Root; this.Root = root?? sourceConnectorInfo.Root;
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false) if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
{ {
@@ -427,17 +427,17 @@ namespace AIStudio.Wpf.DiagramDesigner
#endregion #endregion
#region #region
public SimpleCommand DeleteConnectionCommand public ICommand DeleteConnectionCommand
{ {
get; set; get; set;
} }
public SimpleCommand AddVertexCommand public ICommand AddVertexCommand
{ {
get; set; get; set;
} }
public SimpleCommand AddLabelCommand public ICommand AddLabelCommand
{ {
get; set; get; set;
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Windows.Input;
using AIStudio.Wpf.DiagramDesigner.Geometrys; using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.Models;
using SvgPathProperties; using SvgPathProperties;
@@ -82,12 +83,12 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set; get; set;
} }
public SimpleCommand DeleteLabelCommand public ICommand DeleteLabelCommand
{ {
get; set; get; set;
} }
public SimpleCommand EditCommand public ICommand EditCommand
{ {
get; private set; get; private set;
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Windows.Input;
using AIStudio.Wpf.DiagramDesigner.Geometrys; using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.Models;
@@ -68,7 +69,7 @@ namespace AIStudio.Wpf.DiagramDesigner
public override PointBase MiddlePosition => new PointBase(Connector.Area.Left + Left + ConnectorWidth / 2, Connector.Area.Top + Top + ConnectorHeight / 2); public override PointBase MiddlePosition => new PointBase(Connector.Area.Left + Left + ConnectorWidth / 2, Connector.Area.Top + Top + ConnectorHeight / 2);
public SimpleCommand DeleteVertexCommand public ICommand DeleteVertexCommand
{ {
get; set; get; set;
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Input;
using AIStudio.Wpf.DiagramDesigner.Geometrys; using AIStudio.Wpf.DiagramDesigner.Geometrys;
using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.Models;
@@ -185,11 +186,11 @@ namespace AIStudio.Wpf.DiagramDesigner
#endregion #endregion
#region #region
public SimpleCommand DeleteCommand public ICommand DeleteCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand MenuItemCommand public ICommand MenuItemCommand
{ {
get; private set; get; private set;
} }

View File

@@ -13,7 +13,7 @@ namespace AIStudio.Wpf.DiagramDesigner
public interface ISelectItems public interface ISelectItems
{ {
SimpleCommand SelectItemCommand ICommand SelectItemCommand
{ {
get; get;
} }
@@ -64,7 +64,7 @@ namespace AIStudio.Wpf.DiagramDesigner
return true; return true;
} }
public SimpleCommand SelectItemCommand public ICommand SelectItemCommand
{ {
get; private set; get; private set;
} }

View File

@@ -84,12 +84,12 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
public SimpleCommand AddItemCommand public ICommand AddItemCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand ImageSwitchCommand public ICommand ImageSwitchCommand
{ {
get; private set; get; private set;
} }

View File

@@ -141,8 +141,8 @@ namespace AIStudio.Wpf.DiagramDesigner
menuOptions.Add(menuItem); menuOptions.Add(menuItem);
} }
private SimpleCommand _menuItemCommand; private ICommand _menuItemCommand;
public SimpleCommand MenuItemCommand public ICommand MenuItemCommand
{ {
get get
{ {

View File

@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.Models;
@@ -11,8 +12,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
public abstract class LogicalGateItemViewModelBase : DesignerItemViewModelBase public abstract class LogicalGateItemViewModelBase : DesignerItemViewModelBase
{ {
public SimpleCommand AddInputCommand { get; private set; } public ICommand AddInputCommand { get; private set; }
public SimpleCommand AddOutputCommand { get; private set; } public ICommand AddOutputCommand { get; private set; }
public LogicalGateItemViewModelBase(LogicalType logicalType) : this(null, logicalType) public LogicalGateItemViewModelBase(LogicalType logicalType) : this(null, logicalType)

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text; using System.Text;
using System.Windows.Input;
using AIStudio.Wpf.DiagramDesigner.Models; using AIStudio.Wpf.DiagramDesigner.Models;
namespace AIStudio.Wpf.DiagramDesigner namespace AIStudio.Wpf.DiagramDesigner
@@ -69,8 +70,8 @@ namespace AIStudio.Wpf.DiagramDesigner
menuOptions.Add(menuItem); menuOptions.Add(menuItem);
} }
private SimpleCommand _menuItemCommand; private ICommand _menuItemCommand;
public SimpleCommand MenuItemCommand public ICommand MenuItemCommand
{ {
get get
{ {

View File

@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
@@ -75,7 +76,7 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
} }
public SimpleCommand MenuItemCommand public ICommand MenuItemCommand
{ {
get; private set; get; private set;
} }

View File

@@ -31,190 +31,198 @@ namespace AIStudio.Wpf.DiagramDesigner
get; get;
} }
SimpleCommand CreateNewDiagramCommand ICommand CreateNewDiagramCommand
{ {
get; get;
} }
SimpleCommand DirectAddItemCommand ICommand DirectAddItemCommand
{ {
get; get;
} }
SimpleCommand AddItemCommand ICommand AddItemCommand
{ {
get; get;
} }
SimpleCommand RemoveItemCommand ICommand RemoveItemCommand
{ {
get; get;
} }
SimpleCommand DirectRemoveItemCommand ICommand DirectRemoveItemCommand
{ {
get; get;
} }
SimpleCommand ClearSelectedItemsCommand ICommand ClearSelectedItemsCommand
{ {
get; get;
} }
SimpleCommand AlignTopCommand ICommand AlignTopCommand
{ {
get; get;
} }
SimpleCommand AlignVerticalCentersCommand ICommand AlignVerticalCentersCommand
{ {
get; get;
} }
SimpleCommand AlignBottomCommand ICommand AlignBottomCommand
{ {
get; get;
} }
SimpleCommand AlignLeftCommand ICommand AlignLeftCommand
{ {
get; get;
} }
SimpleCommand AlignHorizontalCentersCommand ICommand AlignHorizontalCentersCommand
{ {
get; get;
} }
SimpleCommand AlignRightCommand ICommand AlignRightCommand
{ {
get; get;
} }
SimpleCommand BringForwardCommand ICommand BringForwardCommand
{ {
get; get;
} }
SimpleCommand BringToFrontCommand ICommand BringToFrontCommand
{ {
get; get;
} }
SimpleCommand SendBackwardCommand ICommand SendBackwardCommand
{ {
get; get;
} }
SimpleCommand SendToBackCommand ICommand SendToBackCommand
{ {
get; get;
} }
SimpleCommand DistributeHorizontalCommand ICommand DistributeHorizontalCommand
{ {
get; get;
} }
SimpleCommand DistributeVerticalCommand ICommand DistributeVerticalCommand
{ {
get; get;
} }
SimpleCommand SelectAllCommand ICommand SelectAllCommand
{ {
get; get;
} }
SimpleCommand SelectInverseCommand ICommand SelectInverseCommand
{ {
get; get;
} }
SimpleCommand SelectItemCommand ICommand SelectItemCommand
{ {
get; get;
} }
SimpleCommand CopyCommand ICommand CopyCommand
{ {
get; get;
} }
SimpleCommand PasteCommand ICommand PasteCommand
{ {
get; get;
} }
SimpleCommand CutCommand ICommand CutCommand
{ {
get; get;
} }
SimpleCommand DeleteCommand ICommand DeleteCommand
{ {
get; get;
} }
SimpleCommand LeftMoveCommand ICommand LeftMoveCommand
{ {
get; get;
} }
SimpleCommand RightMoveCommand ICommand RightMoveCommand
{ {
get; get;
} }
SimpleCommand UpMoveCommand ICommand UpMoveCommand
{ {
get; get;
} }
SimpleCommand DownMoveCommand ICommand DownMoveCommand
{ {
get; get;
} }
SimpleCommand CenterMoveCommand ICommand CenterMoveCommand
{ {
get; get;
} }
SimpleCommand SameSizeCommand ICommand SameSizeCommand
{ {
get; get;
} }
SimpleCommand SameWidthCommand ICommand SameWidthCommand
{ {
get; get;
} }
SimpleCommand SameHeightCommand ICommand SameHeightCommand
{ {
get; get;
} }
SimpleCommand SameAngleCommand ICommand SameAngleCommand
{ {
get; get;
} }
SimpleCommand GroupCommand ICommand FitAutoCommand
{ {
get; get;
} }
SimpleCommand UngroupCommand ICommand FitWidthCommand
{ {
get; get;
} }
SimpleCommand LockCommand ICommand FitHeightCommand
{ {
get; get;
} }
SimpleCommand UnlockCommand ICommand GroupCommand
{ {
get; get;
} }
ICommand UngroupCommand
SimpleCommand EditCommand
{ {
get; get;
} }
ICommand LockCommand
SimpleCommand UndoCommand
{ {
get; get;
} }
SimpleCommand RedoCommand ICommand UnlockCommand
{ {
get; get;
} }
ICommand EditCommand
SimpleCommand ResetLayoutCommand {
get;
}
ICommand UndoCommand
{
get;
}
ICommand RedoCommand
{
get;
}
ICommand ResetLayoutCommand
{
get;
}
ICommand SearchDownCommand
{
get;
}
ICommand SearchUpCommand
{ {
get; get;
} }
event DiagramEventHandler Event; event DiagramEventHandler Event;
Func<SelectableDesignerItemViewModelBase, bool> OutAddVerify
{
get; set;
}
//void ClearSelectedItems();
//bool BelongToSameGroup(IGroupable item1, IGroupable item2);
//Rectangle GetBoundingRectangle(IEnumerable<DesignerItemViewModelBase> items);
//void UpdateZIndex();
bool IsReadOnly bool IsReadOnly
{ {
get; set; get; set;

View File

@@ -79,7 +79,12 @@
<TextBlock>插入同级主题</TextBlock> <TextBlock>插入同级主题</TextBlock>
</StackPanel> </StackPanel>
</Button> </Button>
<Button Style="{StaticResource FlatButtonStyle}" Command="{Binding AddRootCommand}">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Stretch="Uniform" Fill="Black" Data="M696 334.2H326.6c-27.4 0-49.7-22.3-49.7-49.7V114c0-27.4 22.3-49.7 49.7-49.7H696c27.4 0 49.7 22.3 49.7 49.7v170.5c0.1 27.4-22.2 49.7-49.7 49.7zM326.6 106.8c-3.9 0-7.1 3.3-7.1 7.1v170.5c0 3.9 3.3 7.1 7.1 7.1H696c3.9 0 7.1-3.3 7.1-7.1V114c0-3.9-3.3-7.1-7.1-7.1H326.6zM895 960.8H127.7c-27.4 0-49.7-22.3-49.7-49.7V541.6c0-27.4 22.3-49.7 49.7-49.7H895c27.4 0 49.7 22.3 49.7 49.7V911c0 27.5-22.3 49.8-49.7 49.8zM127.7 534.5c-3.9 0-7.1 3.3-7.1 7.1V911c0 3.9 3.3 7.1 7.1 7.1H895c3.9 0 7.1-3.3 7.1-7.1V541.6c0-3.9-3.3-7.1-7.1-7.1H127.7zM511.4 533.1c-11.8 0-21.3-9.5-21.3-21.3l-0.1-198.9c0-11.8 9.5-21.3 21.3-21.3s21.3 9.5 21.3 21.3l0.1 198.9c0 11.8-9.5 21.3-21.3 21.3z"></Path>
<TextBlock>新建根主题</TextBlock>
</StackPanel>
</Button>
</UniformGrid> </UniformGrid>
<Line Grid.Column="3" X1="0" Y1="0" X2="0" Y2="100" StrokeDashArray="1" Stroke="Gray" StrokeThickness="1"></Line> <Line Grid.Column="3" X1="0" Y1="0" X2="0" Y2="100" StrokeDashArray="1" Stroke="Gray" StrokeThickness="1"></Line>
<UniformGrid Rows="2" Grid.Row="0" Grid.Column="4" > <UniformGrid Rows="2" Grid.Row="0" Grid.Column="4" >
@@ -611,7 +616,7 @@
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using AIStudio.Wpf.DiagramDesigner; using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.Mind.Helpers; using AIStudio.Wpf.Mind.Helpers;
@@ -20,67 +21,111 @@ namespace AIStudio.Wpf.Mind.ViewModels
get; set; get; set;
} }
MindNode RootItem List<MindNode> RootItems
{ {
get; get;
} }
ICommand AddRootCommand
SimpleCommand AddParentCommand
{ {
get; get;
} }
ICommand AddParentCommand
SimpleCommand AddChildCommand
{ {
get; get;
} }
ICommand AddChildCommand
SimpleCommand AddPearCommand
{ {
get; get;
} }
ICommand AddPearCommand
SimpleCommand MoveForwardCommand
{ {
get; get;
} }
ICommand MoveForwardCommand
SimpleCommand MoveBackCommand
{ {
get; get;
} }
ICommand MoveBackCommand
SimpleCommand ChangeMindTypeCommand
{ {
get; get;
} }
ICommand SelectBrotherCommand
SimpleCommand ChangeMindThemeCommand
{ {
get; get;
} }
ICommand SelectPearCommand
SimpleCommand SelectBrotherCommand
{ {
get; get;
} }
ICommand SelectRouteCommand
SimpleCommand SelectPearCommand
{ {
get; get;
} }
ICommand SelectChildCommand
SimpleCommand SelectRouteCommand
{ {
get; get;
} }
ICommand AddLinkCommand
SimpleCommand SelectChildCommand
{ {
get; get;
} }
ICommand RemoveLinkCommand
SimpleCommand Expand2LevelCommand {
get;
}
ICommand AddImageCommand
{
get;
}
ICommand RemoveImageCommand
{
get;
}
ICommand AddRemarkCommand
{
get;
}
ICommand RemoveRemarkCommand
{
get;
}
ICommand AddPriorityCommand
{
get;
}
ICommand AddRatioCommand
{
get;
}
ICommand AddTagCommand
{
get;
}
ICommand RemoveTagCommand
{
get;
}
ICommand ChangeMindTypeCommand
{
get;
}
ICommand ChangeMindThemeCommand
{
get;
}
ICommand ClearThemeCommand
{
get;
}
ICommand CopyThemeCommand
{
get;
}
ICommand PasteThemeCommand
{
get;
}
ICommand Expand2LevelCommand
{ {
get; get;
} }

View File

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

View File

@@ -8,6 +8,7 @@ using System.Security.Policy;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Xml.Linq; using System.Xml.Linq;
using AIStudio.Wpf.DiagramDesigner; using AIStudio.Wpf.DiagramDesigner;
@@ -139,7 +140,14 @@ namespace AIStudio.Wpf.Mind.ViewModels
{ {
return Parent as MindNode; return Parent as MindNode;
} }
}
public MindNode RootNode
{
get
{
return GetLevel1Node();
}
} }
public int NodeLevel public int NodeLevel
@@ -373,32 +381,32 @@ namespace AIStudio.Wpf.Mind.ViewModels
#endregion #endregion
#region #region
public SimpleCommand AddParentCommand public ICommand AddParentCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand AddChildCommand public ICommand AddChildCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand AddPearCommand public ICommand AddPearCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand DeleteCommand public ICommand DeleteCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand MoveForwardCommand public ICommand MoveForwardCommand
{ {
get; private set; get; private set;
} }
public SimpleCommand MoveBackCommand public ICommand MoveBackCommand
{ {
get; private set; get; private set;
} }
@@ -490,9 +498,10 @@ namespace AIStudio.Wpf.Mind.ViewModels
public void InitConnectLayout() public void InitConnectLayout()
{ {
var connector = Root?.Items.OfType<ConnectionViewModel>().Where(p => p.IsFullConnection).FirstOrDefault(p => p.SinkConnectorInfoFully.DataItem == this); var connector = Root?.Items.OfType<ConnectionViewModel>().Where(p => p.IsFullConnection).FirstOrDefault(p => p.SinkConnectorInfoFully.DataItem == this);
if (connector != null) var newconnecter = MindLayout?.GetOrSetConnectionViewModel(connector.SourceConnectorInfo.DataItem as MindNode, connector.SinkConnectorInfoFully.DataItem as MindNode, connector);
if (connector == null)
{ {
MindLayout?.GetOrSetConnectionViewModel(connector.SourceConnectorInfo.DataItem as MindNode, connector.SinkConnectorInfoFully.DataItem as MindNode, connector); Root?.DirectAddItemCommand.Execute(new SelectableDesignerItemViewModelBase[] { newconnecter });
} }
} }
#endregion #endregion