Example #1
0
        public Render(string inputFile)
        {
            InitializeComponent();
            InitializeResources();

            var parser = new Parser(inputFile);
            InitializeParser(parser);
            Shown += (sender, args) => parser.Start();

            renderPanel.Paint += (sender, args) => RenderPicture(args.Graphics);
        }
Example #2
0
        public Render(string inputFile)
        {
            InitializeComponent();

            _mainFigures = new List<Figure<Point2D, Matrix2D>[]>();
            _matrices = new Matrix2D[4];
            for (var i = 0; i < _matrices.Length; ++i)
                _matrices[i] = new Matrix2D().IdentMatrix<Matrix2D>();
            _transform = new ReduceTransform();

            var parser = new Parser(inputFile);
            InitializeParser(parser);
            Shown += (sender, args) => parser.Start();

            renderPanel.Paint += (sender, args) => RenderPicture(args.Graphics);
        }
Example #3
0
        public Render(string inputFile)
        {
            InitializeComponent();

            _mainFigures = new List<Figure<Point3D, Matrix3D>>();
            _projectionMatrix = new Matrix3D().IdentMatrix<Matrix3D>().Chain(
                new Matrix3D().MovementMatrix(0, 0, 800),
                new Matrix3D().ProjectionMatrix());
            _transformMatrix = new Matrix3D().IdentMatrix<Matrix3D>();
            _mouseXMatrix = new Matrix3D();
            _mouseYMatrix = new Matrix3D();

            var parser = new Parser(inputFile);
            InitializeParser(parser);
            Shown += (sender, args) => parser.Start();

            renderPanel.Paint += (sender, args) => RenderPicture(args.Graphics);
            InitializeMouse();
        }
Example #4
0
        private void InitializeParser(Parser parser)
        {
            parser.Add("addTetraedron", new Action<string, int, object[], int>(
                (color, width, pattern, size) =>
                AddFigure(FigureFactory3D.CreateSimplexBody(size,
                    width, ColorTranslator.FromHtml(color), ParsePattern(pattern)))));

            parser.Add("addIJK", new Action<string, int, object[], int, object[], object[]>(
                (color, width, pattern, size, point, colors) =>
                AddFigure(FigureFactory3D.CreateIjk(Simplex.ToMedian(size, ParseValue(point)),
                    width, ColorTranslator.FromHtml(color),
                    colors.Select(c => ColorTranslator.FromHtml((string)c)).ToArray(),
                    ParsePattern(pattern)))));

            parser.Add("addVector", new Action<string, int, object[], int, object[]>(
                (color, width, pattern, size, point) =>
                AddFigure(FigureFactory3D.CreateVector(Simplex.ToVector(size, ParseValue(point)),
                    width, ColorTranslator.FromHtml(color), ParsePattern(pattern)))));

            parser.Add("addPath", new Action<string, int, object[], int, object[]>(
                (color, width, pattern, size, path) => AddFigure(FigureFactory3D.CreateVector(
                    path.Select(c=>Simplex.ToPoint(size, ParseValue(c))).ToArray(),
                    width, ColorTranslator.FromHtml(color), ParsePattern(pattern)))));

            parser.Add("addPoint", new Action<string, int, string, int, object>(
                (color, width, pattern, size, point) =>
                    AddFigure(FigureFactory3D.CreatePoint(Simplex.ToPoint(size, ParseValue(point)),
                        width, ColorTranslator.FromHtml(color), (PointType) Enum.Parse(typeof(PointType), pattern)))));

            parser.Add("setViewPort", new Action<double, double>((a1, a2) =>
            {
                _mouseXMatrix.RotateMatrixX(a1 * Math.PI / 180);
                _mouseYMatrix.RotateMatrixY(a2 * Math.PI / 180);

                _transformMatrix.IdentMatrix<Matrix3D>().Chain(
                    _mouseYMatrix,
                    _mouseXMatrix);
            }));

            parser.Reloaded += (sender, args) => Invoke(new Action(() =>
            {
                if (args.Message == null)
                {
                    renderPanel.Invalidate();
                }
                else
                {
                    MessageBox.Show(args.Message);
                }
            }));
            parser.Reloading += (sender, args) => ResetData();
        }
Example #5
0
        private void InitializeParser(Parser parser)
        {
            parser.Add("addStudent", new Action<dynamic>(student =>
                _students.Add(new Student
                {
                    Name = student.n,
                    Info = student.a,
                    Grades = ((object[]) student.g)
                        .Select(a => ((object[]) a)
                            .Select(b => (float) (double) b)
                            .ToArray())
                        .ToArray()
                })));

            parser.Add("addDelimiter", new Action(() =>
                _part.Add(_students.Count)
                ));

            parser.Add("setDates", new Action<object[]>(dates =>
                _dates.AddRange(dates.Cast<string>())
                ));

            parser.Add("setViewPort", new Action<int, int, float, int>((width, height, ratio, render) =>
            {
                _width = width;
                _height = height;
                _ratio = ratio;
            }));

            parser.Add("setTitles", new Action<dynamic>(parameters =>
            {
                foreach (dynamic parameter in parameters)
                {
                    _localizations.Add(parameter.Key, parameter.Value);
                }
            }));

            parser.Add("setThresholds", new Action<object[]>(grades =>
                _grades.AddRange(grades.Select(a => (float)(double)a))
                ));

            parser.Add("setAdditionalsParam", new Action<object[]>(parameters =>
            {
                foreach (dynamic param in parameters)
                {
                    _additionalName.Add(param.t);
                    _additionalData.Add(new Pen(ColorTranslator.FromHtml(param.c), (float)param.w)
                    {
                        DashPattern = ((object[])param.p).Select(a=>(float)(double)a).ToArray()
                    });
                }
            }));

            parser.Add("setPieMode", new Action<dynamic>(colors =>
            {
                _mode = Mode.Pie;
                foreach (dynamic color in colors)
                {
                    _brushes.Add(new HatchBrush(
                        (HatchStyle)Enum.Parse(typeof(HatchStyle), color.p),
                        ColorTranslator.FromHtml(color.m), ColorTranslator.FromHtml(color.s)));
                }
            }));

            parser.Add("setColorRoundMode", new Action<object[]>(parameters =>
            {
                _mode = Mode.ColorRound;
                _modeParam.AddRange(parameters.Select(a=>(float)(double) a));
            }));

            parser.Add("setBlackRoundMode", new Action<int>(ratio =>
            {
                _mode = Mode.BlackRound;
                _hatchRatio = ratio;
            }));

            parser.Reloaded += (sender, args) => Invoke(new Action(() =>
            {
                if (args.Message == null)
                {
                    Width += _width - renderPanel.Width;
                    Height += _height - renderPanel.Height;
                    renderPanel.Invalidate();
                }
                else
                {
                    MessageBox.Show(args.Message);
                }
            }));
            parser.Reloading += (sender, args) => ResetData();
        }
Example #6
0
        private void InitializeParser(Parser parser)
        {
            parser.Add("addTetraedron", new Action<string, int, object[], int>(
                (color, width, pattern, size) =>
                AddFigure(()=>FigureFactory2D.CreateSimplexBody(
                    size, width, ColorTranslator.FromHtml(color), ParsePattern(pattern)))));

            parser.Add("addIJK", new Action<string, int, object[], int, object[], object[]>(
                (color, width, pattern, size, point, colors) =>
                    AddFigure((a, c) => FigureFactory2D.CreateIjk(Simplex.ToMedian(size, a),
                        width, ColorTranslator.FromHtml(color),
                        c,
                        ParsePattern(pattern)), ParseValue(point),
                        colors.Select(c => ColorTranslator.FromHtml((string) c)).ToArray())));

            parser.Add("addVector", new Action<string, int, object[], int, object[]>(
                (color, width, pattern, size, point) =>
                    AddFigure(a => FigureFactory2D.CreateVector(Simplex.ToVector(size, a),
                        width, ColorTranslator.FromHtml(color),
                        ParsePattern(pattern)), ParseValue(point))));

            parser.Add("addPath", new Action<string, int, object[], int, object[]>(
                (color, width, pattern, size, path) =>
                    AddFigure(a=>FigureFactory2D.CreateVector(
                        a.Select(c=>Simplex.ToPoint(size, c)).ToArray(),
                        width, ColorTranslator.FromHtml(color),
                        ParsePattern(pattern)), path.Select(ParseValue).ToArray())));

            parser.Add("addPoint", new Action<string, int, string, int, object[]>(
                (color, width, pattern, size, point) =>
                    AddFigure(a=>FigureFactory2D.CreatePoint(Simplex.ToPoint(size, a),
                        width, ColorTranslator.FromHtml(color),
                        (PointType)Enum.Parse(typeof(PointType), pattern)),ParseValue(point))));

            parser.Add("setTransform", new Action<int>(type =>
            {
                _transform.Type = type;
            }));

            parser.Add("setView", new Action<int>(RecalculateMatrix));

            parser.Reloaded += (sender, args) => Invoke(new Action(() =>
            {
                if (args.Message == null)
                {
                    foreach (var figure in _mainFigures)
                    {
                        for (var j = 0; j < _matrices.Length; ++j)
                        {
                            figure[j].SetTransform(_matrices[j]);
                        }
                    }
                    renderPanel.Invalidate();
                }
                else
                {
                    MessageBox.Show(args.Message);
                }
            }));
            parser.Reloading += (sender, args) => ResetData();
        }