From e0bb8072149d11d3ccaeace2cfcaf0b6040ed35a Mon Sep 17 00:00:00 2001 From: zengwenjie <1663900244@qq.com> Date: Fri, 19 Sep 2025 16:51:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8F=82=E6=95=B0=E5=88=86?= =?UTF-8?q?=E7=BB=84=E6=9E=84=E5=BB=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attribute/ParamDefineAttribute.cs | 6 ++ .../Attribute/ParamGroupAttribute.cs | 60 +++++++++++++++++++ DeedyDesigner/Deedy.Activity/BasalAction.cs | 5 +- .../Collection/ParamGroupCollection.cs | 40 ++++++++++++- .../Deedy.Activity/DeedyVisual/DeedyLayout.cs | 4 +- .../Deedy.Activity/Helpers/ActionHelper.cs | 10 +--- .../Deedy.Activity/Helpers/ElementHelper.cs | 27 +++++++++ DeedyDesigner/Deedy.Activity/IActivity.cs | 3 +- DeedyDesigner/Deedy.Activity/IElement.cs | 2 + 9 files changed, 143 insertions(+), 14 deletions(-) diff --git a/DeedyDesigner/Deedy.Activity/Attribute/ParamDefineAttribute.cs b/DeedyDesigner/Deedy.Activity/Attribute/ParamDefineAttribute.cs index 29cc4f2..c53f89f 100644 --- a/DeedyDesigner/Deedy.Activity/Attribute/ParamDefineAttribute.cs +++ b/DeedyDesigner/Deedy.Activity/Attribute/ParamDefineAttribute.cs @@ -10,5 +10,11 @@ namespace Deedy.Activity public class ParamDefineAttribute : Attribute, IInitialSortable { public int InitialSort { get; set; } = 0; + public ParamDefineAttribute() { } + public string Title { get; set; } = "参数名称"; + public string Remark { get; set; } = "参数描述"; + public string Default { get; set; } = ""; + public string DesignValue { get; set; } = ""; + public string GroupName { get; set; } = ""; } } diff --git a/DeedyDesigner/Deedy.Activity/Attribute/ParamGroupAttribute.cs b/DeedyDesigner/Deedy.Activity/Attribute/ParamGroupAttribute.cs index e98eae3..cbc53df 100644 --- a/DeedyDesigner/Deedy.Activity/Attribute/ParamGroupAttribute.cs +++ b/DeedyDesigner/Deedy.Activity/Attribute/ParamGroupAttribute.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Security.Policy; using System.Text; using System.Threading.Tasks; @@ -8,6 +10,64 @@ namespace Deedy.Activity { public class ParamGroupAttribute : Attribute, IInitialSortable { + protected internal ParamGroupAttribute() { } + public ParamGroupAttribute(string groupName, int initialSort = 0, bool canAddNew = false) + { + if (string.IsNullOrWhiteSpace(groupName)) throw new ArgumentNullException("参数分组名称不可为「null」或「空白字符」"); + if (groupName == RuntimeParams || groupName == WorkingParams || groupName == DefaultParams) throw new ArgumentException("不可以用系统保留名称做为自定义分组名称..."); + this.GroupName = groupName; + this.InitialSort = initialSort; + this.CanAddNew = canAddNew; + } + public const string RuntimeParams = "系统参数"; + public const string WorkingParams = "工作参数"; + public const string DefaultParams = "其它参数"; public int InitialSort { get; set; } = 0; + private string _GroupName = ""; + public string GroupName + { + get + { + if (string.IsNullOrEmpty(_GroupName)) _GroupName = DefaultParams; + return _GroupName; + } + private set + { + if (value == _GroupName) return; + if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(value.Trim())) _GroupName = DefaultParams; + else _GroupName = value; + } + } + [AllowNull] + private string _Description; + + public string Description + { + get { return string.IsNullOrEmpty(_Description) ? _GroupName : _Description; } + set { _Description = string.IsNullOrEmpty(value) ? _GroupName : value; } + } + + public bool CanAddNew { get; protected internal set; } + + public ParamDefineCollection Params { get; protected internal set; } = []; + + internal static ParamGroupAttribute CreateRuntimeGroup() => new() + { + GroupName = RuntimeParams, + Description = "运行时需要的参数,自定义参数尽量不要放置到此分组中...", + InitialSort = int.MinValue + }; + internal static ParamGroupAttribute CreateWorkingParams() => new() + { + GroupName = WorkingParams, + Description = "动作执行时的工作逻辑所需要的参数", + InitialSort = int.MinValue + 1 + }; + internal static ParamGroupAttribute CreateDefaultGroup() => new() + { + GroupName = DefaultParams, + Description = "所有未分组参数均会被默认放置到此分组中", + InitialSort = int.MaxValue + }; } } diff --git a/DeedyDesigner/Deedy.Activity/BasalAction.cs b/DeedyDesigner/Deedy.Activity/BasalAction.cs index 357b0a1..89c4dd0 100644 --- a/DeedyDesigner/Deedy.Activity/BasalAction.cs +++ b/DeedyDesigner/Deedy.Activity/BasalAction.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; using System.Text; @@ -38,8 +39,8 @@ namespace Deedy.Activity public IActionViewer? ActionViewer { get; protected internal set; } public IElement RootElement => (this.ParentElement == null) ? this : this.ParentElement.RootElement; - - public Runtime Runtime => throw new NotImplementedException(); + public Runtime? Runtime { get; protected internal set; } + public ParamDefineCollection ParamsMapping { get; set; } = []; public event PropertyChangedEventHandler? PropertyChanged; diff --git a/DeedyDesigner/Deedy.Activity/Collection/ParamGroupCollection.cs b/DeedyDesigner/Deedy.Activity/Collection/ParamGroupCollection.cs index c3d1ee3..f28b181 100644 --- a/DeedyDesigner/Deedy.Activity/Collection/ParamGroupCollection.cs +++ b/DeedyDesigner/Deedy.Activity/Collection/ParamGroupCollection.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Windows.Documents; namespace Deedy.Activity { @@ -12,6 +14,42 @@ namespace Deedy.Activity [DebuggerDisplay("Count = {Count}")] public class ParamGroupCollection : InitialSortedObservableCollection { - internal ParamGroupCollection() { } + private ParamGroupAttribute _DefaultGroup = ParamGroupAttribute.CreateDefaultGroup(); + internal ParamGroupCollection() + { + this.Add(ParamGroupAttribute.CreateRuntimeGroup()); + this.Add(ParamGroupAttribute.CreateWorkingParams()); + this.Add(_DefaultGroup); + } + public override void Add(ParamGroupAttribute item) + { + foreach (var oldItem in this) + { + if (oldItem.GroupName == item.GroupName) return; + } + base.Add(item); + } + public void AddFromType(Type type) + { + var pgas = type.GetCustomAttributes(true); + foreach (var attr in pgas) this.Add(attr); + } + public void AppendParamDefine(ParamDefineAttribute paramDefine) + { + foreach (var item in this) + { + if (item.GroupName == paramDefine.GroupName) + { + item.Params.Add(paramDefine); + return; + } + } + paramDefine.GroupName = ParamGroupAttribute.DefaultParams; + this._DefaultGroup.Params.Add(paramDefine); + } + public void AppendParamRange(IEnumerable paramDefines) + { + foreach (var paramDefine in paramDefines) this.AppendParamDefine(paramDefine); + } } } diff --git a/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs b/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs index 9de85e5..b9509aa 100644 --- a/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs +++ b/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs @@ -24,7 +24,9 @@ namespace Deedy.Activity public ElementCollection Elements { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public Runtime Runtime => throw new NotImplementedException(); + public Runtime? Runtime => throw new NotImplementedException(); + + public ParamDefineCollection ParamsMapping { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public event PropertyChangedEventHandler? PropertyChanged; diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs index 5c578cf..6b2c272 100644 --- a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs +++ b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs @@ -152,15 +152,7 @@ namespace Deedy.Activity if (oldIndex < 0) @this.Help_Insert(element, (uint)newIndex); else @this.Elements.Move(oldIndex, newIndex); } - /// - /// 帮助一个IElement节点构建参数映射表 - /// - /// 需要构建参数映射表的Element节点 - /// 消息输出器 - public static void Help_BuildParamMapping(this IElement element, Output? output = null) - { - //TODO:构建元素的参数映射表 - } + /// /// 将一个元素插入到当前节点前方「前提:当前节点的父级必须是可变容器节点」 /// diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs index 74b0ff1..af163e5 100644 --- a/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs +++ b/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs @@ -91,5 +91,32 @@ namespace Deedy.Activity } [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "set_ParentElement")] private static extern void ActionSetter_ParentElement(BasalAction action, IElement? value); + /// + /// 帮助一个IElement节点构建参数映射表 + /// + /// 需要构建参数映射表的Element节点 + /// 消息输出器 + public static void Help_BuildParamMapping(this IElement element, Output? output = null) + { + //TODO:构建元素的参数映射表 + if (element == null) return; + if (element.ParamsMapping == null) element.ParamsMapping = new(); + } + /// + /// 构建一个元素的参数分组,为设计器准备的辅助方法 + /// + /// + /// + /// + public static ParamGroupCollection Help_BuildParamGroup(this IElement element, Output? output = null) + { + ParamGroupCollection result = new(); + if (element != null) + { + result.AddFromType(element.GetType()); + result.AppendParamRange(element.ParamsMapping); + } + return result; + } } } diff --git a/DeedyDesigner/Deedy.Activity/IActivity.cs b/DeedyDesigner/Deedy.Activity/IActivity.cs index 0191d57..f991fb5 100644 --- a/DeedyDesigner/Deedy.Activity/IActivity.cs +++ b/DeedyDesigner/Deedy.Activity/IActivity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,7 +9,7 @@ namespace Deedy.Activity { public interface IActivity { - public Runtime Runtime { get; } + public Runtime? Runtime { get; } public void ReadyToWorking(IElement? element = null, Output? output = null); public void ReadyToEditing(Runtime runtime); public void ReadyToRunning(Runtime runtime); diff --git a/DeedyDesigner/Deedy.Activity/IElement.cs b/DeedyDesigner/Deedy.Activity/IElement.cs index e347939..780ab24 100644 --- a/DeedyDesigner/Deedy.Activity/IElement.cs +++ b/DeedyDesigner/Deedy.Activity/IElement.cs @@ -19,6 +19,8 @@ namespace Deedy.Activity public int DepthLevel { get; } public IElement? ParentElement { get; } public IElement RootElement { get; } + public ParamDefineCollection ParamsMapping { get; set; } + /// /// 将当前节点链接到一个节点上 ///