This commit is contained in:
kwai
2023-03-01 19:28:06 +08:00
parent 84d4035e6d
commit 9966656269
17 changed files with 525 additions and 30 deletions

View File

@@ -20,7 +20,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AIStudio.Wpf.Flowchart\AIStudio.Wpf.Flowchart.csproj" />
<ProjectReference Include="..\AIStudio.Wpf.DiagramModels\AIStudio.Wpf.DiagramModels.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,44 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:AIStudio.Wpf.Mind.Controls"
xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Mind;component/Themes/MindNode.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.DiagramDesigner;component/Styles/ComboBox.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="AIStudio.Styles.MindEditor" TargetType="{x:Type controls:MindEditor}">
<Setter Property="Focusable" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:MindEditor}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<!-- ToolBox Control -->
<ContentControl Template="{Binding ToolBox,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
<ScrollViewer Grid.Column="1">
<!-- Diagram Control -->
<dd:DiagramControl x:Name="PART_DiagramControl" MinWidth="1000" MinHeight="1000" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="AIStudio.Styles.MindEditor.Default" TargetType="{x:Type controls:MindEditor}" BasedOn="{StaticResource AIStudio.Styles.MindEditor}">
<Setter Property="ToolBox">
<Setter.Value>
<ControlTemplate TargetType="Control">
<controls:ToolBoxControl />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type controls:MindEditor}" BasedOn="{StaticResource AIStudio.Styles.MindEditor.Default}" />
</ResourceDictionary>

View File

@@ -159,6 +159,26 @@ namespace AIStudio.Wpf.Mind.Controls
}
}
#region ToolBox
/// <summary>
/// 附加组件模板
/// </summary>
public static readonly DependencyProperty ToolBoxProperty = DependencyProperty.Register(
nameof(ToolBox), typeof(ControlTemplate), typeof(MindEditor), new FrameworkPropertyMetadata(default(ControlTemplate)));
public ControlTemplate ToolBox
{
get
{
return (ControlTemplate)GetValue(ToolBoxProperty);
}
set
{
SetValue(ToolBoxProperty, value);
}
}
#endregion
#region SelectedObject
public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register(nameof(SelectedObject), typeof(object), typeof(MindEditor), new UIPropertyMetadata(default(object)));

View File

@@ -0,0 +1,37 @@
<UserControl x:Class="AIStudio.Wpf.Mind.Controls.ToolBoxControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:AIStudio.Wpf.Mind.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" >
<Grid Height="60">
<TabControl>
<TabItem Header="思路">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
</TabItem>
<TabItem Header="外观">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
</TabItem>
<TabItem Header="视图">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
</TabItem>
</TabControl>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AIStudio.Wpf.Mind.Controls
{
/// <summary>
/// ToolBoxControl.xaml 的交互逻辑
/// </summary>
public partial class ToolBoxControl : UserControl
{
public ToolBoxControl()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,84 @@
using System.Windows;
using System.Xml.Serialization;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.Mind.ViewModels;
using Newtonsoft.Json;
namespace AIStudio.Wpf.Mind.Models
{
public class MindNodeDesignerItem : DesignerItemBase
{
public MindNodeDesignerItem()
{
}
public MindNodeDesignerItem(MindNode item) : base(item)
{
NodeLevel = item.NodeLevel;
MindType = item.MindType;
Spacing = item.Spacing;
Offset = item.Offset;
IsExpanded = item.IsExpanded;
}
[XmlAttribute]
public NodeLevel NodeLevel
{
get; set;
}
[XmlAttribute]
public MindType MindType
{
get; set;
}
[XmlIgnore]
public Size Spacing
{
get; set;
}
[JsonIgnore]
[XmlAttribute("Spacing")]
public string XmlSpacing
{
get
{
return SerializeHelper.SerializeSize(Spacing);
}
set
{
Spacing = SerializeHelper.DeserializeSize(value);
}
}
[XmlIgnore]
public Point Offset
{
get; set;
}
[JsonIgnore]
[XmlAttribute("Offset")]
public string XmlOffset
{
get
{
return SerializeHelper.SerializePoint(Offset);
}
set
{
Offset = SerializeHelper.DeserializePoint(value);
}
}
[XmlAttribute]
public bool IsExpanded
{
get; set;
}
}
}

View File

@@ -0,0 +1,51 @@
using System.Windows;
using AIStudio.Wpf.DiagramModels;
using AIStudio.Wpf.DiagramModels.ViewModels;
using AIStudio.Wpf.Mind;
using AIStudio.Wpf.Mind.ViewModels;
namespace AIStudio.Wpf.Flowchart.Models
{
public class MindNodeModel : DiagramNode
{
public NodeLevel NodeLevel
{
get; set;
}
public MindType MindType
{
get; set;
}
public Size Spacing
{
get; set;
}
public Point Offset
{
get; set;
}
public bool IsExpanded
{
get; set;
}
public override DiagramItemViewModel ToNodel()
{
MindNode mindNode = new MindNode(NodeLevel, MindType);
mindNode.Spacing = Spacing;
mindNode.Offset = Offset;
mindNode.IsExpanded = IsExpanded;
return mindNode;
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Markup;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
@@ -8,3 +9,9 @@ using System.Windows;
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
[assembly: XmlnsDefinition("https://gitee.com/akwkevin/aistudio.-wpf.-diagram", "AIStudio.Wpf.Mind")]
[assembly: XmlnsDefinition("https://gitee.com/akwkevin/aistudio.-wpf.-diagram", "AIStudio.Wpf.Mind.Controls")]
[assembly: XmlnsDefinition("https://gitee.com/akwkevin/aistudio.-wpf.-diagram", "AIStudio.Wpf.Mind.Controls")]
[assembly: XmlnsPrefix("https://gitee.com/akwkevin/aistudio.-wpf.-diagram", "dd")]

View File

@@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Flowchart;component/Controls/FlowchartEditor.xaml"/>-->
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Mind;component/Controls/MindEditor.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

View File

@@ -8,16 +8,21 @@ using System.Text;
using System.Windows;
using System.Windows.Controls;
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.Flowchart.Models;
using AIStudio.Wpf.Mind.Helpers;
using AIStudio.Wpf.Mind.Models;
namespace AIStudio.Wpf.Mind.ViewModels
{
public class MindNode : DesignerItemViewModelBase
public class MindNode : DiagramItemViewModel
{
public MindNode(NodeLevel nodeLevel, MindType mindType = MindType.Mind) : this(null, nodeLevel, mindType)
{
@@ -42,6 +47,11 @@ namespace AIStudio.Wpf.Mind.ViewModels
InitLayout();
}
public override SelectableItemBase GetSerializableObject()
{
return new MindNodeDesignerItem(this);
}
protected override void Init(IDiagramViewModel root)
{
base.Init(root);
@@ -65,6 +75,35 @@ namespace AIStudio.Wpf.Mind.ViewModels
MindLayout = layout != null ? (System.Activator.CreateInstance(layout) as IMindLayout) : new MindLayout();
}
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
{
base.LoadDesignerItemViewModel(designerbase);
if (designerbase is MindNodeDesignerItem designer)
{
NodeLevel = designer.NodeLevel;
MindType = designer.MindType;
Spacing = designer.Spacing;
Offset = designer.Offset;
IsExpanded = designer.IsExpanded;
}
}
public override DiagramNode ToDiagram()
{
var mindNodeModel = new MindNodeModel();
mindNodeModel.NodeLevel = NodeLevel;
mindNodeModel.MindType = MindType;
mindNodeModel.Spacing = Spacing;
mindNodeModel.Offset = Offset;
mindNodeModel.IsExpanded = IsExpanded;
return mindNodeModel;
}
private bool Level_Enable(object obj)
{
@@ -103,33 +142,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
SetProperty(ref _mindType, value);
}
}
private CornerRadius _cornerRadius = new CornerRadius(3);
public CornerRadius CornerRadius
{
get
{
return _cornerRadius;
}
set
{
SetProperty(ref _cornerRadius, value);
}
}
private Thickness _borderThickness = new Thickness(1);
public Thickness BorderThickness
{
get
{
return _borderThickness;
}
set
{
SetProperty(ref _borderThickness, value);
}
}
}
private bool _isExpanded = true;
public bool IsExpanded