private void CancelBtn_Click(object sender, EventArgs e) { _modulationKrystal = null; _xInputFilepath = ""; _yInputFilepath = ""; _modulatorFilepath = ""; Close(); }
private void SetForModulationKrystal(ModulationKrystal mk) { this.Controls.Remove(LineStrandLabel); ModulationTreeView modulationTreeView = new ModulationTreeView(StrandsTreeView, mk); mk.Modulate(); modulationTreeView.DisplayModulationResults(mk); StrandsTreeView.ExpandAll(); this.Height = Screen.GetWorkingArea(this).Height; }
/// <summary> /// Appends the modulation results to the existing tree view of the input values. /// The values are displayed in round () brackets. /// </summary> public void DisplayModulationResults(ModulationKrystal modulationKrystal) { //(List<ModulationNode> modulationNodeList, uint outputKrystalLevel) _treeView.BeginUpdate(); #region display single results foreach (ModulationNode modulationNode in _modulationNodeList) { int resultStartIndex = modulationNode.Text.IndexOf(" ("); if (resultStartIndex > 0) { modulationNode.Text = modulationNode.Text.Remove(resultStartIndex); } int result = modulationNode.ModResult; modulationNode.Text = modulationNode.Text + " (" + result.ToString() + ")"; } #endregion display single results #region display strand values (one level higher) uint strandValueLevel = modulationKrystal.Level + 1; StringBuilder strandSB = new StringBuilder(" ("); ModulationNode m; for (int index = 0; index < _modulationNodeList.Count; index++) { m = _modulationNodeList[index]; if (m.ModLevel < strandValueLevel && index > 0) { strandSB[strandSB.Length - 1] = ')'; // overwrites final comma int resultStartIndex = _modulationNodeList[index - 1].Parent.Text.IndexOf(" ("); if (resultStartIndex > 0) { _modulationNodeList[index - 1].Parent.Text = _modulationNodeList[index - 1].Parent.Text.Remove(resultStartIndex); } _modulationNodeList[index - 1].Parent.Text = _modulationNodeList[index - 1].Parent.Text + strandSB.ToString(); strandSB = new StringBuilder(" ("); } int result = m.ModResult; strandSB.Append(result.ToString()); strandSB.Append(","); } strandSB[strandSB.Length - 1] = ')'; // overwrites final comma int bracketIndex = _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text.IndexOf(" ("); if (bracketIndex > 0) { _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text = _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text.Remove(bracketIndex); } _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text = _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text + strandSB.ToString(); #endregion display strand values (one level higher) _treeView.EndUpdate(); }
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 ModulationEditor(ModulationKrystal outputKrystal) { InitializeComponent(); _outputKrystal = outputKrystal; _modulator = _outputKrystal.Modulator; if(string.IsNullOrEmpty(_outputKrystal.Name)) _originalKrystalName = ""; else _originalKrystalName = _outputKrystal.Name; _originalModulatorName = _modulator.Name; //_modulator.Name = ""; //_outputKrystal.Name = ""; if(String.IsNullOrEmpty(_originalModulatorName)) // the modulator has not been loaded from a file _modulatorWasOriginallyLoadedFromAFile = false; else _modulatorWasOriginallyLoadedFromAFile = true; //if(String.IsNullOrEmpty(_originalKrystalName)) // the krystal has not been loaded from a file // _krystalWasOriginallyLoadedFromAFile = false; //else // _krystalWasOriginallyLoadedFromAFile = true; _modulationTreeView = new ModulationTreeView(TreeView, _outputKrystal ); _uintTable = new UIntTable(_modulator.XDim, _modulator.YDim, outputKrystal.XInputKrystal, outputKrystal.YInputKrystal); this.splitContainer.Panel2.Controls.Add(_uintTable); if(_modulatorWasOriginallyLoadedFromAFile) // the modulator has been loaded from a file _uintTable.IntArray = _modulator.Array; _uintTable.EventHandler += new UIntTable.UIntTableEventHandler(HandleUIntTableEvents); this.DoModulation(); _saved = true; SetFormTextAndButtons(); }
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 OpenKrystalButton_Click(object sender, EventArgs e) { try { string modulationKrystalFilepath = K.GetFilepathFromOpenFileDialog(K.DialogFilterIndex.modulation); if(modulationKrystalFilepath.Length > 0) { ModulationKrystal mk = new ModulationKrystal(modulationKrystalFilepath); _modulationKrystal = mk; _xInputFilepath = K.KrystalsFolder + @"\" + mk.XInputFilename; _yInputFilepath = K.KrystalsFolder + @"\" + mk.YInputFilename; _modulatorFilepath = K.ModulationOperatorsFolder + @"\" + mk.ModulatorFilename; XInputFilenameLabel.Text = mk.XInputFilename; YInputFilenameLabel.Text = mk.YInputFilename; ModulatorFilenameLabel.Text = mk.ModulatorFilename; } } catch(ApplicationException ae) { MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public ModulationTreeView(TreeView treeView, ModulationKrystal modulationKrystal) { _modulationNodeList = modulationKrystal.ModulationNodeList; _treeView = treeView; #region constant krystal inputs // It is pointless to have two constant inputs for a modulation // so I have forbidden this combination in the ModulationKrystal constructor. #endregion constant krystal inputs #region line krystal inputs if(modulationKrystal.Level == 1) // line krystal { _treeView.BeginUpdate(); TreeNode root = new TreeNode(); root.Text = "1: m1"; _treeView.Nodes.Add(root); foreach(ModulationNode modulationNode in _modulationNodeList) { int m = modulationNode.ModMoment; int x = modulationNode.X; int y = modulationNode.Y; modulationNode.Text = m.ToString() + ": m" + m.ToString() + ", x" + x.ToString() + ", y" + y.ToString(); root.Nodes.Add(modulationNode); } _treeView.EndUpdate(); } #endregion line krystal inputs else #region higher level krystal inputs { // Construct the levels of the tree above the modulationNodeList, adding the ModulationNodes // where necessary. (The upper levels consist of pure TreeNodes and include the single root // node.) TreeNode[] currentNode = new TreeNode[modulationKrystal.Level]; int[] localSectionNumber = new int[modulationKrystal.Level];// does not include the local strand section numbers int localModulationSectionNumber = 0; foreach(ModulationNode modulationNode in _modulationNodeList) { if(modulationNode.ModLevel <= modulationKrystal.Level) { localModulationSectionNumber = 0; int levelIndex = modulationNode.ModLevel - 1; while(levelIndex < modulationKrystal.Level) { 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++; } } localModulationSectionNumber++; currentNode[modulationKrystal.Level - 1].Nodes.Add(modulationNode); localSectionNumber[modulationKrystal.Level - 1]++; int m = modulationNode.ModMoment; int x = modulationNode.X; int y = modulationNode.Y; modulationNode.Text = modulationNode.Parent.Text + "." + localModulationSectionNumber.ToString() + ": m" + m.ToString() + ", x" + x.ToString() + ", y" + y.ToString(); } // Now add the moment numbers to the pure TreeNode.Texts // collapsing the level above the modulationNodes. foreach(ModulationNode modulationNode in _modulationNodeList) { if(modulationNode.ModLevel <= modulationKrystal.Level) { TreeNode tn = modulationNode.Parent; tn.Collapse(); bool continueUp = true; while(continueUp) { if(tn.Text.EndsWith(".1") && tn.Level > 0) continueUp = true; else continueUp = false; int m = modulationNode.ModMoment; 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> /// Appends the modulation results to the existing tree view of the input values. /// The values are displayed in round () brackets. /// </summary> public void DisplayModulationResults(ModulationKrystal modulationKrystal) { //(List<ModulationNode> modulationNodeList, uint outputKrystalLevel) _treeView.BeginUpdate(); #region display single results foreach(ModulationNode modulationNode in _modulationNodeList) { int resultStartIndex = modulationNode.Text.IndexOf(" ("); if(resultStartIndex > 0) modulationNode.Text = modulationNode.Text.Remove(resultStartIndex); int result = modulationNode.ModResult; modulationNode.Text = modulationNode.Text + " (" + result.ToString() + ")"; } #endregion display single results #region display strand values (one level higher) uint strandValueLevel = modulationKrystal.Level + 1; StringBuilder strandSB = new StringBuilder(" ("); ModulationNode m; for(int index = 0 ; index < _modulationNodeList.Count ; index++) { m = _modulationNodeList[index]; if(m.ModLevel < strandValueLevel && index > 0) { strandSB[strandSB.Length - 1] = ')'; // overwrites final comma int resultStartIndex = _modulationNodeList[index - 1].Parent.Text.IndexOf(" ("); if(resultStartIndex > 0) _modulationNodeList[index - 1].Parent.Text = _modulationNodeList[index - 1].Parent.Text.Remove(resultStartIndex); _modulationNodeList[index - 1].Parent.Text = _modulationNodeList[index - 1].Parent.Text + strandSB.ToString(); strandSB = new StringBuilder(" ("); } int result = m.ModResult; strandSB.Append(result.ToString()); strandSB.Append(","); } strandSB[strandSB.Length - 1] = ')'; // overwrites final comma int bracketIndex = _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text.IndexOf(" ("); if(bracketIndex > 0) _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text = _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text.Remove(bracketIndex); _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text = _modulationNodeList[_modulationNodeList.Count - 1].Parent.Text + strandSB.ToString(); #endregion display strand values (one level higher) _treeView.EndUpdate(); }
private void OpenModulatedKrystal() { try { string modulatedKrystalFilepath = K.GetFilepathFromOpenFileDialog(K.DialogFilterIndex.modulation); if (modulatedKrystalFilepath.Length > 0) { ModulationKrystal outputKrystal = new ModulationKrystal(modulatedKrystalFilepath); ModulationEditor editor = new ModulationEditor(outputKrystal); editor.EventHandler = new ModulationEditor.ModulationEditorEventHandler(HandleModulationEditorEvents); editor.Show(); } } catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void NewModulatedKrystal() { using(NewModulationDialog kd = new NewModulationDialog()) { DialogResult result = kd.ShowDialog(); ModulationKrystal mKrystal = null; if(result == DialogResult.OK) { if(string.IsNullOrEmpty(kd.XInputFilepath) || string.IsNullOrEmpty(kd.YInputFilepath)) { MessageBox.Show("Both the XInput and the YInput krystals must be set.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); NewModulatedKrystal(); // recursive call } else if(kd.ModulationKrystal != null) mKrystal = kd.ModulationKrystal; else mKrystal = new ModulationKrystal(kd.XInputFilepath, kd.YInputFilepath, kd.ModulatorFilepath); ModulationEditor editor = new ModulationEditor(mKrystal); editor.EventHandler = new ModulationEditor.ModulationEditorEventHandler(HandleModulationEditorEvents); editor.Show(); } } }
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> /// 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 SetXInputButton_Click(object sender, EventArgs e) { _modulationKrystal = null; _xInputFilepath = K.GetFilepathFromOpenFileDialog(K.DialogFilterIndex.allKrystals); XInputFilenameLabel.Text = Path.GetFileName(_xInputFilepath); }
private void SetModulatorButton_Click(object sender, EventArgs e) { _modulationKrystal = null; _modulatorFilepath = K.GetFilepathFromOpenFileDialog(K.DialogFilterIndex.modulator); ModulatorFilenameLabel.Text = Path.GetFileName(_modulatorFilepath); }
public ModulationTreeView(TreeView treeView, ModulationKrystal modulationKrystal) { _modulationNodeList = modulationKrystal.ModulationNodeList; _treeView = treeView; #region constant krystal inputs // It is pointless to have two constant inputs for a modulation // so I have forbidden this combination in the ModulationKrystal constructor. #endregion constant krystal inputs #region line krystal inputs if (modulationKrystal.Level == 1) // line krystal { _treeView.BeginUpdate(); TreeNode root = new TreeNode(); root.Text = "1: m1"; _treeView.Nodes.Add(root); foreach (ModulationNode modulationNode in _modulationNodeList) { int m = modulationNode.ModMoment; int x = modulationNode.X; int y = modulationNode.Y; modulationNode.Text = m.ToString() + ": m" + m.ToString() + ", x" + x.ToString() + ", y" + y.ToString(); root.Nodes.Add(modulationNode); } _treeView.EndUpdate(); } #endregion line krystal inputs else #region higher level krystal inputs { // Construct the levels of the tree above the modulationNodeList, adding the ModulationNodes // where necessary. (The upper levels consist of pure TreeNodes and include the single root // node.) TreeNode[] currentNode = new TreeNode[modulationKrystal.Level]; int[] localSectionNumber = new int[modulationKrystal.Level]; // does not include the local strand section numbers int localModulationSectionNumber = 0; foreach (ModulationNode modulationNode in _modulationNodeList) { if (modulationNode.ModLevel <= modulationKrystal.Level) { localModulationSectionNumber = 0; int levelIndex = modulationNode.ModLevel - 1; while (levelIndex < modulationKrystal.Level) { 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++; } } localModulationSectionNumber++; currentNode[modulationKrystal.Level - 1].Nodes.Add(modulationNode); localSectionNumber[modulationKrystal.Level - 1]++; int m = modulationNode.ModMoment; int x = modulationNode.X; int y = modulationNode.Y; modulationNode.Text = modulationNode.Parent.Text + "." + localModulationSectionNumber.ToString() + ": m" + m.ToString() + ", x" + x.ToString() + ", y" + y.ToString(); } // Now add the moment numbers to the pure TreeNode.Texts // collapsing the level above the modulationNodes. foreach (ModulationNode modulationNode in _modulationNodeList) { if (modulationNode.ModLevel <= modulationKrystal.Level) { TreeNode tn = modulationNode.Parent; tn.Collapse(); bool continueUp = true; while (continueUp) { if (tn.Text.EndsWith(".1") && tn.Level > 0) { continueUp = true; } else { continueUp = false; } int m = modulationNode.ModMoment; 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 }
private void SetForModulationKrystal(ModulationKrystal mk) { MissingValues.Text = "Missing Values: " + _krystal.MissingValues; Shape.Text = "Shape: " + _krystal.Shape; StrandsTreeView.Nodes.Clear(); ModulationTreeView modulationTreeView = new ModulationTreeView(StrandsTreeView, mk); mk.Modulate(); modulationTreeView.DisplayModulationResults(mk); StrandsTreeView.ExpandAll(); }
/// <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 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; }