コード例 #1
0
        private static string InstructionTime(this GCodeFile loadedGCode, int startLayer, int endLayer)
        {
            if (loadedGCode == null || loadedGCode.LayerCount == 0)
            {
                return("---");
            }

            int startInstruction      = loadedGCode.GetFirstLayerInstruction(startLayer);
            int endInstruction        = loadedGCode.GetFirstLayerInstruction(endLayer);
            var secondsToEndFromStart = loadedGCode.Instruction(startInstruction).SecondsToEndFromHere;
            var secondsToEndFromEnd   = loadedGCode.Instruction(endInstruction).SecondsToEndFromHere;

            return(SecondsToTime(secondsToEndFromStart - secondsToEndFromEnd));
        }
コード例 #2
0
        public static List <List <Vector2> > GetExtrusionsForLayer(this GCodeFile gcode, int layerIndex)
        {
            var extrusions = new List <List <Vector2> >();

            bool           addingExtrudePath  = false;
            List <Vector2> currentExtrudePath = null;

            int startRenderIndex = gcode.GetFirstLayerInstruction(layerIndex);
            int endRenderIndex   = gcode.LineCount - 1;

            if (layerIndex < gcode.LayerCount - 1)
            {
                endRenderIndex = gcode.GetFirstLayerInstruction(layerIndex + 1);
            }

            for (int instructionIndex = startRenderIndex; instructionIndex < endRenderIndex; instructionIndex++)
            {
                PrinterMachineInstruction currentInstruction  = gcode.Instruction(instructionIndex);
                PrinterMachineInstruction previousInstruction = currentInstruction;
                if (instructionIndex > 0)
                {
                    previousInstruction = gcode.Instruction(instructionIndex - 1);
                }

                if (currentInstruction.Position != previousInstruction.Position)
                {
                    if (gcode.IsExtruding(instructionIndex))
                    {
                        if (!addingExtrudePath)
                        {
                            currentExtrudePath = new List <Vector2>();
                            extrusions.Add(currentExtrudePath);
                            addingExtrudePath = true;
                        }

                        currentExtrudePath.Add(new Vector2(currentInstruction.Position.X, currentInstruction.Position.Y));
                    }
                    else
                    {
                        addingExtrudePath = false;
                    }
                }
            }

            return(extrusions);
        }
コード例 #3
0
        public static string GetLayerFanSpeeds(this GCodeFile loadedGCode, int activeLayerIndex)
        {
            if (loadedGCode == null || loadedGCode.LayerCount == 0)
            {
                return("---");
            }

            int startInstruction = loadedGCode.GetFirstLayerInstruction(activeLayerIndex);

            if (activeLayerIndex == 0)
            {
                startInstruction = 0;
            }

            int endInstruction = loadedGCode.GetFirstLayerInstruction(activeLayerIndex + 1);

            string separator = "";
            string fanSpeeds = "";

            for (int i = startInstruction; i < endInstruction; i++)
            {
                var line = loadedGCode.Instruction(i).Line;
                if (line.StartsWith("M107"))                 // fan off
                {
                    fanSpeeds += separator + "Off";
                    separator  = ", ";
                }
                else if (line.StartsWith("M106"))                 // fan on
                {
                    double speed = 0;
                    if (GCodeFile.GetFirstNumberAfter("M106", line, ref speed, 0, ""))
                    {
                        fanSpeeds += separator + $"{speed / 255 * 100:0}%";
                        separator  = ", ";
                    }
                }
            }

            return(fanSpeeds);
        }