[HttpGet("Split/{xSplit:float}/{splitDegrees:float}/{zClearance:float}/{index:int}")] // GET /api/Editor/Split/20/10/20/0 public IActionResult Split(float xSplit, float splitDegrees, float zClearance, int index) { // index means which side to get back if (xSplit != 0) { var splitPoint = new Point3D(xSplit, 0, 0); var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel"); if (drawModel != null) { var gCode = DrawModel.ToGCode(drawModel); SaveToFile("before_split.txt", gCode); var parsedInstructions = SimpleGCodeParser.ParseText(gCode); var gCodeArray = GCodeSplitter.Split(parsedInstructions, splitPoint, splitDegrees, zClearance); SaveToFile("after_split_1.txt", GCodeUtils.GetGCode(gCodeArray[0])); SaveToFile("after_split_2.txt", GCodeUtils.GetGCode(gCodeArray[1])); // clean up the mess with too many G0 commands var cleanedGCode = GCodeUtils.GetMinimizeGCode(gCodeArray[index]); SaveToFile("after_split_clean.txt", GCodeUtils.GetGCode(cleanedGCode)); var gCodeResult = Block.BuildGCodeOutput("Block_1", cleanedGCode, false); SaveToFile("after_split_build_output.txt", gCodeResult); // convert gcode to draw model var newDrawModel = DrawModel.FromGCode(gCodeResult, drawModel.FileName); HttpContext.Session.SetObjectAsJson("DrawModel", newDrawModel); } return(Ok()); } return(BadRequest()); }
[HttpGet("Split/{xSplit:float}/{splitDegrees:float}/{zClearance:float}")] // GET /api/Editor/Split/100/0/10 public IActionResult Split(float xSplit, float splitDegrees, float zClearance) { // index means which side to get back if (xSplit != 0) { var splitPoint = new Point3D(xSplit, 0, 0); var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel"); if (drawModel != null) { var gCode = DrawModel.ToGCode(drawModel); // SaveToFile("before_split.txt", gCode); var parsedInstructions = SimpleGCodeParser.ParseText(gCode); var gCodeArray = GCodeSplitter.Split(parsedInstructions, splitPoint, splitDegrees, zClearance); // SaveToFile("after_split_1.txt", GCodeUtils.GetGCode(gCodeArray[0])); // SaveToFile("after_split_2.txt", GCodeUtils.GetGCode(gCodeArray[1])); // clean up the mess with too many G0 commands var cleanedGCode1 = GCodeUtils.GetMinimizeGCode(gCodeArray[0]); var cleanedGCode2 = GCodeUtils.GetMinimizeGCode(gCodeArray[1]); // SaveToFile("after_split_clean_1.txt", GCodeUtils.GetGCode(cleanedGCode1)); // SaveToFile("after_split_clean_2.txt", GCodeUtils.GetGCode(cleanedGCode2)); var gCodeResult1 = Block.BuildGCodeOutput("Block_1", cleanedGCode1, false); var gCodeResult2 = Block.BuildGCodeOutput("Block_1", cleanedGCode2, false); // SaveToFile("after_split_build_output_1.txt", gCodeResult1); // SaveToFile("after_split_build_output_2.txt", gCodeResult2); // convert gcode to draw model var fileName = Path.GetFileNameWithoutExtension(drawModel.FileName); var extension = Path.GetExtension(drawModel.FileName); var newDrawModel1 = DrawModel.FromGCode(gCodeResult1, fileName + "_split_1" + extension); var newDrawModel2 = DrawModel.FromGCode(gCodeResult2, fileName + "_split_2" + extension); // store with index HttpContext.Session.SetObjectAsJson("Split-0", newDrawModel1); HttpContext.Session.SetObjectAsJson("Split-1", newDrawModel2); } return(Ok()); } return(BadRequest()); }