static void LoadGeneratedGCodeFile(string sPath) { // read gcode file GenericGCodeParser parser = new GenericGCodeParser(); GCodeFile gcode; using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { using (TextReader reader = new StreamReader(fs)) { gcode = parser.Parse(reader); } } // write back out gcode we loaded //StandardGCodeWriter writer = new StandardGCodeWriter(); //using ( StreamWriter w = new StreamWriter("../../../sample_output/writeback.gcode") ) { // writer.WriteFile(gcode, w); //} GCodeToToolpaths converter = new GCodeToToolpaths(); MakerbotInterpreter interpreter = new MakerbotInterpreter(); interpreter.AddListener(converter); InterpretArgs interpArgs = new InterpretArgs(); interpreter.Interpret(gcode, interpArgs); View.SetPaths(converter.PathSet); if (LastSettings != null) { View.PathDiameterMM = (float)LastSettings.Machine.NozzleDiamMM; } }
static void LoadGCodeFile(string sPath) { GenericGCodeParser parser = new GenericGCodeParser(); GCodeFile gcode; using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { using (TextReader reader = new StreamReader(fs)) { gcode = parser.Parse(reader); } } GCodeToToolpaths converter = new GCodeToToolpaths(); MakerbotInterpreter interpreter = new MakerbotInterpreter(); interpreter.AddListener(converter); InterpretArgs interpArgs = new InterpretArgs(); interpreter.Interpret(gcode, interpArgs); ToolpathSet Paths = converter.PathSet; View.SetPaths(Paths); }
public void Compute() { RequestCancel = false; printer = new SingleMaterialFFFPrintGenerator(Meshes, SliceSet, PrintSettings); if (PrintSettings.EnableSupportReleaseOpt) { printer.LayerPostProcessor = new SupportConnectionPostProcessor() { ZOffsetMM = PrintSettings.SupportReleaseGap }; } // if we aren't interpreting GCode, we want generator to return its path set printer.AccumulatePathSet = (InterpretGCodePaths == false); // set clip region Box2d clip_box = new Box2d(Vector2d.Zero, new Vector2d(CC.Settings.BedSizeXMM / 2, CC.Settings.BedSizeYMM / 2)); printer.PathClipRegions = new List <GeneralPolygon2d>() { new GeneralPolygon2d(new Polygon2d(clip_box.ComputeVertices())) }; printer.ErrorF = (msg, trace) => { if (RequestCancel == false) { DebugUtil.Log(2, "Slicer Error! msg: {0} stack {1}", msg, trace); } }; DebugUtil.Log(2, "Generating gcode..."); try { if (printer.Generate() == false) { throw new Exception("generate failed"); // this will be caught below } gcode = printer.Result; //DebugUtil.Log(2, "Interpreting gcode..."); if (InterpretGCodePaths) { GCodeToToolpaths converter = new GCodeToToolpaths(); MakerbotInterpreter interpreter = new MakerbotInterpreter(); interpreter.AddListener(converter); InterpretArgs interpArgs = new InterpretArgs(); interpreter.Interpret(gcode, interpArgs); paths = converter.PathSet; } else { paths = printer.AccumulatedPaths; } //DebugUtil.Log(2, "Detecting layers..."); layerInfo = new LayersDetector(paths); Success = true; } catch (Exception e) { DebugUtil.Log("ToolpathGenerator.Compute: exception: " + e.Message); Success = false; } Finished = true; }