コード例 #1
0
ファイル: PuzzleStructure.cs プロジェクト: nanma80/MPUlt
        private void FillFromStrings(string[] descr)
        {
            int       naxis = 0;
            int       caxis = 0;
            PBaseAxis ax    = null;
            int       state = 0;
            int       nv;
            int       fline = 0;

            QSimplified = false;
            try {
                while (state >= 0)
                {
                    if (fline == descr.Length)
                    {
                        if (state != 7)
                        {
                            throw new Exception("Unexpected end");
                        }
                        break;
                    }
                    string line = descr[fline++];
                    if (line == "" || line == null || line[0] == '#')
                    {
                        continue;
                    }
                    string[] str = line.Split(' ', '\t');
                    if (str.Length == 0 || str[0] == "" || str[0] == null)
                    {
                        continue;
                    }
                    string cmd = str[0].ToLowerInvariant();
                    switch (state)
                    {
                    case 0:
                        if (cmd != "dim")
                        {
                            throw new Exception("'Dim' required");
                        }
                        Dim = int.Parse(str[1]);
                        break;

                    case 1:
                        if (cmd != "naxis")
                        {
                            throw new Exception("'NAxis' required");
                        }
                        naxis    = int.Parse(str[1]);
                        BaseAxes = new PBaseAxis[naxis];
                        break;

                    case 2:
                        if (cmd != "faces")
                        {
                            throw new Exception("'Faces' required");
                        }
                        nv        = str.Length - 1;
                        BaseFaces = new PBaseFace[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            BaseFaces[i] = new PBaseFace(GetVector(str[i + 1], Dim));
                        }
                        break;

                    case 3:
                        if (cmd == "simplified")
                        {
                            QSimplified = true; state--; break;
                        }
                        if (cmd != "group")
                        {
                            throw new Exception("'Group' required");
                        }
                        nv    = str.Length - 1;
                        Group = new double[nv][];
                        for (int i = 0; i < nv; i++)
                        {
                            Group[i] = GetVector(str[i + 1], 2 * Dim);
                            PGeom.GetOrder(Group[i]);
                        }
                        if (naxis == 0)
                        {
                            state = -2;
                        }
                        break;

                    case 4:
                        if (cmd != "axis")
                        {
                            throw new Exception("'Axis' required");
                        }
                        ax = new PBaseAxis(GetVector(str[1], Dim));
                        break;

                    case 5:
                        if (cmd != "twists")
                        {
                            throw new Exception("'Twists' required");
                        }
                        nv        = str.Length - 1;
                        ax.Twists = new PBaseTwist[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            ax.Twists[i] = new PBaseTwist(GetVector(str[i + 1], 2 * Dim));
                        }
                        break;

                    case 6:
                        if (cmd != "cuts")
                        {
                            throw new Exception("'Cuts' required");
                        }
                        nv     = str.Length - 1;
                        ax.Cut = new double[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            ax.Cut[i] = double.Parse(str[i + 1], CultureInfo.InvariantCulture);
                        }
                        ax.AdjustCuts();
                        BaseAxes[caxis++] = ax;
                        ax = null;
                        break;

                    case 7: {
                        if (cmd == "fixedmask")
                        {
                            BaseAxes[caxis - 1].FixedMask = int.Parse(str[1]);
                            if (caxis == naxis)
                            {
                                state = -2;
                            }
                            else
                            {
                                state = 3;
                            }
                            break;
                        }
                        if (caxis != naxis)
                        {
                            state = 4; goto case 4;
                        }
                        state = -2;
                        break;
                    }
                    }
                    state++;
                }
            } catch (Exception e) {
                throw new Exception("Error: " + e.Message + " in line " + fline + ": " + (descr[fline] ?? "{null}"));
            }
        }
コード例 #2
0
ファイル: PuzzleParts.cs プロジェクト: nanma80/MPUlt
 internal PBaseTwist(double[] dir)
 {
     Dir   = dir;
     Order = PGeom.GetOrder(Dir);
 }