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 void ExpectedPropertiesOnlyTest() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); var expectedProperties = new HashSet <string>( new[] { "DocumentVersion", "ID", "StagedUserSettings", "Macros", "OemLayer", "UserLayer", "MaterialLayers", "QualityLayers" }); var printer = new PrinterConfig(new PrinterSettings()); var levelingSolution = new LevelWizard3Point(printer.Shim()); var printerSettings = printer.Settings; var json = printer.Settings.ToJson(); var jObject = JObject.Parse(json); foreach (var item in jObject) { Assert.IsTrue(expectedProperties.Contains(item.Key), $"Unexpected property ({item.Key}) in PrinterSettings - add to list or use @JsonIgnore"); } }
private void SaveGCodeToNewLocation(string source, string dest) { if (ActivePrinterProfile.Instance.DoPrintLeveling) { GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(source); if (applyLeveling.Checked) { PrintLevelingPlane.Instance.ApplyLeveling(unleveledGCode); PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); if (levelingData != null) { for (int lineIndex = 0; lineIndex < unleveledGCode.LineCount; lineIndex++) { PrinterMachineInstruction instruction = unleveledGCode.Instruction(lineIndex); List <string> linesToWrite = null; switch (levelingData.levelingSystem) { case PrintLevelingData.LevelingSystem.Probe2Points: linesToWrite = LevelWizard2Point.ProcessCommand(instruction.Line); break; case PrintLevelingData.LevelingSystem.Probe3Points: linesToWrite = LevelWizard3Point.ProcessCommand(instruction.Line); break; } 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); }
public void Check3PointLevelingPositions() { AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData")); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); var levelingSolution = new LevelWizard3Point(ActiveSliceSettings.Instance.printer); var printerSettings = ActiveSliceSettings.Instance; { var samples = levelingSolution.GetPrintLevelPositionToSample().ToList(); Assert.AreEqual("200,200", ActiveSliceSettings.Instance.GetValue(SettingsKey.bed_size)); Assert.AreEqual("100,100", ActiveSliceSettings.Instance.GetValue(SettingsKey.print_center)); Assert.AreEqual("rectangular", ActiveSliceSettings.Instance.GetValue(SettingsKey.bed_shape)); Assert.AreEqual(new Vector2(20, 20), samples[0]); Assert.AreEqual(new Vector2(180, 20), samples[1]); Assert.AreEqual(new Vector2(100, 180), samples[2]); } }
public void Check3PointLevelingPositions() { StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"); MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); var printer = new PrinterConfig(new PrinterSettings()); var levelingSolution = new LevelWizard3Point(printer); var printerSettings = printer.Settings; { var samples = levelingSolution.GetPositionsToSample(default(Vector3)).ToList(); Assert.AreEqual("200,200", printerSettings.GetValue(SettingsKey.bed_size)); Assert.AreEqual("100,100", printerSettings.GetValue(SettingsKey.print_center)); Assert.AreEqual("rectangular", printerSettings.GetValue(SettingsKey.bed_shape)); Assert.AreEqual(new Vector2(20, 20), samples[0]); Assert.AreEqual(new Vector2(180, 20), samples[1]); Assert.AreEqual(new Vector2(100, 180), samples[2]); } }
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}"); } }; }
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 { } }
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))); } } } }
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))); } } } }