示例#1
0
        /// <summary>
        /// To check Syntax used for exception when the value are input by the user
        /// </summary>
        /// <param name="e">Exception</param>
        /// <param name="newCanvass">Display window to draw on</param>
        public void chk_var(Exception e, Canvass newCanvass, int line, int location)
        {
            Font       paramenterFont = new Font("Arial", 10);
            SolidBrush solidBrush     = new SolidBrush(Color.Black);

            if (location == 0)
            {
                newCanvass.RESET();
            }
            if ((line + 1) == 0)
            {
                newCanvass.g.DrawString("Wrong number of parameters inserted", paramenterFont, solidBrush, 0, 0 + location);
            }
            else
            {
                newCanvass.g.DrawString("Wrong number of parameters inserted on line" + (line + 1), paramenterFont, solidBrush, 0, 0 + location);
            }

            newCanvass.Error = true;
        }
示例#2
0
    {/// <summary>
     /// This Class is used to display some error when user's input command doesn't found
     /// </summary>
     /// <param name="newCanvass">Canvass used to display error message</param>
     /// <param name="line">the line number of the command to checl</param>
     /// <param name="location">location of output window where error message is displayed</param>
        public void chk_cmd(Canvass newCanvass, int line, int location)
        {
            Font       newFont    = new Font("Arial", 10);
            SolidBrush solidBrush = new SolidBrush(Color.Black);

            line++;
            if (line != 0)
            {
                if (location == 0)
                {
                    newCanvass.RESET();
                }
                newCanvass.g.DrawString("Command on line " + (line) + " doesn't exist", newFont, solidBrush, 0, 0 + location);
            }
            else
            {
                newCanvass.g.DrawString("Command doesn't exist", newFont, solidBrush, 0, 0 + location);
            }
            newCanvass.Error = true;
        }
 /// <summary>
 /// This help to check or reads command line if the line command is single or multiple commands
 /// </summary>
 /// <param name="command">Single Line command</param>
 /// <param name="multicmd">Multiple Line commands</param>
 /// <param name="NewCanvass">Display window to draw on</param>
 public void Cmd(String command, String multicmd, Canvass NewCanvass)
 {
     if (NewCanvass.Error)
     {
         NewCanvass.RESET();
         NewCanvass.Error = false;
     }
     if (multicmd.Length.Equals(0))
     {
         oneCommand(command, NewCanvass);
     }
     else if (command.Equals("run"))
     {
         manyCommand(multicmd, NewCanvass);
     }
     else
     {
         manyCommand(multicmd, NewCanvass);
     }
 }
示例#4
0
 /// <summary>
 /// Displays error when enetered parameters are not valid in the context
 /// </summary>
 /// <param name="parameter">Boolean value which gets value accordingly to check valid parameters</param>
 /// <param name="data">invalid parameter</param>
 /// <param name="line">line number of the command</param>
 /// <param name="newCanvass">Canvass used to display error message</param>
 /// <param name="location">location of canvass where error message is displayed</param>
 public void chk_var(bool parameter, String data, int line, Canvass newCanvass, int location)
 {
     if (!parameter)
     {
         Font       parameterFont = new Font("Arial", 10);
         SolidBrush solidBrush    = new SolidBrush(Color.Black);
         if (location == 0)
         {
             newCanvass.RESET();
         }
         if ((line + 1) == 0)
         {
             newCanvass.g.DrawString("Invalid Parameters on " + data, parameterFont, solidBrush, 0, 0 + location);
         }
         else
         {
             newCanvass.g.DrawString("Parameter " + data + " on line " + (line + 1) + " is invalid", parameterFont, solidBrush, 0, 0 + location);
         }
         newCanvass.Error = true;
     }
 }
        /// <summary>
        /// This help to execute application provided by user based on the instructions
        /// </summary>
        /// <param name="splitCommand">User entered commands</param>
        /// <param name="newCanvass">Display window to draw on</param>
        public void userCommands(String[] splitCommand, Canvass newCanvass, int n)
        {
            cmdChecker commandCheck = new cmdChecker();

            try
            {
                String[] method = splitCommand[0].Split('(', ')');
                if (splitCommand[0].Equals("moveto"))
                {
                    String[] data     = splitCommand[1].Split(',');
                    int      x        = 0;
                    int      y        = 0;
                    bool     variable = false;

                    try
                    {
                        if (!int.TryParse(data[0], out x))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                x = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)

                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out y))
                        {
                            if (!newCanvass.Ki.existingValue(data[1]))
                            {
                                variable = true;
                            }
                            else
                            {
                                y = newCanvass.Ki.Commitdata(data[1]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[1], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        newCanvass.moveTo(x, y);
                    }
                }

                else if (splitCommand[0].Equals("drawto"))
                {
                    String[] data     = splitCommand[1].Split(',');
                    int      x        = 0;
                    int      y        = 0;
                    bool     variable = false;

                    try
                    {
                        if (!int.TryParse(data[0], out x))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                x = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out y))
                        {
                            if (!newCanvass.Ki.existingValue(data[1]))
                            {
                                variable = true;
                            }
                            else
                            {
                                y = newCanvass.Ki.Commitdata(data[1]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[1], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        newCanvass.drawTo(x, y);
                    }
                }

                else if (splitCommand[0].Equals("polygon"))
                {
                    String[]   data            = splitCommand[1].Split(',');
                    List <int> temporaryPoints = new List <int>();
                    int        i    = 0;
                    int        x    = 0;
                    int        y    = 0;
                    int        z    = 0;
                    bool       var1 = false;
                    try
                    {
                        while (data.Length > i)
                        {
                            if (!int.TryParse(data[i], out x))
                            {
                                if (!newCanvass.Ki.existingValue(data[i]))
                                {
                                    var1 = true;
                                }
                                else
                                {
                                    temporaryPoints.Add(newCanvass.Ki.Commitdata(data[i]));
                                }
                                if (var1)
                                {
                                    newCanvass.cmd_chk.chk_var(false, data[i], n, newCanvass, lne);
                                    lne = lne + 20;
                                }
                            }
                            temporaryPoints.Add(x);
                            i++;
                        }
                    }
                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        int[]  arr  = temporaryPoints.ToArray();
                        design poly = new drawPolygon(arr);
                        poly.draw(newCanvass);
                    }
                }
                else if (splitCommand[0].Equals("rectangle"))
                {
                    String[] data = splitCommand[1].Split(',');
                    int      H    = 0;
                    int      W    = 0;

                    bool variable = false;

                    try
                    {
                        if (!int.TryParse(data[0], out H))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                H = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out W))
                        {
                            if (!newCanvass.Ki.existingValue(data[1]))
                            {
                                variable = true;
                            }
                            else
                            {
                                W = newCanvass.Ki.Commitdata(data[1]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[1], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        design rectangle = new drawRectangle(H, W);
                        rectangle.draw(newCanvass);
                    }
                }

                //Square(s) command
                else if (splitCommand[0].Equals("square"))
                {
                    String[] data = splitCommand[1].Split(',');
                    int      s    = 0;

                    bool variable = false;

                    try
                    {
                        if (!int.TryParse(data[0], out s))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                s = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        design square = new drawRectangle(s, s);
                        square.draw(newCanvass);
                    }
                }
                //Circle(r) command
                else if (splitCommand[0].Equals("circle"))
                {
                    String[] data     = splitCommand[1].Split(',');
                    int      R        = 0;
                    bool     variable = false;
                    try
                    {
                        if (!int.TryParse(data[0], out R))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                R = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                    }

                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        design circle = new drawCircle(R);
                        circle.draw(newCanvass);
                    }
                }
                //Triangle(h,b,a) command
                else if (splitCommand[0].Equals("triangle"))
                {
                    String[] data     = splitCommand[1].Split(',');
                    int      h        = 0;
                    int      b        = 0;
                    int      a        = 0;
                    bool     variable = false;

                    try
                    {
                        if (!int.TryParse(data[0], out h))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                h = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out b))
                        {
                            if (!newCanvass.Ki.existingValue(data[1]))
                            {
                                variable = true;
                            }
                            else
                            {
                                b = newCanvass.Ki.Commitdata(data[1]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[1], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                        if (!int.TryParse(data[0], out a))
                        {
                            if (!newCanvass.Ki.existingValue(data[0]))
                            {
                                variable = true;
                            }
                            else
                            {
                                a = newCanvass.Ki.Commitdata(data[0]);
                            }
                            if (variable)
                            {
                                newCanvass.cmd_chk.chk_var(false, data[0], n, newCanvass, lne);
                                lne = lne + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        design triangle = new drawTriangle(h, b, a);
                        triangle.draw(newCanvass);
                    }
                }
                //Pen command
                else if (splitCommand[0].Equals("pen"))
                {
                    Color penColor = Color.FromName(splitCommand[1]);
                    if (penColor.IsKnownColor == false)
                    {
                        commandCheck.chk_var(false, splitCommand[1], n, newCanvass, lne);
                        lne = lne + 20;
                    }

                    if (!newCanvass.Error)
                    {
                        newCanvass.Set_Pencolor(penColor);
                    }
                }
                //Fill command
                else if (splitCommand[0].Equals("fill"))
                {
                    bool valueOn  = splitCommand[1].Equals("on");
                    bool valueOff = splitCommand[1].Equals("off");

                    if (valueOn == false && valueOff == false)
                    {
                        commandCheck.chk_var(false, splitCommand[1], n, newCanvass, lne);
                        lne = lne + 20;
                    }
                    if (!newCanvass.Error)
                    {
                        if (valueOn)
                        {
                            newCanvass.fil = true;
                        }
                        else if (valueOff)
                        {
                            newCanvass.fil = false;
                        }
                    }
                }
                //Reset command
                else if (splitCommand[0].Equals("reset"))
                {
                    newCanvass.RESET();
                }

                //Clear command
                else if (splitCommand[0].Equals("clear"))
                {
                    newCanvass.CLEAR();
                }

                //Exit command
                else if (splitCommand[0].Equals("exit"))
                {
                    Application.Exit();
                }
                else if (newCanvass.km.existingValue(method[0]))
                {
                    String[] methodValue   = (newCanvass.km.Commitdata(method[0])).Split(',');
                    String   methodCmd     = method[0] + "command";
                    String   methodCommand = newCanvass.km.Commitdata(methodCmd);
                    String[] userValue     = method[1].Split(',');
                    int      x             = 0;
                    while (methodValue.Length > x)
                    {
                        String[] valueStore = (methodValue[x] + " = " + userValue[x]).Split(' ');
                        userCommands(valueStore, newCanvass, n);
                        x++;
                    }
                    manyCommand(methodCommand, newCanvass);
                }


                else if (splitCommand[1].Equals("="))
                {
                    try
                    {
                        if (splitCommand[3].Equals("+"))
                        {
                            int  variableValue;
                            int  x        = 0;
                            int  y        = 0;
                            bool variable = false;
                            try
                            {
                                if (!int.TryParse(splitCommand[2], out x))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[2]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        x = newCanvass.Ki.Commitdata(splitCommand[2]);
                                    }
                                }
                                if (!int.TryParse(splitCommand[4], out y))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[4]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        y = newCanvass.Ki.Commitdata(splitCommand[4]);
                                    }
                                }
                                if (variable)
                                {
                                    commandCheck.chk_var(false, splitCommand[2], n, newCanvass, lne);
                                    lne = lne + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                commandCheck.chk_var(e, newCanvass, n, lne);
                                lne = lne + 20;
                            }
                            variableValue = x + y;
                            newCanvass.Ki.addValue(splitCommand[0], variableValue);
                        }
                        if (splitCommand[3].Equals("-"))
                        {
                            int  variableValue;
                            int  x        = 0;
                            int  y        = 0;
                            bool variable = false;
                            try
                            {
                                if (!int.TryParse(splitCommand[2], out x))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[2]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        x = newCanvass.Ki.Commitdata(splitCommand[2]);
                                    }
                                }
                                if (!int.TryParse(splitCommand[4], out y))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[4]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        y = newCanvass.Ki.Commitdata(splitCommand[4]);
                                    }
                                }
                                if (variable)
                                {
                                    commandCheck.chk_var(false, splitCommand[2], n, newCanvass, lne);
                                    lne = lne + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                commandCheck.chk_var(e, newCanvass, n, lne);
                                lne = lne + 20;
                            }
                            variableValue = x - y;
                            newCanvass.Ki.addValue(splitCommand[0], variableValue);
                        }
                        if (splitCommand[3].Equals("*"))
                        {
                            int  variableValue;
                            int  x        = 0;
                            int  y        = 0;
                            bool variable = false;
                            try
                            {
                                if (!int.TryParse(splitCommand[2], out x))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[2]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        x = newCanvass.Ki.Commitdata(splitCommand[2]);
                                    }
                                }
                                if (!int.TryParse(splitCommand[4], out y))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[4]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        y = newCanvass.Ki.Commitdata(splitCommand[4]);
                                    }
                                }
                                if (variable)
                                {
                                    commandCheck.chk_var(false, splitCommand[2], n, newCanvass, lne);
                                    lne = lne + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                commandCheck.chk_var(e, newCanvass, n, lne);
                                lne = lne + 20;
                            }
                            variableValue = x * y;
                            newCanvass.Ki.addValue(splitCommand[0], variableValue);
                        }
                        if (splitCommand[3].Equals("/"))
                        {
                            int  variableValue;
                            int  x        = 0;
                            int  y        = 0;
                            bool variable = false;
                            try
                            {
                                if (!int.TryParse(splitCommand[2], out x))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[2]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        x = newCanvass.Ki.Commitdata(splitCommand[2]);
                                    }
                                }
                                if (!int.TryParse(splitCommand[4], out y))
                                {
                                    if (!newCanvass.Ki.existingValue(splitCommand[4]))
                                    {
                                        variable = true;
                                    }
                                    else
                                    {
                                        y = newCanvass.Ki.Commitdata(splitCommand[4]);
                                    }
                                }
                                if (variable)
                                {
                                    commandCheck.chk_var(false, splitCommand[2], n, newCanvass, lne);
                                    lne = lne + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                commandCheck.chk_var(e, newCanvass, n, lne);
                                lne = lne + 20;
                            }
                            variableValue = x / y;
                            newCanvass.Ki.addValue(splitCommand[0], variableValue);
                        }
                    }
                    catch
                    {
                        int x = 0;

                        try
                        {
                            bool variable = false;
                            if (!int.TryParse(splitCommand[2], out x))
                            {
                                if (!newCanvass.Ki.existingValue(splitCommand[2]))
                                {
                                    variable = true;
                                }
                                else
                                {
                                    x = newCanvass.Ki.Commitdata(splitCommand[2]);
                                }
                                if (variable)
                                {
                                    newCanvass.cmd_chk.chk_var(false, splitCommand[2], n, newCanvass, lne);
                                    lne = lne + 20;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            newCanvass.cmd_chk.chk_var(e, newCanvass, n, lne);
                            lne = lne + 20;
                        }
                        if (!newCanvass.Error)
                        {
                            if (!newCanvass.Ki.existingValue(splitCommand[0]))
                            {
                                newCanvass.Ki.KeepData(splitCommand[0], x);
                            }
                            else
                            {
                                newCanvass.Ki.addValue(splitCommand[0], x);
                            }
                        }
                    }
                }
                ///Executes if the given data is not recognized by the application
                else
                {
                    commandCheck.chk_cmd(newCanvass, n, lne);
                    lne = lne + 20;
                }
            }
            catch
            {
                commandCheck.chk_cmd(newCanvass, n, lne);
                lne = lne + 20;
            }
        }