Exemplo n.º 1
0
        [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());
        }
Exemplo n.º 2
0
        [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());
        }
Exemplo n.º 3
0
        void BtnUseClick(object sender, EventArgs e)
        {
            if (_cancelTokenSource != null)
            {
                btnStartStop.Text = "Start";
                _alg.Running      = false;
                _cancelTokenSource.Cancel();
            }

            // first sort by z-order
            var    sortedBestPath = GCodeUtils.SortBlocksByZDepth(_alg.BestPath, _points);
            string gCode          = GCodeUtils.GetGCode(sortedBestPath, _points);

            _plotter.ParseGCodeString(gCode);
            this.Close();
        }