public Diode(Joint j1, Joint j2, Wire w) { Joints[0] = j1; Joints[1] = j2; W = w; w.Direction = Wire.WireDirection.J1ToJ2; constructor(); }
public override Joint[] FindAccessibleJoints(Joint from) { if (from == Joints[0])//input joint if (Joints[1].SendingVoltage != 0)//gate is open return new Joint[] { Joints[2] }; //no other joint can conduct current to another joint or gate is closed return new Joint[0]; }
public override Joint[] FindAccessibleJoints(Joint from) { if ((Logics as Logics.CapacitorLogics).IndividualPass) return new Joint[0]; if (from == Joints[0]) return new Joint[] { Joints[1] }; else return new Joint[] { Joints[0] }; }
public Wire(int id1, int id2) { Component t = ComponentsManager.GetComponent(id1); if (t == null || !(t is Joint)) J1 = new Joint(); else J1 = (Joint)t; t = ComponentsManager.GetComponent(id2); if (t == null || !(t is Joint)) J2 = new Joint(); else J2 = (Joint)t; constructor(); }
/// <summary> /// Returns joints that current can pass to from certain joint. These joints don't have to be connected directly. /// </summary> /// <param name="from"></param> /// <returns></returns> public virtual Joint[] FindAccessibleJoints(Joint from) { return new Joint[0]; }
public override Joint[] FindAccessibleJoints(Joint from) { if (W.IsConnected) return new Joint[] { from == Joints[0] ? Joints[1] : Joints[0] }; return new Joint[0]; }
public override Joint[] FindAccessibleJoints(Joint from) { if (from == Joints[0]) return new Joint[] { W1.IsConnected ? Joints[1] : Joints[2] }; else if ((from == Joints[1] && W1.IsConnected) || (from == Joints[2] && W2.IsConnected)) return new Joint[] { Joints[0] }; return new Joint[0]; }
public override Joint[] FindAccessibleJoints(Joint from) { if ((from == Joints[0] || from == Joints[1]) && W1.VoltageDropAbs > 0.0001) return new Joint[] { Joints[2] }; return new Joint[0]; }
public void SetIsolated(Wire from, Joint j) { if (j.IsUpdated || j.ConnectedWires.Count > 2) return; j.IsUpdated = true; for (int i = 0; i < j.ConnectedWires.Count; i++) { if (j.ConnectedWires[i] != from && !j.ConnectedWires[i].IsUpdated && !j.ConnectedWires[i].IsIsolated) { j.ConnectedWires[i].IsUpdated = true; j.ConnectedWires[i].IsIsolated = true; if (j.ConnectedWires[i].J1 == j) SetIsolated(j.ConnectedWires[i], j.ConnectedWires[i].J2); else SetIsolated(j.ConnectedWires[i], j.ConnectedWires[i].J1); } } }
public Wire(Joint j1, Joint j2) { J1 = j1; J2 = j2; constructor(); }
public override Joint[] FindAccessibleJoints(Joint from) { List<Joint> t = new List<Joint>(); if (from == Joints[0]) { if (left == PortState.Input) return new Joint[0]; if (leftUp && up != PortState.Input) t.Add(Joints[1]); if (leftRight && right != PortState.Input) t.Add(Joints[2]); if (leftDown && down != PortState.Input) t.Add(Joints[3]); } else if (from == Joints[1]) { if (up == PortState.Input) return new Joint[0]; if (leftUp && left != PortState.Input) t.Add(Joints[0]); if (upRight && right != PortState.Input) t.Add(Joints[2]); if (upDown && down != PortState.Input) t.Add(Joints[3]); } else if (from == Joints[2]) { if (right == PortState.Input) return new Joint[0]; if (leftRight && left != PortState.Input) t.Add(Joints[0]); if (upRight && up != PortState.Input) t.Add(Joints[1]); if (rightDown && down != PortState.Input) t.Add(Joints[3]); } else if (from == Joints[3]) { if (down == PortState.Input) return new Joint[0]; if (leftDown && left != PortState.Input) t.Add(Joints[0]); if (upDown && up != PortState.Input) t.Add(Joints[1]); if (rightDown && right != PortState.Input) t.Add(Joints[2]); } return t.ToArray(); }
public override Joint[] FindAccessibleJoints(Joint from) { if (from == Joints[0]) return new Joint[] { Joints[1] }; return new Joint[0]; }
public override void InitAddChildComponents() { for (int i = 0; i < Joints.Length; i++) { switch (rotation) { case Rotation.cw0: Joints[i] = Joint.GetJoint(new Vector2(JointLocs0cw[i * 2], JointLocs0cw[i * 2 + 1]) + Graphics.Position); break; case Rotation.cw90: Joints[i] = Joint.GetJoint(new Vector2(JointLocs90cw[i * 2], JointLocs90cw[i * 2 + 1]) + Graphics.Position); break; case Rotation.cw180: Joints[i] = Joint.GetJoint(new Vector2(JointLocs180cw[i * 2], JointLocs180cw[i * 2 + 1]) + Graphics.Position); break; case Rotation.cw270: Joints[i] = Joint.GetJoint(new Vector2(JointLocs270cw[i * 2], JointLocs270cw[i * 2 + 1]) + Graphics.Position); break; default: break; } Joints[i].CanRemove = false; Joints[i].ContainingComponents.Add(this); } Joints[3].Graphics.Visible = false; Joints[3].CanBeGround = true; Joints[3].IsGround = true; Joints[3].CanProvidePower = false; Joints[3].IsProvidingPower = false; Joints[4].Graphics.Visible = false; Joints[4].CanProvidePower = true; Joints[4].IsProvidingPower = true; Joints[4].CanBeGround = false; Joints[4].IsGround = false; Joints[5].Graphics.Visible = false; Joints[5].CanBeGround = true; Joints[5].IsGround = true; Joints[5].CanProvidePower = false; Joints[5].IsProvidingPower = false; for (int i = 0; i < Joints.Length; i++) { Joints[i].Initialize(); } W1 = new Wire(Joints[0], Joints[3]); W1.Direction = Wire.WireDirection.J1ToJ2; W1.Resistance = 300; W1.AddComponentToManager(); W1.Graphics.Visible = false; W1.Initialize(); W2 = new Wire(Joints[1], Joints[5]); W2.Direction = Wire.WireDirection.J1ToJ2; W2.Resistance = 300; W2.AddComponentToManager(); W2.Graphics.Visible = false; W2.Initialize(); W3 = new Wire(Joints[4], Joints[2]); //W3.Direction = Wire.WireDirection.J1ToJ2; W3.Resistance = 5; W3.AddComponentToManager(); W3.Graphics.Visible = false; W3.Initialize(); }
void CircuitPart_onJointIsProviderChanged(Joint j, bool v_new, bool v_old) { lock (A) { lock (J) { for (int i = 0; i < potentialGrounds.Count; i++) { if (v_new && joints[potentialGrounds[i]].IsGround) { SetAWire(wires.Count + i * potentialPowerSources.Count + j.LocalProviderInd, potentialGrounds[i], potentialPowerSources[j.LocalProviderInd], 1, -1); J[0, wires.Count + i * potentialPowerSources.Count + j.LocalProviderInd] = j.SendingVoltage; onAChanged(); } else { SetAWire(wires.Count + i * potentialPowerSources.Count + j.LocalProviderInd, potentialGrounds[i], potentialPowerSources[j.LocalProviderInd], 0, 0); J[0, wires.Count + i * potentialPowerSources.Count + j.LocalProviderInd] = 0; onAChanged(); } } onAChanged(); Recalculate = true; } } }
private void SetBranchCurrent(Wire from, Joint j, double current, Wire start = null) { if (j.ConnectedWires.Count > 2 || from == start) return; if (start == null) start = from; for (int i = 0; i < j.ConnectedWires.Count; i++) { if (j.ConnectedWires[i] != from) { j.ConnectedWires[i].SetCurrent(current); j.ConnectedWires[i].IsUpdated = true; if (j.ConnectedWires[i].J2 != j) SetBranchCurrent(j.ConnectedWires[i], j.ConnectedWires[i].J2, current, start); if (j.ConnectedWires[i].J1 != j) SetBranchCurrent(j.ConnectedWires[i], j.ConnectedWires[i].J1, current, start); } } }
private void HasWireVoltageSourceAtBranch(Wire w, Joint from, ref bool has) { if (w.IsUpdated) return; has |= w.CanSendVoltageOrCurrent; if (has) return; w.IsUpdated = true; if (from != w.J1) for (int i = 0; i < w.J1.ConnectedWires.Count; i++) HasWireVoltageSourceAtBranch(w.J1.ConnectedWires[i], w.J1, ref has); if (from != w.J2) for (int i = 0; i < w.J2.ConnectedWires.Count; i++) HasWireVoltageSourceAtBranch(w.J2.ConnectedWires[i], w.J2, ref has); }
private void HasGroundProviderAtBranch(Wire from, Joint j, ref bool ground, ref bool provider) { if (ground && provider) return; if (j.IsUpdated) return; ground |= j.IsGround; provider |= j.IsProvidingPower; j.IsUpdated = true; for (int i = 0; i < j.ConnectedWires.Count; i++) { if (j.ConnectedWires[i] != from && !j.ConnectedWires[i].IsUpdated && !j.ConnectedWires[i].IsIsolated) { j.ConnectedWires[i].IsUpdated = true; if (j.ConnectedWires[i].J1 == j) { if (j.ConnectedWires[i].IsConnected) HasGroundProviderAtBranch(j.ConnectedWires[i], j.ConnectedWires[i].J2, ref ground, ref provider); } else if (j.ConnectedWires[i].IsConnected) HasGroundProviderAtBranch(j.ConnectedWires[i], j.ConnectedWires[i].J1, ref ground, ref provider); } } }
private void GetBranchInfoForCurrent(Wire from, Joint j, ref double Resistance, ref Joint end, Wire start = null) { if (j.ConnectedWires.Count > 2 || from == start) { end = j; return; } if (start == null) start = from; for (int i = 0; i < j.ConnectedWires.Count; i++) { if (j.ConnectedWires[i] != from) { Resistance += j.ConnectedWires[i].Resistance; if (j.ConnectedWires[i].J2 != j) GetBranchInfoForCurrent(j.ConnectedWires[i], j.ConnectedWires[i].J2, ref Resistance, ref end, start); if (j.ConnectedWires[i].J1 != j) GetBranchInfoForCurrent(j.ConnectedWires[i], j.ConnectedWires[i].J1, ref Resistance, ref end, start); } } if (end == null) end = j; }
void CircuitPart_onJointSendingVoltageChanged(Joint j, double v_new, double v_old) { lock (J) { for (int i = 0; i < potentialGrounds.Count; i++) { if (joints[potentialGrounds[i]].IsGround) J[0, wires.Count + i * potentialPowerSources.Count + j.LocalProviderInd] = v_new; } Recalculate = true; } }
public override Joint[] FindAccessibleJoints(Joint from) { if (from == Joints[4] || from == Joints[5] || from == Joints[6] || from == Joints[7]) return new Joint[0]; if ((from == Joints[0] && left == PortState.Input) || (from == Joints[1] && up == PortState.Input) || (from == Joints[2] && right == PortState.Input) || (from == Joints[3] && down == PortState.Input)) return new Joint[0]; List<Joint> t = new List<Joint>(); if (from != Joints[0] && left != PortState.Input) t.Add(Joints[0]); if (from != Joints[1] && up != PortState.Input) t.Add(Joints[1]); if (from != Joints[2] && right != PortState.Input) t.Add(Joints[2]); if (from != Joints[3] && down != PortState.Input) t.Add(Joints[3]); return t.ToArray(); }
public override Joint[] FindAccessibleJoints(Joint from) { return new Joint[] { from == Joints[0] ? Joints[1] : Joints[0] }; }
public override void PostLoad() { base.PostLoad(); J1 = (Joint)ComponentsManager.GetComponent(j1); J2 = (Joint)ComponentsManager.GetComponent(j2); if (dp != null) { var a = dp.Split(';'); var g = Graphics as Graphics.WireGraphics; g.DrawPath.Clear(); g.IgnoreNextPathFinder = true; for (int i = 0; i < a.Length; i += 2) { g.DrawPath.Add(new Vector2((float)Convert.ToDouble(a[i]), (float)Convert.ToDouble(a[i + 1]))); } } (Graphics as Graphics.WireGraphics).GenerateElectrons(); updateVoltageCurrent(); }
public override Joint[] FindAccessibleJoints(Joint from) { for (int i = 0; i < 4; i++) if (Wires[i].IsConnected) { if (from == Wires[i].J1) return new Joint[] { Wires[i].J2 }; if (from == Wires[i].J2) return new Joint[] { Wires[i].J1 }; } return new Joint[0]; }
public override Joint[] FindAccessibleJoints(Joint from) { return(new Joint[] { from == Joints[0] ? Joints[1] : Joints[0] }); }