public void Rebuild() { if (_unknownParentsList.Count > 0) { StringBuilder orphans = new StringBuilder(); foreach (Dependency d in _unknownParentsList) { orphans.Append("\n"); orphans.Append(d.Name); } string msg = "The following krystals contain fatal errors,\n" + "which mean that they cannot be (re)constructed:\n" + orphans.ToString() + "\n\nDelete?"; DialogResult result = MessageBox.Show(msg, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { foreach (Dependency d in _unknownParentsList) { File.Delete(K.KrystalsFolder + @"\" + d.Name); } } } foreach (Dependency d in _dependencyList) { string path = K.KrystalsFolder + @"\" + d.Name; if (K.IsExpansionKrystalFilename(d.Name)) { ExpansionKrystal xk = new ExpansionKrystal(path); xk.Rebuild(); } if (K.IsShapedExpansionKrystalFilename(d.Name)) { ShapedExpansionKrystal sk = new ShapedExpansionKrystal(path); sk.Rebuild(); } if (K.IsModulationKrystalFilename(d.Name)) { ModulationKrystal mk = new ModulationKrystal(path); mk.Rebuild(); } if (K.IsPermutationKrystalFilename(d.Name)) { PermutationKrystal pk = new PermutationKrystal(path); pk.Rebuild(); } } }
/// <summary> /// Finds an identical, already saved krystal /// </summary> /// <param name="nameIntro">one of "ck", "lk", "mk", "xk", "sk"</param> /// <returns></returns> protected string GetNameOfEquivalentSavedKrystal(string nameIntro) { Debug.Assert(_name == "" || _name == K.UntitledKrystalName); string newName = ""; DirectoryInfo dir = new DirectoryInfo(K.KrystalsFolder); Krystal otherKrystal = null; foreach (FileInfo fileInfo in dir.GetFiles("*.krys")) { if (fileInfo.Name[0] == nameIntro[0]) { switch (fileInfo.Name[0]) { case 'c': otherKrystal = new ConstantKrystal(K.KrystalsFolder + @"\" + fileInfo.Name); break; case 'l': otherKrystal = new LineKrystal(K.KrystalsFolder + @"\" + fileInfo.Name); break; case 'm': otherKrystal = new ModulationKrystal(K.KrystalsFolder + @"\" + fileInfo.Name); break; case 'p': otherKrystal = new PermutationKrystal(K.KrystalsFolder + @"\" + fileInfo.Name); break; case 's': otherKrystal = new ShapedExpansionKrystal(K.KrystalsFolder + @"\" + fileInfo.Name); break; case 'x': otherKrystal = new ExpansionKrystal(K.KrystalsFolder + @"\" + fileInfo.Name); break; } if (this.CompareTo(otherKrystal) == 0) { newName = otherKrystal.Name; break; } } } return(newName); }
public static Krystal LoadKrystal(string pathname) { Krystal krystal = null; string filename = Path.GetFileName(pathname); if (IsConstantKrystalFilename(filename)) { krystal = new ConstantKrystal(pathname); } else if (IsLineKrystalFilename(filename)) { krystal = new LineKrystal(pathname); } else if (IsExpansionKrystalFilename(filename)) { krystal = new ExpansionKrystal(pathname); } else if (IsShapedExpansionKrystalFilename(filename)) { krystal = new ShapedExpansionKrystal(pathname); } else if (IsModulationKrystalFilename(filename)) { krystal = new ModulationKrystal(pathname); } else if (IsPermutationKrystalFilename(filename)) { krystal = new PermutationKrystal(pathname); } else { string msg = pathname + "\r\n\r\n is not a known type of krystal."; MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(krystal); }
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 }
/// <summary> /// Loads all the krystals in K.KrystalsFolder into a list of dependencies, /// in which later entries in the list are dependent on earlier entries. /// </summary> public KrystalFamily(string krystalsFolder) { DirectoryInfo dir = new DirectoryInfo(krystalsFolder); string allConstants = "ck*.krys"; foreach(FileInfo f in dir.GetFiles(allConstants)) { Dependency d = new Dependency(); d.Name = f.Name; _dependencyList.Add(d); } string allLines = "lk*.krys"; foreach(FileInfo f in dir.GetFiles(allLines)) { Dependency d = new Dependency(); d.Name = f.Name; _dependencyList.Add(d); } #region add expansions to the _unknownParentsList string expansions = "xk*.krys"; ExpansionKrystal xk = null; foreach(FileInfo f in dir.GetFiles(expansions)) { string path = K.KrystalsFolder + @"\" + f.Name; xk = new ExpansionKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if(xk != null) { d.Input1 = xk.DensityInputFilename; d.Input2 = xk.PointsInputFilename; d.Field = xk.Expander.Name; } _unknownParentsList.Add(d); } #endregion add expansions to the _unknownParentsList #region add shaped expansions to the _unknownParentsList string shapedExpansions = "sk*.krys"; ShapedExpansionKrystal sk = null; foreach(FileInfo f in dir.GetFiles(shapedExpansions)) { string path = K.KrystalsFolder + @"\" + f.Name; sk = new ShapedExpansionKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if(sk != null) { d.Input1 = sk.DensityInputFilename; d.Input2 = sk.PointsInputFilename; d.Input3 = sk.AxisInputFilename; d.Input4 = sk.ContourInputFilename; d.Field = sk.Expander.Name; } _unknownParentsList.Add(d); } #endregion add shaped expansions to the _unknownParentsList #region add modulations to the _unknownParentsList string allModulations = "mk*.krys"; ModulationKrystal mk = null; foreach(FileInfo f in dir.GetFiles(allModulations)) { string path = K.KrystalsFolder + @"\" + f.Name; mk = new ModulationKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if(mk != null) { d.Input1 = mk.XInputFilename; d.Input2 = mk.YInputFilename; d.Field = mk.Modulator.Name; } _unknownParentsList.Add(d); } #endregion add modulations to the _unknownParentsList #region add permutation krystals to the _unknownParentsList string allPermutations = "pk*.krys"; PermutationKrystal pk = null; foreach(FileInfo f in dir.GetFiles(allPermutations)) { string path = K.KrystalsFolder + @"\" + f.Name; pk = new PermutationKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if(pk != null) { d.Input1 = pk.SourceInputFilename; d.Input2 = pk.AxisInputFilename; d.Input3 = pk.ContourInputFilename; } _unknownParentsList.Add(d); } #endregion add permutation krystals to the _unknownParentsList #region insert Dependencies from the _unknownParentsList in the sorted _dependencyList bool found = true; int[] inputIndex = new int[4]; int minIndex = -1; int maxIndex = -1; while(_unknownParentsList.Count > 0 && found) { inputIndex[0] = inputIndex[1] = inputIndex[2] = inputIndex[3] = -1; found = false; foreach(Dependency d in _unknownParentsList) { if(string.IsNullOrEmpty(d.Input1) == false) { for(int index = 0 ; index < _dependencyList.Count ; index++) { if(d.Input1.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[0] = index; // save the index of the input file in the dependency list break; } } if(string.IsNullOrEmpty(d.Input2) == false) { for(int index = 0 ; index < _dependencyList.Count ; index++) { if(d.Input2.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[1] = index; // save the index of the input file in the dependency list break; } } } if(string.IsNullOrEmpty(d.Input3) == false) { for(int index = 0 ; index < _dependencyList.Count ; index++) { if(d.Input3.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[2] = index; // save the index of the input file in the dependency list break; } } } if(string.IsNullOrEmpty(d.Input4) == false) { for(int index = 0 ; index < _dependencyList.Count ; index++) { if(d.Input4.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[3] = index; // save the index of the input file in the dependency list break; } } } if(inputIndex[0] < inputIndex[1]) { minIndex = inputIndex[0]; maxIndex = inputIndex[1]; } else { minIndex = inputIndex[1]; maxIndex = inputIndex[0]; } if(string.IsNullOrEmpty(d.Input3) == false || string.IsNullOrEmpty(d.Input4) == false) { minIndex = minIndex < inputIndex[2] ? minIndex : inputIndex[2]; minIndex = minIndex < inputIndex[3] ? minIndex : inputIndex[3]; maxIndex = maxIndex > inputIndex[2] ? maxIndex : inputIndex[2]; maxIndex = maxIndex > inputIndex[3] ? maxIndex : inputIndex[3]; } if(minIndex >= 0) // all the inputs are currently in the _dependencyList { _dependencyList.Insert(maxIndex + 1, d); } } } int removed = 0; foreach(Dependency d in _dependencyList) if(_unknownParentsList.Remove(d)) removed++; if(removed > 0) found = true; } #endregion move Dependencies from the _unknownParentsList to the sorted _dependencyList }
public void Rebuild() { if(_unknownParentsList.Count > 0) { StringBuilder orphans = new StringBuilder(); foreach(Dependency d in _unknownParentsList) { orphans.Append("\n"); orphans.Append(d.Name); } string msg = "The following krystals contain fatal errors,\n" + "which mean that they cannot be (re)constructed:\n" + orphans.ToString() + "\n\nDelete?"; DialogResult result = MessageBox.Show(msg, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if(result == DialogResult.Yes) foreach(Dependency d in _unknownParentsList) File.Delete(K.KrystalsFolder + @"\" + d.Name); } foreach(Dependency d in _dependencyList) { string path = K.KrystalsFolder + @"\" + d.Name; if(K.IsExpansionKrystalFilename(d.Name)) { ExpansionKrystal xk = new ExpansionKrystal(path); xk.Rebuild(); } if(K.IsShapedExpansionKrystalFilename(d.Name)) { ShapedExpansionKrystal sk = new ShapedExpansionKrystal(path); sk.Rebuild(); } if(K.IsModulationKrystalFilename(d.Name)) { ModulationKrystal mk = new ModulationKrystal(path); mk.Rebuild(); } if(K.IsPermutationKrystalFilename(d.Name)) { PermutationKrystal pk = new PermutationKrystal(path); pk.Rebuild(); } } }
public static Krystal LoadKrystal(string pathname) { Krystal krystal = null; string filename = Path.GetFileName(pathname); if(IsConstantKrystalFilename(filename)) krystal = new ConstantKrystal(pathname); else if(IsLineKrystalFilename(filename)) krystal = new LineKrystal(pathname); else if(IsExpansionKrystalFilename(filename)) krystal = new ExpansionKrystal(pathname); else if(IsShapedExpansionKrystalFilename(filename)) krystal = new ShapedExpansionKrystal(pathname); else if(IsModulationKrystalFilename(filename)) krystal = new ModulationKrystal(pathname); else if(IsPermutationKrystalFilename(filename)) krystal = new PermutationKrystal(pathname); else { string msg = pathname + "\r\n\r\n is not a known type of krystal."; MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return krystal; }
private void SetForPermutationKrystal(PermutationKrystal pk) { MissingValues.Text = "Missing Values: " + _krystal.MissingValues; Shape.Text = "Shape: " + _krystal.Shape; StrandsTreeView.Nodes.Clear(); PermutationTreeView permutationTreeView = new PermutationTreeView(StrandsTreeView, pk); //pk.Permute(); permutationTreeView.DisplayStrands(pk.Strands, pk.PermutationNodeList); StrandsTreeView.ExpandAll(); }
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 }
/// <summary> /// Loads all the krystals in K.KrystalsFolder into a list of dependencies, /// in which later entries in the list are dependent on earlier entries. /// </summary> public KrystalFamily(string krystalsFolder) { DirectoryInfo dir = new DirectoryInfo(krystalsFolder); string allConstants = "ck*.krys"; foreach (FileInfo f in dir.GetFiles(allConstants)) { Dependency d = new Dependency(); d.Name = f.Name; _dependencyList.Add(d); } string allLines = "lk*.krys"; foreach (FileInfo f in dir.GetFiles(allLines)) { Dependency d = new Dependency(); d.Name = f.Name; _dependencyList.Add(d); } #region add expansions to the _unknownParentsList string expansions = "xk*.krys"; ExpansionKrystal xk = null; foreach (FileInfo f in dir.GetFiles(expansions)) { string path = K.KrystalsFolder + @"\" + f.Name; xk = new ExpansionKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if (xk != null) { d.Input1 = xk.DensityInputFilename; d.Input2 = xk.PointsInputFilename; d.Field = xk.Expander.Name; } _unknownParentsList.Add(d); } #endregion add expansions to the _unknownParentsList #region add shaped expansions to the _unknownParentsList string shapedExpansions = "sk*.krys"; ShapedExpansionKrystal sk = null; foreach (FileInfo f in dir.GetFiles(shapedExpansions)) { string path = K.KrystalsFolder + @"\" + f.Name; sk = new ShapedExpansionKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if (sk != null) { d.Input1 = sk.DensityInputFilename; d.Input2 = sk.PointsInputFilename; d.Input3 = sk.AxisInputFilename; d.Input4 = sk.ContourInputFilename; d.Field = sk.Expander.Name; } _unknownParentsList.Add(d); } #endregion add shaped expansions to the _unknownParentsList #region add modulations to the _unknownParentsList string allModulations = "mk*.krys"; ModulationKrystal mk = null; foreach (FileInfo f in dir.GetFiles(allModulations)) { string path = K.KrystalsFolder + @"\" + f.Name; mk = new ModulationKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if (mk != null) { d.Input1 = mk.XInputFilename; d.Input2 = mk.YInputFilename; d.Field = mk.Modulator.Name; } _unknownParentsList.Add(d); } #endregion add modulations to the _unknownParentsList #region add permutation krystals to the _unknownParentsList string allPermutations = "pk*.krys"; PermutationKrystal pk = null; foreach (FileInfo f in dir.GetFiles(allPermutations)) { string path = K.KrystalsFolder + @"\" + f.Name; pk = new PermutationKrystal(path); Dependency d = new Dependency(); d.Name = f.Name; if (pk != null) { d.Input1 = pk.SourceInputFilename; d.Input2 = pk.AxisInputFilename; d.Input3 = pk.ContourInputFilename; } _unknownParentsList.Add(d); } #endregion add permutation krystals to the _unknownParentsList #region insert Dependencies from the _unknownParentsList in the sorted _dependencyList bool found = true; int[] inputIndex = new int[4]; int minIndex = -1; int maxIndex = -1; while (_unknownParentsList.Count > 0 && found) { inputIndex[0] = inputIndex[1] = inputIndex[2] = inputIndex[3] = -1; found = false; foreach (Dependency d in _unknownParentsList) { if (string.IsNullOrEmpty(d.Input1) == false) { for (int index = 0; index < _dependencyList.Count; index++) { if (d.Input1.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[0] = index; // save the index of the input file in the dependency list break; } } if (string.IsNullOrEmpty(d.Input2) == false) { for (int index = 0; index < _dependencyList.Count; index++) { if (d.Input2.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[1] = index; // save the index of the input file in the dependency list break; } } } if (string.IsNullOrEmpty(d.Input3) == false) { for (int index = 0; index < _dependencyList.Count; index++) { if (d.Input3.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[2] = index; // save the index of the input file in the dependency list break; } } } if (string.IsNullOrEmpty(d.Input4) == false) { for (int index = 0; index < _dependencyList.Count; index++) { if (d.Input4.Equals(_dependencyList[index].Name)) // InputIndex[inputNameIndex] is currently -1 { inputIndex[3] = index; // save the index of the input file in the dependency list break; } } } if (inputIndex[0] < inputIndex[1]) { minIndex = inputIndex[0]; maxIndex = inputIndex[1]; } else { minIndex = inputIndex[1]; maxIndex = inputIndex[0]; } if (string.IsNullOrEmpty(d.Input3) == false || string.IsNullOrEmpty(d.Input4) == false) { minIndex = minIndex < inputIndex[2] ? minIndex : inputIndex[2]; minIndex = minIndex < inputIndex[3] ? minIndex : inputIndex[3]; maxIndex = maxIndex > inputIndex[2] ? maxIndex : inputIndex[2]; maxIndex = maxIndex > inputIndex[3] ? maxIndex : inputIndex[3]; } if (minIndex >= 0) // all the inputs are currently in the _dependencyList { _dependencyList.Insert(maxIndex + 1, d); } } } int removed = 0; foreach (Dependency d in _dependencyList) { if (_unknownParentsList.Remove(d)) { removed++; } } if (removed > 0) { found = true; } } #endregion move Dependencies from the _unknownParentsList to the sorted _dependencyList }
private void SetForPermutationKrystal(PermutationKrystal pk) { this.Controls.Remove(LineStrandLabel); PermutationTreeView permutationTreeView = new PermutationTreeView(StrandsTreeView, pk); permutationTreeView.DisplayStrands(pk.Strands, pk.PermutationNodeList); StrandsTreeView.ExpandAll(); this.Height = Screen.GetWorkingArea(this).Height; }