Ejemplo n.º 1
0
 private void gcode2()
 {
     line line;
     this.liy.Clear();
     using (StringReader reader = new StringReader(this.yuan))
     {
         char[] separator = new char[] { 'X', ' ', 'Y', 'F' };
         char[] chArray2 = new char[] { 'X', ' ', 'F' };
         char[] chArray3 = new char[] { 'Y', ' ', 'F' };
         char[] chArray4 = new char[] { 'X', ' ', 'Y', 'F', 'I', 'J' };
         char[] chArray5 = new char[] { 'X', ' ', 'Y', 'F', 'R' };
         while (reader.Peek() >= 0)
         {
             float num;
             int num2;
             string[] strArray;
             string source = reader.ReadLine().Replace(',', '.');
             if (source.StartsWith("G01 ") || source.StartsWith("G1 "))
             {
                 if (source.Contains<char>('X'))
                 {
                     if (source.Contains<char>('Y'))
                     {
                         line = new line {
                             lx = 1
                         };
                         strArray = source.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                         num = float.Parse(strArray[1], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.x = num2;
                         num = float.Parse(strArray[2], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.y = num2;
                         this.liy.Add(line);
                     }
                     else
                     {
                         line = new line {
                             lx = 1
                         };
                         num = float.Parse(source.Split(chArray2, StringSplitOptions.RemoveEmptyEntries)[1], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.x = num2;
                         line.y = this.liy[this.liy.Count - 1].y;
                         this.liy.Add(line);
                     }
                 }
                 else if (source.Contains<char>('Y'))
                 {
                     line = new line {
                         lx = 1
                     };
                     num = float.Parse(source.Split(chArray3, StringSplitOptions.RemoveEmptyEntries)[1], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     line.y = num2;
                     line.x = this.liy[this.liy.Count - 1].x;
                     this.liy.Add(line);
                 }
             }
             else if (source.StartsWith("G02 ") || source.StartsWith("G2 "))
             {
                 if (source.Contains<char>('R'))
                 {
                     line = new line {
                         lx = 1
                     };
                     strArray = source.Split(chArray5, StringSplitOptions.RemoveEmptyEntries);
                     this.xpo = this.liy[this.liy.Count - 1].x;
                     this.ypo = this.liy[this.liy.Count - 1].y;
                     num = float.Parse(strArray[1], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hx = num2;
                     num = float.Parse(strArray[2], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hy = num2;
                     num = float.Parse(strArray[3], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hi = num2;
                     line.x = this.hx;
                     line.y = this.hy;
                     this.liy.Add(line);
                 }
                 else
                 {
                     strArray = source.Split(chArray4, StringSplitOptions.RemoveEmptyEntries);
                     this.xpo = this.liy[this.liy.Count - 1].x;
                     this.ypo = this.liy[this.liy.Count - 1].y;
                     num = float.Parse(strArray[1], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hx = num2;
                     num = float.Parse(strArray[2], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hy = num2;
                     num = float.Parse(strArray[3], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hi = num2;
                     num = float.Parse(strArray[4], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hj = num2;
                     this.qdx = this.liy[this.liy.Count - 1].x;
                     this.qdy = this.liy[this.liy.Count - 1].y;
                     this.yxx = this.qdx + this.hi;
                     this.yxy = this.qdy + this.hj;
                     this.NR = 0;
                     this.yhcb(this.qdx - this.yxx, this.qdy - this.yxy, this.hx - this.yxx, this.hy - this.yxy);
                 }
             }
             else if (source.StartsWith("G03 ") || source.StartsWith("G3 "))
             {
                 if (source.Contains<char>('R'))
                 {
                     line = new line {
                         lx = 1
                     };
                     strArray = source.Split(chArray5, StringSplitOptions.RemoveEmptyEntries);
                     this.xpo = this.liy[this.liy.Count - 1].x;
                     this.ypo = this.liy[this.liy.Count - 1].y;
                     num = float.Parse(strArray[1], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hx = num2;
                     num = float.Parse(strArray[2], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hy = num2;
                     num = float.Parse(strArray[3], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hi = num2;
                     line.x = this.hx;
                     line.y = this.hy;
                     this.liy.Add(line);
                 }
                 else
                 {
                     strArray = source.Split(chArray4, StringSplitOptions.RemoveEmptyEntries);
                     this.xpo = this.liy[this.liy.Count - 1].x;
                     this.ypo = this.liy[this.liy.Count - 1].y;
                     num = float.Parse(strArray[1], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hx = num2;
                     num = float.Parse(strArray[2], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hy = num2;
                     num = float.Parse(strArray[3], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hi = num2;
                     num = float.Parse(strArray[4], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     this.hj = num2;
                     this.qdx = this.liy[this.liy.Count - 1].x;
                     this.qdy = this.liy[this.liy.Count - 1].y;
                     this.yxx = this.qdx + this.hi;
                     this.yxy = this.qdy + this.hj;
                     this.NR = 1;
                     this.yhcb(this.qdx - this.yxx, this.qdy - this.yxy, this.hx - this.yxx, this.hy - this.yxy);
                 }
             }
             else if (source.StartsWith("G00") || source.StartsWith("G0 "))
             {
                 if (source.Contains<char>('X'))
                 {
                     if (source.Contains<char>('Y'))
                     {
                         line = new line {
                             lx = 0
                         };
                         strArray = source.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                         num = float.Parse(strArray[1], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.x = num2;
                         num = float.Parse(strArray[2], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.y = num2;
                         this.liy.Add(line);
                     }
                     else
                     {
                         line = new line {
                             lx = 0
                         };
                         num = float.Parse(source.Split(chArray2, StringSplitOptions.RemoveEmptyEntries)[1], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.x = num2;
                         line.y = this.liy[this.liy.Count - 1].y;
                         this.liy.Add(line);
                     }
                 }
                 else if (source.Contains<char>('Y'))
                 {
                     line = new line {
                         lx = 0
                     };
                     num = float.Parse(source.Split(chArray3, StringSplitOptions.RemoveEmptyEntries)[1], this.nfi) * this.fd;
                     num2 = (int) Math.Round((double) num);
                     line.y = num2;
                     line.x = this.liy[this.liy.Count - 1].x;
                     this.liy.Add(line);
                 }
             }
             else if (source.Contains<char>('X'))
             {
                 if (this.liy.Count > 0)
                 {
                     if (source.Contains<char>('Y'))
                     {
                         line = new line {
                             lx = this.liy[this.liy.Count - 1].lx
                         };
                         strArray = source.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                         num = float.Parse(strArray[0], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.x = num2;
                         num = float.Parse(strArray[1], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.y = num2;
                         this.liy.Add(line);
                     }
                     else
                     {
                         line = new line {
                             lx = this.liy[this.liy.Count - 1].lx
                         };
                         num = float.Parse(source.Split(chArray2, StringSplitOptions.RemoveEmptyEntries)[0], this.nfi) * this.fd;
                         num2 = (int) Math.Round((double) num);
                         line.x = num2;
                         line.y = this.liy[this.liy.Count - 1].y;
                         this.liy.Add(line);
                     }
                 }
             }
             else if (source.Contains<char>('Y') && (this.liy.Count > 0))
             {
                 line = new line {
                     lx = this.liy[this.liy.Count - 1].lx
                 };
                 num = float.Parse(source.Split(chArray3, StringSplitOptions.RemoveEmptyEntries)[0], this.nfi) * this.fd;
                 num2 = (int) Math.Round((double) num);
                 line.y = num2;
                 line.x = this.liy[this.liy.Count - 1].x;
                 this.liy.Add(line);
             }
         }
     }
     if (this.liy.Count > 0)
     {
         while (this.liy[this.liy.Count - 1].lx == 0)
         {
             if ((this.liy[this.liy.Count - 1].x == 0) || (this.liy[this.liy.Count - 1].y == 0))
             {
                 this.liy.RemoveAt(this.liy.Count - 1);
             }
             else
             {
                 break;
             }
         }
         this.bianjie(ref this.liy);
         this.ymaxx = this.maxx;
         this.ymaxy = this.maxy;
         this.yminx = this.minx;
         this.yminy = this.miny;
         this.li.Clear();
         foreach (line line2 in this.liy)
         {
             line = new line {
                 lx = line2.lx,
                 x = line2.x,
                 y = line2.y
             };
             this.li.Add(line);
         }
     }
 }
Ejemplo n.º 2
0
        private void yhcb(int xs, int ys, int xe, int ye)
        {
            line line;
            bool flag;
            byte num2 = 0;
            int num3 = 0;
            this.XS = xs;
            this.YS = ys;
            this.FM = 0;
            byte num = this.weizhi(this.XS, this.YS);
            this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
            this.XS = Math.Abs(this.XS);
            this.YS = Math.Abs(this.YS);
            xe = Math.Abs(xe);
            ye = Math.Abs(ye);
            this.R = (this.XS * this.XS) + (this.YS * this.YS);
            if (this.R > 0x22551000)
            {
                this.yhfd = this.yhsz[0x11];
            }
            else if (this.R > 0x1de84000)
            {
                this.yhfd = this.yhsz[0x11];
            }
            else if (this.R > 0x19c99000)
            {
                this.yhfd = this.yhsz[0x10];
            }
            else if (this.R > 0x15f90000)
            {
                this.yhfd = this.yhsz[15];
            }
            else if (this.R > 0x12769000)
            {
                this.yhfd = this.yhsz[14];
            }
            else if (this.R > 0xf424000)
            {
                this.yhfd = this.yhsz[13];
            }
            else if (this.R > 0xc5c1000)
            {
                this.yhfd = this.yhsz[12];
            }
            else if (this.R > 0x9c40000)
            {
                this.yhfd = this.yhsz[11];
            }
            else if (this.R > 0x77a1000)
            {
                this.yhfd = this.yhsz[10];
            }
            else if (this.R > 0x57e4000)
            {
                this.yhfd = this.yhsz[9];
            }
            else if (this.R > 0x3d09000)
            {
                this.yhfd = this.yhsz[8];
            }
            else if (this.R > 0x2710000)
            {
                this.yhfd = this.yhsz[7];
            }
            else if (this.R > 0x15f9000)
            {
                this.yhfd = this.yhsz[6];
            }
            else if (this.R > 0x9c4000)
            {
                this.yhfd = this.yhsz[5];
            }
            else if (this.R > 0x271000)
            {
                this.yhfd = this.yhsz[4];
            }
            else if (this.R > 0x9c400)
            {
                this.yhfd = this.yhsz[3];
            }
            else if (this.R > 0x27100)
            {
                this.yhfd = this.yhsz[2];
            }
            else if (this.R > 0x1900)
            {
                this.yhfd = this.yhsz[1];
            }
            else
            {
                this.yhfd = this.yhsz[0];
            }
            goto Label_079B;
        Label_0436:
            this.n--;
            if (this.n == 0)
            {
                line = new line {
                    lx = 1,
                    x = this.hx,
                    y = this.hy
                };
                this.liy.Add(line);
                return;
            }
            if (this.NR == 1)
            {
                if ((num == 1) && (this.XS == 0))
                {
                    num = 2;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
                if ((num == 2) && (this.YS == 0))
                {
                    num = 3;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
                if ((num == 3) && (this.XS == 0))
                {
                    num = 4;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
                if ((num == 4) && (this.YS == 0))
                {
                    num = 1;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
            }
            if (this.NR == 0)
            {
                if ((num == 5) && (this.YS == 0))
                {
                    num = 8;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
                if ((num == 8) && (this.XS == 0))
                {
                    num = 7;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
                if ((num == 7) && (this.YS == 0))
                {
                    num = 6;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
                if ((num == 6) && (this.XS == 0))
                {
                    num = 5;
                    num2 = (byte) (num2 + 1);
                    this.n = Math.Abs((int) (xe - this.XS)) + Math.Abs((int) (ye - this.YS));
                }
            }
            if (num2 > 3)
            {
                line = new line {
                    lx = 1,
                    x = this.hx,
                    y = this.hy
                };
                this.liy.Add(line);
                return;
            }
            num3++;
            if (num3 == this.yhfd)
            {
                num3 = 0;
                line = new line {
                    lx = 1,
                    x = this.xpo,
                    y = this.ypo
                };
                this.liy.Add(line);
            }
        Label_079B:
            flag = true;
            switch (num)
            {
                case 1:
                    this.xoy1y();
                    goto Label_0436;

                case 2:
                    this.xoy2y();
                    goto Label_0436;

                case 3:
                    this.xoy3y();
                    goto Label_0436;

                case 4:
                    this.xoy4y();
                    goto Label_0436;

                case 5:
                    this.xoy5y();
                    goto Label_0436;

                case 6:
                    this.xoy6y();
                    goto Label_0436;

                case 7:
                    this.xoy7y();
                    goto Label_0436;

                case 8:
                    this.xoy8y();
                    goto Label_0436;

                default:
                    goto Label_0436;
            }
        }
Ejemplo n.º 3
0
 private void ci()
 {
     this.lic.Clear();
     int num = (int) this.cinum.Value;
     int num2 = 0;
     bool flag = false;
     int num3 = 0;
     int num4 = 0;
     int num7 = 0;
     int num8 = this.li.Count - 1;
     for (int i = 0; i < this.li.Count; i++)
     {
         int num5;
         int num6;
         line line;
         if (this.li[i].lx == 1)
         {
             flag = true;
         }
         if (i == num8)
         {
             num4 = num3;
             num3 = i + 1;
             if ((num3 != num4) && flag)
             {
                 flag = false;
                 line = new line {
                     lx = this.li[num4].lx,
                     x = this.li[num4].x,
                     y = this.li[num4].y
                 };
                 this.lic.Add(line);
                 num2 = num3 - num4;
                 num2--;
                 num2 *= num;
                 num5 = num4 + 1;
                 num6 = num3 - 1;
                 num7 = 0;
                 while (num2 != 0)
                 {
                     if (num7 == 0)
                     {
                         line = new line {
                             lx = 1,
                             x = this.li[num5].x,
                             y = this.li[num5].y
                         };
                         this.lic.Add(line);
                         if (num5 == (num3 - 1))
                         {
                             num7 = 1;
                             num5--;
                         }
                         else
                         {
                             num5++;
                         }
                         num2--;
                     }
                     else
                     {
                         line = new line {
                             lx = 1,
                             x = this.li[num5].x,
                             y = this.li[num5].y
                         };
                         this.lic.Add(line);
                         if (num5 == num4)
                         {
                             num7 = 0;
                             num5++;
                         }
                         else
                         {
                             num5--;
                         }
                         num2--;
                     }
                 }
             }
         }
         if (this.li[i].lx == 0)
         {
             num4 = num3;
             num3 = i;
             if ((num3 != num4) && flag)
             {
                 flag = false;
                 line = new line {
                     lx = this.li[num4].lx,
                     x = this.li[num4].x,
                     y = this.li[num4].y
                 };
                 this.lic.Add(line);
                 num2 = num3 - num4;
                 num2--;
                 num2 *= num;
                 num5 = num4 + 1;
                 num6 = num3 - 1;
                 num7 = 0;
                 while (num2 != 0)
                 {
                     if (num7 == 0)
                     {
                         line = new line {
                             lx = 1,
                             x = this.li[num5].x,
                             y = this.li[num5].y
                         };
                         this.lic.Add(line);
                         if (num5 == (num3 - 1))
                         {
                             num7 = 1;
                             num5--;
                         }
                         else
                         {
                             num5++;
                         }
                         num2--;
                     }
                     else
                     {
                         line = new line {
                             lx = 1,
                             x = this.li[num5].x,
                             y = this.li[num5].y
                         };
                         this.lic.Add(line);
                         if (num5 == num4)
                         {
                             num7 = 0;
                             num5++;
                         }
                         else
                         {
                             num5--;
                         }
                         num2--;
                     }
                 }
             }
         }
     }
 }