Exemplo n.º 1
0
 // a = +1 if press button plus and a = -1 if press minus
 private void PlusOrMinusParametr(int a)
 {
     if (inputInfoMode)
     {
         TrainParametrs[inputInfoParametr] += a;
         Klub_u.SetInfo(InputInfoParametrs[inputInfoParametr] + " - " + TrainParametrs[inputInfoParametr].ToString() + " ");
     }
     else if (inputPathMode)
     {
         PathNumber += (byte)a;
         Klub_u.SetInfo("Номер пути = " + PathNumber.ToString() + " ");
     }
     else if (inputPathCorrectnessMode)
     {
         CorrectPath = !CorrectPath;
         Klub_u.SetInfo("Признак правильности пути = " + (CorrectPath ? "1" : "0") + " ");
     }
 }
Exemplo n.º 2
0
 public override void PressButtonP()
 {
     if (inputPathMode)
     {
         NextInputPath();
     }
     else
     {
         if (inputPathCorrectnessMode)
         {
             NextInputPathCorrectness();
         }
         else
         {
             inputCommandMode = false;
             inputInfoMode    = false;
             inputPathMode    = true;
             Klub_u.SetInfo("Номер пути = " + PathNumber.ToString() + " ");
         }
     }
 }
Exemplo n.º 3
0
 private void PressNumberButtonN(byte n)
 {
     if (inputInfoMode)
     {
         TrainParametrs[inputInfoParametr] = TrainParametrs[inputInfoParametr] * 10 + n;
         Klub_u.SetInfo(InputInfoParametrs[inputInfoParametr] + " - " + TrainParametrs[inputInfoParametr].ToString() + " ");
     }
     else if (inputPathMode)
     {
         PathNumber = (byte)(PathNumber * 10 + n);
         Klub_u.SetInfo("Номер пути = " + PathNumber.ToString() + " ");
     }
     else if (inputPathCorrectnessMode)
     {
         CorrectPath = n == 1;
         Klub_u.SetInfo("Признак правильности пути = " + (CorrectPath ? "1" : "0") + " ");
     }
     else
     {
         inputNumberTool.AddSimvol(n);
     }
 }
Exemplo n.º 4
0
        //判断一种类型的数据是不是读取完了,如对于M类型,后面跟两个数据
        private static bool isEndOfOneTypeNumber(PathNumber pathNumber, ref int currentIndex)
        {
            bool isEnd = false;

            switch (pathNumber.Type)
            {
            case "M":
            case "m":
            case "L":
            case "l":
            {
                if (pathNumber.Numbers.Count() == 2)
                {
                    currentIndex++;
                    isEnd = true;
                }
                break;
            }

            case "H":
            case "h":
            case "V":
            case "v":
            {
                if (pathNumber.Numbers.Count() == 1)
                {
                    currentIndex++;
                    isEnd = true;
                }
                break;
            }

            case "C":
            case "c":
            {
                if (pathNumber.Numbers.Count() == 6)
                {
                    currentIndex++;
                    isEnd = true;
                }
                break;
            }

            case "S":
            case "s":
            case "Q":
            case "q":
            case "T":
            case "t":
            {
                if (pathNumber.Numbers.Count() == 4)
                {
                    currentIndex++;
                    isEnd = true;
                }
                break;
            }

            case "A":
            case "a":
            {
                if (pathNumber.Numbers.Count() == 5)
                {
                    currentIndex++;
                    isEnd = true;
                }
                break;
            }
            }

            return(isEnd);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parse a number from an SVG path.  path值对应的只有一个M/m,如果有多个,数据
        /// 处理不了,需要手动转换
        /// </summary>
        /// <param name="path">path 对应的element中d所对应的值</param>
        /// <returns></returns>
        public static List <PathNumber> transferPathToNumber(string path)
        {
            var currentIndex = 1;

            var startIndex = currentIndex;
            var endIndex   = path.Length;

            List <PathNumber> pathNumbers = new List <PathNumber>();

            //跳过字符串中的空格位置
            skipOptionalSpaces(path, ref currentIndex, endIndex);

            while (currentIndex < endIndex)
            {
                PathNumber pathNumber = new PathNumber();
                pathNumber.Numbers = new List <double>();
                pathNumber.Type    = path[currentIndex - 1].ToString();


                do
                {
                    var     exponent      = 0; //指数
                    var     integer       = 0; //整数
                    var     frac          = 1;
                    decimal decimalNumber = 0; //小数
                    var     sign          = 1; //符号
                    var     expsign       = 1;
                    // Read the sign.
                    if (currentIndex < endIndex && path[currentIndex] == '+')
                    {
                        currentIndex++;
                    }
                    else if (currentIndex < endIndex && path[currentIndex] == '-')
                    {
                        currentIndex++;
                        sign = -1;
                    }

                    if (currentIndex == endIndex || ((path[currentIndex] < '0' || path[currentIndex] > '9') && path[currentIndex] != '.'))
                    {
                        // The first character of a number must be one of [0-9+-.].
                        return(null);
                    }

                    // Read the integer part, build right-to-left.
                    var startIntPartIndex = currentIndex;
                    while (currentIndex < endIndex && path[currentIndex] >= '0' && path[currentIndex] <= '9')
                    {
                        currentIndex++; // Advance to first non-digit.
                    }
                    if (currentIndex != startIntPartIndex)
                    {
                        var scanIntPartIndex = currentIndex - 1;
                        var multiplier       = 1;
                        while (scanIntPartIndex >= startIntPartIndex)
                        {
                            integer    += multiplier * (path[scanIntPartIndex--] - '0');
                            multiplier *= 10;
                        }
                    }

                    // Read the decimals.
                    if (currentIndex < endIndex && path[currentIndex] == '.')
                    {
                        currentIndex++;

                        // There must be a least one digit following the .
                        if (currentIndex >= endIndex || path[currentIndex] < '0' || path[currentIndex] > '9')
                        {
                            return(null);
                        }
                        while (currentIndex < endIndex && path[currentIndex] >= '0' && path[currentIndex] <= '9')
                        {
                            frac          *= 10;
                            decimalNumber += (decimal)(path[currentIndex] - '0') / frac;
                            currentIndex  += 1;
                        }
                    }

                    // Read the exponent part.
                    if (currentIndex != startIndex && currentIndex + 1 < endIndex && (path[currentIndex] == 'e' || path[currentIndex] == 'E') && (path[currentIndex + 1] != 'x' && path[currentIndex + 1] != 'm'))
                    {
                        currentIndex++;

                        // Read the sign of the exponent.
                        if (path[currentIndex] == '+')
                        {
                            currentIndex++;
                        }
                        else if (path[currentIndex] == '-')
                        {
                            currentIndex++;
                            expsign = -1;
                        }

                        // There must be an exponent.
                        if (currentIndex >= endIndex || path[currentIndex] < '0' || path[currentIndex] > '9')
                        {
                            return(null);
                        }

                        while (currentIndex < endIndex && path[currentIndex] >= '0' && path[currentIndex] <= '9')
                        {
                            exponent *= 10;
                            exponent += (path[currentIndex] - '0');
                            currentIndex++;
                        }
                    }

                    var number = integer + decimalNumber;
                    number *= sign;

                    if (exponent > 0)
                    {
                        number *= (decimal)Math.Pow(10, expsign * exponent);
                    }

                    if (startIndex == currentIndex)
                    {
                        return(null);
                    }
                    pathNumber.Numbers.Add((double)number);
                    skipOptionalSpacesOrDelimiter(path, ref currentIndex, endIndex);
                } while (!isEndOfOneTypeNumber(pathNumber, ref currentIndex));
                pathNumbers.Add(pathNumber);
            }

            if (path[endIndex - 1] == 'Z' || path[endIndex - 1] == 'z')
            {
                PathNumber pathNumber = new PathNumber();
                pathNumber.Type = path[endIndex - 1].ToString();
                pathNumbers.Add(pathNumber);
            }
            return(pathNumbers);
        }