コード例 #1
0
        private async Task LoadAzureAsync(LoadOptions info)
        {
            using (var client = CreateHttpClient())
            {
                info.FileContent = await File.ReadAllBytesAsync(info.FileName);

                var response = await client.PostAsJsonAsync(api, info);

                var gcode = await response.Content.ReadAsAsync <string[]>();

                if (response.IsSuccessStatusCode)
                {
                    var load = new LoadGCode();
                    load.Load(gcode);
                    Commands.Clear();
                    Commands.AddRange(load.Commands);
                    if (!string.IsNullOrEmpty(info.GCodeWriteToFileName))
                    {
                        using (var sw = File.CreateText(Environment.ExpandEnvironmentVariables(info.GCodeWriteToFileName)))
                        {
                            load.WriteGCodeFile(sw);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public async Task <IActionResult> Render([FromBody] PreviewGCode opt)
        {
            var gCodeDraw = new GCodeBitmapDraw()
            {
                SizeX      = opt.SizeX,
                SizeY      = opt.SizeY,
                SizeZ      = opt.SizeZ,
                RenderSize = new Size(opt.RenderSizeX, opt.RenderSizeY),
                OffsetX    = opt.OffsetX,
                OffsetY    = opt.OffsetY,
                OffsetZ    = opt.OffsetZ,

                Zoom       = opt.Zoom,
                CutterSize = opt.CutterSize,
                LaserSize  = opt.LaserSize,
                KeepRatio  = opt.KeepRatio
            };

            if (opt.Rotate3DVect != null && opt.Rotate3DVect.Count() == 3)
            {
                gCodeDraw.Rotate = new Rotate3D(opt.Rotate3DAngle, opt.Rotate3DVect.ToArray());
            }

            var load = new LoadGCode();

            load.Load(opt.Commands.ToArray());
            var commands = load.Commands;
            var bitmap   = gCodeDraw.DrawToBitmap(commands);

            var memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Png);
            memoryStream.Position = 0;
            var fileName = "preview.png";

            return(File(memoryStream, this.GetContentType(fileName), fileName));
        }
コード例 #3
0
        public async Task <IActionResult> Render([FromBody] PreviewGCode opt)
        {
            await Task.CompletedTask;

            var gCodeDraw = new GCodeBitmapDraw()
            {
                SizeX      = opt.SizeX,
                SizeY      = opt.SizeY,
                SizeZ      = opt.SizeZ,
                RenderSize = new Size(opt.RenderSizeX, opt.RenderSizeY),
                OffsetX    = opt.OffsetX,
                OffsetY    = opt.OffsetY,
                OffsetZ    = opt.OffsetZ,

                Zoom       = opt.Zoom,
                CutterSize = opt.CutterSize,
                LaserSize  = opt.LaserSize,
                KeepRatio  = opt.KeepRatio,
            };

            if (!string.IsNullOrEmpty(opt.MachineColor))
            {
                gCodeDraw.MachineColor = System.Drawing.ColorTranslator.FromHtml(opt.MachineColor);
            }
            if (!string.IsNullOrEmpty(opt.LaserOnColor))
            {
                gCodeDraw.LaserOnColor = System.Drawing.ColorTranslator.FromHtml(opt.LaserOnColor);
            }
            if (!string.IsNullOrEmpty(opt.LaserOffColor))
            {
                gCodeDraw.LaserOffColor = System.Drawing.ColorTranslator.FromHtml(opt.LaserOffColor);
            }
            if (!string.IsNullOrEmpty(opt.CutColor))
            {
                gCodeDraw.CutColor = System.Drawing.ColorTranslator.FromHtml(opt.CutColor);
            }
            if (!string.IsNullOrEmpty(opt.CutDotColor))
            {
                gCodeDraw.CutDotColor = System.Drawing.ColorTranslator.FromHtml(opt.CutDotColor);
            }
            if (!string.IsNullOrEmpty(opt.CutEllipseColor))
            {
                gCodeDraw.CutEllipseColor = System.Drawing.ColorTranslator.FromHtml(opt.CutEllipseColor);
            }
            if (!string.IsNullOrEmpty(opt.CutArcColor))
            {
                gCodeDraw.CutArcColor = System.Drawing.ColorTranslator.FromHtml(opt.CutArcColor);
            }
            if (!string.IsNullOrEmpty(opt.FastMoveColor))
            {
                gCodeDraw.FastMoveColor = System.Drawing.ColorTranslator.FromHtml(opt.FastMoveColor);
            }
            if (!string.IsNullOrEmpty(opt.HelpLineColor))
            {
                gCodeDraw.HelpLineColor = System.Drawing.ColorTranslator.FromHtml(opt.HelpLineColor);
            }

            if (opt.Rotate3DVect != null && opt.Rotate3DVect.Count() == 3)
            {
                gCodeDraw.Rotate = new Rotate3D(opt.Rotate3DAngle, opt.Rotate3DVect.ToArray());
            }

            var load = new LoadGCode();

            load.Load(opt.Commands.ToArray());
            var commands = load.Commands;
            var bitmap   = gCodeDraw.DrawToBitmap(commands);

            var memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Png);
            memoryStream.Position = 0;
            var fileName = "preview.png";

            return(File(memoryStream, this.GetContentType(fileName), fileName));
        }
コード例 #4
0
ファイル: SerialPortController.cs プロジェクト: lulzzz/CNCLib
        public async Task <IActionResult> Render(int id, [FromBody] PreviewGCode opt)
        {
            var port = await SerialPortList.GetPortAndRescan(id);

            if (port == null)
            {
                return(NotFound());
            }

            var gCodeDraw = new GCodeBitmapDraw()
            {
                SizeX      = opt.SizeX,
                SizeY      = opt.SizeY,
                SizeZ      = opt.SizeZ,
                RenderSize = new Size(opt.RenderSizeX, opt.RenderSizeY),
                OffsetX    = opt.OffsetX,
                OffsetY    = opt.OffsetY,
                OffsetZ    = opt.OffsetZ,

                Zoom       = opt.Zoom,
                CutterSize = opt.CutterSize,
                LaserSize  = opt.LaserSize,
                KeepRatio  = opt.KeepRatio
            };

            if (opt.Rotate3DVect != null && opt.Rotate3DVect.Count() == 3)
            {
                gCodeDraw.Rotate = new Rotate3D(opt.Rotate3DAngle, opt.Rotate3DVect.ToArray());
            }

            if (!string.IsNullOrEmpty(opt.MachineColor))
            {
                gCodeDraw.MachineColor = System.Drawing.ColorTranslator.FromHtml(opt.MachineColor);
            }
            if (!string.IsNullOrEmpty(opt.LaserOnColor))
            {
                gCodeDraw.LaserOnColor = System.Drawing.ColorTranslator.FromHtml(opt.LaserOnColor);
            }
            if (!string.IsNullOrEmpty(opt.LaserOffColor))
            {
                gCodeDraw.LaserOffColor = System.Drawing.ColorTranslator.FromHtml(opt.LaserOffColor);
            }
            if (!string.IsNullOrEmpty(opt.CutColor))
            {
                gCodeDraw.CutColor = System.Drawing.ColorTranslator.FromHtml(opt.CutColor);
            }
            if (!string.IsNullOrEmpty(opt.CutDotColor))
            {
                gCodeDraw.CutDotColor = System.Drawing.ColorTranslator.FromHtml(opt.CutDotColor);
            }
            if (!string.IsNullOrEmpty(opt.CutEllipseColor))
            {
                gCodeDraw.CutEllipseColor = System.Drawing.ColorTranslator.FromHtml(opt.CutEllipseColor);
            }
            if (!string.IsNullOrEmpty(opt.CutArcColor))
            {
                gCodeDraw.CutArcColor = System.Drawing.ColorTranslator.FromHtml(opt.CutArcColor);
            }
            if (!string.IsNullOrEmpty(opt.FastMoveColor))
            {
                gCodeDraw.FastMoveColor = System.Drawing.ColorTranslator.FromHtml(opt.FastMoveColor);
            }
            if (!string.IsNullOrEmpty(opt.HelpLineColor))
            {
                gCodeDraw.HelpLineColor = System.Drawing.ColorTranslator.FromHtml(opt.HelpLineColor);
            }

            var hisCommands = port.Serial.CommandHistoryCopy.OrderBy(x => x.SeqId).Select(c => c.CommandText);

            var load = new LoadGCode();

            load.Load(hisCommands.ToArray());
            var commands = load.Commands;
            var bitmap   = gCodeDraw.DrawToBitmap(commands);

            var memoryStream = new MemoryStream();

            bitmap.Save(memoryStream, ImageFormat.Png);
            memoryStream.Position = 0;
            var fileName = "preview.png";

            return(File(memoryStream, this.GetContentType(fileName), fileName));
        }