public DrawingSurface() { InitializeComponent(); worldTransform = new WorldTransform(); CurrentTool = new NullTool(); // attach to the run control service if this is runtime if (LicenseManager.UsageMode == LicenseUsageMode.Runtime) { Services.RunControlService.DrawCycle += RunControlService_DrawCycle; } }
public void Render(IGraphics g, WorldTransform wt) { if (avoidanceDetails == null) return; if (drawBoundPoints) { PointF vehicleLoc = Utility.ToPointF(Services.VehicleStateService.Location); g.GoToVehicleCoordinates(vehicleLoc, (float)Services.VehicleStateService.Heading + (float)Math.PI/2.0f); for (int i = 0; i < avoidanceDetails.smoothingDetails.leftBounds.Length; i++) { BoundInformation b = avoidanceDetails.smoothingDetails.leftBounds[i]; DrawingUtility.DrawControlPoint(g, b.point, Color.Blue, null, ContentAlignment.MiddleRight, ControlPointStyle.LargeX, wt); } for (int i = 0; i < avoidanceDetails.smoothingDetails.rightBounds.Length; i++) { BoundInformation b = avoidanceDetails.smoothingDetails.rightBounds[i]; DrawingUtility.DrawControlPoint(g, b.point, Color.Red, null, ContentAlignment.MiddleRight, ControlPointStyle.LargeX, wt); } g.ComeBackFromVehicleCoordinates(); } }
public void Render(IGraphics g, WorldTransform wt) { Coordinates wll = wt.WorldLowerLeft; Coordinates wur = wt.WorldUpperRight; PointF ll = new PointF((float)wll.X, (float)wll.Y); PointF ur = new PointF((float)wur.X, (float)wur.Y); float startX = (float)Math.Floor(wll.X / spacing) * spacing; float endX = (float)Math.Ceiling(wur.X / spacing) * spacing; float startY = (float)Math.Floor(wll.Y / spacing) * spacing; float endY = (float)Math.Ceiling(wur.Y / spacing) * spacing; IPen p = g.CreatePen(); p.Color = color; p.Width = nominal_pixel_width/wt.Scale; string formatString; if (spacing >= 1) { formatString = "F0"; } else if (spacing >= 0.1) { formatString = "F1"; } else if (spacing >= 0.01) { formatString = "F2"; } else { formatString = "F4"; } // find the largest value (in magnitude) that we'll need to draw, assuming this will be the max length string float testVal = Math.Max(Math.Max(Math.Abs(startX), Math.Abs(endX)), Math.Max(Math.Abs(startY), Math.Abs(endY))); string testString = testVal.ToString(formatString); SizeF nomStringSize = g.MeasureString(testString, labelFont); SizeF unitStringSize = g.MeasureString(testString + " m", labelFont); float pixelSpacing = spacing * wt.Scale; bool drawLabels = showLabels && pixelSpacing >= (nomStringSize.Width + nominal_label_spacing*2); bool drawUnits = pixelSpacing >= (unitStringSize.Width + nominal_label_spacing*2); float labelSpacing = nominal_label_spacing/wt.Scale; // don't draw if there are too many lines if ((endX - startX) / spacing <= max_lines && (endY - startY) / spacing <= max_lines && pixelSpacing >= min_pixel_spacing) { for (float x = startX; x <= endX; x += spacing) { g.DrawLine(p, new PointF(x, ll.Y), new PointF(x, ur.Y)); } for (float y = startY; y <= endY; y += spacing) { g.DrawLine(p, new PointF(ll.X, y), new PointF(ur.X, y)); } if (drawLabels) { float minX = ll.X + unitStringSize.Width/wt.Scale + 2*labelSpacing; for (float x = startX; x <= endX; x += spacing) { if (x > minX) { g.DrawString(x.ToString(formatString) + (drawUnits ? " m" : ""), labelFont, Color.Black, new PointF(x + labelSpacing, ll.Y + labelSpacing + nomStringSize.Height/wt.Scale)); } } for (float y = startY; y <= endY; y += spacing) { g.DrawString(y.ToString(formatString) + (drawUnits ? " m" : ""), labelFont, Color.Black, new PointF(ll.X + labelSpacing, y + labelSpacing)); } } } }
public WorldTransform Clone() { WorldTransform wt = new WorldTransform(scale, centerPoint, screenSize); wt.centerScreen = centerScreen; return wt; }