Exemple #1
0
 internal void ClearSettings(Component comp)
 {
     if (comp is Input)
     {
         Input i = comp as Input;
         i.Clear();
     }
     else if (comp is And)
     {
         foreach (Link x in listLinks)
         {
             And m = comp as And;
             m.Clear(x);
             m.Clear();
         }
     }
     else if (comp is XOR)
     {
         foreach (Link x in listLinks)
         {
             XOR s = comp as XOR;
             s.Clear(x);
             s.Clear();
         }
     }
     else if (comp is NOT)
     {
         foreach (Link x in listLinks)
         {
             NOT s = comp as NOT;
             s.Clear(x);
             s.Clear();
         }
     }
     else if (comp is OR)
     {
         foreach (Link x in listLinks)
         {
             OR s = comp as OR;
             s.Clear(x);
             s.Clear();
         }
     }
     else if (comp is Output)
     {
         Output s = comp as Output;
         s.Clear();
     }
 }
Exemple #2
0
        /// <summary>
        /// Remove link from the links list
        /// </summary>
        /// <param name="comp"></param>
        public void RemoveLink(Component comp)
        {
            // this.listLinks.Remove(l);
            List <Link>      toRemove    = new List <Link>();
            List <Component> compToClear = new List <Component>();

            foreach (Link x in listLinks)
            {
                if (x.startComponent == comp)
                {
                    int counter = 0;
                    foreach (Component y in listComponents)
                    {
                        if (y == x.endComponent)
                        {
                            if (y is Input)
                            {
                                Input s = y as Input;
                                s.Clear();
                                // listComponents[counter] = s;
                            }
                            else if (y is OR)
                            {
                                OR s = y as OR;
                                s.Clear(x);
                                //  listComponents[counter] = s;
                            }
                            else if (y is XOR)
                            {
                                XOR s = y as XOR;
                                s.Clear(x);
                                //  listComponents[counter] = s;
                            }
                            else if (y is NOT)
                            {
                                NOT i = y as NOT;
                                i.Clear(x);
                                listComponents[counter] = i;
                            }
                            else if (y is And)
                            {
                                And s = y as And;
                                s.Clear(x);
                                //  listComponents[counter] = s;
                            }
                        }
                        counter++;
                    }
                    toRemove.Add(x);
                    compToClear.Add(x.startComponent);
                    compToClear.Add(x.endComponent);
                }
                if (x.endComponent == comp)
                {
                    int counter = 0;
                    foreach (Component y in listComponents)
                    {
                        if (y == x.startComponent)
                        {
                            if (y is Output)
                            {
                                Output s = y as Output;
                                s.Clear();
                                //  listComponents[counter] = s;
                            }
                            else if (y is OR)
                            {
                                OR s = y as OR;
                                s.Clear(x);
                                //  listComponents[counter] = s;
                            }
                            else if (y is XOR)
                            {
                                XOR s = y as XOR;
                                s.Clear(x);
                                //listComponents[counter] = s;
                            }
                            else if (y is NOT)
                            {
                                NOT i = y as NOT;
                                i.Clear(x);
                                listComponents[counter] = i;
                            }
                            else if (y is And)
                            {
                                And s = y as And;
                                s.Clear(x);
                                //listComponents[counter] = s;
                            }
                        }
                    }
                    toRemove.Add(x);
                    compToClear.Add(x.startComponent);
                    compToClear.Add(x.endComponent);
                }
            }
            foreach (var c in compToClear)
            {
                ClearSettings(c);
            }
            foreach (Link c1 in toRemove)
            {
                listLinks.Remove(c1);
            }
        }
Exemple #3
0
        /// <summary>
        /// Remove component from the components list
        /// </summary>
        /// <param name="comp"></param>
        public void RemoveComponent(Component comp)
        {
            List <Link> toRemove   = new List <Link>();
            Component   losesInput = null;

            if (listLinks.Count != 0)
            {
                foreach (Link x in listLinks)
                {
                    if (x.startComponent == comp)
                    {
                        //int counter = 0;
                        foreach (Component y in listComponents)
                        {
                            if (y == x.endComponent)
                            {
                                if (y is Input)
                                {
                                    Input i = y as Input;
                                    i.Clear();
                                    //listComponents[counter] = i;
                                }
                                else if (y is OR)
                                {
                                    OR i = y as OR;
                                    i.Clear(x);
                                    //listComponents[counter] = i;
                                }
                                else if (y is XOR)
                                {
                                    XOR i = y as XOR;
                                    i.Clear(x);
                                    //listComponents[counter] = i;
                                }
                                else if (y is NOT)
                                {
                                    NOT i = y as NOT;
                                    i.Clear(x);
                                    //listComponents[counter] = i;
                                }
                                else if (y is And)
                                {
                                    And i = y as And;
                                    i.Clear(x);
                                    //listComponents[counter] = i;
                                }
                            }
                            //counter++;
                        }
                        toRemove.Add(x);
                    }
                    if (x.endComponent == comp)
                    {
                        //int counter = 0;
                        foreach (Component y in listComponents)
                        {
                            if (y == x.startComponent)
                            {
                                if (y is Output)
                                {
                                    Output s = y as Output;
                                    s.Clear();
                                    //listComponents[counter] = s;
                                }
                                else if (y is OR)
                                {
                                    OR s = y as OR;
                                    s.Clear(x);
                                    //listComponents[counter] = s;
                                }
                                else if (y is XOR)
                                {
                                    XOR s = y as XOR;
                                    s.Clear(x);
                                    //listComponents[counter] = s;
                                }
                                else if (y is NOT)
                                {
                                    NOT i = y as NOT;
                                    i.Clear(x);
                                    //listComponents[counter] = i;
                                }
                                else if (y is And)
                                {
                                    And s = y as And;
                                    s.Clear(x);
                                    //listComponents[counter] = s;
                                }
                            }
                        }
                        toRemove.Add(x);
                    }
                }
            }

            foreach (Link checkIfOutput in toRemove)
            {
                if (checkIfOutput.startComponent == comp)
                {
                    losesInput = checkIfOutput.endComponent;
                }
            }

            foreach (Link l1 in toRemove)
            {
                listLinks.Remove(l1);
            }
            // this.RemoveLink();
            this.listComponents.Remove(comp);
            if (losesInput != null)
            {
                losesInput.CalculateValue();
            }
        }