예제 #1
0
        /// <summary>
        /// Seconds until the next tool change while printing.
        /// </summary>
        /// <returns>The time tool index we are switching to and the time until it will switch.</returns>
        private (int toolIndex, double time) NextToolChange(int toolToLookFor = -1)
        {
            if (gCodeMemoryFile != null)
            {
                var timeToTool = gCodeMemoryFile.NextToolChange(gcodeLineReader.LineIndex, -1, toolToLookFor);
                return(timeToTool);
            }

            return(-1, 0);
        }
예제 #2
0
        private void LayerFeaturesScrollbar_SecondValueChanged(object sender, EventArgs e)
        {
            var renderInfo      = sceneContext.RenderInfo;
            int layerIndex      = renderInfo.EndLayerIndex - 1;
            int featuresOnLayer = sceneContext.GCodeRenderer.GetNumFeatures(layerIndex);
            int featureIndex    = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5);

            int activeFeatureIndex = Math.Max(0, Math.Min(featureIndex, featuresOnLayer - 1) - 1);

            if (sceneContext.GCodeRenderer[layerIndex, activeFeatureIndex] is RenderFeatureTravel line)
            {
                if (rawLine != null)
                {
                    rawLine.Text = gCodeMemoryFile.Instruction(line.InstructionIndex).Line;
                }

                var start = line.Start;
                var end   = line.End;

                startPointWidget.Text = $"{start}";
                endPointWidget.Text   = $"{end}";

                var length = new Vector2(start).Distance(new Vector2(end));
                lengthWidget.Text = $"{length:0.###}";

                // Slope
                // m = (y_2 - y_1) / (x_2 - x_1)

                // Y-Intercept
                // n = -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1

                var slope = (end.Y - start.Y) / (end.X - start.X);
                if (slopeWidget != null)
                {
                    slopeWidget.Text = $"{slope:0.###}";
                }

                if (yInterceptWidget != null)
                {
                    // -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1
                    var yIntercept = -start.X * slope + start.Y;
                    yInterceptWidget.Text = $"{yIntercept:0.###}";
                }

                if (xInterceptWidget != null)
                {
                    // x_1 - y_1*(x_2-x_1)/(y_2-y_1)
                    var xIntercept = start.X - start.Y * (end.X - start.X) / (end.Y - start.Y);
                    xInterceptWidget.Text = $"{xIntercept:0.###}";
                }

                // put in the time until the next tool change
                if (timeToToolChange != null)
                {
                    var toolChange = gCodeMemoryFile.NextToolChange(line.InstructionIndex);
                    if (toolChange.time < double.PositiveInfinity)
                    {
                        timeToToolChange.Text = $"T{toolChange.toolIndex} : {toolChange.time:0.00}s";
                    }
                    else
                    {
                        timeToToolChange.Text = $"No More Changes";
                    }
                }
            }
        }