Example #1
0
        /// <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);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="slotId_"></param>
        /// <param name="node_"></param>
        /// <param name="text_"></param>
        /// <param name="connectionType_"></param>
        /// <param name="type_"></param>
        /// <param name="controlType_"></param>
        /// <param name="tag_"></param>
        public NodeSlotVar(int slotId_, SequenceNode node_, string text_,
                           SlotType connectionType_, Type type_ = null,
                           VariableControlType controlType_     = VariableControlType.ReadOnly,
                           object tag_ = null, bool saveValue_ = true) :
            base(slotId_, node_, text_, connectionType_, type_, controlType_, tag_)
        {
            m_SaveValue = saveValue_;

            object val = null;

            if (type_ == typeof(bool))
            {
                val = true;
            }
            else if (type_ == typeof(sbyte) ||
                     type_ == typeof(char) ||
                     type_ == typeof(short) ||
                     type_ == typeof(int) ||
                     type_ == typeof(long) ||
                     type_ == typeof(byte) ||
                     type_ == typeof(ushort) ||
                     type_ == typeof(uint) ||
                     type_ == typeof(ulong) ||
                     type_ == typeof(float) ||
                     type_ == typeof(double))
            {
                val = Convert.ChangeType(0, type_);
            }
            else if (type_ == typeof(string))
            {
                val = string.Empty;
            }

            m_Value = new ValueContainer(type_, val);
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="slotId_"></param>
 /// <param name="node_"></param>
 /// <param name="text_"></param>
 /// <param name="connectionType_"></param>
 /// <param name="type_"></param>
 /// <param name="controlType_"></param>
 /// <param name="tag_"></param>
 public NodeSlot(int slotId_, SequenceNode node_, string text_,
                 SlotType connectionType_, Type type_ = null,
                 VariableControlType controlType_     = VariableControlType.ReadOnly,
                 object tag_ = null) :
     this(slotId_, node_, connectionType_, controlType_, tag_)
 {
     Text         = text_;
     VariableType = type_;
 }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node_"></param>
        public NodeViewModel(SequenceNode node_)
        {
            SeqNode = node_;
            SeqNode.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnSeqNodePropertyChanged);

            allConnectors.ItemsAdded += new EventHandler<CollectionItemsChangedEventArgs>(allConnectors_ItemsAdded);
            allConnectors.ItemsRemoved += new EventHandler<CollectionItemsChangedEventArgs>(allConnectors_ItemsRemoved);

            InitializeConnectors();
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="slotId_"></param>
        /// <param name="node_"></param>
        /// <param name="connectionType_"></param>
        /// <param name="controlType_"></param>
        /// <param name="tag_"></param>
        protected NodeSlot(int slotId_, SequenceNode node_, SlotType connectionType_,
                           VariableControlType controlType_ = VariableControlType.ReadOnly,
                           object tag_ = null)
        {
            ConnectedNodes = new List <NodeSlot>();

            ID             = slotId_;
            Node           = node_;
            ConnectionType = connectionType_;
            ControlType    = controlType_;
            Tag            = tag_;
        }
Example #6
0
        /// <summary>
        /// Call after Load() to connect nodes each others
        /// </summary>
        /// <param name="node_"></param>
        /// <param name="connectionListNode_"></param>
        internal virtual void ResolveLinks(XmlNode connectionListNode_, SequenceBase sequence_)
        {
            foreach (XmlNode connNode in connectionListNode_.SelectNodes("Connection[@srcNodeID='" + Id + "']"))
            {
                int outputSlotID    = int.Parse(connNode.Attributes["srcNodeSlotID"].Value);
                int destNodeID      = int.Parse(connNode.Attributes["destNodeID"].Value);
                int destNodeInputID = int.Parse(connNode.Attributes["destNodeSlotID"].Value);

                SequenceNode destNode = sequence_.GetNodeById(destNodeID);
                GetSlotById(outputSlotID).ConnectTo(destNode.GetSlotById(destNodeInputID));
            }
        }
Example #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="slotId_"></param>
 /// <param name="node_"></param>
 /// <param name="connectionType_"></param>
 /// <param name="slot_"></param>
 /// <param name="controlType_"></param>
 /// <param name="tag_"></param>
 /// <param name="saveValue_"></param>
 public NodeFunctionSlot(
     int slotId_, 
     SequenceNode node_, 
     SlotType connectionType_, 
     SequenceFunctionSlot slot_,
     VariableControlType controlType_ = VariableControlType.ReadOnly,
     object tag_ = null, 
     bool saveValue_ = true)
     : base(slotId_, 
             node_, 
             slot_.Name,
             connectionType_, 
             slot_.VariableType,
             controlType_,
             tag_, 
             saveValue_)
 {
     m_FuncSlot = slot_;
     m_FuncSlot.PropertyChanged += new PropertyChangedEventHandler(OnFunctionSlotPropertyChanged);
 }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="slotId_"></param>
        /// <param name="node_"></param>
        /// <param name="connectionType_"></param>
        /// <param name="slot_"></param>
        /// <param name="controlType_"></param>
        /// <param name="tag_"></param>
        /// <param name="saveValue_"></param>
        public NodeFunctionSlot(
            int slotId_,
            SequenceNode node_,
            SlotType connectionType_,
            SequenceFunctionSlot slot_,
            VariableControlType controlType_ = VariableControlType.ReadOnly,
            object tag_     = null,
            bool saveValue_ = true) :

            base(slotId_,
                 node_,
                 slot_.Name,
                 connectionType_,
                 slot_.VariableType,
                 controlType_,
                 tag_,
                 saveValue_)
        {
            m_FuncSlot = slot_;
            m_FuncSlot.PropertyChanged += new PropertyChangedEventHandler(OnFunctionSlotPropertyChanged);
        }
 /// <summary>
 /// Creates a new node in the network at the current mouse location.
 /// </summary>
 private void CreateNode(SequenceNode node_)
 {
     //var newNodePosition = Mouse.GetPosition(networkControl);
     this.ViewModel.CreateNode(node_, origContentMouseDownPoint, true);
 }
        /// <summary>
        /// Create a node and add it to the view-model.
        /// </summary>
        public NodeViewModel CreateNode(SequenceNode node_, Point nodeLocation, bool centerNode)
        {
            NodeViewModel node = new NodeViewModel(node_);
            node.X = nodeLocation.X;
            node.Y = nodeLocation.Y;

            if (centerNode)
            {
                //
                // We want to center the node.
                //
                // For this to happen we need to wait until the UI has determined the
                // size based on the node's data-template.
                //
                // So we define an anonymous method to handle the SizeChanged event for a node.
                //
                // Note: If you don't declare sizeChangedEventHandler before initializing it you will get
                //       an error when you try and unsubscribe the event from within the event handler.
                //
                EventHandler<EventArgs> sizeChangedEventHandler = null;
                sizeChangedEventHandler =
                    delegate(object sender, EventArgs e)
                    {
                        //
                        // This event handler will be called after the size of the node has been determined.
                        // So we can now use the size of the node to modify its position.
                        //
                        node.X -= node.Size.Width / 2;
                        node.Y -= node.Size.Height / 2;

                        //
                        // Don't forget to unhook the event, after the initial centering of the node
                        // we don't need to be notified again of any size changes.
                        //
                        node.SizeChanged -= sizeChangedEventHandler;
                    };

                //
                // Now we hook the SizeChanged event so the anonymous method is called later
                // when the size of the node has actually been determined.
                //
                node.SizeChanged += sizeChangedEventHandler;
            }

            AddNode(node, true);

            return node;
        }
Example #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="slotId_"></param>
        /// <param name="node_"></param>
        /// <param name="text_"></param>
        /// <param name="connectionType_"></param>
        /// <param name="type_"></param>
        /// <param name="controlType_"></param>
        /// <param name="tag_"></param>
        public NodeSlotVar(int slotId_, SequenceNode node_, string text_,
            SlotType connectionType_, Type type_ = null,
            VariableControlType controlType_ = VariableControlType.ReadOnly,
            object tag_ = null, bool saveValue_ = true)
            : base(slotId_, node_, text_, connectionType_, type_, controlType_, tag_)
        {
            m_SaveValue = saveValue_;

            object val = null;

            if (type_ == typeof(bool))
            {
                val = true;
            }
            else if (type_ == typeof(sbyte)
                || type_ == typeof(char)
                || type_ == typeof(short)
                || type_ == typeof(int)
                || type_ == typeof(long)
                || type_ == typeof(byte)
                || type_ == typeof(ushort)
                || type_ == typeof(uint)
                || type_ == typeof(ulong)
                || type_ == typeof(float)
                || type_ == typeof(double))
            {
                val = Convert.ChangeType(0, type_);
            }
            else if (type_ == typeof(string))
            {
                val = string.Empty;
            }

            m_Value = new ValueContainer(type_, val);
        }
Example #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="slotId_"></param>
        /// <param name="node_"></param>
        /// <param name="connectionType_"></param>
        /// <param name="controlType_"></param>
        /// <param name="tag_"></param>
        protected NodeSlot(int slotId_, SequenceNode node_, SlotType connectionType_,
            VariableControlType controlType_ = VariableControlType.ReadOnly,
            object tag_ = null)
        {
            ConnectedNodes = new List<NodeSlot>();

            ID = slotId_;
            Node = node_;
            ConnectionType = connectionType_;
            ControlType = controlType_;
            Tag = tag_;
        }
Example #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="slotId_"></param>
 /// <param name="node_"></param>
 /// <param name="text_"></param>
 /// <param name="connectionType_"></param>
 /// <param name="type_"></param>
 /// <param name="controlType_"></param>
 /// <param name="tag_"></param>
 public NodeSlot(int slotId_, SequenceNode node_, string text_,
     SlotType connectionType_, Type type_ = null,
     VariableControlType controlType_ = VariableControlType.ReadOnly,
     object tag_ = null)
     : this(slotId_, node_, connectionType_, controlType_, tag_)
 {
     Text = text_;
     VariableType = type_;
 }