Exemple #1
0
        /// <summary>
        /// Undo a previously marked drawing 
        /// Takes a boolean argument that detemines if the element is to be deleted 
        /// from concerned arrayList
        /// </summary>
        /// <param name="deleteItem"></param>
        /// <returns></returns>
        private Boolean undoDrawing(Boolean deleteItem)
        {
            //Undo option
            //There is a stack called actionState that stores all the actions
            //actions here are elements that are identified - capacitors, etc
            //     and the circle is drawn around them
            //When an option is undo-ed the stack pops and the element is examined
            //That element has info on coordinates
            //erase graphics method is called

            ArrayList foo = new ArrayList();
            if (actionState.Count > 0)
            {
                foo = actionState.Pop();
                string sfoo = null;
                char[] delims = { '_' };
                string[] foob = null;
                if (foo.Equals(Transistors))
                {
                    sfoo = Transistors[Transistors.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if(deleteItem) Transistors.RemoveAt(Transistors.Count - 1);
                    //MessageBox.Show("It was transistors");

                }
                else if (foo.Equals(Resistors))
                {
                    sfoo = Resistors[Resistors.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Resistors.RemoveAt(Resistors.Count - 1);
                }
                else if (foo.Equals(Capacitors))
                {
                    sfoo = Capacitors[Capacitors.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Capacitors.RemoveAt(Capacitors.Count - 1);
                }
                else if (foo.Equals(Inductors))
                {
                    sfoo = Inductors[Inductors.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Inductors.RemoveAt(Inductors.Count - 1);
                }
                else if (foo.Equals(CS))
                {
                    sfoo = CS[CS.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) CS.RemoveAt(CS.Count - 1);
                }
                else if (foo.Equals(VS))
                {
                    sfoo = VS[VS.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) VS.RemoveAt(VS.Count - 1);
                }
                else if (foo.Equals(Diodes))
                {
                    sfoo = Diodes[Diodes.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Diodes.RemoveAt(Diodes.Count - 1);
                }
                else if (foo.Equals(Nodes))
                {
                    sfoo = Nodes[Nodes.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Nodes.RemoveAt(Nodes.Count - 1);
                }

                 else if (foo.Equals(Amplifier))
                {
                    sfoo = Amplifier[Amplifier.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Amplifier.RemoveAt(Amplifier.Count - 1);
                }
                else if (foo.Equals(Attenuator))
                {
                    sfoo = Attenuator[Attenuator.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Attenuator.RemoveAt(Attenuator.Count - 1);
                }
                else if (foo.Equals(Bias))
                {
                    sfoo = Bias[Bias.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Bias.RemoveAt(Bias.Count - 1);
                }
                else if (foo.Equals(PDet))
                {
                    sfoo = PDet[PDet.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) PDet.RemoveAt(PDet.Count - 1);
                }
                else if (foo.Equals(Switch))
                {
                    sfoo = Switch[Switch.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Switch.RemoveAt(Switch.Count - 1);
                }
                else if (foo.Equals(Other_c))
                {
                    sfoo = Other_c[Other_c.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Other_c.RemoveAt(Other_c.Count - 1);
                }
                else if (foo.Equals(ANDgate))
                {
                    sfoo = ANDgate[ANDgate.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) ANDgate.RemoveAt(ANDgate.Count - 1);
                }
                else if (foo.Equals(Tgate))
                {
                    sfoo = Tgate[Tgate.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Tgate.RemoveAt(Tgate.Count - 1);
                }
                else if (foo.Equals(ORgate))
                {
                    sfoo = ORgate[ORgate.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) ORgate.RemoveAt(ORgate.Count - 1);
                }
                else if (foo.Equals(NORgate))
                {
                    sfoo = NORgate[NORgate.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) NORgate.RemoveAt(NORgate.Count - 1);
                }
                else if (foo.Equals(Other_bb))
                {
                    sfoo = Other_bb[Other_bb.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Other_bb.RemoveAt(Other_bb.Count - 1);
                }
                else if (foo.Equals(Buffer))
                {
                    sfoo = Buffer[Buffer.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Buffer.RemoveAt(Buffer.Count - 1);
                }
                else if (foo.Equals(Supply))
                {
                    sfoo = Supply[Supply.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Supply.RemoveAt(Supply.Count - 1);
                }
                else if (foo.Equals(Ground))
                {
                    sfoo = Ground[Ground.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) Ground.RemoveAt(Ground.Count - 1);
                }
                else if (foo.Equals(newC))
                {
                    sfoo = newC[newC.Count - 1].ToString();
                    foob = sfoo.Split(delims, StringSplitOptions.RemoveEmptyEntries);
                    eraseGraphics(int.Parse(foob[1]), int.Parse(foob[2]));
                    if (deleteItem) newC.RemoveAt(newC.Count - 1);
                }

            }
            else
            {
                //writeLog("Nothing to UNDO");
                return false;
            }
            return true;
        }