/// <summary>
        /// changes the new x/y to be a point .1mm away from the original location, away from the next location, to force the knife to turn the right direction before entering the material
        /// </summary>
        /// <param name="entry">Array holding the entry point coordinates</param>
        /// <param name="next">Array holding the next point after entry point</param>
        void InsertNewPoint(double[] entry, double[] next, int i)
        {
            double x1 = entry[0]; double y1 = entry[1];
            double x2 = next[0]; double y2 = next[1];
            //adds a new line with the original x/y coordinates
            string newline = "N" + (file.GetLineBlock(i) + 1) + " " + file.GetCode(i);

            //Finds how much relative x/y should change for newX/newY
            double relativeX = -(x2 - x1);
            double relativeY = -(y2 - y1);
            double changeX; if (relativeX < 0)

            {
                changeX = relativeX / -1;
            }
            else
            {
                changeX = relativeX;
            }
            double changeY; if (relativeY < 0)

            {
                changeY = relativeY / -1;
            }
            else
            {
                changeY = relativeY;
            }

            if (changeX > changeY)
            {
                relativeY = relativeY / Math.Abs(relativeX) * .1;
                relativeX = relativeX / Math.Abs(relativeX) * .1;
            }
            else
            {
                relativeX = relativeX / Math.Abs(relativeY) * .1;
                relativeY = relativeY / Math.Abs(relativeY) * .1;
            }

            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";
            string line = "N" + file.GetLineBlock(i) + " G00 X";
            double temp = Math.Round((x1 + relativeX), 3);

            line = line + file.DoubleToString(temp) + " Y";
            temp = Math.Round((y1 + relativeY), 3);
            line = line + file.DoubleToString(temp);

            line = line + "\r\n" + newline;
            file.UpdateLine(i, line);
        }
Example #2
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);
        }
Example #3
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 #4
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);
        }