Example #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);
        }
        public KnifeDirection(NCFile[] files)
        {
            int i = 0;

            while (i < files.Length)
            {
                file = files[i];
                if (!files[i].PreviousPPP)
                {
                    DetectRapidMovement();
                }
                i++;
            }
        }
Example #3
0
        public LongArcFixer(NCFile[] files)
        {
            int i = 0;

            while (i < files.Length)
            {
                if (!files[i].PreviousPPP)
                {
                    file = files[i];
                    file = DetectLongArc(file);
                }
                i++;
            }
        }
Example #4
0
        /// <summary>
        /// Gets a list of all the *.nc files in the apps directory, for further processing
        /// </summary>
        public FileManager()
        {
            Console.WriteLine("Finding files...");
            String[]      fl       = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.nc");
            List <string> fileList = new List <string>();
            int           i        = 0;

            while (i < fl.Length)
            {
                string s = Path.GetFileNameWithoutExtension(fl[i]);
                int    number;
                if (int.TryParse(s, out number))
                {
                    if (number < 2000)
                    {
                        fileList.Add(fl[i]);
                    }
                }
                i++;
            }

            if (fileList.Count > 0)
            {
                Console.WriteLine("Found " + fileList.Count + " .nc files:");
                i = 0;
                while (i < fileList.Count)
                {
                    fileList[i] = Path.GetFileName(fileList[i]);
                    Console.Write(fileList[i] + ", ");
                    i++;
                }
                Console.WriteLine();
                files = new NCFile[fileList.Count];
                i     = 0;
                while (i < fileList.Count)
                {
                    files[i] = new NCFile(fileList[i]);
                    i++;
                }
            }
        }
Example #5
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);
        }
Example #6
0
        NCFile DetectLongArc(NCFile file)
        {
            int i = 0; double[][] whereAmINow = new double[5][]; //[][0]=X, [][1]=Y, [][2]=Z, [][3]=F, [][4]=A, [][5]=R, [][6]=movement type, [][7]=line number in the file

            while (i < file.AmountLines())
            {
                if (file.CheckLineBlock(i))
                {
                    string line = file.GetCode(i);
                    whereAmINow = GetLocation(line, whereAmINow, i);
                    if (line.Contains("A"))
                    {
                        double startA = SharedMethods.DetectStartingDirectionOfArc(whereAmINow);
                        double endA   = GetValue(line, 'A');
                        double changed;
                        if (whereAmINow[0][6] == 2)
                        {   // turn clockwise
                            changed = startA - endA;
                            if (changed < 0)
                            {
                                changed = startA + (360 - endA);
                            }
                        }
                        else
                        {   // turn counter clockwise
                            changed = endA - startA;
                            if (changed < 0)
                            {
                                changed = endA + (360 - startA);
                            }
                        }
                        string newLine = ""; int blockNumber = file.GetLineBlock(i);
                        if (changed > 359)
                        {
                            blockNumber -= 3;
                        }                                        //      changes starting block number to correspond to amount of new lines being added
                        else if (changed > 269)
                        {
                            blockNumber -= 2;
                        }                                            //  infront of the line being examined
                        else if (changed > 179)
                        {
                            blockNumber -= 1;
                        }

                        double[] d = SharedMethods.DetectArcSenter(whereAmINow);//[0]=x, [1]=y
                        if (changed > 179)
                        {
                            while (true)
                            {
                                if (changed > 179)
                                {
                                    double x = d[0]; double y = d[1]; double newAngle;
                                    if (whereAmINow[0][6] == 2)
                                    {   // turn clockwise
                                        if (startA <= 90)
                                        {
                                            newAngle = 0; y += whereAmINow[0][5];
                                        }
                                        else if (startA <= 180)
                                        {
                                            newAngle = 90; x -= whereAmINow[0][5];
                                        }
                                        else if (startA <= 270)
                                        {
                                            newAngle = 180; y -= whereAmINow[0][5];
                                        }
                                        else
                                        {
                                            newAngle = 270; x += whereAmINow[0][5];
                                        }
                                    }
                                    else
                                    {   // turn counter clockwise
                                        if (startA >= 270)
                                        {
                                            newAngle = 0; y -= whereAmINow[0][5];
                                        }
                                        else if (startA >= 180)
                                        {
                                            newAngle = 270; x -= whereAmINow[0][5];
                                        }
                                        else if (startA >= 90)
                                        {
                                            newAngle = 180; y += whereAmINow[0][5];
                                        }
                                        else
                                        {
                                            newAngle = 90; x += whereAmINow[0][5];
                                        }
                                    }
                                    newLine = newLine + "N" + blockNumber + " G0" + Convert.ToInt32(whereAmINow[0][6]) + " X" + file.DoubleToString(x) + " Y" +
                                              file.DoubleToString(y) + " A" + file.DoubleToString(newAngle) + " R" + file.DoubleToString(whereAmINow[0][5]);
                                    if (!newLine.Contains("F"))
                                    {
                                        newLine = newLine + " F" + file.DoubleToString(whereAmINow[0][3]);
                                    }
                                    newLine = newLine + "\n";
                                    blockNumber++; changed -= 90;
                                    startA = newAngle;
                                }
                                else
                                {
                                    string oldLine = "N" + Convert.ToString(file.GetLineBlock(i)) + " X" + file.DoubleToString(whereAmINow[0][0]) + " Y" + file.DoubleToString(whereAmINow[0][1])
                                                     + " A" + file.DoubleToString(whereAmINow[0][4]) + " R" + file.DoubleToString(whereAmINow[0][5]);
                                    newLine = newLine + oldLine;
                                    file.UpdateLine(i, newLine);
                                    break;
                                }
                            }
                        }
                    }
                }
                i++;
            }
            file.RebuildLines();
            return(file);
        }