YAMP.SubPlotValue.Perform C# (CSharp) Method

Perform() public method

Gets a (sub) plot from this container.
public Perform ( ParseContext context, Value argument ) : Value
context ParseContext The context from which this is going on.
argument Value The indices as arguments.
return Value
        public Value Perform(ParseContext context, Value argument)
        {
            if (argument is ScalarValue)
            {
                var index = ((ScalarValue)argument).IntValue;

                if (index < 1 || index > subplots.Count)
                    throw new YAMPIndexOutOfBoundException(index, 1, subplots.Count);

                return subplots[index - 1].Plot;
            }
            else if (argument is ArgumentsValue)
            {
                var av = (ArgumentsValue)argument;

                if (av.Length != 2)
                    throw new YAMPArgumentNumberException("SubPlot", av.Length, 2);

                var row = 1;
                var column = 1;

                if (av[1] is ScalarValue)
                    row = ((ScalarValue)av[1]).IntValue;
                else
                    throw new YAMPArgumentWrongTypeException(av[1].Header, "Scalar", "SubPlot");

                if (av[2] is ScalarValue)
                    column = ((ScalarValue)av[2]).IntValue;
                else
                    throw new YAMPArgumentWrongTypeException(av[2].Header, "Scalar", "SubPlot");

                if (row < 1 || row > Rows)
                    throw new YAMPIndexOutOfBoundException(row, 1, Rows);
                else if (column < 1 || column > Columns)
                    throw new YAMPIndexOutOfBoundException(column, 1, Columns);

                for (var i = subplots.Count - 1; i >= 0; i--)
                {
                    if (subplots[i].Row <= row && subplots[i].Row + subplots[i].RowSpan - 1 >= row &&
                        subplots[i].Column <= column && subplots[i].Column + subplots[i].ColumnSpan - 1 >= column)
                        return subplots[i].Plot;
                }

                return this;
            }

            throw new YAMPWrongTypeSuppliedException(argument.Header, "Scalar");
        }

Same methods

SubPlotValue::Perform ( ParseContext context, Value indices, Value values ) : Value