private void MachineFrameChanged(object sender, FrameChangedEventArgs e) { if (!e.Frame.Coordinate.NotEmpty()) { return; } var gModalGroup1 = _machineSimulator.ModalGCodes.Single(c => GCodeExpression.MutuallyExclusiveCodes[0].Contains(c)); if (_machineSimulator.OldCoordinates.X != null && _machineSimulator.OldCoordinates.Y != null && _machineSimulator.OldCoordinates.Z != null) { var oldCoordinates = new Point3D(_machineSimulator.OldCoordinates.X.Value, _machineSimulator.OldCoordinates.Y.Value, _machineSimulator.OldCoordinates.Z.Value); var centers = new ArcCenters { I = e.Frame.IValue, J = e.Frame.JValue, K = e.Frame.KValue }; bool absolute = !_machineSimulator.ModalGCodes.Contains(91); var newCoordinates = new Point3D(CalculateNewCoordinate(_machineSimulator.CurrentCoordinates.X, oldCoordinates.X, absolute), CalculateNewCoordinate(_machineSimulator.CurrentCoordinates.Y, oldCoordinates.Y, absolute), CalculateNewCoordinate(_machineSimulator.CurrentCoordinates.Z, oldCoordinates.Z, absolute)); var radius = e.Frame.RValue; ScaleCoordinates(10, ref oldCoordinates, ref newCoordinates, ref centers, ref radius); Draw(gModalGroup1, oldCoordinates, newCoordinates, radius, centers, e); } }
private void Draw(float gModalGroup1, Point3D oldCoordinates, Point3D newCoordinates, float?radius, ArcCenters centers, FrameChangedEventArgs e) { ArcInterpolation interpolation; switch (gModalGroup1) { case 0: //Rapid AddLine(oldCoordinates.ToVector3(), newCoordinates.ToVector3(), RapidGeometry); break; case 1: //Linear AddLine(oldCoordinates.ToVector3(), newCoordinates.ToVector3(), LinearGeometry); break; case 2: //Arc clockwise interpolation = e.Frame.RValue.HasValue ? new ArcInterpolation(oldCoordinates, radius: radius.Value, newCoordinates, true) : new ArcInterpolation(oldCoordinates, centers, newCoordinates, true); for (int i = 0; i <= 100; i += 5) { var point = interpolation.GetArcCoordinatesEx(i); AddLine(oldCoordinates.ToVector3(), point.ToVector3(), LinearGeometry); oldCoordinates = point; } AddLine(oldCoordinates.ToVector3(), newCoordinates.ToVector3(), LinearGeometry); break; case 3: //Arc Counter-clockwise if (e.Frame.RValue.HasValue) { interpolation = new ArcInterpolation(oldCoordinates, radius: radius.Value, newCoordinates, false); } else { interpolation = new ArcInterpolation(oldCoordinates, centers, newCoordinates, false); } for (int i = 100; i >= 0; i -= 5) { var point = interpolation.GetArcCoordinatesEx(i); AddLine(oldCoordinates.ToVector3(), point.ToVector3(), LinearGeometry); oldCoordinates = point; } AddLine(oldCoordinates.ToVector3(), newCoordinates.ToVector3(), LinearGeometry); break; } }
private void ScaleCoordinates(int scale, ref Point3D oldCoordinates, ref Point3D newCoordinates, ref ArcCenters centers, ref float?radius) { oldCoordinates.X /= scale; oldCoordinates.Y /= scale; oldCoordinates.Z /= scale; newCoordinates.X /= scale; newCoordinates.Y /= scale; newCoordinates.Z /= scale; centers.I /= scale; centers.J /= scale; centers.K /= scale; radius /= scale; }