public override JobCreateResult Create(PrinterInfo printerInfo) { Status = JobStatus.SavingToFile; JobCreateResult jobCreateResult = base.Create(printerInfo); if (jobCreateResult.Result == ProcessReturn.SUCCESS) { try { using (var gcodeFileReader = new GCodeFileReader(GCodeFilename)) { using (var gcodeFileWriter = new GCodeFileWriter(Details.jobParams.outputfile, true)) { GCode nextLine; while ((nextLine = gcodeFileReader.GetNextLine(true)) != null) { gcodeFileWriter.Write(nextLine); } } } } catch (Exception ex) { jobCreateResult.Result = ProcessReturn.FAILURE; } } return(jobCreateResult); }
private void ProcessGCode_EndGCode(GCodeFileWriter output_writer, JobDetails jobdetails, InternalPrinterProfile printerProfile) { foreach (var s in GCodeInitializationPreprocessor.GenerateEndGCode(jobdetails, printerProfile, true)) { output_writer.Write(new GCode(s)); } }
public void doTackPoint(GCode currLine, GCode Last_Tack_Point, GCodeFileWriter output_writer) { var num = (int)Math.Ceiling(distance(new BondingPreprocessor.Vector2(currLine), new BondingPreprocessor.Vector2(Last_Tack_Point))); if (num <= 5) { return; } output_writer.Write(new GCode("G4 P" + num.ToString())); }
internal override bool ProcessGCode(GCodeFileReader input_reader, GCodeFileWriter output_writer, Calibration calibration, JobDetails jobdetails, InternalPrinterProfile printerProfile) { UpdateConfigurations(calibration, printerProfile.PrinterSizeConstants); var flag1 = true; var flag2 = true; var flag3 = false; var flag4 = false; var num1 = 0; var num2 = 0; var num3 = 0.0; var position = new Position(); var num4 = (float)num3; var num5 = 0.0f; while (true) { GCode nextLine = input_reader.GetNextLine(false); if (nextLine != null) { if (nextLine.HasG && (nextLine.G == 0 || nextLine.G == 1) && !flag1) { if (nextLine.HasX || nextLine.HasY) { flag4 = true; } if (nextLine.HasZ) { nextLine.Z += entire_z_height_offset; } var num6 = !nextLine.HasX ? 0.0f : nextLine.X - position.relativeX; var num7 = !nextLine.HasY ? 0.0f : nextLine.Y - position.relativeY; var num8 = !nextLine.HasZ ? 0.0f : nextLine.Z - position.relativeZ; var num9 = !nextLine.HasE ? 0.0f : nextLine.E - position.relativeE; position.absoluteX += num6; position.absoluteY += num7; position.absoluteZ += num8; position.absoluteE += num9; position.relativeX += num6; position.relativeY += num7; position.relativeZ += num8; position.relativeE += num9; if (nextLine.hasF) { position.F = nextLine.F; } if (num8 > 1.40129846432482E-45 || num8 < -1.40129846432482E-45) { if (!flag3) { num2 = 1; } else { ++num2; } flag2 = num2 == 0 || num2 == 1; } var num10 = (float)Math.Sqrt(num6 * (double)num6 + num7 * (double)num7); var num11 = 1; if (num10 > 2.0) { num11 = (int)(num10 / 2.0); } var num12 = position.absoluteX - num6; var num13 = position.absoluteY - num7; var num14 = position.relativeX - num6; var num15 = position.relativeY - num7; var num16 = position.relativeZ - num8; var num17 = position.relativeE - num9; var num18 = num6 / num10; var num19 = num7 / num10; var num20 = num8 / num10; var num21 = num9 / num10; if (num9 > 0.0) { flag3 = true; } var num22 = flag2 ? 1 : 0; if (num9 > 0.0) { for (var index = 1; index < num11 + 1; ++index) { float x; float y; float num23; float num24; float num25; float num26; if (index == num11) { x = position.absoluteX; y = position.absoluteY; num23 = position.relativeX; num24 = position.relativeY; num25 = position.relativeZ; num26 = position.relativeE; } else { x = num12 + index * 2f * num18; y = num13 + index * 2f * num19; num23 = num14 + index * 2f * num18; num24 = num15 + index * 2f * num19; num25 = num16 + index * 2f * num20; num26 = num17 + index * 2f * num21; } var adjustmentRequired = GetHeightAdjustmentRequired(x, y); if (index != num11) { var code = new GCode { G = nextLine.G }; if (nextLine.HasX) { code.X = (float)(position.relativeX - (double)num6 + (num23 - (double)num14)); } if (nextLine.HasY) { code.Y = (float)(position.relativeY - (double)num7 + (num24 - (double)num15)); } if (nextLine.hasF && index == 1) { code.F = nextLine.F; } if (flag4) { code.Z = (float)(position.relativeZ - (double)num8 + (num25 - (double)num16)) + adjustmentRequired; } else if (nextLine.HasZ && (num8 > 1.40129846432482E-45 || num8 < -1.40129846432482E-45)) { code.Z = (float)(position.relativeZ - (double)num8 + (num25 - (double)num16)); } code.E = (float)(position.relativeE - (double)num9 + (num26 - (double)num17)) + num4; output_writer.Write(code); } else { if (flag4) { if (nextLine.HasZ) { nextLine.Z += adjustmentRequired; } else { nextLine.Z = num16 + num8 + adjustmentRequired; } } nextLine.E += num4; } num5 = num26; } } else { if (flag4) { var num23 = flag2 ? 1 : 0; var adjustmentRequired = GetHeightAdjustmentRequired(position.absoluteX, position.absoluteY); if (nextLine.HasZ) { nextLine.Z += adjustmentRequired; } else { nextLine.Z = position.relativeZ + adjustmentRequired; } } if (nextLine.HasE) { nextLine.E += num4; } num5 = position.relativeE; } } else if (nextLine.HasG && nextLine.G == 92) { if (nextLine.HasE) { position.relativeE = nextLine.E; } if (printerProfile.OptionsConstants.G92WorksOnAllAxes) { if (nextLine.HasX) { position.relativeX = nextLine.X; } if (nextLine.HasY) { position.relativeY = nextLine.Y; } if (nextLine.HasZ) { position.relativeZ = nextLine.Z; } } if (!nextLine.HasE && !nextLine.HasX && (!nextLine.HasY && !nextLine.HasZ)) { position.relativeE = 0.0f; if (printerProfile.OptionsConstants.G92WorksOnAllAxes) { position.relativeX = 0.0f; position.relativeY = 0.0f; position.relativeZ = 0.0f; } } } else if (nextLine.HasG && nextLine.G == 90) { flag1 = false; } else if (nextLine.HasG && nextLine.G == 91) { flag1 = true; } else if (nextLine.HasG && nextLine.G == 28) { position.relativeX = position.absoluteX = 54f; position.relativeY = position.absoluteY = 50f; } output_writer.Write(nextLine); ++num1; } else { break; } } return(true); }
internal override bool ProcessGCode(GCodeFileReader input_reader, GCodeFileWriter output_writer, Calibration calibration, JobDetails jobdetails, InternalPrinterProfile printerProfile) { var backlashX = calibration.BACKLASH_X; var backlashY = calibration.BACKLASH_Y; var flag = true; var position = new Position(); var num1 = 1000f; BackLashPreprocessor.Direction direction1 = BackLashPreprocessor.Direction.Neither; BackLashPreprocessor.Direction direction2 = BackLashPreprocessor.Direction.Neither; var num2 = 0.0f; var num3 = 0.0f; for (GCode nextLine = input_reader.GetNextLine(false); nextLine != null; nextLine = input_reader.GetNextLine(false)) { if (nextLine.HasG && (nextLine.G == 0 || nextLine.G == 1) && !flag) { if (nextLine.hasF) { num1 = nextLine.F; } var num4 = !nextLine.HasX ? 0.0f : nextLine.X - position.relativeX; var num5 = !nextLine.HasY ? 0.0f : nextLine.Y - position.relativeY; var num6 = !nextLine.HasZ ? 0.0f : nextLine.Z - position.relativeZ; var num7 = !nextLine.HasE ? 0.0f : nextLine.E - position.relativeE; BackLashPreprocessor.Direction direction3 = num4 <= 1.40129846432482E-45 ? num4 >= -1.40129846432482E-45 ? direction1 : BackLashPreprocessor.Direction.Negative : BackLashPreprocessor.Direction.Positive; BackLashPreprocessor.Direction direction4 = num5 <= 1.40129846432482E-45 ? num5 >= -1.40129846432482E-45 ? direction2 : BackLashPreprocessor.Direction.Negative : BackLashPreprocessor.Direction.Positive; var code = new GCode { G = nextLine.G }; if (direction3 != direction1 && direction1 != BackLashPreprocessor.Direction.Neither || direction4 != direction2 && direction2 != BackLashPreprocessor.Direction.Neither) { if (direction3 != direction1 && direction1 != BackLashPreprocessor.Direction.Neither) { num2 += direction3 == BackLashPreprocessor.Direction.Positive ? backlashX : -backlashX; } if (direction4 != direction2 && direction2 != BackLashPreprocessor.Direction.Neither) { num3 += direction4 == BackLashPreprocessor.Direction.Positive ? backlashY : -backlashY; } var num8 = position.relativeX + num2; var num9 = position.relativeY + num3; code.X = num8; code.Y = num9; code.F = calibration.BACKLASH_SPEED; output_writer.Write(code); nextLine.F = num1; } if (nextLine.HasX) { nextLine.X += num2; } if (nextLine.HasY) { nextLine.Y += num3; } position.relativeX += num4; position.relativeY += num5; position.relativeZ += num6; position.relativeE += num7; if (nextLine.hasF) { position.F = nextLine.F; } position.absoluteX += num4; position.absoluteY += num5; position.absoluteZ += num6; position.absoluteE += num7; direction1 = direction3; direction2 = direction4; } else if (nextLine.HasG && nextLine.G == 92) { if (nextLine.HasE) { position.relativeE = nextLine.E; } if (printerProfile.OptionsConstants.G92WorksOnAllAxes) { if (nextLine.HasX) { position.relativeX = nextLine.X; } if (nextLine.HasY) { position.relativeY = nextLine.Y; } if (nextLine.HasZ) { position.relativeZ = nextLine.Z; } } if (!nextLine.HasE && !nextLine.HasX && (!nextLine.HasY && !nextLine.HasZ)) { position.relativeE = 0.0f; if (printerProfile.OptionsConstants.G92WorksOnAllAxes) { position.relativeX = 0.0f; position.relativeY = 0.0f; position.relativeZ = 0.0f; } } } else if (nextLine.HasG && nextLine.G == 90) { flag = false; } else if (nextLine.HasG && nextLine.G == 91) { flag = true; } else if (nextLine.HasG && nextLine.G == 28) { position.relativeX = position.absoluteX = 54f; position.relativeY = position.absoluteY = 50f; } output_writer.Write(nextLine); } return(true); }
private bool ProcessGCode_HelperLayerComments(GCodeFileReader input_reader, GCodeFileWriter output_writer, JobDetails jobdetails, InternalPrinterProfile printerProfile, InitialPrintPreProcessorData initial_print_settings) { var flag1 = false; var num1 = 0; var num2 = 0; var flag2 = false; var flag3 = false; var flag4 = false; var flag5 = false; var useFanPreprocessor = jobdetails.jobParams.options.use_fan_preprocessor; GCode nextLine; while ((nextLine = input_reader.GetNextLine(false)) != null) { if (nextLine.orig.StartsWith(";LAYER:")) { if (nextLine.ToString().ToLower().Contains(";layer:-")) { flag5 = true; } flag1 = true; flag2 = true; } else if (nextLine.HasZ & flag3 && !flag1) { output_writer.Write(new GCode(";LAYER:" + num1++)); flag2 = true; } else if (nextLine.HasG) { if (nextLine.G == 90) { flag3 = true; } else if (nextLine.G == 91) { flag3 = false; } } if (!(nextLine.orig.ToLower() == "t0") && nextLine.orig.ToLower().IndexOf(" t0 ") <= -1 && (!nextLine.hasM || nextLine.M != 104 && nextLine.M != 109) && (!useFanPreprocessor || !nextLine.hasM || nextLine.M != 106 && nextLine.M != 107)) { var flag6 = false; if (nextLine.orig.StartsWith(";LAYER:")) { output_writer.Write(nextLine); flag6 = true; } if (flag2) { int num3; switch (num2) { case 0: var layerTemperature = (float)initial_print_settings.FirstRaftLayerTemperature; output_writer.Write(new GCode("M109 S" + layerTemperature.ToString())); output_writer.Write(new GCode("G90")); BoundingBox bounds = printerProfile.PrinterSizeConstants.WarningRegion.bounds_list[0]; output_writer.Write(new GCode(PrinterCompatibleString.Format("G0 X{0} Y{1} Z0.5 F3600", (float)((double)bounds.max.x - 1.0), (float)(((double)bounds.min.y + (double)bounds.max.y) / 2.0 + 10.0)))); output_writer.Write(new GCode("G91 ;Go relative")); output_writer.Write(new GCode(PrinterCompatibleString.Format("G0 E{0} F{1} ;prime the nozzle", initial_print_settings.PrimeAmount, 72f))); output_writer.Write(new GCode("G4 S0")); output_writer.Write(new GCode("G92 E0 ;reset E")); output_writer.Write(new GCode("G90 ;Go absolute")); goto label_22; case 1: num3 = initial_print_settings.SecondRaftResetTemp ? 1 : 0; break; default: num3 = 0; break; } var num4 = flag5 ? 1 : 0; if ((num3 & num4) != 0) { var filamentTemperature = (float)jobdetails.jobParams.filament_temperature; output_writer.Write(new GCode(";Reset to the ideal temperature")); output_writer.Write(new GCode("M104 S" + filamentTemperature.ToString())); flag4 = true; } label_22: ++num2; flag2 = false; } if (!flag4 && (flag5 && nextLine.ToString().ToLower() == ";layer:0" || !flag5 && num2 > 2 || num2 > 4)) { var filamentTemperature = (float)jobdetails.jobParams.filament_temperature; output_writer.Write(new GCode(";Reset to the ideal temperature")); output_writer.Write(new GCode("M104 S" + filamentTemperature.ToString())); flag4 = true; } if (!flag6) { output_writer.Write(nextLine); } } } return(true); }
private void ProcessGCode_AddStartGCode(GCodeFileReader input_reader, GCodeFileWriter output_writer, JobOptions jobOptions, Calibration calibration, InternalPrinterProfile printerProfile, InitialPrintPreProcessorData initial_print_settings) { var num = 0; if (jobOptions.use_heated_bed && printerProfile.AccessoriesConstants.HeatedBedConstants.HasBuiltinHeatedBed) { num = initial_print_settings.BedTemperature; } output_writer.Write(new GCode("M106 S1")); if (0 < num) { output_writer.Write(new GCode("M18")); output_writer.Write(new GCode("M104 S0")); output_writer.Write(new GCode(PrinterCompatibleString.Format("M140 S{0}", (object)num))); for (var index = 0; index < 8; ++index) { output_writer.Write(new GCode("G4 S15")); } output_writer.Write(new GCode("M140 S0")); } output_writer.Write(new GCode("M17")); output_writer.Write(new GCode("G4 S1")); if (0 < num) { output_writer.Write(new GCode(PrinterCompatibleString.Format("M104 S{0}", (object)175))); } else { output_writer.Write(new GCode(PrinterCompatibleString.Format("M104 S{0}", (object)initial_print_settings.StartingTemp))); } output_writer.Write(new GCode("G90")); output_writer.Write(new GCode(PrinterCompatibleString.Format("G0 Z5 F{0}", (object)(float)(printerProfile.SpeedLimitConstants.DEFAULT_FEEDRATE_Z * 60.0)))); if (0 < num) { output_writer.Write(new GCode("M18")); output_writer.Write(new GCode(PrinterCompatibleString.Format("M109 S{0}", (object)175))); output_writer.Write(new GCode("G4 S5")); output_writer.Write(new GCode(PrinterCompatibleString.Format("M104 S{0}", (object)130))); output_writer.Write(new GCode(PrinterCompatibleString.Format("M140 S{0}", (object)num))); for (var index = 0; index < 8; ++index) { output_writer.Write(new GCode("G4 S15")); } output_writer.Write(new GCode(PrinterCompatibleString.Format("M104 S{0}", (object)initial_print_settings.StartingTemp))); for (var index = 0; index < 3; ++index) { output_writer.Write(new GCode("G4 S15")); } output_writer.Write(new GCode("M17")); for (var index = 0; index < 1; ++index) { output_writer.Write(new GCode("G4 S15")); } } output_writer.Write(new GCode("G28")); if (0 < num) { output_writer.Write(new GCode(PrinterCompatibleString.Format("M190 S{0}", (object)num))); } output_writer.Write(new GCode("M106 S1")); output_writer.Write(new GCode("G90")); output_writer.Write(new GCode(PrinterCompatibleString.Format("M109 S{0}", (object)initial_print_settings.StartingTemp))); if (initial_print_settings.StartingTempStabilizationDelay != 0) { output_writer.Write(new GCode(PrinterCompatibleString.Format("G4 S{0}", (object)initial_print_settings.StartingTempStabilizationDelay))); } if (jobOptions.use_fan_preprocessor && initial_print_settings.StartingFanValue != 0) { output_writer.Write(new GCode(PrinterCompatibleString.Format("M106 S{0}", (object)initial_print_settings.StartingFanValue))); } output_writer.Write(new GCode(PrinterCompatibleString.Format("G0 F{0}", (object)1800))); output_writer.Write(new GCode("; can extrude")); }
internal override bool ProcessGCode(GCodeFileReader input_reader, GCodeFileWriter output_writer, Calibration calibration, JobDetails jobdetails, InternalPrinterProfile printerProfile) { var wave_step = 0; var num1 = 0; var flag1 = true; var flag2 = true; var flag3 = false; var num2 = 0; var num3 = 0.0; var position = new Position(); var num4 = (float)num3; var num5 = 0.0f; var firstLayerTemp = jobdetails.jobParams.preprocessor.bonding.FirstLayerTemp; var secondLayerTemp = jobdetails.jobParams.preprocessor.bonding.SecondLayerTemp; while (true) { GCode nextLine = input_reader.GetNextLine(false); if (nextLine != null) { if (!jobdetails.jobParams.options.use_wave_bonding) { output_writer.Write(nextLine); } else { if (nextLine.ToString().Contains(";LAYER:")) { int num6; try { num6 = int.Parse(nextLine.ToString().Substring(7)); } catch (Exception ex) { num6 = 0; ErrorLogger.LogException("Exception in BondingPreProcessor.ProcessGcode " + ex.Message, ex); } if (num6 < num1) { num1 = num6; } flag2 = num6 == num1; } if (nextLine.HasG && (nextLine.G == 0 || nextLine.G == 1) && !flag1) { if (nextLine.HasX || nextLine.HasY) { flag3 = true; } var num6 = !nextLine.HasX ? 0.0f : nextLine.X - position.relativeX; var num7 = !nextLine.HasY ? 0.0f : nextLine.Y - position.relativeY; var num8 = !nextLine.HasZ ? 0.0f : nextLine.Z - position.relativeZ; var num9 = !nextLine.HasE ? 0.0f : nextLine.E - position.relativeE; position.absoluteX += num6; position.absoluteY += num7; position.absoluteZ += num8; position.absoluteE += num9; position.relativeX += num6; position.relativeY += num7; position.relativeZ += num8; position.relativeE += num9; if (nextLine.hasF) { position.F = nextLine.F; } var num10 = (float)Math.Sqrt(num6 * (double)num6 + num7 * (double)num7); var num11 = 1; if (num10 > 1.25) { num11 = (int)(num10 / 1.25); } var num12 = position.absoluteX - num6; var num13 = position.absoluteY - num7; var num14 = position.relativeX - num6; var num15 = position.relativeY - num7; var num16 = position.relativeZ - num8; var num17 = position.relativeE - num9; var num18 = num6 / num10; var num19 = num7 / num10; var num20 = num8 / num10; var num21 = num9 / num10; if (flag2 && num9 > 0.0) { for (var index = 1; index < num11 + 1; ++index) { float num22; float num23; float num24; float num25; if (index == num11) { var absoluteX = (double)position.absoluteX; var absoluteY = (double)position.absoluteY; num22 = position.relativeX; num23 = position.relativeY; num24 = position.relativeZ; num25 = position.relativeE; } else { num22 = num14 + index * 1.25f * num18; num23 = num15 + index * 1.25f * num19; num24 = num16 + index * 1.25f * num20; num25 = num17 + index * 1.25f * num21; } var num26 = num25 - (double)num5; if (index != num11) { var code = new GCode { G = nextLine.G }; if (nextLine.HasX) { code.X = (float)(position.relativeX - (double)num6 + (num22 - (double)num14)); } if (nextLine.HasY) { code.Y = (float)(position.relativeY - (double)num7 + (num23 - (double)num15)); } if (nextLine.hasF && index == 1) { code.F = nextLine.F; } if (flag3) { code.Z = (float)(position.relativeZ - (double)num8 + (num24 - (double)num16)) + CurrentAdjustmentsZ(ref wave_step); } else if (nextLine.HasZ && (num8 > 1.40129846432482E-45 || num8 < -1.40129846432482E-45)) { code.Z = (float)(position.relativeZ - (double)num8 + (num24 - (double)num16)); } code.E = (float)(position.relativeE - (double)num9 + (num25 - (double)num17)) + num4; output_writer.Write(code); } else { if (flag3) { if (nextLine.HasZ) { nextLine.Z += CurrentAdjustmentsZ(ref wave_step); } else { nextLine.Z = num16 + num8 + CurrentAdjustmentsZ(ref wave_step); } } nextLine.E += num4; } num5 = num25; } } } else if (nextLine.HasG && nextLine.G == 92) { if (nextLine.HasE) { position.relativeE = nextLine.E; } if (printerProfile.OptionsConstants.G92WorksOnAllAxes) { if (nextLine.HasX) { position.relativeX = nextLine.X; } if (nextLine.HasY) { position.relativeY = nextLine.Y; } if (nextLine.HasZ) { position.relativeZ = nextLine.Z; } } if (!nextLine.HasE && !nextLine.HasX && (!nextLine.HasY && !nextLine.HasZ)) { position.relativeE = 0.0f; if (printerProfile.OptionsConstants.G92WorksOnAllAxes) { position.relativeX = 0.0f; position.relativeY = 0.0f; position.relativeZ = 0.0f; } } } else if (nextLine.HasG && nextLine.G == 90) { flag1 = false; } else if (nextLine.HasG && nextLine.G == 91) { flag1 = true; } output_writer.Write(nextLine); ++num2; } } else { break; } } return(true); }