Ejemplo n.º 1
0
        public void Permute()
        {
            this.Strands.Clear();
            if (_permutationLevel < _sourceInputKrystal.Level)
            {
                this.Strands.Clear();
                foreach (PermutationNode pn in _permutationNodeList)
                {
                    Debug.Assert(pn.SourceStrandNumber > 0 && pn.SourceStrandNumber <= _sourceInputKrystal.Strands.Count);

                    this.Strands.Add(_sourceInputKrystal.Strands[pn.SourceStrandNumber - 1]);
                }
            }
            else // _permutationLevel == _sourceInputKrystal.Level
            {
                for (int i = 0; i < _sourceInputKrystal.Strands.Count; i++)
                {
                    PermutationNode pn      = this._permutationNodeList[i];
                    Strand          strand  = _sourceInputKrystal.Strands[i];
                    int             density = strand.Values.Count;
                    int[]           contour = K.Contour(density, pn.Contour, pn.Axis);
                    if (_sortFirst)
                    {
                        strand.Values.Sort();
                    }
                    Strand newStrand = new Strand(strand.Level);
                    for (int j = 0; j < density; j++)
                    {
                        newStrand.Values.Add(strand.Values[contour[j] - 1]);
                    }
                    this.Strands.Add(newStrand);
                }
            }
            this.Update(Strands);
        }
Ejemplo n.º 2
0
        public PermutationTreeView(TreeView treeView, PermutationKrystal pk)
        {
            _treeView = treeView;
            int dKrystalLevel = (int)pk.Level - 1;

            #region line krystal inputs
            if (dKrystalLevel == 1) // line krystal
            {
                _treeView.BeginUpdate();

                foreach (PermutationNode permutationNode in pk.PermutationNodeList)
                {
                    permutationNode.Text =
                        ": m1, a" + permutationNode.Axis.ToString() +
                        ", c" + permutationNode.Contour.ToString();
                    _treeView.Nodes.Add(permutationNode);
                }
                _treeView.EndUpdate();
            }
            #endregion line krystal inputs
            else
            #region higher level krystal inputs
            {
                // Construct the levels of the tree above the permutationNodeList, adding the PermutationNodes where
                // necessary. (The upper levels consist of pure TreeNodes and include the single root node.)
                TreeNode[] currentNode              = new TreeNode[dKrystalLevel];
                int[]      localSectionNumber       = new int[dKrystalLevel];     // does not include the local strand section numbers
                int        localStrandSectionNumber = 0;
                for (int i = 0; i < pk.Strands.Count; i++)
                {
                    Strand          strand          = pk.Strands[i];
                    PermutationNode permutationNode = pk.PermutationNodeList[i];
                    if (strand.Level <= dKrystalLevel)
                    {
                        localStrandSectionNumber = 0;
                        int levelIndex = (int)strand.Level - 1;
                        while (levelIndex < dKrystalLevel)
                        {
                            TreeNode tn = new TreeNode();
                            tn.Expand();
                            currentNode[levelIndex] = tn;
                            if (levelIndex > 0)                            // there is only one node at levelIndex == 0, and it has no text
                            {
                                currentNode[levelIndex - 1].Nodes.Add(tn);
                                localSectionNumber[levelIndex - 1]++;
                                localSectionNumber[levelIndex] = 0;
                                if (levelIndex == 1)
                                {
                                    tn.Text = localSectionNumber[levelIndex - 1].ToString();
                                }
                                else
                                {
                                    tn.Text = tn.Parent.Text + "." + localSectionNumber[levelIndex - 1].ToString();
                                }
                            }
                            levelIndex++;
                        }
                    }
                    localStrandSectionNumber++;
                    currentNode[dKrystalLevel - 1].Nodes.Add(permutationNode);
                    localSectionNumber[dKrystalLevel - 1]++;
                    int moment       = i + 1;
                    int sourceMoment = permutationNode.SourceStrandNumber;
                    int axis         = permutationNode.Axis;
                    int contour      = permutationNode.Contour;
                    permutationNode.Text = permutationNode.Parent.Text
                                           + "." + localStrandSectionNumber.ToString()
                                           + ": m" + moment.ToString();
                    if (sourceMoment > 0)
                    {
                        permutationNode.Text = permutationNode.Text +
                                               ", sm" + sourceMoment.ToString();
                    }
                    else
                    {
                        permutationNode.Text = permutationNode.Text +
                                               ", a" + axis.ToString() +
                                               ", c" + contour.ToString();
                    }
                }
                // Now add the moment numbers to the pure TreeNode.Texts
                for (int i = 0; i < pk.Strands.Count; i++)
                {
                    Strand          strand          = pk.Strands[i];
                    PermutationNode permutationNode = pk.PermutationNodeList[i];
                    if (strand.Level <= dKrystalLevel)
                    {
                        TreeNode tn         = permutationNode.Parent;
                        bool     continueUp = true;
                        while (continueUp)
                        {
                            if (tn.Text.EndsWith(".1") && tn.Level > 0)
                            {
                                continueUp = true;
                            }
                            else
                            {
                                continueUp = false;
                            }
                            int m = i + 1;
                            tn.Text = tn.Text + ": m" + m.ToString();
                            if (continueUp)
                            {
                                tn = tn.Parent;
                            }
                        }
                    }
                }
                _treeView.BeginUpdate();
                _treeView.Nodes.Clear();
                foreach (TreeNode n in currentNode[0].Nodes)
                {
                    _treeView.Nodes.Add(n);
                }
                _treeView.EndUpdate();
            }
            #endregion higher level krystal inputs
        }