Beispiel #1
0
 /// <summary>
 /// Sorts and connects all inputs
 /// </summary>
 /// <returns></returns>
 public void ConnectAllInputs()
 {
     foreach (Sketch.EndPoint endpoint in InputEndpoints)
     {
         WireMesh wire = EndpointsToWires[endpoint];
         wire.ConnectDependent(this);//, _inputWires.IndexOf(wire));
     }
     OrderInputs();
 }
Beispiel #2
0
        /// <summary>
        /// Connects a wire-mesh to the invoking circuit output, making
        /// the circuit output's value dependent on this wire.
        /// </summary>
        /// <param name="wire">The wire to connect</param>
        public void Connect(WireMesh wire)
        {
            // If we already connected to this wire, we're done!
            if (_outputWires.Contains(wire) || _inputWires.ContainsKey(wire))
            {
                return;
            }

            // If this wire doesn't come from somewhere, it comes from here.  Otherwise, it gives us value.
            if (!wire.HasSource)
            {
                _outputWires.Add(wire);
                wire.ConnectSource(this, 0);
            }
            else
            {
                _inputWires[wire] = wire.ConnectedEndpoints(this);
                wire.ConnectDependent(this);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Connects not bubbles to gates and wires
        /// </summary>
        /// <param name="gate"></param>
        private void connectNotBubble(LogicGate bubble)
        {
            LogicGate parentGate = null;
            WireMesh  wire       = null;

            // Get the components this not bubble is connected to
            foreach (Shape connected in bubble.Shape.ConnectedShapes)
            {
                if (LogicDomain.IsGate(connected.Type) && parentGate == null)
                {
                    parentGate = _logicGates[connected];
                }
                else if (LogicDomain.IsWire(connected.Type))
                {
                    wire = _wireMeshes[connected];
                }
            }

            // If this is not connected to a gate, connect it like a normal logic gate
            if (parentGate == null)
            {
                connectWiresTo(bubble);
                return;
            }

            // Is this bubble on the output or the input?
            Sketch.EndPoint connectingEndpoint =
                parentGate.Shape.ClosestEndpointFrom(bubble.Shape);
            bool isInput = parentGate.ShouldBeInput(connectingEndpoint);

            if (isInput)
            {
                wire.ConnectDependent(bubble);
                parentGate.ConnectInput(bubble, 0);
            }
            else
            {
                wire.ConnectSource(bubble, 0);
                parentGate.ConnectOutput(bubble, 0);
            }
        }