Ejemplo n.º 1
0
        /// <summary>
        /// Removes a terminal from this node.
        /// </summary>
        /// <param name="terminal">The terminal to remove.</param>
        public virtual void RemoveTerminal(TerminalModel terminal)
        {
            if (!Terminals.Contains(terminal))
            {
                throw new ModelValidationException(this, "Add terminal before removing it");
            }

            if (terminal.ConnectedWires.Any())
            {
                throw new ModelValidationException(this, "Disconnect terminal before removing it");
            }

            terminal.ParentNode = null;
            Terminals.Remove(terminal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a terminal to this node.
        /// </summary>
        /// <param name="terminal">The terminal to add.</param>
        public virtual void AddTerminal(TerminalModel terminal)
        {
            if (Terminals.Contains(terminal))
            {
                throw new ModelValidationException(this, "This terminal has already been added");
            }

            if (terminal.ParentNode is object)
            {
                throw new ModelValidationException(this, "Remove terminal from its current node before adding it to this one");
            }

            terminal.ParentNode = this;
            Terminals.Add(terminal);
        }
        /// <summary>
        /// Connects this terminal to another terminal via a wire.
        /// </summary>
        /// <param name="wire">The wire to connect the terminals with.</param>
        /// <param name="otherTerminal">The terminal to wire to.</param>
        public override void ConnectWire(WireModel wire, TerminalModel otherTerminal)
        {
            if (ConnectedWires.Contains(wire))
            {
                throw new ModelValidationException(this, "Remove this wire from a terminal before connecting it again");
            }

            if (otherTerminal is InputTerminalModel)
            {
                throw new ModelValidationException(this, "Connect this terminal to an output instead of an input");
            }

            wire.SinkTerminal   = this;
            wire.SourceTerminal = otherTerminal;
            otherTerminal.ConnectedWires.Add(wire);
            ConnectedWires.Add(wire);
            wire.PropagateData();
        }