Ejemplo n.º 1
0
        /// <summary>
        /// レンズ情報を定義したXMLドキュメントを解析し,フィールド変数に値を設定します.
        /// </summary>
        private void parseCcdXml()
        {
            XmlNodeList nodeList = xmlDocument.GetElementsByTagName("lens");

            LensList = new List <LensStatus>(nodeList.Count);
            for (int i = 0; i < nodeList.Count; ++i)
            {
                LensStatus lens = new LensStatus();
                lens.Magnification
                    = int.Parse(nodeList[i].Attributes["magnification"].Value);
                lens.CcdResolution = new Vector2();
                lens.LensOffset    = new Vector2();
                lens.SpiralShift   = new Vector2();
                bool[] compFlag = new bool[8];
                foreach (XmlElement element in nodeList[i].ChildNodes)
                {
                    double val;
                    switch (element.Name)
                    {
                    case "resolutionX":
                        val = double.Parse(element.InnerText);
                        lens.CcdResolution.X = val;
                        lens.ImageLength.X   = val * ParameterManager.ImageResolution.Width;
                        compFlag[0]          = true;
                        break;

                    case "resolutionY":
                        val = double.Parse(element.InnerText);
                        lens.CcdResolution.Y = val;
                        lens.ImageLength.Y   = val * ParameterManager.ImageResolution.Height;
                        compFlag[1]          = true;
                        break;

                    case "offsetDX":
                        lens.LensOffset.X = double.Parse(element.InnerText);
                        compFlag[2]       = true;
                        break;

                    case "offsetDY":
                        lens.LensOffset.Y = double.Parse(element.InnerText);
                        compFlag[3]       = true;
                        break;

                    case "spiralDX":
                        lens.SpiralShift.X = double.Parse(element.InnerText);
                        compFlag[4]        = true;
                        break;

                    case "spiralDY":
                        lens.SpiralShift.Y = double.Parse(element.InnerText);
                        compFlag[5]        = true;
                        break;

                    case "zStep":
                        lens.ZStep  = double.Parse(element.InnerText);
                        compFlag[6] = true;
                        break;

                    case "gridMarkSize":
                        lens.GridMarkSize = double.Parse(element.InnerText);
                        compFlag[7]       = true;
                        break;

                    case "ledParam":
                        lens.LedParameter = int.Parse(element.InnerText);
                        break;

                    default:
                        break;
                    }
                }
                // 上記switchのすべての項目が読み込まれていなければ例外を投げる.
                if (!isCompLensItems(compFlag))
                {
                    string message =
                        string.Format(Properties.Strings.LensNodeParseException01, ConfigureFile);
                    throw new XmlException(message);
                }
                LensList.Add(lens);
            }
        }
Ejemplo n.º 2
0
        private void parseConfigureFile()
        {
            if (!File.Exists(ConfigureFile))
            {
                throw new FileNotFoundException(ConfigureFile + " is not found. Loading CCD Profile is failed.");
            }

            LensList = new List <LensStatus>();

            StreamReader streamReader = File.OpenText(ConfigureFile);

            streamReader.ReadLine();
            streamReader.ReadLine();

            string line;

            string[] elements;
            bool     continueFlag = true;

            char[] delimiterChars = { ' ', '\t' };
            while (continueFlag)
            {
                line     = streamReader.ReadLine();
                elements = line.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                if (elements.Length > 0)
                {
                    LensStatus lens = new LensStatus();
                    lens.Magnification   = int.Parse(elements[0]);
                    lens.CcdResolution.X = double.Parse(elements[1]);
                    lens.CcdResolution.Y = double.Parse(elements[2]);
                    lens.LensOffset.X    = double.Parse(elements[3]);
                    lens.LensOffset.Y    = double.Parse(elements[4]);
                    lens.SpiralShift.X   = double.Parse(elements[5]);
                    lens.SpiralShift.Y   = double.Parse(elements[6]);
                    lens.ZStep           = double.Parse(elements[7]);
                    lens.ImageLength.X   = lens.CcdResolution.X * ParameterManager.ImageResolution.Width;
                    lens.ImageLength.Y   = lens.CcdResolution.Y * ParameterManager.ImageResolution.Height;
                    switch (lens.Magnification)
                    {
                    case 10:
                        lens.GridMarkSize = 50;
                        lens.LedParameter = 40;
                        break;

                    case 20:
                        lens.GridMarkSize = 110;
                        lens.LedParameter = 40;
                        break;

                    case 50:
                        lens.GridMarkSize = 250;
                        lens.LedParameter = 80;
                        break;

                    default:
                        lens.GridMarkSize = 0;
                        break;
                    }
                    LensList.Add(lens);
                }
                else
                {
                    continueFlag = false;
                }
            }

            streamReader.ReadLine();
            streamReader.ReadLine();

            // スキャン範囲の読み込み
            line     = streamReader.ReadLine();
            elements = line.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
            xm       = double.Parse(elements[0]);
            xp       = double.Parse(elements[1]);
            ym       = double.Parse(elements[2]);
            yp       = double.Parse(elements[3]);
            streamReader.Close();
        }