Пример #1
0
        public string PreprocessGCode(string filename, PrinterInfo printerInfo, InternalPrinterProfile printerProfile, IPreprocessor processor, JobDetails bounds, int number)
        {
            var    fileInfo      = new FileInfo(filename);
            var    directoryName = fileInfo.DirectoryName;
            var    name          = fileInfo.Name;
            var    length        = name.IndexOf('_');
            string str;

            if (length > 0)
            {
                str = name.Substring(0, length) + "_" + number + "_" + processor.Name + "_processed.gcode";
            }
            else
            {
                str = name.Substring(0, name.Length - fileInfo.Extension.Length) + "_" + number + "_" + processor.Name + "_processed.gcode";
            }

            var gcodefilename = directoryName + Path.DirectorySeparatorChar.ToString() + str;
            var input_reader  = new GCodeFileReader(filename);
            var output_writer = new GCodeFileWriter(gcodefilename);

            if (!processor.ProcessGCode(input_reader, output_writer, printerInfo.calibration, bounds, printerProfile))
            {
                return(null);
            }

            input_reader.Close();
            output_writer.Close();
            return(gcodefilename);
        }
Пример #2
0
        private AbstractPreprocessedJob.PrintJobWarning GatherInitialInformation(string filename, InternalPrinterProfile printerProfile)
        {
            GCodeFileReader gcodeFileReader;

            try
            {
                gcodeFileReader = new GCodeFileReader(filename);
                if (!gcodeFileReader.IsOpen)
                {
                    throw new Exception(string.Format("Unable to open file: {0}", filename));
                }
            }
            catch (ThreadAbortException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception("PrinterJob.GatherInitialInformation ", ex);
            }
            EstimatedFilamentUsed = 0.0f;
            if (gcodeFileReader != null)
            {
                var   boundsCheckXy = Details.jobParams.options.bounds_check_xy;
                var   flag          = false;
                var   p             = new Vector3D(float.NaN, float.NaN, float.NaN);
                GCode nextLine;
                while ((nextLine = gcodeFileReader.GetNextLine(false)) != null)
                {
                    if (nextLine.HasG)
                    {
                        if (nextLine.G == 90)
                        {
                            flag = true;
                        }
                        else if (nextLine.G == 91)
                        {
                            flag = false;
                        }
                        else if (((nextLine.G == 0 ? 1 : (nextLine.G == 1 ? 1 : 0)) & (flag ? 1 : 0)) != 0)
                        {
                            if (nextLine.HasE)
                            {
                                if (flag)
                                {
                                    EstimatedFilamentUsed = nextLine.E;
                                }
                                else
                                {
                                    EstimatedFilamentUsed += nextLine.E;
                                }
                            }
                            if (nextLine.HasZ)
                            {
                                p.z = nextLine.Z;
                                if (nextLine.Z < (double)Details.bounds.min.z)
                                {
                                    Details.bounds.min.z = nextLine.Z;
                                }

                                if (nextLine.Z > (double)Details.bounds.max.z)
                                {
                                    Details.bounds.max.z = nextLine.Z;
                                }
                            }
                            if (boundsCheckXy)
                            {
                                if (nextLine.HasX)
                                {
                                    p.x = nextLine.X;
                                    if (nextLine.X < (double)Details.bounds.min.x)
                                    {
                                        Details.bounds.min.x = nextLine.X;
                                    }

                                    if (nextLine.X > (double)Details.bounds.max.x)
                                    {
                                        Details.bounds.max.x = nextLine.X;
                                    }
                                }
                                if (nextLine.HasY)
                                {
                                    p.y = nextLine.Y;
                                    if (nextLine.Y < (double)Details.bounds.min.y)
                                    {
                                        Details.bounds.min.y = nextLine.Y;
                                    }

                                    if (nextLine.Y > (double)Details.bounds.max.y)
                                    {
                                        Details.bounds.max.y = nextLine.Y;
                                    }
                                }
                            }
                            if (!printerProfile.PrinterSizeConstants.PrintableRegion.InRegionNaN(p))
                            {
                                gcodeFileReader.Close();
                                return(AbstractPreprocessedJob.PrintJobWarning.Error_OutOfBounds);
                            }
                        }
                        if (nextLine != null && nextLine.ToString().IndexOf("ideal temp:") > -1)
                        {
                            Details.ideal_temperature = (int)float.Parse(Regex.Match(nextLine.ToString(), "ideal temp:([-.0-9]+)").Groups[1].Value);
                        }
                    }
                    if (nextLine != null && nextLine.ToString().IndexOf("ideal temp:") > -1)
                    {
                        Details.ideal_temperature = (int)float.Parse(Regex.Match(nextLine.ToString(), "ideal temp:([-.0-9]+)").Groups[1].Value);
                    }
                }
                gcodeFileReader.Close();
                if (Details.jobParams.filament_type == FilamentSpool.TypeEnum.ABS && (Details.bounds.max.x - (double)Details.bounds.min.x > printerProfile.PrinterSizeConstants.ABSWarningDim || Details.bounds.max.y - (double)Details.bounds.min.y > printerProfile.PrinterSizeConstants.ABSWarningDim || Details.bounds.max.z - (double)Details.bounds.min.z > printerProfile.PrinterSizeConstants.ABSWarningDim))
                {
                    return(AbstractPreprocessedJob.PrintJobWarning.Warning_ABS_Size);
                }
            }
            return(AbstractPreprocessedJob.PrintJobWarning.Job_OK);
        }