Exemplo n.º 1
0
        public void Analyze()
        {
            //获得参数的个数。
            QLineInfo line = GetPram("K0100");

            //默认为-1,如果没读取值还是-1.
            int count = -1;

            if (line != null)
            {
                count = int.Parse(line.value);
                for (int j = 0; j < count; j++)
                {
                    Charactericstics.Add(new QCharacteristic());
                }
            }

            //小于0的话就退出。
            if (count < 0)
            {
                return;
            }

            //对每一个参数进行初始化。
            for (int i = 0; i < Lines.Count; i++)
            {
                line = Lines[i];
                int id = line.pid;

                if (id > 0)
                {
                    QCharacteristic p = Charactericstics[id - 1];
                    p.DealLine(line);
                }
            }

            //参数进行调整
            for (int i = 0; i < Charactericstics.Count; i++)
            {
                //pramters[i].Adjust();
            }

            //对数据进行调整,移除第1个参数为256的项。
            for (int i = 0; i < Data.Count; i++)
            {
                QData qd = Data[i];
                for (int j = 0; j < qd.items.Count; j++)
                {
                    if (!qd.items[j].addon[1].Equals("256"))
                    {
                        Charactericstics[j].data.Add(qd.items[j]);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static QFile LoadFromStrings(string[] data)
        {
            QFile qf = new QFile();

            //开始默认加载100个参数,方便下面的ps[line.pid - 1]的调用
            List <QCharacteristic> ps = new List <QCharacteristic>();

            for (int i = 0; i < 100; i++)
            {
                ps.Add(new QCharacteristic());
            }

            // 文件读取部分,完成了以下几件事:
            // 1、读取每行,生成每行的QLineInfo对象
            // 2、先交给对应的参数处理,如果处理失败,再交给QFile处理
            // 3、如果不是QlineInfo对象,那么交给QFile的Data


            for (int i = 0; i < data.Length; i++)
            {
                string s = data[i];

                if (s == null || s.Length == 0)
                {
                    continue;
                }

                if (s[s.Length - 1] == '\r')
                {
                    s = s.Substring(0, s.Length - 1);
                }

                //如果是K开头,那么就是定义,如果是‘/’那么就是注释,取消,否则就是数据。
                if (s[0] == 'K' || s[0] == 'k')
                {
                    QLineInfo line = new QLineInfo(s);

                    //如果是零配件信息,交由QF处理。
                    if (s[1] == '1')
                    {
                        qf.DealLine(line);
                    }
                    //否则是参数信息,交由参数层处理
                    else if (line.pid > 0)
                    {
                        QCharacteristic p = ps[line.pid - 1];
                        p.DealLine(line);
                    }
                }
                //如果是/,那么就是注释,忽略。
                else if (s[0] == '/')
                {
                }
                else
                {
                    qf.Data.Add(new QData(s));
                }
            }


            //取出生成的参数,添加至QFile中
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].id > 0)
                {
                    qf.Charactericstics.Add(ps[i]);
                }
            }

            //此处将QFile中的Data中的DataItem与
            //每个QPramater的QDataItem数据组一一对应。
            for (int i = 0; i < qf.Data.Count; i++)
            {
                for (int j = 0; j < qf.Data[i].items.Count; j++)
                {
                    qf.Charactericstics[j].data.Add(qf.Data[i].items[j]);
                }
            }

            return(qf);
        }