/// <summary> /// Gets the value of the first node connected to the slot with the Id id_ /// </summary> /// <param name="index_"></param> /// <returns></returns> public object GetValueFromSlot(int id_) { NodeSlot slot = GetSlotById(id_); if (slot.ConnectedNodes.Count > 0) { NodeSlot dstSlot = slot.ConnectedNodes[0]; SequenceNode node = slot.ConnectedNodes[0].Node; // Connected directly to a NodeSlot value (VarOut) ? if (dstSlot is NodeSlotVar) { return(((NodeSlotVar)dstSlot).Value); } else if (node is VariableNode) { return(((VariableNode)node).Value); } else { throw new InvalidOperationException( string.Format("Node({0}) GetValueFromSlot({1}) : type of link not supported", Id, id_)); } } // if no node is connected, we take the nested value of the slot else if (slot is NodeSlotVar) { return(((NodeSlotVar)slot).Value); } return(null); }
/// <summary> /// /// </summary> /// <param name="name"></param> public ConnectorViewModel(NodeSlot slot) { if (slot == null) { throw new InvalidOperationException("ConnectorViewModel() NodeSlot is null"); } SourceSlot = slot; SourceSlot.PropertyChanged += new PropertyChangedEventHandler(OnSlotPropertyChanged); }
/// <summary> /// /// </summary> /// <param name="id_"></param> /// <param name="value_"></param> public void SetValueInSlot(int id_, object value_) { NodeSlot slot = GetSlotById(id_); if (slot.ConnectedNodes.Count > 0) { foreach (NodeSlot other in slot.ConnectedNodes) { if (other.Node is VariableNode) { (other.Node as VariableNode).Value = value_; } } } else if (slot is NodeSlotVar) { ((NodeSlotVar)slot).Value = value_; } }
/// <summary> /// /// </summary> /// <param name="dst_"></param> public bool ConnectTo(NodeSlot dst_) { if (dst_.Node == Node) { throw new InvalidOperationException("Try to connect itself"); } foreach (NodeSlot s in ConnectedNodes) { if (s.Node == dst_.Node) // already connected { return(true); //throw new InvalidOperationException(""); } } switch (ConnectionType) { case SlotType.NodeIn: case SlotType.NodeOut: if ((dst_.Node is VariableNode) == true) { return(false); } break; case SlotType.VarIn: case SlotType.VarOut: case SlotType.VarInOut: if ((dst_.Node is VariableNode) == false && (dst_ is NodeSlotVar) == false) { return(false); } break; } ConnectedNodes.Add(dst_); return(true); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object val = GetValueFromSlot((int)NodeSlotId.Message); if (val == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a string variable node"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : No message display because no variable node connected. {1}.", Title, info.ErrorMessage); } else { LogManager.Instance.WriteLine(LogVerbosity.Info, val.ToString()); } ActivateOutputLink(context_, (int)NodeSlotId.Out); return info; }
/// <summary> /// /// </summary> /// <param name="item_"></param> private void AddSlot(NodeSlot item_) { foreach (NodeSlot slot in m_Slots) { if (slot.ID == item_.ID) { throw new InvalidOperationException("A slot with the Id '" + item_.ID + "' already exists."); } } if (HasSlotConnectorIn == false && item_.ConnectionType == SlotType.NodeIn) { throw new InvalidOperationException("This type of node can not have IN connector."); } if (HasSlotConnectorOut == false && item_.ConnectionType == SlotType.NodeOut) { throw new InvalidOperationException("This type of node can not have OUT connector."); } if (HasSlotVariableIn == false && item_.ConnectionType == SlotType.VarIn) { throw new InvalidOperationException("This type of node can not have IN variable."); } if (HasSlotVariableOut == false && item_.ConnectionType == SlotType.VarOut) { throw new InvalidOperationException("This type of node can not have OUT variable."); } m_Slots.Add(item_); }
/// <summary> /// Methods call when the node is activated. /// The other node connected to the input connector has activated his output link. /// </summary> /// <param name="context_"></param> /// <param name="slot_"></param> /// <returns></returns> public abstract ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_);
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="slot"></param> /// <returns></returns> public ProcessingInfo Activate(ProcessingContext context, NodeSlot slot) { State = ActivateLogic(context, slot); return(State); }
/// <summary> /// /// </summary> /// <param name="slot_"></param> public bool DisconnectFrom(NodeSlot slot_) { ConnectedNodes.Remove(slot_); return(true); }
/// <summary> /// /// </summary> /// <param name="node_"></param> public ProcessingContextStep RegisterNextExecution(NodeSlot slot_) { if (slot_.Node is ActionNode == false) { throw new InvalidOperationException("ProcessingContext.RegisterNextExecution() : the node is not an ActionNode"); } ProcessingContextStep step = new ProcessingContextStep(SequenceBase, CurrentFrame, slot_); CurrentProcessingContext.m_NextExecutions.Add(step); return step; }
/// <summary> /// /// </summary> /// <param name="slot_"></param> public bool DisconnectFrom(NodeSlot slot_) { ConnectedNodes.Remove(slot_); return true; }
/// <summary> /// /// </summary> /// <param name="dst_"></param> public bool ConnectTo(NodeSlot dst_) { if (dst_.Node == Node) { throw new InvalidOperationException("Try to connect itself"); } foreach (NodeSlot s in ConnectedNodes) { if (s.Node == dst_.Node) // already connected { return true; //throw new InvalidOperationException(""); } } switch (ConnectionType) { case SlotType.NodeIn: case SlotType.NodeOut: if ((dst_.Node is VariableNode) == true) { return false; } break; case SlotType.VarIn: case SlotType.VarOut: case SlotType.VarInOut: if ((dst_.Node is VariableNode) == false && (dst_ is NodeSlotVar) == false) { return false; } break; } ConnectedNodes.Add(dst_); return true; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="slot"></param> /// <returns></returns> public ProcessingInfo Activate(ProcessingContext context, NodeSlot slot) { State = ActivateLogic(context, slot); return State; }
/// <summary> /// /// </summary> /// <param name="slot_"></param> /// <returns></returns> private bool ContainsConnectorFromNodeSlots(NodeSlot slot_) { foreach (ConnectorViewModel c in allConnectors) { if (c.SourceSlot.ID == slot_.ID) { return true; } } return false; }