Ejemplo n.º 1
0
        /// <summary>
        /// Converts RepRapGCode into ModiPrintGCode.
        /// </summary>
        public string ConvertGCode(string repRapGCodeInput)
        {
            //Reset parameters for the new conversion.
            InstantiateGCodeConverterClasses();

            //The input string is split into a 2D array, delimited first by linebreaks and then by whitespaces.
            string[][] repRapGCode = GCodeStringParsing.GCodeTo2DArr(repRapGCodeInput);

            //The return string which is the converted GCode.
            //Each line of the GCode is an index in the string.
            //Each line will be delimited by \r\n when converting to a string.
            List <ConvertedGCodeLine> convertedGCode = new List <ConvertedGCodeLine>();

            //Converted GCode commands for starting up the printer.
            convertedGCode.Add(new ConvertedGCodeLine("", "Setup"));

            //Set the current X and Y positions as the origin.
            convertedGCode.Add(new ConvertedGCodeLine(SerialMessageCharacters.SerialCommandSetCharacter + "OriginXY"));

            //Iterates through each line of RepRap's GCode and converts it to ModiPrint's flavor of GCode.
            convertedGCode.Add(new ConvertedGCodeLine("", "Print Start"));
            for (_parametersModel.RepRapLine = 0; (_parametersModel.RepRapLine < repRapGCode.Length) && (repRapGCode != null); _parametersModel.RepRapLine++)
            {
                if (repRapGCode[_parametersModel.RepRapLine] != null &&
                    !String.IsNullOrWhiteSpace(repRapGCode[_parametersModel.RepRapLine][0]))
                {
                    //Processes the single line of GCode and returns a converted string.
                    List <ConvertedGCodeLine> appendModiPrintGCode;
                    appendModiPrintGCode = SetProcessGCodeCommand(GCodeStringParsing.RemoveGCodeComments(repRapGCode[_parametersModel.RepRapLine]));

                    //Adds a converted GCode line to the return string with line breaks and comments.
                    if ((appendModiPrintGCode != null) && (appendModiPrintGCode.Count != 0))
                    {
                        //Comment the repRap line at the end of the converted GCode line.
                        appendModiPrintGCode[appendModiPrintGCode.Count - 1].Comment += (_parametersModel.RepRapLine + 1); //(repRapLine + 1) because repRapLine is index 0 where line count is index 1.
                        convertedGCode.AddRange(appendModiPrintGCode);
                    }
                }
                int percentCompleted = ((_parametersModel.RepRapLine + 1) * 100) / repRapGCode.Length;
                _parametersModel.ReportProgress("Converting GCode " + percentCompleted + "%");
            }

            //Calculates the deceleration steps parameter in G00 commands.
            _corneringModel.AddDecelerationStepsParameter(ref convertedGCode);

            //Retract this Z Axis.
            string retractZ = SerialMessageCharacters.SerialCommandSetCharacter + "RetractZ";

            convertedGCode.Add(new ConvertedGCodeLine(retractZ));

            _parametersModel.ReportProgress("");

            return(GCodeLinesConverter.GCodeLinesListToString(convertedGCode));
        }