コード例 #1
0
        public void SwitchTo(string gcodeFilename)
        {
            if (GCodeFile is GCodeMemoryFile)
            {
                Task.Run(() =>
                {
                    var settings        = this.printer.Settings;
                    var maxAcceleration = settings.GetValue <double>(SettingsKey.max_acceleration);
                    var maxVelocity     = settings.GetValue <double>(SettingsKey.max_velocity);
                    var jerkVelocity    = settings.GetValue <double>(SettingsKey.jerk_velocity);
                    var multiplier      = settings.GetValue <double>(SettingsKey.print_time_estimate_multiplier) / 100.0;

                    var switchToGCode = GCodeFile.Load(new StreamReader(gcodeFilename).BaseStream,
                                                       new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration),
                                                       new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity),
                                                       new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity),
                                                       new Vector4(multiplier, multiplier, multiplier, multiplier),
                                                       CancellationToken.None);

                    if (switchToGCode is GCodeMemoryFile memoryFile)
                    {
                        this.switchToGCode = memoryFile;
                    }
                });
            }
        }
コード例 #2
0
        public GCodeDebugView(PrinterTabPage printerTabPage, GCodeFile gCodeFile, ISceneContext sceneContext, ThemeConfig theme)
            : base(theme)
        {
            this.gCodeFile      = gCodeFile;
            this.printerTabPage = printerTabPage;
            this.sceneContext   = sceneContext;

            gCodeMemoryFile = gCodeFile as GCodeMemoryFile;
            if (gCodeMemoryFile != null)
            {
                rawLine = this.AddSetting("G-Code Line".Localize(), "");
            }

            startPointWidget = this.AddSetting("Start".Localize(), "");
            endPointWidget   = this.AddSetting("End".Localize(), "");
            lengthWidget     = this.AddSetting("Length".Localize(), "");
            //slopeWidget = this.AddSetting("Slope".Localize(), "");
            //yInterceptWidget = this.AddSetting("Y Intercept".Localize(), "");
            //xInterceptWidget = this.AddSetting("X Intercept".Localize(), "");
            if (gCodeMemoryFile != null)
            {
                timeToToolChange = this.AddSetting("Time to Tool Change".Localize(), "");
            }

            // Register listeners
            printerTabPage.LayerFeaturesScrollbar.SecondValueChanged += this.LayerFeaturesScrollbar_SecondValueChanged;
        }
コード例 #3
0
        public SpeedsLegend(GCodeFile gcodeFileTest, ThemeConfig theme, PrinterConfig printer)
            : base(FlowDirection.TopToBottom)
        {
            GCodeMemoryFile memoryFile = gcodeFileTest as GCodeMemoryFile;

            if (memoryFile == null)
            {
                // File was too big to load, content contained in GCodeFileStream and speeds should not be rendered
                return;
            }

            GCodeRenderer renderer = printer.Bed.GCodeRenderer;

            if (renderer == null)
            {
                // Renderer did not load for content and speeds should not be rendered
                return;
            }

            var speeds = memoryFile.Speeds;

            if (speeds.Count <= 0)
            {
                // No speeds were discovered during parsing and speeds should not be rendered
                return;
            }

            float min      = speeds.Min();
            float max      = speeds.Max();
            int   maxItems = Math.Min(7, speeds.Count);

            int   count     = maxItems - 1;
            float increment = (max - min) / count;
            int   index     = 0;

            int[] rangeValues;
            if (speeds.Count < 8)
            {
                rangeValues = speeds.Select(s => (int)s).OrderBy(i => i).ToArray();
            }
            else
            {
                rangeValues = Enumerable.Range(0, maxItems).Select(x => (int)(min + increment * index++)).ToArray();
            }

            Color[] speedColors = rangeValues.OrderBy(s => s).Select(speed => renderer.ExtrusionColors.GetColorForSpeed(speed)).ToArray();

            for (int i = 0; i < speedColors.Length; i++)
            {
                int feedrate = rangeValues[i];

                this.AddChild(
                    new SpeedLegendRow(speedColors[i], millimetersPerSecond: feedrate / 60, pointSize: theme.FontSize10)
                {
                    Margin  = new BorderDouble(5, 2, 2, 2),
                    HAnchor = HAnchor.Stretch
                });
            }
        }
コード例 #4
0
        public override string ReadLine()
        {
            if (LineIndex < GCodeFile.LineCount)
            {
                if (LineIndex > 1 &&
                    GCodeFile is GCodeMemoryFile currentMemoryFile &&
                    switchToGCode != null)
                {
                    var prevlayerIndex = currentMemoryFile.GetLayerIndex(LineIndex - 1);
                    var layerIndex     = currentMemoryFile.GetLayerIndex(LineIndex);
                    // we only try to switch as we are changing layers
                    if (prevlayerIndex < layerIndex)
                    {
                        var currentBottom = currentMemoryFile.GetLayerBottom(layerIndex);
                        // see if there is a layer height that is compatible in the new gcode
                        for (int i = 0; i < switchToGCode.LayerCount; i++)
                        {
                            // find the first layer in the new code that is greater than or eaqual to our current height
                            var switchBottom = switchToGCode.GetLayerBottom(i);
                            if (switchBottom >= currentBottom)
                            {
                                // is the current gcode the same or bigger than the new gcode
                                if (currentBottom >= switchBottom)
                                {
                                    // switch the first time we can
                                    GCodeFile = switchToGCode;
                                    LineIndex = switchToGCode.GetFirstLayerInstruction(i);
                                    var line = $"G92 E{switchToGCode.Instruction(LineIndex).EPosition:0.###}";
                                    switchToGCode = null;
                                    return(line);
                                }
                                else                                 // only switch if we are within one layer height of the new gcode
                                {
                                    if (currentBottom - switchBottom < switchToGCode.GetLayerHeight(layerIndex))
                                    {
                                        GCodeFile     = switchToGCode;
                                        LineIndex     = switchToGCode.GetFirstLayerInstruction(i);
                                        switchToGCode = null;
                                        var line = $"G92 E{switchToGCode.Instruction(LineIndex).EPosition:0.###}";
                                        switchToGCode = null;
                                        return(line);
                                    }
                                }
                                // we are done evaluating after the first found layer
                                break;
                            }
                        }
                    }
                }
                return(GCodeFile.Instruction(LineIndex++).Line);
            }

            return(null);
        }
コード例 #5
0
        public ToolChangeStream(PrinterConfig printer, GCodeStream internalStream, QueuedCommandsStream queuedCommandsStream, IGCodeLineReader gcodeLineReader)
            : base(printer, internalStream)
        {
            this.gcodeLineReader = gcodeLineReader;
            if (gcodeLineReader != null)
            {
                this.gCodeMemoryFile = gcodeLineReader.GCodeFile as GCodeMemoryFile;
            }

            this.queuedCommandsStream = queuedCommandsStream;
            extruderCount             = printer.Settings.GetValue <int>(SettingsKey.extruder_count);
            activeTool = printer.Connection.ActiveExtruderIndex;
        }
コード例 #6
0
        public void SwitchTo(string gcodeFilename)
        {
            if (GCodeFile is GCodeMemoryFile)
            {
                Task.Run(() =>
                {
                    var switchToGCode = GCodeFile.Load(gcodeFilename,
                                                       new Vector4(),
                                                       new Vector4(),
                                                       new Vector4(),
                                                       Vector4.One,
                                                       CancellationToken.None);

                    if (switchToGCode is GCodeMemoryFile memoryFile)
                    {
                        this.switchToGCode = memoryFile;
                    }
                });
            }
        }
コード例 #7
0
        public override string ReadLine()
        {
            lock (locker)
            {
                if (commandQueue.Count > 0)
                {
                    var lineToSend = commandQueue[0];
                    commandQueue.RemoveAt(0);
                    return(lineToSend);
                }
            }

            if (LineIndex < GCodeFile.LineCount)
            {
                if (LineIndex > 1 &&
                    GCodeFile is GCodeMemoryFile currentMemoryFile &&
                    switchToGCode != null)
                {
                    var prevlayerIndex = currentMemoryFile.GetLayerIndex(LineIndex - 1);
                    var layerIndex     = currentMemoryFile.GetLayerIndex(LineIndex);
                    // we only try to switch as we are changing layers
                    if (prevlayerIndex < layerIndex)
                    {
                        var currentBottom = currentMemoryFile.GetLayerBottom(layerIndex);
                        // see if there is a layer height that is compatible in the new gcode
                        for (int i = 0; i < switchToGCode.LayerCount; i++)
                        {
                            // find the first layer in the new code that is greater than or equal to our current height
                            var switchBottom = switchToGCode.GetLayerBottom(i);
                            if (switchBottom >= currentBottom)
                            {
                                bool change = false;
                                // is the current gcode the same or bigger than the new gcode
                                if (currentBottom >= switchBottom)
                                {
                                    change = true;
                                }
                                else                                 // only switch if we are within one layer height of the new gcode
                                {
                                    if (currentBottom - switchBottom < switchToGCode.GetLayerHeight(layerIndex))
                                    {
                                        change = true;
                                    }
                                }

                                if (change)
                                {
                                    GCodeFile = switchToGCode;
                                    LineIndex = switchToGCode.GetFirstLayerInstruction(i);
                                    var line = $"G92 E{switchToGCode.Instruction(LineIndex).EPosition:0.###}";
                                    lock (locker)
                                    {
                                        commandQueue.Add(line);
                                    }
                                    switchToGCode = null;
                                    // return a dwell to exhaust the command queue on the firmware
                                    return("G4 P1");
                                }

                                // we are done evaluating after the first found layer
                                break;
                            }
                        }
                    }
                }

                return(GCodeFile.Instruction(LineIndex++).Line);
            }

            return(null);
        }