private void Slice(ISlicerBroker slicer, string LocalFilePath, string OutputPath = "")
        {
            PrusaSlicerBroker prusaSlicer = (PrusaSlicerBroker)slicer;

            if (prusaSlicer == null)
            {
                return;
            }
            SliceWithPrusa(LocalFilePath, OutputPath);
        }
Exemple #2
0
        private async Task HandleWebSocketDataAsync(WebSocket webSocket, string data)
        {
            PrusaSlicerCLICommands commands;

            try
            {
                //convert json to object
                commands = JsonSerializer.Deserialize <PrusaSlicerCLICommands>(data, new JsonSerializerOptions()
                {
                    IgnoreNullValues = true
                });
            }
            catch (Exception)
            {
                await SendErrorMessageForInvalidCommandsAsync(webSocket);

                return;
            }

            if (!commands.isValid())
            {
                await SendErrorMessageForInvalidCommandsAsync(webSocket);

                return;
            }

            // Ouput folder and config file path. These parameters need to be overwritten.
            commands.Output = GCodePath;
            if (!SetSlicingProfilPath(commands))
            {
                await SendErrorMessageForInvalidProfile(webSocket);

                return;
            }

            await SendSlicingStartedAsync(webSocket);

            var prusaSlicerBroker = new PrusaSlicerBroker(slicerPath);

            prusaSlicerBroker.FileSliced   += PrusaSlicerBroker_FileSliced(webSocket);
            prusaSlicerBroker.DataReceived += async(sender, args) =>
            {
                await SendSlicingProgressMessageAsync(webSocket, args);
            };

            var fileUri = new Uri(commands.FileURI);

            await DownloadModelAsync(fileUri, commands.FileName);

            var localPath = Path.Combine(ModelDownloadPath, commands.FileName);

            // use the local file on the disk
            commands.File = localPath;
            await prusaSlicerBroker.SliceAsync(commands);
        }
Exemple #3
0
        // POST: api/Slice
        public async Task <string> Post([FromBody] string filepath, [FromUri] int fill = 20, [FromUri] double layer = 0.3, [FromUri] bool support = false)
        {
            var octoConnection = await WebApiApplication.GetOctoConnectionAsync();

            var octofile = OctoPrintFileServices.CreateOctoFile(octoConnection, filepath);

            if (octofile != null)
            {
                string downloadpath = octoConnection.ApplicationFolderPath;

                octofile.DownloadAssociatedOnlineFile("local", downloadpath, octoConnection);

                // Change to be a global class instance and just set the slicing variables with every request
                // would be better not to create a new instance with each request
                PrusaSlicerBroker prusaSlicer = new PrusaSlicerBroker(prusaSlicerPath, fill, layer, support);

                //await octofile.Slice(prusaSlicer, octofile.SlicedFilePath);

                await prusaSlicer.SliceAsync(octofile.LocalFilePath);

                octofile.SetSlicedInPlaceFileInfo();

                var uploadResponse = await octofile.UploadToOctoprintAsync(octofile.SlicedFilePath, octoConnection);

                if (uploadResponse.Contains("done\":true"))
                {
                    return($"{octofile.SlicedFileName}");
                }
                else
                {
                    var errorResponse = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Problem occured while uploading sliced file to Octoprint");
                    throw new HttpResponseException(errorResponse);
                }
            }

            else
            {
                var errorResponse = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Problem occured while downloading file from Octoprint");
                throw new HttpResponseException(errorResponse);
            }
        }
        public void SliceWithPrusa(string LocalFilePath, string OutputPath = "", int fill = 20, double layer = 0.3, bool support = false, string outputname = "")
        {
            PrusaSlicerBroker prusaSlicer = new PrusaSlicerBroker(this.LocalFilePath, fill, layer, support);


            //if the path of the output gcode file is specified then slice and put it in that path (must be specified without .gcode extension)
            if (!string.IsNullOrEmpty(OutputPath))
            {
                prusaSlicer.OutputPath = OutputPath;
            }
            if (!string.IsNullOrEmpty(outputname))
            {
                prusaSlicer.OutputName = outputname;
            }
            // if there is no specific slicing path, slice in the same place of the stl but remove the .stl first of the sliced path then append .gcode
            else
            {
                OutputPath = System.IO.Path.ChangeExtension(LocalFilePath, null);
            }
            prusaSlicer.Slice();
            this.SlicedFilePath = OutputPath + ".gcode";
            FileSliced?.Invoke(this, new FileSlicedArgs(SlicedFilePath));
        }