/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, true); } if (slot_.ID == (int)NodeSlotId.InEnter) { bool val = (bool)memoryItem.Value; memoryItem.Value = !((bool)memoryItem.Value); SetValueInSlot((int)NodeSlotId.VarOutIsA, val); if (val == true) { ActivateOutputLink(context_, (int)NodeSlotId.OutA); } else { ActivateOutputLink(context_, (int)NodeSlotId.OutB); } } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, false); } if (slot_.ID == (int)NodeSlotId.InReset) { memoryItem.Value = false; } else if (slot_.ID == (int)NodeSlotId.InEnter) { if ((bool)memoryItem.Value == false) { memoryItem.Value = true; ActivateOutputLink(context_, (int)NodeSlotId.Out); } } return(info); }
/// <summary> /// /// </summary> /// <param name="id_"></param> /// <param name="val_"></param> /// <returns></returns> public MemoryStackItem Allocate(object val_) { int id = GetUnusedId(); MemoryStackItem item = new MemoryStackItem(id, val_); m_Variable.Add(id, item); return item; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object intVal = GetValueFromSlot((int)NodeSlotId.Delay); if (intVal == null) { info.State = ActionNode.LogicState.Ok; info.ErrorMessage = "Please connect a integer variable node"; LogManager.Instance.WriteLine(LogVerbosity.Error, "{0} : {1}.", Title, info.ErrorMessage); return(info); } MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, TimeSpan.Zero); } TimeSpan startTime = (TimeSpan)memoryItem.Value; int delay = (int)intVal; double delayDouble = ((double)delay) / 1000.0; TimeSpan t = DateTime.Now.TimeOfDay.Subtract(startTime); double totalSecs = t.TotalSeconds; //this is the first time, so we set the current time if (startTime == TimeSpan.Zero) { totalSecs = 0.0; startTime = DateTime.Now.TimeOfDay; memoryItem.Value = startTime; } else if (totalSecs >= delayDouble) { startTime = TimeSpan.Zero; memoryItem.Value = startTime; ActivateOutputLink(context_, (int)NodeSlotId.Out); CustomText = String.Empty; return(info); } CustomText = string.Format("Delay ({0:0.000} seconds left)", delayDouble - totalSecs); context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); return(info); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnLoopBodyFinished(object sender, EventArgs e) { ProcessingContext context = sender as ProcessingContext; context.Finished -= new EventHandler(OnLoopBodyFinished); MemoryStackItem memoryItem = context.Parent.CurrentFrame.GetValueFromID(Id); ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; memoryInfo.IsWaitingLoopBody = false; memoryItem.Value = memoryInfo; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.InReset) { m_Counter = 0; m_IsInitial = false; } else if (slot_.ID == (int)NodeSlotId.InEnter) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (m_IsInitial == false) { object objN = GetValueFromSlot((int)NodeSlotId.VarInN); if (objN == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot N"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : DoN failed. {1}.", Title, info.ErrorMessage); } if (objN != null) { int n = (int)objN; if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, n); } memoryItem.Value = n; } m_IsInitial = true; } if (m_Counter < (int)memoryItem.Value) { m_Counter++; ActivateOutputLink(context_, (int)NodeSlotId.Out); } } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { object a = GetValueFromSlot((int)NodeSlotId.VarInStartClosed); bool state = a != null ? (bool)a : true; memoryItem = context_.CurrentFrame.Allocate(Id, state); } bool val = (bool)memoryItem.Value; if (slot_.ID == (int)NodeSlotId.InEnter) { if (val == true) { ActivateOutputLink(context_, (int)NodeSlotId.Out); } } else if (slot_.ID == (int)NodeSlotId.InOpen) { memoryItem.Value = true; } else if (slot_.ID == (int)NodeSlotId.InClose) { memoryItem.Value = false; } else if (slot_.ID == (int)NodeSlotId.InToggle) { memoryItem.Value = !val; } return(info); }
/// <summary> /// /// </summary> /// <param name="item_"></param> public void Deallocate(MemoryStackItem item_) { Deallocate(item_.ID); }
/// <summary> /// /// </summary> /// <param name="id_"></param> /// <param name="val_"></param> /// <returns></returns> public MemoryStackItem Allocate(int id_, object val_) { MemoryStackItem item = new MemoryStackItem(id_, val_); m_Variable.Add(id_, item); return item; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.In) { int firstIndex = 0, lastIndex = -1; #region first index object objFirstIndex = GetValueFromSlot((int)NodeSlotId.VarInFirstIndex); if (objFirstIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot First Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return(info); } if (objFirstIndex != null) { firstIndex = (int)objFirstIndex; } #endregion // first index #region last index object objLastIndex = GetValueFromSlot((int)NodeSlotId.VarInLastIndex); if (objLastIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot Last Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return(info); } if (objLastIndex != null) { lastIndex = (int)objLastIndex; } #endregion last index MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, new ForLoopNodeInfo { Counter = firstIndex, IsWaitingLoopBody = false }); } ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; if (memoryInfo.IsWaitingLoopBody == false) { SetValueInSlot((int)NodeSlotId.VarOutIndex, memoryInfo.Counter); if (memoryInfo.Counter <= lastIndex) { memoryInfo.IsWaitingLoopBody = true; memoryInfo.Counter++; // register again this node in order to active itself // after the sequence activated by the loop body slot // is finished memoryInfo.Step = context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); memoryItem.Value = memoryInfo; ProcessingContext newContext = context_.PushNewContext(); newContext.Finished += new EventHandler(OnLoopBodyFinished); ActivateOutputLink(newContext, (int)NodeSlotId.OutLoop); } else { context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } } } else if (slot_.ID == (int)NodeSlotId.InBreak) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; context_.RemoveExecution(context_, memoryInfo.Step); context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } return(info); }