Example #1
0
        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);
            }
        }
Example #2
0
        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();
            }
        }