Beispiel #1
0
        /// <summary>
        /// The total number of values in the returned list of int lists is equal to the number of values in
        /// the larger krystal. Each inner list corresponds to a value in this krystal, and contains that value
        /// repeated the appropriate number of times.
        /// Values in this krystal's strands are repeated according to the shape of the larger krystal.
        /// Restrictions:
        /// 1. the level of the largerKrystal must be greater than the level of this krystal.
        /// 2. the shape of this krystal must be contained in the shape of the larger krystal.
        /// </summary>
        /// <param name="largerKrystal"></param>
        /// <returns></returns>
        public List <List <int> > GetValuePerValue(Krystal largerKrystal)
        {
            Debug.Assert(largerKrystal.Shape.Contains(this.Shape));
            Debug.Assert(largerKrystal.Level > this.Level);

            List <List <int> > returnValue  = new List <List <int> >();
            List <List <int> > largerValues = largerKrystal.GetValues(this.Level + 1);
            // each list in largerValues corresponds to a value in this krystal
            int  thisStrandIndex = 0;
            int  thisValueIndex  = 0;
            uint thisValue       = this.Strands[thisStrandIndex].Values[thisValueIndex];

            foreach (List <int> listInt in largerValues)
            {
                List <int> innerList = new List <int>();
                returnValue.Add(innerList);
                foreach (int i in listInt)
                {
                    innerList.Add((int)thisValue);
                }

                thisValueIndex++;
                if (thisValueIndex == this.Strands[thisStrandIndex].Values.Count)
                {
                    thisValueIndex = 0;
                    thisStrandIndex++;
                }

                if (thisStrandIndex < this.Strands.Count)
                {
                    thisValue = this.Strands[thisStrandIndex].Values[thisValueIndex];
                }
            }
            return(returnValue);
        }
Beispiel #2
0
        /// <summary>
        /// This function returns 0 if the shape and numeric content are the same,
        /// Otherwise it compares the two names.
        /// </summary>
        /// <param name="otherKrystal"></param>
        /// <returns></returns>
        public int CompareTo(object other)
        {
            Krystal otherKrystal = other as Krystal;

            if (otherKrystal == null)
            {
                throw new ArgumentException();
            }

            bool isEquivalent = false;

            if (this.Shape == otherKrystal.Shape &&
                this.Strands.Count == otherKrystal.Strands.Count &&
                this.Level == otherKrystal.Level &&
                this.MaxValue == otherKrystal.MaxValue &&
                this.MinValue == otherKrystal.MinValue &&
                this.NumValues == otherKrystal.NumValues &&
                this.MissingValues == otherKrystal.MissingValues)
            {
                isEquivalent = true;
                for (int i = 0; i < this.Strands.Count; i++)
                {
                    Strand thisStrand  = this.Strands[i];
                    Strand otherStrand = otherKrystal.Strands[i];
                    if (thisStrand.Values.Count != otherStrand.Values.Count ||
                        thisStrand.Level != otherStrand.Level)
                    {
                        isEquivalent = false;
                        break;
                    }
                    for (int j = 0; j < thisStrand.Values.Count; j++)
                    {
                        if (thisStrand.Values[j] != otherStrand.Values[j])
                        {
                            isEquivalent = false;
                            break;
                        }
                    }
                }
            }
            if (isEquivalent == true)
            {
                return(0);
            }
            else
            {
                return(this.Name.CompareTo(otherKrystal.Name));
            }
        }
Beispiel #3
0
        public static Krystal GetKrystal(string krystalFileName)
        {
            Krystal krystal = null;

            try
            {
                string krystalPath = KrystalsFolder + @"\" + krystalFileName;
                krystal = K.LoadKrystal(krystalPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading krystal.\n\n" + ex.Message);
                krystal = null;
            }
            return(krystal);
        }
Beispiel #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);
        }
Beispiel #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);
        }