From c85bb43830967490ae626f0897231e3e587ab210 Mon Sep 17 00:00:00 2001 From: zengwenjie <1663900244@qq.com> Date: Thu, 18 Sep 2025 15:37:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E7=A7=81=E6=9C=89=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BE=E7=BD=AE=E8=BE=85=E5=8A=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DeedyDesigner/Deedy.Activity/ActionViewer.cs | 1 + .../Attribute/CombinePartActionAttribute.cs | 20 +++++++ DeedyDesigner/Deedy.Activity/BasalAction.cs | 10 ++-- .../Collection/ElementCollection.cs | 2 +- .../Collection/ExpandoMapping.cs | 15 +++++ .../Contract/Interface/ICombinedElement.cs | 3 + .../Deedy.Activity/Controller/Runtime.cs | 2 + .../Deedy.Activity/DeedyVisual/DeedyLayout.cs | 10 ++-- DeedyDesigner/Deedy.Activity/Helper.cs | 60 ++++++++++++++++++- DeedyDesigner/Deedy.Activity/IActionViewer.cs | 1 - DeedyDesigner/Deedy.Activity/IActivity.cs | 2 + DeedyDesigner/Deedy.Activity/IElement.cs | 23 ++++--- .../Deedy.Testing/Deedy.Testing.csproj | 4 ++ 13 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs create mode 100644 DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs diff --git a/DeedyDesigner/Deedy.Activity/ActionViewer.cs b/DeedyDesigner/Deedy.Activity/ActionViewer.cs index a4eb42b..c2a8eb1 100644 --- a/DeedyDesigner/Deedy.Activity/ActionViewer.cs +++ b/DeedyDesigner/Deedy.Activity/ActionViewer.cs @@ -31,6 +31,7 @@ namespace Deedy.Activity { public static double IndentRuler { get; set; } = 30; + public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping(); public const string PART_ItemsContainer = "PART_ItemsContainer"; public const string PART_TitleContainer = "PART_TitleContainer"; diff --git a/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs b/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs new file mode 100644 index 0000000..bf44ce0 --- /dev/null +++ b/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Deedy.Activity +{ + [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] + public class CombinePartActionAttribute : Attribute + { + public CombinePartActionAttribute(int sort) { this.Sort = sort; } + public int Sort { get; private set; } + public void Binding(object target, PropertyInfo property) + { + if (!property.CanRead || !property.CanWrite) throw new ArgumentException("绑定为组装部件的属性必须具备写访问器..."); + } + } +} diff --git a/DeedyDesigner/Deedy.Activity/BasalAction.cs b/DeedyDesigner/Deedy.Activity/BasalAction.cs index 0a07465..0262239 100644 --- a/DeedyDesigner/Deedy.Activity/BasalAction.cs +++ b/DeedyDesigner/Deedy.Activity/BasalAction.cs @@ -10,11 +10,13 @@ namespace Deedy.Activity { public abstract class BasalAction : IActionElement { + public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping(); + protected internal BasalAction() { } - public string DEClass { get; protected internal set; } = ""; - public string DETitle { get; set; } = ""; - public string DERemark { get; set; } = ""; - public string DEIdentify { get; set; } = ""; + public string Class { get; protected internal set; } = ""; + public string Title { get; set; } = ""; + public string Remark { get; set; } = ""; + public string Identify { get; set; } = ""; public int DepthLevel { get; protected internal set; } = 0; public bool IsLockedElement { get; set; } = false; protected internal LogInfo _InstantInfo = LogInfo.Empty; diff --git a/DeedyDesigner/Deedy.Activity/Collection/ElementCollection.cs b/DeedyDesigner/Deedy.Activity/Collection/ElementCollection.cs index 24df19e..2b37b39 100644 --- a/DeedyDesigner/Deedy.Activity/Collection/ElementCollection.cs +++ b/DeedyDesigner/Deedy.Activity/Collection/ElementCollection.cs @@ -31,7 +31,7 @@ namespace Deedy.Activity { foreach (var item in this.Items) { - if (element.DEClass == item.DEClass && element.DETitle == item.DETitle) return; + if (element.Class == item.Class && element.Title == item.Title) return; } } base.Add(element); diff --git a/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs b/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs new file mode 100644 index 0000000..d6d2dd1 --- /dev/null +++ b/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Deedy.Activity +{ + /// + /// 用于扩展一个对象的非必要属性 + /// + public class ExpandoMapping : Dictionary + { + } +} diff --git a/DeedyDesigner/Deedy.Activity/Contract/Interface/ICombinedElement.cs b/DeedyDesigner/Deedy.Activity/Contract/Interface/ICombinedElement.cs index f616413..e46843d 100644 --- a/DeedyDesigner/Deedy.Activity/Contract/Interface/ICombinedElement.cs +++ b/DeedyDesigner/Deedy.Activity/Contract/Interface/ICombinedElement.cs @@ -7,6 +7,9 @@ using System.Threading.Tasks; namespace Deedy.Activity { + /// + /// 组合元素:内部由多个元素组合而成,但不允许修改内部元素的组合逻辑 + /// public interface ICombinedElement : IElement { public ElementCollection Elements { get; set; } diff --git a/DeedyDesigner/Deedy.Activity/Controller/Runtime.cs b/DeedyDesigner/Deedy.Activity/Controller/Runtime.cs index 3c5d296..02260c3 100644 --- a/DeedyDesigner/Deedy.Activity/Controller/Runtime.cs +++ b/DeedyDesigner/Deedy.Activity/Controller/Runtime.cs @@ -8,5 +8,7 @@ namespace Deedy.Activity { public sealed class Runtime { + public Runtime() { } + public WorkMode WorkMode { get; internal set; } = WorkMode.Waiting; } } diff --git a/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs b/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs index 7d5bd90..2083095 100644 --- a/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs +++ b/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs @@ -10,10 +10,12 @@ namespace Deedy.Activity { public class DeedyLayout : IDeedyLayout { - public string DEClass { get; protected internal set; } = ""; - public string DETitle { get; set; } = ""; - public string DERemark { get; set; } = ""; - public string DEIdentify { get; set; } = ""; + public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping(); + public DeedyLayout() { } + public string Class { get; protected internal set; } = ""; + public string Title { get; set; } = ""; + public string Remark { get; set; } = ""; + public string Identify { get; set; } = ""; public int DepthLevel { get; protected internal set; } = 0; public IElement? ParentElement { get; protected internal set; } diff --git a/DeedyDesigner/Deedy.Activity/Helper.cs b/DeedyDesigner/Deedy.Activity/Helper.cs index e728369..b74f37e 100644 --- a/DeedyDesigner/Deedy.Activity/Helper.cs +++ b/DeedyDesigner/Deedy.Activity/Helper.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Windows; +using System.Runtime.CompilerServices; namespace Deedy.Activity { @@ -212,6 +213,10 @@ namespace Deedy.Activity return default; } + /// + /// 调整子节点的退出线位置 + /// + /// 要调整的带退出线容器 public static void AdjustExitlinePosition(this IContainerWithExitline container) { if (container != null @@ -237,9 +242,62 @@ namespace Deedy.Activity if (container.ExitlinePosition == ExitlinePosition.Rightlower) lastChild.ExitlinePosition = ExitlinePosition.Rightlower; } - //lastChild.AdjustExitlinePosition(); } } } + /// + /// 设置「IElement」对象的「DepthLevel」属性值 + /// + /// 要设置的对象 + /// 层级深度 + /// 如果设置失败则返回「False」 + public static bool Setter_DepthLevel(this IElement element, int depthLevel) + { + if (element is BasalAction action) + { + ActionSetter_DepthLevel(action, depthLevel); + return true; + } + else + { + try + { + element.SetNamedPropertyValue(nameof(IElement.DepthLevel), depthLevel); + return true; + } + catch { return false; } + } + } + [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "set_DepthLevel")] + private static extern void ActionSetter_DepthLevel(BasalAction action, int value); + + /// + /// 设置「IElement」对象的「ParentElement」属性值 + /// + /// 要设置的对象 + /// 属性值 + /// 如果设置失败则返回「False」 + public static bool Setter_ParentElement(this IElement element, IElement? parent) + { + if (element is BasalAction action) + { + ActionSetter_ParentElement(action, parent); + return true; + } + else + { + try + { + element.SetNamedPropertyValue(nameof(IElement.ParentElement), parent); + return true; + } + catch + { + return false; + } + } + } + [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "set_ParentElement")] + private static extern void ActionSetter_ParentElement(BasalAction action, IElement? value); } } diff --git a/DeedyDesigner/Deedy.Activity/IActionViewer.cs b/DeedyDesigner/Deedy.Activity/IActionViewer.cs index f04d387..78c14cc 100644 --- a/DeedyDesigner/Deedy.Activity/IActionViewer.cs +++ b/DeedyDesigner/Deedy.Activity/IActionViewer.cs @@ -42,7 +42,6 @@ namespace Deedy.Activity [AllowNull] public LogInfoCollection LogInfos { get; } public ViewerState ViewerState { get; } - public WorkMode WorkMode { get; } public Brush FillBrush { get; set; } public Brush StrokeBrush { get; set; } public double StrokeThickness { get; set; } diff --git a/DeedyDesigner/Deedy.Activity/IActivity.cs b/DeedyDesigner/Deedy.Activity/IActivity.cs index 4eddd66..0191d57 100644 --- a/DeedyDesigner/Deedy.Activity/IActivity.cs +++ b/DeedyDesigner/Deedy.Activity/IActivity.cs @@ -12,5 +12,7 @@ namespace Deedy.Activity public void ReadyToWorking(IElement? element = null, Output? output = null); public void ReadyToEditing(Runtime runtime); public void ReadyToRunning(Runtime runtime); + public WorkMode WorkMode => Runtime?.WorkMode ?? WorkMode.Waiting; + public ExpandoMapping ExpandoMapping { get; set; } } } diff --git a/DeedyDesigner/Deedy.Activity/IElement.cs b/DeedyDesigner/Deedy.Activity/IElement.cs index ed395ff..f4193de 100644 --- a/DeedyDesigner/Deedy.Activity/IElement.cs +++ b/DeedyDesigner/Deedy.Activity/IElement.cs @@ -12,10 +12,10 @@ namespace Deedy.Activity { public interface IElement : IActivity, INotifyPropertyChanged { - public string DEClass { get; } - public string DETitle { get; set; } - public string DERemark { get; set; } - public string DEIdentify { get; set; } + public string Class { get; } + public string Title { get; set; } + public string Remark { get; set; } + public string Identify { get; set; } public int DepthLevel { get; } public IElement? ParentElement { get; } public IElement RootElement { get; } @@ -39,15 +39,18 @@ namespace Deedy.Activity { container.Remove(this); container.Append(this); - this.SetNamedPropertyValue(nameof(ParentElement), element); + //this.SetNamedPropertyValue(nameof(ParentElement), element); + this.Setter_ParentElement(element); } } } else { - this.SetNamedPropertyValue(nameof(ParentElement), element); + //this.SetNamedPropertyValue(nameof(ParentElement), element); + this.Setter_ParentElement(element); } - this.SetNamedPropertyValue(nameof(DepthLevel), (this.ParentElement?.DepthLevel ?? 0) + 1); + //this.SetNamedPropertyValue(nameof(DepthLevel), (this.ParentElement?.DepthLevel ?? 0) + 1); + this.Setter_DepthLevel((this.ParentElement?.DepthLevel ?? 0) + 1); } /// /// 断开自身与父级节点的链接关系 @@ -55,8 +58,10 @@ namespace Deedy.Activity public virtual void Unlink() { (this.ParentElement as IContainerElement)?.Remove(this); - this.SetNamedPropertyValue(nameof(ParentElement), null); - this.SetNamedPropertyValue(nameof(DepthLevel), 0); + //this.SetNamedPropertyValue(nameof(ParentElement), null); + this.Setter_ParentElement(null); + //this.SetNamedPropertyValue(nameof(DepthLevel), 0); + this.Setter_DepthLevel(0); } /// /// 构建结构树,设置层级:并且完成参数映射的刷新 diff --git a/DeedyDesigner/Deedy.Testing/Deedy.Testing.csproj b/DeedyDesigner/Deedy.Testing/Deedy.Testing.csproj index e3e33e3..67588fb 100644 --- a/DeedyDesigner/Deedy.Testing/Deedy.Testing.csproj +++ b/DeedyDesigner/Deedy.Testing/Deedy.Testing.csproj @@ -8,4 +8,8 @@ true + + + +