Ejemplo n.º 1
0
        /// <summary>
        /// Takes a file and updates the home for the knife to G56
        /// </summary>
        /// <param name="file">File in question</param>
        /// <returns></returns>
        NCFile SetKnifeHome(NCFile file)
        {
            int amountLines = file.AmountLines();
            int i           = 0;

            while (i < amountLines)
            {
                if (file.CheckLineBlock(i)) //checks if the line actually contains machien code
                {
                    string line = file.GetCode(i);
                    if (line.StartsWith("T25")) // if the line fetches T25(knife), then it starts looking for a following line setting the WorkCoordinateSystem, and makeing sure its set to G56
                    {
                        int j = i + 1;
                        while (j < i + 3)
                        {
                            line = file.GetCode(j);
                            if (line.StartsWith("G54")) //Found a line that sets the wrong WCS and changes it to "G56"
                            {
                                line = file.GetLine(j);
                                line = line.Substring(0, line.IndexOf(" ")) + " G56";
                                file.UpdateLine(j, line);
                            }
                            j++;
                        }
                    }
                }
                i++;
            }
            return(file);
        }
Ejemplo n.º 2
0
        NCFile Xyz(NCFile file)
        {
            int i = 0;

            while (i < file.AmountLines())
            {
                if (file.CheckLineBlock(i))
                {
                    string line  = file.GetCode(i);
                    double value = 0;
                    if (line.IndexOf("X") > -1)
                    {
                        string xblock = line.Substring(line.IndexOf("X") + 1);
                        if (xblock.IndexOf(" ") > -1)
                        {
                            xblock = xblock.Substring(0, xblock.IndexOf(" "));
                        }
                        if (double.TryParse(xblock, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo("en-US"), out value))
                        {
                            if (value < double.Parse(ConfigurationManager.AppSettings["maxNegativeX"]))
                            {
                                file.negativeXYZ('X');
                            }
                        }
                    }
                    if (line.IndexOf("Y") > -1)
                    {
                        string yblock = line.Substring(line.IndexOf("Y") + 1);
                        if (yblock.IndexOf(" ") > -1)
                        {
                            yblock = yblock.Substring(0, yblock.IndexOf(" "));
                        }
                        if (double.TryParse(yblock, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo("en-US"), out value))
                        {
                            if (value < double.Parse(ConfigurationManager.AppSettings["maxNegativeY"]))
                            {
                                file.negativeXYZ('Y');
                            }
                        }
                    }
                    if (line.IndexOf("Z") > -1)
                    {
                        string zblock = line.Substring(line.IndexOf("Z") + 1);
                        if (zblock.IndexOf(" ") > -1)
                        {
                            zblock = zblock.Substring(0, zblock.IndexOf(" "));
                        }
                        if (double.TryParse(zblock, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo("en-US"), out value))
                        {
                            if (value < double.Parse(ConfigurationManager.AppSettings["maxNegativeZ"]))
                            {
                                file.negativeXYZ('Z');
                            }
                        }
                    }
                }

                i++;
            }

            //Adds a comment to the top line indicating if xyz values are ok
            {
                string status;
                if (file.CheckNegativeXYZ())
                {
                    status = "Warning! negative XYZ values detected";
                }
                else
                {
                    status = "XYZok";
                }

                string line = file.GetLine(0);
                if (line.IndexOf("(") > -1)
                {
                    status = line.Substring(0, line.IndexOf("(") + 1) + status + " " + line.Substring(line.IndexOf("(") + 1);
                    file.UpdateLine(0, status);
                }
                else
                {
                    status = "(" + status + ")";
                    file.UpdateLine(0, status);
                }
            }
            return(file);
        }