Exemple #1
0
        public Token CopyToken(Token token)
        {
            var             t       = Token.CustomToken(this.GetType(), new List <PlotInfo>());
            List <PlotInfo> oldList = (List <PlotInfo>)token.CustomData;

            foreach (PlotInfo pi in oldList)
            {
                PlotInfo p = new PlotInfo
                {
                    X          = pi.X,
                    Y          = pi.Y,
                    Color      = pi.Color,
                    Pen        = pi.Pen,
                    Rotation   = pi.Rotation,
                    Thickness  = pi.Thickness,
                    XTranslate = pi.XTranslate,
                    YTranslate = pi.YTranslate,
                    Brush      = pi.Brush
                };
                ((List <PlotInfo>)t.CustomData).Add(p);
            }
            return(t);
        }
Exemple #2
0
        public static Token AddPlot(string operation, List <Token> arguments)
        {
            if (arguments.Count < 3 || arguments.Count > 9)
            {
                return(Token.Error("Wrong number of arguments passed to the function"));
            }
            var    plot       = arguments[0];
            Color  color      = defaultColors[nextColorIndex];
            double rotation   = 0;
            float  xTranslate = 0;
            float  yTranslate = 0;
            float  thickness  = 1;
            Brush  brush      = null;

            if (!plot.IsOfType(typeof(PlotToken)))
            {
                return(Token.Error("1st parameter must be a plot created through a call to createplot() function"));
            }
            if (arguments[1].TokenType != TokenType.Vector)
            {
                return(Token.Error("2nd parameter must be a numeric array"));
            }
            if (arguments[2].TokenType != TokenType.Vector)
            {
                return(Token.Error("3rd parameter must be a numeric array"));
            }
            if (arguments[1].Count != arguments[2].Count)
            {
                return(Token.Error("2nd & 3rd parameters must be of equal length"));
            }
            if (arguments.Count > 3)
            {
                if (arguments[3].TokenType != TokenType.Vector && arguments[3].Count != 1)
                {
                    return(Token.Error("4th parameter, when provided, must be a number (rotation)."));
                }
                rotation = arguments[3].FirstValue;
            }
            if (arguments.Count > 4)
            {
                if (arguments[4].TokenType != TokenType.Vector && arguments[4].Count != 1)
                {
                    return(Token.Error("5th parameter must be a number (line width). If not provided, default value of 1 will be used."));
                }
                thickness = (float)arguments[4].FirstValue;
            }
            if (arguments.Count > 5)
            {
                try
                {
                    if (arguments[5].TokenType != TokenType.Text)
                    {
                        throw new Exception();
                    }
                    string str = arguments[5].StrData.Trim();
                    if (str.Length > 0)
                    {
                        color = createColor(str);
                    }
                    else
                    {
                        nextColorIndex++;
                        nextColorIndex %= defaultColors.Count;
                    }
                }
                catch
                {
                    return(Token.Error("6th parameter must be a valid color name. Leave out to get a random color."));
                }
            }
            else
            {
                nextColorIndex++;
                nextColorIndex %= defaultColors.Count;
            }
            if (arguments.Count > 6)
            {
                if (arguments[6].TokenType != TokenType.Vector && arguments[6].Count != 1)
                {
                    return(Token.Error("7th parameter, when provided, must be a number (x translation)."));
                }
                xTranslate = (float)arguments[6].FirstValue;
            }
            if (arguments.Count > 7)
            {
                if (arguments[7].TokenType != TokenType.Vector && arguments[7].Count != 1)
                {
                    return(Token.Error("8th parameter, when provided, must be a number (y translation)."));
                }
                yTranslate = (float)arguments[7].FirstValue;
            }
            if (arguments.Count > 8)
            {
                if (arguments[8].TokenType == TokenType.Text)
                {
                    try
                    {
                        brush = new SolidBrush(createColor(arguments[8].StrData));
                    }
                    catch
                    {
                        return(Token.Error("9th parameter is not a valid color value (colro name or (A)RGB value)."));
                    }
                }
                else if (arguments[8].IsOfType(typeof(BrushToken)))
                {
                    brush = (Brush)arguments[8].CustomData;
                }
                else
                {
                    return(Token.Error("9th parameter, when provided, must either be a Brush (use createbrush()) or a color name or (A)RGB value."));
                }
            }

            Pen             pen  = new Pen(color, (float)Math.Max(0.5, Math.Min(100, thickness)));
            List <PlotInfo> list = (List <PlotInfo>)plot.CustomData;
            var             pi   = new PlotInfo
            {
                X          = arguments[1].FloatArray,
                Y          = arguments[2].FloatArray,
                Color      = color,
                Rotation   = (float)rotation,
                Thickness  = thickness,
                Pen        = pen,
                XTranslate = xTranslate,
                YTranslate = yTranslate,
                Brush      = brush,
            };

            list.Add(pi);
            return(Token.Void);
        }