Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// This constructor creates strands from the complete, checked inputs of its ExpansionKrystal argument.
 /// (No further checking is done.)
 /// After expanding the strands normally, they are contoured.
 /// </summary>
 /// <param name="ek">An expansion krystal with complete, checked inputs</param>
 public Expansion(ShapedExpansionKrystal ek)
 {
     try
     {
         Expander expander = ek.Expander;
         expander.CalculateAbstractPointPositions(ek.DensityInputKrystal);
         List <StrandNode> strandNodeList = ek.StrandNodeList();
         Expand(strandNodeList, expander);
         ContourStrands(strandNodeList, _strands);
     }
     catch (ApplicationException ex)
     {
         throw ex;
     }
 }
Exemple #3
0
 /// <summary>
 /// This constructor creates strands from the complete, checked inputs of its ExpansionKrystal argument.
 /// (No further checking is done.)
 /// After expanding the strands normally, they are contoured.
 /// </summary>
 /// <param name="ek">An expansion krystal with complete, checked inputs</param>
 public Expansion(ShapedExpansionKrystal ek)
 {
     try
     {
         Expander expander = ek.Expander;
         expander.CalculateAbstractPointPositions(ek.DensityInputKrystal);
         List<StrandNode> strandNodeList = ek.StrandNodeList();
         Expand(strandNodeList, expander);
         ContourStrands(strandNodeList, _strands);
     }
     catch(ApplicationException ex)
     {
         throw ex;
     }
 }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        /// <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
        }
Exemple #7
0
        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();
                }
            }
        }
Exemple #8
0
        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;
        }
Exemple #9
0
        private void SetForShapedExpansionKrystal(ShapedExpansionKrystal sk)
        {
            MissingValues.Text = "Missing Values:  " + _krystal.MissingValues;
            Shape.Text = "Shape:  " + _krystal.Shape;

            StrandsTreeView.Nodes.Clear();
            ExpansionTreeView expansionTreeView = new ExpansionTreeView(StrandsTreeView, sk.StrandNodeList(),
                sk.DensityInputKrystal.Level,
                sk.PointsInputKrystal.MissingAbsoluteValues);
            expansionTreeView.DisplayStrands(sk.Strands);
            StrandsTreeView.ExpandAll();
        }
Exemple #10
0
        /// <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
        }