private List <Point> GetTrianglePoints()
        {
            Int32            sideA            = (Int32)SideALength.Value;
            Int32            sideB            = (Int32)SideBLength.Value;
            Int32            sideC            = (Int32)SideCLength.Value;
            Double           interval         = (Double)Interval.Value;
            DrawingDirection drawingDirection = GetDrawingDirection();

            if (!Triangle.IsExist(sideA, sideB, sideC))
            {
                MessageBox.Show(
                    text: @"A triangle with such sides does not exist.",
                    caption: @"Error"
                    );

                return(null);
            }

            var triangleCoordinateCalculator = new TriangleCoordinateCalculator();
            var triangle = triangleCoordinateCalculator.Calculate(sideA, sideB, sideC, PictureBox.Width, PictureBox.Height);

            var pointsBuilder = new PointsBuilder();
            var points        = pointsBuilder.Build(triangle.ToPolygon(), interval, drawingDirection);

            return(points);
        }
        private void LoadConfigButton_Click(object sender, EventArgs e)
        {
            if (LoadFile.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            var lines = File.ReadAllLines(LoadFile.FileName);

            var parser = new FileParser();

            Scene scene;

            try
            {
                scene = parser.Parse(lines);
            }
            catch
            {
                MessageBox.Show(@"Could not parse file", @"Error");
                return;
            }

            var pointsBuilder = new PointsBuilder();

            var svg = new SvgDocument
            {
                Height = scene.Height,
                Width  = scene.Width
            };

            foreach (var figure in scene.Figures)
            {
                var polyline = new SvgPolyline
                {
                    Points      = new SvgPointCollection(),
                    Fill        = new SvgColourServer(Color.Transparent),
                    Stroke      = new SvgColourServer(figure.LineColor),
                    StrokeWidth = new SvgUnit((float)figure.LineThickness)
                };

                var points = pointsBuilder.Build(figure.Polygon, figure.LineSpacing, figure.DrawingDirection);

                foreach (var point in points)
                {
                    polyline.Points.Add(new SvgUnit(SvgUnitType.Point, (float)point.X));
                    polyline.Points.Add(new SvgUnit(SvgUnitType.Point, (float)point.Y));
                }

                svg.Children.Add(polyline);
            }

            var svgPath = LoadFile.FileName.Substring(0, LoadFile.FileName.Length - 4) + "_image.svg";

            svg.Write(svgPath);
            MessageBox.Show(
                text: svgPath,
                caption: @"Success");
        }
Example #3
0
        private void DrawButton_Click(Object sender, EventArgs e)
        {
            Int32            sideA            = (Int32)SideALength.Value;
            Int32            sideB            = (Int32)SideBLength.Value;
            Int32            sideC            = (Int32)SideCLength.Value;
            Double           interval         = (Double)Interval.Value;
            DrawingDirection drawingDirection = GetDrawingDirection();

            if (!Triangle.IsExist(sideA, sideB, sideC))
            {
                MessageBox.Show(
                    text: @"A triangle with such sides does not exist.",
                    caption: @"Error"
                    );

                return;
            }

            var triangleCoordinateCalculator = new TriangleCoordinateCalculator();
            var triangle = triangleCoordinateCalculator.Calculate(sideA, sideB, sideC, PictureBox.Width, PictureBox.Height);

            var pointsBuilder = new PointsBuilder();
            var points        = pointsBuilder.Build(triangle.ToPolygon(), interval, drawingDirection);

            using (var graphic = PictureBox.CreateGraphics())
            {
                graphic.Clear(Color.White);

                Pen pen = new Pen(Color.Blue, 1.0f);

                graphic.DrawLines(
                    pen,
                    points.Select(p => new PointF((float)p.X, (float)p.Y)).ToArray()
                    );
            }
        }