131 lines
4.8 KiB
C#
131 lines
4.8 KiB
C#
using Aurora.Api;
|
|
using System.Collections.Generic;
|
|
|
|
namespace VisionCommon {
|
|
/// <summary>
|
|
/// 장비에서 시퀀스 노드를 정의하고,
|
|
/// AuroraVision 시퀀스에서 사용하기 위한 클래스
|
|
/// </summary>
|
|
public abstract class SeqAdapter {
|
|
protected Logger _logger;
|
|
private Dictionary<string, DoAction> _actionNodeMap = new Dictionary<string, DoAction>();
|
|
private Dictionary<string, DoDecision> _decisionNodeMap = new Dictionary<string, DoDecision>();
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="logTag">로그 태그명</param>
|
|
public SeqAdapter(string logTag) {
|
|
_logger = new Logger(logTag);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Action 노드를 가져온다.
|
|
/// </summary>
|
|
/// <param name="nodeName">노드 이름</param>
|
|
/// <param name="defaultNode">Default Decision 노드</param>
|
|
/// <returns>Action 노드</returns>
|
|
public DoAction GetActionNode(string nodeName, DoAction defaultNode = default(DoAction)) {
|
|
return GetNode(nodeName, _actionNodeMap, defaultNode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Decision 노드를 가져온다.
|
|
/// </summary>
|
|
/// <param name="nodeName">노드 이름</param>
|
|
/// <param name="defaultNode">Default Decision 노드</param>
|
|
/// <returns>Decision 노드</returns>
|
|
public DoDecision GetDecisionNode(string nodeName, DoDecision defaultNode = default(DoDecision)) {
|
|
return GetNode(nodeName, _decisionNodeMap, defaultNode);
|
|
}
|
|
|
|
private T GetNode<T>(string nodeName, Dictionary<string, T> map, T defaultNode) {
|
|
if (map.ContainsKey(nodeName)) {
|
|
return map[nodeName];
|
|
}
|
|
|
|
_logger.FuncE($"Node does NOT exist : {nodeName}");
|
|
return defaultNode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Action 노드를 등록한다.
|
|
/// </summary>
|
|
/// <param name="nodeName">노드 이름</param>
|
|
/// <param name="node">Action 노드</param>
|
|
protected void SetActionNode(string nodeName, DoAction node) {
|
|
SetNode(nodeName, node, _actionNodeMap);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deicision 노드를 등록한다.
|
|
/// </summary>
|
|
/// <param name="nodeName">노드 이름</param>
|
|
/// <param name="node">Deicision 노드</param>
|
|
protected void SetDeicisionNode(string nodeName, DoDecision node) {
|
|
SetNode(nodeName, node, _decisionNodeMap);
|
|
}
|
|
|
|
private void SetNode<T>(string nodeName, T node, Dictionary<string, T> map) {
|
|
if (!map.ContainsKey(nodeName)) {
|
|
map[nodeName] = node;
|
|
}
|
|
else {
|
|
_logger.I($"Node already exist : {nodeName}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sequence adapter 사용 시 default node ( ActionNode ) 만들어주는 Method
|
|
/// </summary>
|
|
public class DefaultActionNode{
|
|
SequenceActionResult _DefaultActionNodeReturn = SequenceAction.Ok();
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="defaultActionNodeReturn">ActionNode 사용 시 Default로 제공하는 결과값 (default(non param) : SequenceAction.OK())</param>
|
|
public DefaultActionNode(SequenceActionResult defaultActionNodeReturn) {
|
|
_DefaultActionNodeReturn = defaultActionNodeReturn;
|
|
}
|
|
/// <summary>
|
|
/// 생성자 : ActionNode 사용 시 Default로 제공하는 결과값 (default : SequenceAction.OK())
|
|
/// </summary>
|
|
public DefaultActionNode() {
|
|
}
|
|
/// <summary>
|
|
/// Default Action Node
|
|
/// </summary>
|
|
/// <returns>Default Action Node return</returns>
|
|
public SequenceActionResult ActionNode(
|
|
SequenceContext context, string id, SequenceActionResult param) {
|
|
return _DefaultActionNodeReturn;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sequence adapter 사용 시 default node (Decision Node ) 만들어주는 Method
|
|
/// </summary>
|
|
public class DefaultDecisionNode {
|
|
private string _DefaultDecisionNodeReturn = "";
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="defaultDecisionNodeReturn">DecisionNode 사용 시 Default로 제공하는 결과값(default : "")</param>
|
|
public DefaultDecisionNode(string defaultDecisionNodeReturn) {
|
|
_DefaultDecisionNodeReturn = defaultDecisionNodeReturn;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default Decision Node
|
|
/// </summary>
|
|
/// <returns>Default Decision Node return</returns>
|
|
public string DecisionNode(
|
|
SequenceContext context, string id, ICollection<string> branches, SequenceActionResult param) {
|
|
return _DefaultDecisionNodeReturn;
|
|
}
|
|
}
|
|
|
|
}
|