/// <inheritdoc/> internal override void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints, ItemJoin incommingJoin) { if (incommingJoin.Item2 != this) { throw new NotSupportedException("Incomming join point is not valid."); } var cuttingSpeed = workspace.CuttingSpeed; var cutPoints = CutPoints.ToArray(); if (!cutPoints.First().Equals(cutPoints.Last())) { throw new NotSupportedException("Shape is not closed."); } //skip the repetitive point so we can join to whatever shape part. cutPoints = cutPoints.Take(cutPoints.Length - 1).ToArray(); var outJoins = workspace.FindOutgoingJoins(this); var startIndex = incommingJoin.JoinPointIndex2; for (var i = startIndex + 1; i <= startIndex + cutPoints.Length; ++i) { var currentIndex = i % cutPoints.Length; var currentPoint = cutPoints[currentIndex]; speedPoints.Add(currentPoint.With(cuttingSpeed)); var currentOutgoingJoins = workspace.GetOutgoingJoinsFrom(currentIndex, outJoins); foreach (var currentOutgoingJoin in currentOutgoingJoins) { currentOutgoingJoin.Build(workspace, speedPoints); } } }
/// <inheritdoc/> internal override void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints, ItemJoin incommingJoin) { if (incommingJoin.Item1 != workspace.EntryPoint) { throw new NotSupportedException("Native controll item can be run only from entry point."); } var outJoins = workspace.FindOutgoingJoins(this); if (outJoins.Any()) { throw new NotSupportedException("Native controll item cannot have outgoing joins."); } var cutPoints = CutPoints.ToArray(); var speeds = SegmentSpeeds.ToArray(); if (cutPoints.Length != speeds.Length + 1) { throw new NotSupportedException("Invalid point/speed matching."); } for (var i = 1; i < cutPoints.Length; ++i) { speedPoints.Add(cutPoints[i].With(speeds[i - 1])); } }
private void getSpeedVectors(WorkspacePanel workspace, Point4Dmm t1, Point4Dmm t2, out Vector speedVector12UVt, out Vector speedVector12XYt) { var maxSpeed = workspace.CuttingSpeed; var maxSpeedRatio = (maxSpeed.StepCount * Constants.MilimetersPerStep) / (1.0 * maxSpeed.Ticks / Constants.TimerFrequency); //tower speeds speedVector12UVt = diffVector(t1.ToUV(), t2.ToUV()); speedVector12XYt = diffVector(t1.ToXY(), t2.ToXY()); if (speedVector12UVt.Length > speedVector12XYt.Length) { var speedRatio = speedVector12XYt.Length / speedVector12UVt.Length; speedVector12UVt.Normalize(); speedVector12XYt.Normalize(); speedVector12UVt = speedVector12UVt * maxSpeedRatio; speedVector12XYt = speedVector12XYt * speedRatio; } else { var speedRatio = speedVector12UVt.Length / speedVector12XYt.Length; speedVector12UVt.Normalize(); speedVector12XYt.Normalize(); speedVector12UVt = speedVector12UVt * maxSpeedRatio; speedVector12XYt = speedVector12XYt * speedRatio; } }
protected Point4Dmm[] applyKerf(IEnumerable <Point4Dmm> points, WorkspacePanel workspace) { /* var pointsUV = points.ToUV(); * * var offsetCalculator = new OffsetCalculator(pointsUV.Reverse()); * var offsetPoints = offsetCalculator.WithOffset(workspace.CuttingKerf / 2).First(); * * return offsetPoints.DuplicateTo4Dmm().ToArray(); * * throw new NotImplementedException();*/ var pointsArr = points.ToArray(); var result = new List <Point4Dmm>(); for (var i = 0; i < pointsArr.Length; ++i) { var prevPoint = getNextDifferent(pointsArr, i, -1); var point = pointsArr[i]; var nextPoint = getNextDifferent(pointsArr, i, 1); result.Add(applyKerf(prevPoint, point, nextPoint, workspace)); } return(result.ToArray()); }
internal HeadCNC(Color headColor, WorkspacePanel parent) { var brush = new SolidColorBrush(headColor); brush.Opacity = 0.8; _headPen = new Pen(brush, 4.0); _parent = parent; Position = new Point2Dmm(0, 0); }
/// <inheritdoc/> internal override void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints, ItemJoin incommingJoin) { if (incommingJoin != null) { throw new NotSupportedException("Incomming join point has to be empty for entry point."); } foreach (var join in workspace.FindOutgoingJoins(this)) { join.Build(workspace, speedPoints); } }
private double reCalculateKerf(double referentialKerf, double metricSpeed, WorkspacePanel workspace) { referentialKerf = reCalculateKerf(referentialKerf); var referentialSpeed = workspace.CuttingSpeed; var metricReferentialSpeed = Constants.MilimetersPerStep * referentialSpeed.StepCount / (1.0 * referentialSpeed.Ticks / Constants.TimerFrequency); var referenceFactor = metricReferentialSpeed / metricSpeed; var wireKerf = Math.Min(Constants.HotwireThickness / 2, Math.Abs(referentialKerf)); var radiationKerf = Math.Abs(referentialKerf) - wireKerf; var adjustedKerf = radiationKerf * referenceFactor + wireKerf; return(Math.Sign(referentialKerf) * adjustedKerf); }
private void getShapeSpeedVectors(WorkspacePanel workspace, Point4Dmm p1, Point4Dmm p2, out Vector speedVector12UV, out Vector speedVector12XY) { var wireLength = workspace.WireLength; var t1 = projectToTowers(p1, wireLength); var t2 = projectToTowers(p2, wireLength); //tower speeds getSpeedVectors(workspace, t1, t2, out Vector speedVector12UVt, out Vector speedVector12XYt); var facetDistance = wireLength / 2 - MetricThickness / 2; var facetRatio = 1.0 - facetDistance / wireLength; speedVector12UV = speedVector12UVt * facetRatio + speedVector12XYt * (1.0 - facetRatio); speedVector12XY = speedVector12XYt * facetRatio + speedVector12UVt * (1.0 - facetRatio); }
protected Point4Dmm[] applyKerf(IEnumerable <Point4Dmm> points, WorkspacePanel workspace) { var pointsArr = points.ToArray(); var result = new List <Point4Dmm>(); for (var i = 0; i < pointsArr.Length; ++i) { var prevPoint = getNextDifferent(pointsArr, i, -1); var point = pointsArr[i]; var nextPoint = getNextDifferent(pointsArr, i, 1); result.Add(applyKerf(prevPoint, point, nextPoint, workspace)); } return(result.ToArray()); }
/// <summary> /// Builds path to <see cref="Item2"/> and the item recursively. Assumes it starts from <see cref="Item1"/> outgoing point. /// Path ends at the same point it started. /// </summary> internal void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints) { var outgoingPoint = Item1.CutPoints.Skip(JoinPointIndex1).First(); var incommingPoint = Item2.CutPoints.Skip(JoinPointIndex2).First(); var cuttingSpeed = workspace.CuttingSpeed; speedPoints.Add(incommingPoint.With(cuttingSpeed)); Item2.Build(workspace, speedPoints, this); if (Item2 is NativeControlItem) { // Native controls are handled in special way. return; } speedPoints.Add(outgoingPoint.With(cuttingSpeed)); }
/// <inheritdoc/> protected override Point4Dmm applyKerf(Point4Dmm p1, Point4Dmm p2, Point4Dmm p3, WorkspacePanel workspace) { // Native item does not follow kerf settup. return(p2); }
/// <inheritdoc/> internal override void RecalculateToWorkspace(WorkspacePanel workspace, Size size) { base.RecalculateToWorkspace(workspace, size); _wireLength = workspace.WireLength; }
/// <inheritdoc/> internal override void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints, ItemJoin incommingJoin) { //there is nothing to build }
/// <summary> /// Builds cutting plan for the item and all joined items recursively. /// Build assumes we are at item join point. Closed shapes has to return back to that point. /// </summary> /// <param name="workspace">Workspace where joins are defined.</param> /// <param name="speedPoints">Output of the build.</param> /// <param name="incommingJoin">Join which was used to get into the item.</param> internal abstract void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints, ItemJoin incommingJoin);
/// <inheritdoc/> internal override void RecalculateToWorkspace(WorkspacePanel workspace, Size size) { _stepToVisualFactorC1 = size.Width / workspace.StepCountX; _stepToVisualFactorC2 = size.Height / workspace.StepCountY; }
protected override Point4Dmm applyKerf(Point4Dmm p1, Point4Dmm p2, Point4Dmm p3, WorkspacePanel workspace) { var kerf = reCalculateKerf(workspace.CuttingKerf); var shift = calculateKerfShift(p1.ToUV(), p2.ToUV(), p3.ToUV(), kerf); return(new Point4Dmm(p2.U + shift.X, p2.V + shift.Y, p2.X + shift.X, p2.Y + shift.Y)); }
internal virtual void RecalculateToWorkspace(WorkspacePanel workspace, Size size) { //nothing to do by default }
/// <inheritdoc/> internal override void Build(WorkspacePanel workspace, List <Speed4Dstep> speedPoints, ItemJoin incommingJoin) { if (_speedAlgorithm == SpeedAlgorithm.TowerBased || !UseExplicitKerf) { base.Build(workspace, speedPoints, incommingJoin); return; } if (incommingJoin.Item2 != this) { throw new NotSupportedException("Incomming join point is not valid."); } var cuttingSpeed = workspace.CuttingSpeed; var cutPoints = CutPoints.ToArray(); if (!cutPoints.First().Equals(cutPoints.Last())) { throw new NotSupportedException("Shape is not closed."); } var definitionPoints = CutDefinition.ToArray(); if (cutPoints.Count() != definitionPoints.Count()) { throw new NotSupportedException("Invalid cut points count."); } //skip the repetitive point so we can join to whatever shape part. cutPoints = cutPoints.Take(cutPoints.Length - 1).ToArray(); definitionPoints.Take(definitionPoints.Length - 1).ToArray(); var projector = new PlaneProjector(_shapeMetricThickness, _wireLength); var outJoins = workspace.FindOutgoingJoins(this); var startIndex = incommingJoin.JoinPointIndex2; for (var i = startIndex + 1; i <= startIndex + cutPoints.Length; ++i) { var currentIndex = i % cutPoints.Length; var currentPoint = cutPoints[currentIndex]; var speeds = getSpeeds(definitionPoints, currentIndex, cuttingSpeed, projector); //System.Diagnostics.Debug.Print(speeds.ToString()); var speed1Limit = speeds.Item1.ToDeltaT() >= Constants.StartDeltaT || speeds.Item1.ToDeltaT() < 0; var speed2Limit = speeds.Item2.ToDeltaT() >= Constants.StartDeltaT || speeds.Item2.ToDeltaT() < 0; if (!speed1Limit || !speed2Limit) { throw new PlanningException("Speed limit exceeded"); } speedPoints.Add(currentPoint.With(speeds.Item1, speeds.Item2)); var currentOutgoingJoins = workspace.GetOutgoingJoinsFrom(currentIndex, outJoins); foreach (var currentOutgoingJoin in currentOutgoingJoins) { currentOutgoingJoin.Build(workspace, speedPoints); } } }
/// <inheritdoc/> protected override Point4Dmm applyKerf(Point4Dmm p1, Point4Dmm p2, Point4Dmm p3, WorkspacePanel workspace) { double kerfUV, kerfXY; if (UseExplicitKerf) { kerfUV = reCalculateKerf(KerfUV); kerfXY = reCalculateKerf(KerfXY); } else { getShapeSpeedVectors(workspace, p1, p2, out Vector speedVector12UV, out Vector speedVector12XY); getShapeSpeedVectors(workspace, p2, p3, out Vector speedVector23UV, out Vector speedVector23XY); var speedUV = (speedVector12UV.Length + speedVector23UV.Length) / 2; var speedXY = (speedVector12XY.Length + speedVector23XY.Length) / 2; var referentialKerf = workspace.CuttingKerf; kerfUV = reCalculateKerf(referentialKerf, speedUV, workspace); kerfXY = reCalculateKerf(referentialKerf, speedXY, workspace); } var shiftUV = calculateKerfShift(p1.ToUV(), p2.ToUV(), p3.ToUV(), kerfUV); var shiftXY = calculateKerfShift(p1.ToXY(), p2.ToXY(), p3.ToXY(), kerfXY); return(new Point4Dmm(p2.U + shiftUV.X, p2.V + shiftUV.Y, p2.X + shiftXY.X, p2.Y + shiftXY.Y)); }
/// <summary> /// Calculates kerf on the p2 point. /// </summary> /// <param name="p1">Preceding point.</param> /// <param name="p2">Kerfed point.</param> /// <param name="p3">Following point.</param> /// <param name="workspace">Workspace defining the kerf.</param> /// <returns></returns> protected abstract Point4Dmm applyKerf(Point4Dmm p1, Point4Dmm p2, Point4Dmm p3, WorkspacePanel workspace);