/// <summary> /// This constructor creates strands from the complete, checked inputs of its ExpansionKrystal argument. /// (No further checking is done.) /// </summary> /// <param name="ek">An expansion krystal with complete, checked inputs</param> public Expansion(ExpansionKrystal ek) { try { Expander expander = ek.Expander; expander.CalculateAbstractPointPositions(ek.DensityInputKrystal); List <StrandNode> strandNodeList = ek.StrandNodeList(); Expand(strandNodeList, expander); } catch (ApplicationException ex) { throw ex; } }
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> /// This constructor creates strands from the complete, checked inputs of its ExpansionKrystal argument. /// (No further checking is done.) /// </summary> /// <param name="ek">An expansion krystal with complete, checked inputs</param> public Expansion(ExpansionKrystal ek) { try { Expander expander = ek.Expander; expander.CalculateAbstractPointPositions(ek.DensityInputKrystal); List<StrandNode> strandNodeList = ek.StrandNodeList(); Expand(strandNodeList, expander); } catch(ApplicationException ex) { throw ex; } }
/// <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); }
/// <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(); } } }
private void OpenExpansionKrystal() { try { string expansionKrystalFilepath = K.GetFilepathFromOpenFileDialog(K.DialogFilterIndex.expansion); if (expansionKrystalFilepath.Length > 0) { ExpansionKrystal outputKrystal = new ExpansionKrystal(expansionKrystalFilepath); ExpansionEditor editor = new ExpansionEditor(outputKrystal); editor.EventHandler += new ExpansionEditor.ExpansionEditorEventhandler(HandleExpansionEditorEvents); editor.Show(); } } catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
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 SetForExpansionKrystal(ExpansionKrystal xk) { MissingValues.Text = "Missing Values: " + _krystal.MissingValues; Shape.Text = "Shape: " + _krystal.Shape; StrandsTreeView.Nodes.Clear(); ExpansionTreeView expansionTreeView = new ExpansionTreeView(StrandsTreeView, xk.StrandNodeList(), xk.DensityInputKrystal.Level, xk.PointsInputKrystal.MissingAbsoluteValues); expansionTreeView.DisplayStrands(xk.Strands); StrandsTreeView.ExpandAll(); }
public ExpansionEditor(ExpansionKrystal krystal) { InitializeComponent(); _newEditorState = _oldEditorState = EditorState.FixedOutput; _fixedInputPointsIndex = -1; _fixedOutputPointsIndex = -1; _inputPlanetIndex = -1; _outputPlanetIndex = -1; this.FieldPanel.MouseDown += new MouseEventHandler(FieldPanel_MouseDown); _outputKrystal = krystal; if(string.IsNullOrEmpty(_outputKrystal.Name)) _outputKrystal.Name = K.UntitledKrystalName; _expander = _outputKrystal.Expander; _strandNodeList = krystal.StrandNodeList(); _painter = new Painter(_strandNodeList); SetStatusText(); SetTreeView(); LoadGametesIntoEditor(); DisableAllSaving(); _fieldPanelGraphicsBuffer = _bufferedGraphicsContext.Allocate(FieldPanel.CreateGraphics(), FieldPanel.DisplayRectangle); _painter.DrawBackground(_fieldPanelGraphicsBuffer.Graphics); PointGroupParameters.InitSamplePanel(_painter._inputDotSize, _painter._outputDotSize, _painter._theLinePen, _painter._theOutputFillBrush); PointGroupParameters.UpdateFieldEditor += new PointGroupParameters.PointGroupParametersChangedHandler(PointGroupParametersChangedDelegate); ZoomComboBox.SelectedIndex = 4; }
/// <summary> /// Draws the current state of the output Krystal. /// If this._pointMarkers is not empty, this function draws in "time-slice" mode, /// otherwise it draws in normal editing mode, drawing a _singlePointMarker if ther /// is one. /// </summary> /// <param name="g">The field panel's current Graphics property</param> /// <param name="outputKrystal">The outputKrystal in the fieldEditor's database</param> /// <param name="scalePercent">The current value of the ZoomComboBox</param> public void Draw(Graphics g, ExpansionKrystal outputKrystal, float scalePercent) { _g = g; _g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; _g.PageUnit = GraphicsUnit.Pixel; _labelsHeight = (float)_g.MeasureString("1", _labelsFont).Height * 0.9f; // 0.9f centres the letters vertically _theDottedLinePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; #region initialise graphics _scale = scalePercent * _basicScale; _fieldPanelCentreX = _g.VisibleClipBounds.Width / 2; _fieldPanelCentreY = _g.VisibleClipBounds.Height / 2; #endregion initialise graphics #region draw _g.Clear(Color.White); DrawBackground(_g); DrawPointMarkers(_scale, _fieldPanelCentreX, _fieldPanelCentreY); if (outputKrystal != null) { _densityInputKrystal = outputKrystal.DensityInputKrystal; _pointsInputKrystal = outputKrystal.PointsInputKrystal; Expander ef = outputKrystal.Expander; if (ef != null) { foreach (Planet planet in ef.OutputGamete.Planets) { planet.GetPlanetCoordinates(_densityInputKrystal, _fieldPanelCentreX, _fieldPanelCentreY, _scale); DrawPlanetBackground(planet, false); // draws unused input points and the line } foreach (Planet planet in ef.InputGamete.Planets) { planet.GetPlanetCoordinates(_densityInputKrystal, _fieldPanelCentreX, _fieldPanelCentreY, _scale); DrawPlanetBackground(planet, true); // draws unused input points and the line } foreach (Planet planet in ef.OutputGamete.Planets) DrawPlanet(planet, true); // true means draw output planet foreach (PointGroup p in ef.OutputGamete.FixedPointGroups) DrawFixedDots(p, false); foreach (PointGroup p in ef.InputGamete.FixedPointGroups) DrawFixedDots(p, true); foreach (Planet planet in ef.InputGamete.Planets) DrawPlanet(planet, false); // false means draw input planet } // if (ef != null) } #endregion draw }
/// <summary> /// The user can replace expanders and krystals using the Replace command. /// In order to replace (overwrite) an expander, the user loads a krystal which uses it, edits the /// expander, and replaces the krystal using its original name. The krystal's name includes its /// expander's signature (the portion of the krystal's name in brackets), so both the krystal and its /// expander are overwritten. /// To replace a krystal without changing the expander, load the krystal, expand it (with any new input(s) /// but without changing the expander), then replace the krystal and expander. /// When a krystal and/or expander are replaced, all the krystals in the krystals directory have to be /// rebuilt so as to preserve the relations between them. (Krystals contain references to expanders and /// other krystals. Expanders contain references to other expanders.) The edited krystal may itself have /// changed as a result of this rebuilding (its input krystals may have changed), so it is reloaded when /// rebuilding has completed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItemReplace_Click(object sender, EventArgs e) { try { string expansionKrystalFilepath = GetExpansionKrystalFilepathFromReplaceFileDialog(); if (expansionKrystalFilepath.Length > 0) { bool abort = true; string krystalName = Path.GetFileName(expansionKrystalFilepath); CheckExpansionKrystalName(krystalName); // throws exception if name is invalid string expanderName = K.ExpansionOperatorFilename(krystalName); string expanderPath = K.KrystalsFolder + @"\" + expanderName; if (File.Exists(expanderPath)) { string msg = "The following krystal and expander are about to be replaced:\n\n" + " krystal:\t" + krystalName + "\n" + " expander:\t" + expanderName + "\n\nNote: the krystal and expander can only be replaced together. \n\n" + "When a krystal and expander are replaced, all the krystals in the\n" + "krystals directory have to be rebuilt to maintain the consistency\n" + "of the relationships between them. This may result in the current\n" + "krystal changing as the result of its input krystals changing.\n" + "Krystals contain references to expanders and other krystals.\n\n" + "Replace this krystal and expander, rebuild all the other krystals\n" + "and then reload the currently loaded krystal?\n\n"; if (MessageBox.Show(msg, "Replace and rebuild", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) abort = false; else abort = true; } else abort = false; if (!abort) { _expander.Name = expanderName; _outputKrystal.Name = krystalName; _outputKrystal.Save(false, true); // save expander, but not krystal KrystalFamily kFamily = new KrystalFamily(K.KrystalsFolder); kFamily.Rebuild(); _outputKrystal = new ExpansionKrystal(expansionKrystalFilepath); this.ExpandButton.Enabled = false; this.ZoomLabel.Enabled = true; this.ZoomComboBox.Enabled = true; this.PercentLabel.Enabled = true; LoadNewOutputKrystalIntoEditor(); } } } catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } //catch (SystemException ae) //{ // MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //} }
private void MenuItemOpenKrystal_Click(object sender, EventArgs e) { CheckSaved(); try { string expansionKrystalFilepath = K.GetFilepathFromOpenFileDialog(K.DialogFilterIndex.expansion); if (expansionKrystalFilepath.Length > 0) { _outputKrystal = new ExpansionKrystal(expansionKrystalFilepath); //_expanderIsSaved = true; //_krystalIsSaved = true; this.ExpandButton.Enabled = false; this.ZoomLabel.Enabled = true; this.ZoomComboBox.Enabled = true; this.PercentLabel.Enabled = true; LoadNewOutputKrystalIntoEditor(); } } catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } //catch (SystemException ae) //{ // MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //} }
private void MenuItemNew_Click(object sender, EventArgs e) { CheckSaved(); NewExpansionDialog kd = new NewExpansionDialog(); if (kd.ShowDialog() == DialogResult.OK) { try { _outputKrystal = new ExpansionKrystal(kd.DensityInputFilepath, kd.PointsInputFilepath, kd.ExpanderFilepath); //_expanderIsSaved = false; //_krystalIsSaved = false; this.SaveButton.Enabled = false; if (String.IsNullOrEmpty(kd.ExpanderFilepath)) { this.ZoomLabel.Enabled = false; this.ZoomComboBox.Enabled = false; this.PercentLabel.Enabled = false; this.ExpandButton.Enabled = false; } else { this.ZoomLabel.Enabled = true; this.ZoomComboBox.Enabled = true; this.PercentLabel.Enabled = true; this.ExpandButton.Enabled = true; } LoadNewOutputKrystalIntoEditor(); } catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } //catch (SystemException ae) //{ // MessageBox.Show(ae.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //} } }
/// <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 }