[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("Rotate/{degrees:float}")] // GET /api/Editor/Rotate/20 public IActionResult Rotate(float degrees) { var drawModel = HttpContext.Session.GetObjectFromJson <DrawModel>("DrawModel"); if (drawModel != null) { var gCode = DrawModel.ToGCode(drawModel); SaveToFile("before_rotate.txt", gCode); var parsedInstructions = SimpleGCodeParser.ParseText(gCode); var center = new PointF(0, 0); if (degrees == 0) { degrees = 90; } var gcodeInstructions = GCodeUtils.GetRotatedGCode(parsedInstructions, center, degrees); SaveToFile("after_rotate.txt", GCodeUtils.GetGCode(gcodeInstructions)); // clean up the mess with too many G0 commands var cleanedGCode = GCodeUtils.GetMinimizeGCode(gcodeInstructions); SaveToFile("after_rotate_clean.txt", GCodeUtils.GetGCode(cleanedGCode)); var gCodeResult = Block.BuildGCodeOutput("Block_1", cleanedGCode, false); SaveToFile("after_rotate_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()); }