diff --git a/DeedyDesigner/Deedy.Activity/ActionViewer.cs b/DeedyDesigner/Deedy.Activity/ActionViewer.cs
index 801f852..d707464 100644
--- a/DeedyDesigner/Deedy.Activity/ActionViewer.cs
+++ b/DeedyDesigner/Deedy.Activity/ActionViewer.cs
@@ -618,7 +618,7 @@ namespace Deedy.Activity
if (withExitline.ExitlinePosition.HasFlag(ExitlinePosition.Rightlower))
this.ShowRightExitline = Visibility.Visible;
// 新元素被托管渲染后调整子元素退出线位置
- withExitline.Help_AdjustExitlinePosition();
+ withExitline.Help_ExitlinePositionAdjust();
}
if (newValue is ILogicController logicController)
@@ -646,7 +646,7 @@ namespace Deedy.Activity
this.ElementCount = combined.Elements.Count;
}
// 节点集合变更时调整退出线位置
- if (this.ActionElement is IContainerWithExitline container) container.Help_AdjustExitlinePosition();
+ if (this.ActionElement is IContainerWithExitline container) container.Help_ExitlinePositionAdjust();
}
protected virtual void ActionElement_PropertyChanged(object? sender, PropertyChangedEventArgs e)
@@ -662,7 +662,7 @@ namespace Deedy.Activity
break;
case nameof(IContainerWithExitline.ExitlinePosition):
// 自身退出线变更时调整所有子节点退出线位置
- (this.ActionElement as IContainerWithExitline)?.Help_AdjustExitlinePosition();
+ (this.ActionElement as IContainerWithExitline)?.Help_ExitlinePositionAdjust();
break;
default: break;
}
diff --git a/DeedyDesigner/Deedy.Activity/BasalAction.cs b/DeedyDesigner/Deedy.Activity/BasalAction.cs
index 89c4dd0..3594e09 100644
--- a/DeedyDesigner/Deedy.Activity/BasalAction.cs
+++ b/DeedyDesigner/Deedy.Activity/BasalAction.cs
@@ -91,5 +91,25 @@ namespace Deedy.Activity
{
throw new NotImplementedException();
}
+
+ public void LinkTo([AllowNull] IElement element)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Unlink()
+ {
+ throw new NotImplementedException();
+ }
+
+ public IElement? Clone()
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool TryEncode(out string document)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs b/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs
index b9509aa..bd6ec75 100644
--- a/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.cs
+++ b/DeedyDesigner/Deedy.Activity/DeedyVisual/DeedyLayout.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;
@@ -103,5 +104,25 @@ namespace Deedy.Activity
{
throw new NotImplementedException();
}
+
+ public void LinkTo([AllowNull] IElement element)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Unlink()
+ {
+ throw new NotImplementedException();
+ }
+
+ public IElement? Clone()
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool TryEncode(out string document)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs
index b10e8ea..9c4f098 100644
--- a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs
+++ b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs
@@ -228,13 +228,12 @@ namespace Deedy.Activity
public static void Help_RemoveFromParent(this IElement element)
{
if (element != null && element.ParentElement is IContainerElement container) container.Remove(element);
- //TODO:将当前节点从自身的父级节点中移除
}
///
/// 调整子节点的退出线位置
///
/// 要调整的带退出线容器
- public static void Help_AdjustExitlinePosition(this IContainerWithExitline container)
+ public static void Help_ExitlinePositionAdjust(this IContainerWithExitline container)
{
if (container != null
&& (container.ExitlinePosition == ExitlinePosition.LeftLower
diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs
index c47fc1b..4432ad4 100644
--- a/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs
+++ b/DeedyDesigner/Deedy.Activity/Helpers/ElementHelper.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Markup;
namespace Deedy.Activity
{
@@ -134,5 +136,106 @@ namespace Deedy.Activity
}
return result;
}
+ ///
+ /// 构建结构树,设置层级:并且完成参数映射的刷新
+ ///
+ /// 父级元素
+ public static void Help_Element_ReadyToWorking(this IElement @this, IElement? parent = null, Output? output = null)
+ {
+ @this.LinkTo(parent);
+ if (@this is ICombinedElement combined)
+ {
+ combined.Help_CombineElements();
+ foreach (IElement subElement in combined.Elements)
+ subElement.ReadyToWorking(@this);
+ }
+ }
+ public static void Help_Element_ReadyToEditing(this IElement @this, Runtime runtime)
+ {
+ if (@this is null) return;
+ @this.SetNamedPropertyValue(nameof(IActivity.Runtime), runtime);
+ if (@this is ICombinedElement combined)
+ {
+ combined.Help_BuildParamMapping();
+ foreach (var subElement in combined.Elements)
+ subElement.ReadyToEditing(runtime);
+ }
+ }
+ ///
+ /// 将当前节点链接到一个节点上
+ ///
+ /// 要链接到的节点
+ public static void LinkTo(this IElement @this, [AllowNull] IElement element)
+ {
+ if (@this == null) return;
+
+ if (element == null)
+ {
+ @this.Unlink();
+ return;
+ }
+ if (@this.ParentElement != null)
+ {
+ if (@this.ParentElement == element) return;
+ else
+ {
+ if (@this.ParentElement is IContainerElement container)
+ {
+ //this.SetNamedPropertyValue(nameof(ParentElement), element);
+ @this.Help_Setter_ParentElement(element);
+ }
+ }
+ }
+ else
+ {
+ //this.SetNamedPropertyValue(nameof(ParentElement), element);
+ @this.Help_Setter_ParentElement(element);
+ }
+ //this.SetNamedPropertyValue(nameof(DepthLevel), (this.ParentElement?.DepthLevel ?? 0) + 1);
+ @this.Help_Setter_DepthLevel((@this.ParentElement?.DepthLevel ?? 0) + 1);
+ }
+ ///
+ /// 断开自身与父级节点的链接关系
+ ///
+ public static void Unlink(this IElement @this)
+ {
+ if (@this == null) return;
+
+ //this.SetNamedPropertyValue(nameof(ParentElement), null);
+ @this.Help_Setter_ParentElement(null);
+ //this.SetNamedPropertyValue(nameof(DepthLevel), 0);
+ @this.Help_Setter_DepthLevel(0);
+ }
+ ///
+ /// 克隆一个「IElement」节点
+ ///
+ /// 要复制的节点
+ /// 如果复制失败则返回「null」
+ public static IElement? Clone(this IElement @this)
+ {
+ if (@this == null) return null;
+ try
+ {
+ return XamlReader.Parse(XamlWriter.Save(@this)) as IElement;
+ }
+ catch { return null; }
+ }
+ ///
+ /// 尝试将一个「IElement」元素序列化为一个字符串形式档案
+ ///
+ /// 要序列化的元素
+ /// 序列化后的文本文档
+ /// 如果出错则返回「Flase」
+ public static bool TryEncode(this IElement @this, out string document)
+ {
+ bool result = false;
+ try
+ {
+ document = XamlWriter.Save(@this);
+ result = true;
+ }
+ catch { document = string.Empty; }
+ return result;
+ }
}
}
diff --git a/DeedyDesigner/Deedy.Activity/IActivity.cs b/DeedyDesigner/Deedy.Activity/IActivity.cs
index f991fb5..359c948 100644
--- a/DeedyDesigner/Deedy.Activity/IActivity.cs
+++ b/DeedyDesigner/Deedy.Activity/IActivity.cs
@@ -10,7 +10,7 @@ namespace Deedy.Activity
public interface IActivity
{
public Runtime? Runtime { get; }
- public void ReadyToWorking(IElement? element = null, Output? output = null);
+ public void ReadyToWorking(IElement? parent = null, Output? output = null);
public void ReadyToEditing(Runtime runtime);
public void ReadyToRunning(Runtime runtime);
public WorkMode WorkMode => Runtime?.WorkMode ?? WorkMode.Waiting;
diff --git a/DeedyDesigner/Deedy.Activity/IElement.cs b/DeedyDesigner/Deedy.Activity/IElement.cs
index ea2c94e..c490797 100644
--- a/DeedyDesigner/Deedy.Activity/IElement.cs
+++ b/DeedyDesigner/Deedy.Activity/IElement.cs
@@ -10,6 +10,14 @@ using System.Windows.Markup;
namespace Deedy.Activity
{
+ ///
+ /// 所有可「设计」元素的公共接口
+ /// 注意:
+ /// 「LinkTo」与「Unlink」方法只处理父子级关系映射,不处理「Elements」集合的添加与删除...
+ /// 「ReadyToWorking」方法会先进行「LinkTo」再进行「CombineElements」操作...
+ /// 「ReadyToEditing」方法会迭代进行「BuildParamMapping」操作...
+ /// 「ReadyToRunning」方法会迭代进行「CheckLogicConfigs」操作...
+ ///
public interface IElement : IActivity, INotifyPropertyChanged
{
public string Class { get; }
@@ -25,80 +33,13 @@ namespace Deedy.Activity
/// 将当前节点链接到一个节点上
///
/// 要链接到的节点
- public virtual void LinkTo([AllowNull] IElement element)
- {
- if (element == null)
- {
- this.Unlink();
- return;
- }
- if (this.ParentElement != null)
- {
- if (this.ParentElement == element) return;
- else
- {
- if (this.ParentElement is IContainerElement container)
- {
- container.Remove(this);
- container.Append(this);
- //this.SetNamedPropertyValue(nameof(ParentElement), element);
- this.Help_Setter_ParentElement(element);
- }
- }
- }
- else
- {
- //this.SetNamedPropertyValue(nameof(ParentElement), element);
- this.Help_Setter_ParentElement(element);
- }
- //this.SetNamedPropertyValue(nameof(DepthLevel), (this.ParentElement?.DepthLevel ?? 0) + 1);
- this.Help_Setter_DepthLevel((this.ParentElement?.DepthLevel ?? 0) + 1);
- }
+ public void LinkTo([AllowNull] IElement element);
///
/// 断开自身与父级节点的链接关系
///
- public virtual void Unlink()
- {
- (this.ParentElement as IContainerElement)?.Remove(this);
- //this.SetNamedPropertyValue(nameof(ParentElement), null);
- this.Help_Setter_ParentElement(null);
- //this.SetNamedPropertyValue(nameof(DepthLevel), 0);
- this.Help_Setter_DepthLevel(0);
- }
- ///
- /// 构建结构树,设置层级:并且完成参数映射的刷新
- ///
- ///
- public new void ReadyToWorking(IElement? element = null, Output? output = null)
- {
- this.Help_BuildParamMapping(output);
- if (element is ICombinedElement combinedElement)
- combinedElement.Help_CombineElements();
-
- this.LinkTo(element);
- if (this is ICombinedElement combined)
- foreach (IElement subElement in combined.Elements)
- subElement.ReadyToWorking(this);
- }
- public virtual IElement? Clone()
- {
- try
- {
- return XamlReader.Parse(XamlWriter.Save(this)) as IElement;
- }
- catch { return null; }
- }
- public virtual bool TryEncode(out string document)
- {
- bool result = false;
- try
- {
- document = XamlWriter.Save(this);
- result = true;
- }
- catch { document = string.Empty; }
- return result;
- }
+ public void Unlink();
+ public IElement? Clone();
+ public bool TryEncode(out string document);
public static virtual bool TryDecode(string document, out IElement? element)
{
IElement? instance = null;