/// <summary>Get a list of cultivars for crop.</summary>
        /// <param name="crop">The crop.</param>
        /// <returns>A list of cultivars.</returns>
        public static string[] GetCultivarNames(IPlant crop)
        {
            Simulations  simulations  = (crop as IModel).FindAncestor <Simulations>();
            Replacements replacements = simulations.FindChild <Replacements>();

            if (replacements == null)
            {
                return(crop.CultivarNames);
            }

            IPlant replacementCrop = replacements.FindChild((crop as IModel).Name) as IPlant;

            if (replacementCrop != null)
            {
                return(replacementCrop.CultivarNames);
            }

            // Check for cultivar folders under replacements.
            List <string> cultivarNames = crop.CultivarNames.ToList();

            foreach (CultivarFolder cultivarFolder in (crop as IModel).FindAllChildren <CultivarFolder>())
            {
                IModel replacementFolder = replacements.FindChild(cultivarFolder.Name);
                if (replacementFolder != null)
                {
                    // If we find a matching cultivar folder under replacements, remove
                    // all cultivar names added by this folder in the official plant
                    // model, and add the cultivar names added by the matching cultivar
                    // folder under replacements.
                    foreach (IModel cultivar in cultivarFolder.FindAllDescendants <Cultivar>())
                    {
                        cultivarNames.Remove(cultivar.Name);

                        // If the cultivar has memo children, then the memo text will
                        // be appended to the cultivar name after a vertical bar |.
                        // Technically, there could be a cultivar x and x|y, but the UI
                        // will prevent users from doing this, so the user would really
                        // just be digging their own hole at this point.
                        cultivarNames.RemoveAll(c => c.StartsWith(cultivar.Name + "|"));
                    }

                    foreach (Alias alias in cultivarFolder.FindAllDescendants <Alias>())
                    {
                        cultivarNames.RemoveAll(c => c.StartsWith(alias.Name + "|"));
                    }

                    foreach (IModel cultivar in replacementFolder.FindAllDescendants <Cultivar>())
                    {
                        cultivarNames.Add(cultivar.Name);
                    }
                }
            }
            return(cultivarNames.ToArray());
        }
Esempio n. 2
0
        /// <summary>Get a list of Phase Names for life Cycle</summary>
        /// <param name="crop">The crop.</param>
        /// <returns>A list of Phase Names.</returns>
        private string[] GetPhaseNames(LifeCycle lifeCycle)
        {
            if (lifeCycle.LifeCyclePhaseNames.Length == 0)
            {
                Simulations  simulations  = (lifeCycle as IModel).FindAncestor <Simulations>();
                Replacements replacements = simulations.FindChild <Replacements>();
                if (replacements != null)
                {
                    LifeCycle replacementLifeCycle = replacements.FindChild((lifeCycle as IModel).Name) as LifeCycle;
                    if (replacementLifeCycle != null)
                    {
                        return(replacementLifeCycle.LifeCyclePhaseNames);
                    }
                }
            }
            else
            {
                return(lifeCycle.LifeCyclePhaseNames);
            }

            return(new string[0]);
        }
Esempio n. 3
0
        /// <summary>Get a list of cultivars for crop.</summary>
        /// <param name="crop">The crop.</param>
        /// <returns>A list of cultivars.</returns>
        private string[] GetCultivarNames(IPlant crop)
        {
            if (crop.CultivarNames.Length == 0)
            {
                Simulations  simulations  = (crop as IModel).FindAncestor <Simulations>();
                Replacements replacements = simulations.FindChild <Replacements>();
                if (replacements != null)
                {
                    IPlant replacementCrop = replacements.FindChild((crop as IModel).Name) as IPlant;
                    if (replacementCrop != null)
                    {
                        return(replacementCrop.CultivarNames);
                    }
                }
            }
            else
            {
                return(crop.CultivarNames);
            }

            return(new string[0]);
        }