Exemple #1
0
        public void paint(ref System.Drawing.Graphics canvas, ref ViewPort vp, bool polygonOutline = false)
        {
            int   point_r  = 5; // Point radius
            Point p        = new Point();
            int   n_points = 0;

            float line_width_k = (100 / (canvas.DpiX / 25.4f)) * vp.projection_scale; // Line width coefficient. (S52 docs says :"The coordinates are within the range of 0 to 32767 units. Each unit represents 0.01 mm")

            foreach (var geom in geometry)
            {
                int transparency = (4 - geom.transparency) * 64;
                transparency = Math.Min(transparency, 255);
                transparency = Math.Max(0, transparency);

                var color = Color.FromArgb(transparency, Style.S52colors[geom.color]);
                Pen pen   = new Pen(color, geom.penWidth * line_width_k);



                switch (geom.type)
                {
                case GeometryType.LINE:
                    if (geom.points.Count() < 2)
                    {
                        continue;
                    }

                    n_points = geom.points.Count();

                    var projPnts = new Point[n_points];

                    for (int i = 0; i < n_points; i++)
                    {
                        projPnts[i] = vp.project(geom.points[i]);
                    }


                    canvas.DrawLines(pen, projPnts);


                    break;

                case GeometryType.CIRCLE:
                    var circle = geom as HCircle;
                    p = vp.project(circle.points[0]);
                    var radius = circle.radius * vp.projection_scale;
                    if (circle.filled)
                    {
                        canvas.FillEllipse(new SolidBrush(color), p.X - radius, p.Y - radius, radius * 2, radius * 2);
                    }
                    else
                    {
                        canvas.DrawEllipse(pen, p.X - radius, p.Y - radius, radius * 2, radius * 2);
                    }

                    break;

                case GeometryType.POINT:

                    p = vp.project(geom.points[0]);
                    int size = (int)(geom.penWidth * line_width_k);
                    canvas.FillRectangle(new SolidBrush(color), p.X - size / 2, p.Y - size / 2, size, size);

                    break;

                case GeometryType.POLYGON:

                    if (geom.points.Count() < 2)
                    {
                        continue;
                    }

                    n_points = geom.points.Count();
                    projPnts = new Point[n_points];

                    for (int i = 0; i < n_points; i++)
                    {
                        projPnts[i] = vp.project(geom.points[i]);
                    }

                    canvas.FillPolygon(new SolidBrush(color), projPnts);
                    if (polygonOutline)
                    {
                        canvas.DrawPolygon(pen, projPnts);
                    }

                    break;
                }
            }

            foreach (var geom in geometry)
            {
                if (!geom.selected)
                {
                    continue;
                }

                switch (geom.type)
                {
                case GeometryType.LINE:

                    n_points = geom.points.Count();

                    var projPnts = new Point[n_points];

                    for (int i = 0; i < n_points; i++)
                    {
                        projPnts[i] = vp.project(geom.points[i]);
                    }

                    if (n_points > 1)
                    {
                        canvas.DrawLines(new Pen(Color.Red), projPnts);
                    }


                    for (int i = 0; i < n_points; i++)
                    {
                        canvas.DrawEllipse(new Pen(Color.Red), projPnts[i].X - point_r, projPnts[i].Y - point_r, point_r * 2, point_r * 2);
                    }

                    break;

                case GeometryType.CIRCLE:
                    var circle = geom as HCircle;
                    p = vp.project(circle.points[0]);
                    var radius = circle.radius * vp.projection_scale;

                    canvas.DrawEllipse(new Pen(Color.Red), p.X - radius, p.Y - radius, radius * 2, radius * 2);
                    canvas.DrawEllipse(new Pen(Color.Red), p.X - point_r, p.Y - point_r, point_r * 2, point_r * 2);

                    break;

                case GeometryType.POINT:

                    p = vp.project(geom.points[0]);
                    canvas.DrawEllipse(new Pen(Color.Red), p.X - point_r, p.Y - point_r, point_r * 2, point_r * 2);

                    break;

                case GeometryType.POLYGON:
                    n_points = geom.points.Count();

                    projPnts = new Point[n_points];

                    for (int i = 0; i < n_points; i++)
                    {
                        projPnts[i] = vp.project(geom.points[i]);
                    }

                    if (n_points > 1)
                    {
                        canvas.DrawLines(new Pen(Color.Red), projPnts);
                    }


                    for (int i = 0; i < n_points; i++)
                    {
                        canvas.DrawEllipse(new Pen(Color.Red), projPnts[i].X - point_r, projPnts[i].Y - point_r, point_r * 2, point_r * 2);
                    }

                    break;
                }
            }
        }