Beispiel #1
0
        private string RunPrintLevelingTranslations(string lineBeingSent, PrinterMove currentDestination)
        {
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

            if (levelingData != null)
            {
                switch (levelingData.CurrentPrinterLevelingSystem)
                {
                case PrintLevelingData.LevelingSystem.Probe2Points:
                    lineBeingSent = LevelWizard2Point.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute);
                    break;

                case PrintLevelingData.LevelingSystem.Probe3Points:
                    lineBeingSent = LevelWizard3Point.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute);
                    break;

                case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                    lineBeingSent = LevelWizard7PointRadial.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute);
                    break;

                case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                    lineBeingSent = LevelWizard13PointRadial.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(lineBeingSent);
        }
        public static void ShowPrintLevelWizard(PrinterConfig printer, ThemeConfig theme)
        {
            // turn off print leveling
            PrintLevelingStream.AllowLeveling = false;

            // clear any data that we are going to be acquiring (sampled positions, after z home offset)
            var levelingData = new PrintLevelingData()
            {
                LevelingSystem = printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution)
            };

            printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");

            LevelingPlan levelingPlan;

            switch (levelingData.LevelingSystem)
            {
            case LevelingSystem.Probe3Points:
                levelingPlan = new LevelWizard3Point(printer);
                break;

            case LevelingSystem.Probe7PointRadial:
                levelingPlan = new LevelWizard7PointRadial(printer);
                break;

            case LevelingSystem.Probe13PointRadial:
                levelingPlan = new LevelWizard13PointRadial(printer);
                break;

            case LevelingSystem.Probe100PointRadial:
                levelingPlan = new LevelWizard100PointRadial(printer);
                break;

            case LevelingSystem.Probe3x3Mesh:
                levelingPlan = new LevelWizardMesh(printer, 3, 3);
                break;

            case LevelingSystem.Probe5x5Mesh:
                levelingPlan = new LevelWizardMesh(printer, 5, 5);
                break;

            case LevelingSystem.Probe10x10Mesh:
                levelingPlan = new LevelWizardMesh(printer, 10, 10);
                break;

            default:
                throw new NotImplementedException();
            }

            var levelingContext = new PrintLevelingWizard(levelingPlan, printer)
            {
                WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Print Leveling Wizard".Localize()
            };

            var printLevelWizardWindow = DialogWindow.Show(new LevelingWizardRootPage(levelingContext)
            {
                WindowTitle = levelingContext.WindowTitle
            });

            printLevelWizardWindow.Closed += (s, e) =>
            {
                // If leveling was on when we started, make sure it is on when we are done.
                PrintLevelingStream.AllowLeveling = true;

                printLevelWizardWindow = null;

                // make sure we raise the probe on close
                if (printer.Settings.GetValue <bool>(SettingsKey.has_z_probe) &&
                    printer.Settings.GetValue <bool>(SettingsKey.use_z_probe) &&
                    printer.Settings.GetValue <bool>(SettingsKey.has_z_servo))
                {
                    // make sure the servo is retracted
                    var servoRetract = printer.Settings.GetValue <double>(SettingsKey.z_servo_retracted_angle);
                    printer.Connection.QueueLine($"M280 P0 S{servoRetract}");
                }
            };
        }
Beispiel #3
0
        private void SaveGCodeToNewLocation(string source, string dest)
        {
            try
            {
                if (ActiveSliceSettings.Instance.GetValue <bool>("print_leveling_enabled"))
                {
                    GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(source);
                    if (applyLeveling.Checked)
                    {
                        PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();
                        if (levelingData != null)
                        {
                            for (int lineIndex = 0; lineIndex < unleveledGCode.LineCount; lineIndex++)
                            {
                                PrinterMachineInstruction instruction = unleveledGCode.Instruction(lineIndex);
                                Vector3 currentDestination            = instruction.Position;

                                List <string> linesToWrite = null;
                                switch (levelingData.CurrentPrinterLevelingSystem)
                                {
                                case PrintLevelingData.LevelingSystem.Probe2Points:
                                    instruction.Line = LevelWizard2Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    linesToWrite     = LevelWizard2Point.ProcessCommand(instruction.Line);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe3Points:
                                    instruction.Line = LevelWizard3Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    linesToWrite     = LevelWizard3Point.ProcessCommand(instruction.Line);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                                    instruction.Line = LevelWizard7PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    linesToWrite     = LevelWizard7PointRadial.ProcessCommand(instruction.Line);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                                    instruction.Line = LevelWizard13PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    linesToWrite     = LevelWizard13PointRadial.ProcessCommand(instruction.Line);
                                    break;

                                default:
                                    throw new NotImplementedException();
                                }

                                instruction.Line = linesToWrite[0];
                                linesToWrite.RemoveAt(0);

                                // now insert any new lines
                                foreach (string line in linesToWrite)
                                {
                                    PrinterMachineInstruction newInstruction = new PrinterMachineInstruction(line);
                                    unleveledGCode.Insert(++lineIndex, newInstruction);
                                }
                            }
                        }
                    }
                    unleveledGCode.Save(dest);
                }
                else
                {
                    File.Copy(source, dest, true);
                }
                ShowFileIfRequested(dest);
            }
            catch
            {
            }
        }
Beispiel #4
0
        private void sliceItem_Done(object sender, EventArgs e)
        {
            PrintItemWrapper sliceItem = (PrintItemWrapper)sender;

            sliceItem.SlicingDone          -= sliceItem_Done;
            sliceItem.SlicingOutputMessage -= printItemWrapper_SlicingOutputMessage;

            if (File.Exists(sliceItem.FileLocation))
            {
                savedGCodeFileNames.Add(sliceItem.GetGCodePathAndFileName());
            }

            itemCountBeingWorkedOn++;
            if (itemCountBeingWorkedOn < allFilesToExport.Count)
            {
                if (StartingNextPart != null)
                {
                    StartingNextPart(this, new StringEventArgs(ItemNameBeingWorkedOn));
                }
            }
            else
            {
                if (UpdatePartStatus != null)
                {
                    UpdatePartStatus(this, new StringEventArgs("Calculating Total fillament mm..."));
                }

                if (savedGCodeFileNames.Count > 0)
                {
                    double total = 0;
                    foreach (string gcodeFileName in savedGCodeFileNames)
                    {
                        string allContent = File.ReadAllText(gcodeFileName);
                        if (allContent.Length > 0)
                        {
                            string searchString = "filament used =";
                            int    startPos     = allContent.IndexOf(searchString);
                            if (startPos > 0)
                            {
                                int endPos = Math.Min(allContent.IndexOf("\n", startPos), allContent.IndexOf("mm", startPos));
                                if (endPos > 0)
                                {
                                    string value = allContent.Substring(startPos + searchString.Length, endPos - startPos - searchString.Length);
                                    double amountForThisFile;
                                    if (double.TryParse(value, out amountForThisFile))
                                    {
                                        total += amountForThisFile;
                                    }
                                }
                            }
                        }
                    }

                    PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();

                    // now copy all the gcode to the path given
                    for (int i = 0; i < savedGCodeFileNames.Count; i++)
                    {
                        string savedGcodeFileName = savedGCodeFileNames[i];
                        string originalFileName   = Path.GetFileName(allFilesToExport[i].Name);
                        string outputFileName     = Path.ChangeExtension(originalFileName, ".gcode");
                        string outputPathAndName  = Path.Combine(exportPath, outputFileName);

                        if (ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_enabled))
                        {
                            GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(savedGcodeFileName);

                            for (int j = 0; j < unleveledGCode.LineCount; j++)
                            {
                                PrinterMachineInstruction instruction = unleveledGCode.Instruction(j);
                                Vector3 currentDestination            = instruction.Position;

                                switch (levelingData.CurrentPrinterLevelingSystem)
                                {
                                case PrintLevelingData.LevelingSystem.Probe3Points:
                                    instruction.Line = LevelWizard3Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                                    instruction.Line = LevelWizard7PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                                    instruction.Line = LevelWizard13PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                default:
                                    throw new NotImplementedException();
                                }
                            }
                            unleveledGCode.Save(outputPathAndName);
                        }
                        else
                        {
                            File.Copy(savedGcodeFileName, outputPathAndName, true);
                        }
                    }

                    if (DoneSaving != null)
                    {
                        DoneSaving(this, new StringEventArgs(string.Format("{0:0.0}", total)));
                    }
                }
            }
        }
Beispiel #5
0
        private void sliceItem_Done(object sender, EventArgs e)
        {
            PrintItemWrapper sliceItem = (PrintItemWrapper)sender;

            sliceItem.SlicingDone          -= sliceItem_Done;
            sliceItem.SlicingOutputMessage -= printItemWrapper_SlicingOutputMessage;

            if (File.Exists(sliceItem.FileLocation))
            {
                savedGCodeFileNames.Add(sliceItem.GetGCodePathAndFileName());
            }

            itemCountBeingWorkedOn++;
            if (itemCountBeingWorkedOn < allFilesToExport.Count)
            {
                if (StartingNextPart != null)
                {
                    StartingNextPart(this, new StringEventArgs(ItemNameBeingWorkedOn));
                }
            }
            else
            {
                if (UpdatePartStatus != null)
                {
                    UpdatePartStatus(this, new StringEventArgs("Calculating Total cm3..."));
                }

                if (savedGCodeFileNames.Count > 0)
                {
                    double total = 0;
                    foreach (string gcodeFileName in savedGCodeFileNames)
                    {
                        string[] lines = File.ReadAllLines(gcodeFileName);
                        if (lines.Length > 0)
                        {
                            string filamentAmountLine = lines[lines.Length - 1];
                            bool   foundAmountInGCode = false;
                            int    startPos           = filamentAmountLine.IndexOf("(");
                            if (startPos > 0)
                            {
                                int endPos = filamentAmountLine.IndexOf("cm3)", startPos);
                                if (endPos > 0)
                                {
                                    string value = filamentAmountLine.Substring(startPos + 1, endPos - (startPos + 1));
                                    double amountForThisFile;
                                    if (double.TryParse(value, out amountForThisFile))
                                    {
                                        foundAmountInGCode = true;
                                        total += amountForThisFile;
                                    }
                                }
                            }
                        }
                    }

                    PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

                    // now copy all the gcode to the path given
                    for (int i = 0; i < savedGCodeFileNames.Count; i++)
                    {
                        string savedGcodeFileName = savedGCodeFileNames[i];
                        string originalFileName   = Path.GetFileName(allFilesToExport[i].Name);
                        string outputFileName     = Path.ChangeExtension(originalFileName, ".gcode");
                        string outputPathAndName  = Path.Combine(exportPath, outputFileName);

                        if (ActivePrinterProfile.Instance.DoPrintLeveling)
                        {
                            GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(savedGcodeFileName);

                            for (int j = 0; j < unleveledGCode.LineCount; j++)
                            {
                                PrinterMachineInstruction instruction = unleveledGCode.Instruction(j);
                                Vector3 currentDestination            = instruction.Position;

                                switch (levelingData.CurrentPrinterLevelingSystem)
                                {
                                case PrintLevelingData.LevelingSystem.Probe2Points:
                                    instruction.Line = LevelWizard2Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe3Points:
                                    instruction.Line = LevelWizard3Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                                    instruction.Line = LevelWizard7PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                                    instruction.Line = LevelWizard13PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType);
                                    break;

                                default:
                                    throw new NotImplementedException();
                                }
                            }
                            unleveledGCode.Save(outputPathAndName);
                        }
                        else
                        {
                            File.Copy(savedGcodeFileName, outputPathAndName, true);
                        }
                    }

                    if (DoneSaving != null)
                    {
                        DoneSaving(this, new StringEventArgs(string.Format("{0:0.0}", total)));
                    }
                }
            }
        }