private void SaveGCodeToNewLocation(string source, string dest)
		{
			try
			{
				if (ActiveSliceSettings.Instance.DoPrintLeveling)
				{
					GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(source);
					if (applyLeveling.Checked)
					{
						PrintLevelingData levelingData = ActiveSliceSettings.Instance.PrintLevelingData;
						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
			{
			}
		}
예제 #2
0
		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);
		}