private void canvas_Paint(object sender, PaintEventArgs e) { var g = e.Graphics; // Draw working area bounding box var leftTop = vp.project(new Point(0, 0)); var rect_size = 32767 * vp.projection_scale; g.DrawRectangle(new Pen(Color.Black), leftTop.X, leftTop.Y, rect_size, rect_size); // Draw symbol itself symbol.paint(ref g, ref vp, polygonOutlineToolStripMenuItem.Checked); if (_edit_mode == Edit_mode.EDIT_SYMBOL) { // Draw symbol pivot point var origin = vp.project(new Point(symbol.pivot_x, symbol.pivot_y)); g.DrawLine(new Pen(Color.Black, 3), origin.X, origin.Y - 5, origin.X, origin.Y + 5); g.DrawLine(new Pen(Color.Black, 3), origin.X - 5, origin.Y, origin.X + 5, origin.Y); g.DrawLine(new Pen(Color.Yellow), origin.X, origin.Y - 5, origin.X, origin.Y + 5); g.DrawLine(new Pen(Color.Yellow), origin.X - 5, origin.Y, origin.X + 5, origin.Y); } // If geometry selected - its points and rotate origin else { if (selected_geometry_idx != -1) { if (selected_point_idx != -1) { var p = symbol.geometry[selected_geometry_idx].points[selected_point_idx]; p = vp.project(p); g.DrawRectangle(new Pen(Color.Yellow), p.X - 5, p.Y - 5, 10, 10); } // Draw rotate origin var origin = new Point((int)rot_origin_x.Value, (int)rot_origin_y.Value); origin = vp.project(origin); g.DrawLine(new Pen(Color.Black, 3), origin.X, origin.Y - 5, origin.X, origin.Y + 5); g.DrawLine(new Pen(Color.Black, 3), origin.X - 5, origin.Y, origin.X + 5, origin.Y); g.DrawLine(new Pen(Color.Yellow), origin.X, origin.Y - 5, origin.X, origin.Y + 5); g.DrawLine(new Pen(Color.Yellow), origin.X - 5, origin.Y, origin.X + 5, origin.Y); } } }
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; } } }