private void createConesRec(Dictionary <int, Cone> ComponentConeDic, Gate Component) { if (ComponentConeDic.ContainsKey(Component.Id)) { return; } Cone cone = null; if (Component.Output.OutputComponents == null || Component.Output.OutputComponents.Count == 0) { return; } foreach (Gate g in Component.Output.OutputComponents) { createConesRec(ComponentConeDic, g); if (ComponentConeDic.ContainsKey(g.Id)) { if (cone == null) { cone = ComponentConeDic[g.Id]; } else if (cone.Id != ComponentConeDic[g.Id].Id) { cone = new Cone(Component.Id); cone.Output = Component.Output; Cones.Add(cone);// cone.Order = Component.Order; break; } } } if (cone != null) { ComponentConeDic.Add(Component.Id, cone); cone.cone.AddComponent(Component); } }
public void createCones() { if (Cones == null || Cones.Count > 0) { return; } Dictionary <int, Cone> ComponentConeDic = new Dictionary <int, Cone>(); //int Component_id-> Model cone foreach (Wire wire in Output) { Cone cone = new Cone(wire.InputComponent.Id); cone.Output = wire; cone.Order = wire.InputComponent.Order; cone.cone.AddComponent(wire.InputComponent); //if wire.InputComponent==null? ComponentConeDic.Add(wire.InputComponent.Id, cone); Cones.Add(cone); } foreach (Wire wire in Input) { if (wire.OutputComponents == null || wire.OutputComponents.Count == 0) { continue; } foreach (Gate Component in wire.OutputComponents) { createConesRec(ComponentConeDic, Component); if (!ComponentConeDic.ContainsKey(Component.Id)) { Cone newcone = new Cone(Component.Id); newcone.Output = Component.Output; Cones.Add(newcone);// ComponentConeDic.Add(Component.Id, newcone); newcone.cone.AddComponent(Component); newcone.Order = Component.Order; if (Component is MultipleInputComponent) { ComponentConeDic[Component.Id].cone.Input.AddRange(((MultipleInputComponent)Component).Input); } else if (Component is OneInputComponent) { ComponentConeDic[Component.Id].cone.Input.Add(((OneInputComponent)Component).Input1); } } else { ComponentConeDic[Component.Id].cone.Input.Add(wire); } } } //cones input foreach (Cone cone in Cones) { if (cone.Output.OutputComponents != null && cone.Output.OutputComponents.Count != 0)//cone with inside output { foreach (Gate g in cone.Output.OutputComponents) { if (ComponentConeDic.ContainsKey(g.Id)) { ComponentConeDic[g.Id].cone.Input.Add(cone.Output); } } } } Cones.Sort(Gate.CompareComponents); foreach (Cone cone in Cones) { cone.SetInputOutputComponents(); } }