Esempio n. 1
0
        /// <summary>
        /// Attach the model
        /// </summary>
        public void AttachData()
        {
            if (!(forestryModel.Parent is AgroforestrySystem))
            {
                throw new ApsimXException(forestryModel, "Error: TreeProxy must be a child of ForestrySystem.");
            }

            Soil          soil;
            List <IModel> zones = Apsim.ChildrenRecursively(forestryModel.Parent, typeof(Zone));

            if (zones.Count == 0)
            {
                return;
            }

            // Setup tree heights.
            forestryViewer.SetupHeights(forestryModel.Dates, forestryModel.Heights, forestryModel.NDemands, forestryModel.ShadeModifiers);

            // Get the first soil. For now we're assuming all soils have the same structure.
            soil = Apsim.Find(zones[0], typeof(Soil)) as Soil;

            forestryViewer.SoilMidpoints = soil.DepthMidPoints;

            // Setup columns.
            List <string> colNames = new List <string>();

            colNames.Add("Parameter");
            colNames.Add("0");
            colNames.Add("0.5h");
            colNames.Add("1h");
            colNames.Add("1.5h");
            colNames.Add("2h");
            colNames.Add("2.5h");
            colNames.Add("3h");
            colNames.Add("4h");
            colNames.Add("5h");
            colNames.Add("6h");

            if (forestryModel.Table.Count == 0)
            {
                forestryModel.Table = new List <List <string> >();
                forestryModel.Table.Add(colNames);

                // Setup rows.
                List <string> rowNames = new List <string>();

                rowNames.Add("Shade (%)");
                rowNames.Add("Root Length Density (cm/cm3)");
                rowNames.Add("Depth (cm)");

                foreach (string s in APSIM.Shared.APSoil.SoilUtilities.ToDepthStrings(soil.Thickness))
                {
                    rowNames.Add(s);
                }

                forestryModel.Table.Add(rowNames);
                for (int i = 2; i < colNames.Count + 1; i++)
                {
                    forestryModel.Table.Add(Enumerable.Range(1, rowNames.Count).Select(x => "0").ToList());
                }

                for (int i = 2; i < forestryModel.Table.Count; i++)
                {
                    // Set Depth and RLD rows to empty strings.
                    forestryModel.Table[i][1] = string.Empty;
                    forestryModel.Table[i][2] = string.Empty;
                }
            }
            else
            {
                // add Zones not in the table
                IEnumerable <string> except = colNames.Except(forestryModel.Table[0]);
                foreach (string s in except)
                {
                    forestryModel.Table.Add(Enumerable.Range(1, forestryModel.Table[1].Count).Select(x => "0").ToList());
                }

                forestryModel.Table[0].AddRange(except);
                for (int i = 2; i < forestryModel.Table.Count; i++)
                {
                    // Set Depth and RLD rows to empty strings.
                    forestryModel.Table[i][2] = string.Empty;
                }

                // Remove Zones from table that don't exist in simulation.
                except = forestryModel.Table[0].Except(colNames);
                List <int> indexes = new List <int>();
                foreach (string s in except.ToArray())
                {
                    indexes.Add(forestryModel.Table[0].FindIndex(x => s == x));
                }

                indexes.Sort();
                indexes.Reverse();

                foreach (int i in indexes)
                {
                    forestryModel.Table[0].RemoveAt(i);
                    forestryModel.Table.RemoveAt(i + 1);
                }
            }
            forestryViewer.SpatialData = forestryModel.Table;
        }
Esempio n. 2
0
        public void AttachData()
        {
            if (!(ForestryModel.Parent is AgroforestrySystem))
            {
                throw new ApsimXException(ForestryModel, "Error: TreeProxy must be a child of ForestrySystem.");
            }

            Soil          Soil;
            List <IModel> Zones = Apsim.ChildrenRecursively(ForestryModel.Parent, typeof(Zone));

            if (Zones.Count == 0)
            {
                return;
            }

            // setup tree heights
            ForestryViewer.SetupHeights(ForestryModel.dates, ForestryModel.heights, ForestryModel.NDemands, ForestryModel.CanopyWidths, ForestryModel.TreeLeafAreas);

            /*      //get the distance of each Zone from Tree.
             *    double zoneWidth = 0;
             *    double[] ZoneWidths = new double[Zones.Count];
             *
             *    for (int i = 1; i < Zones.Count; i++) //skip first Zone with tree
             *    {
             *        if (Zones[i] is RectangularZone)
             *            zoneWidth = (Zones[i] as RectangularZone).Width;
             *        else if (Zones[i] is CircularZone)
             *            zoneWidth = (Zones[i] as CircularZone).Width;
             *
             *            ZoneWidths[i] = ZoneWidths[i - 1] + zoneWidth;
             *    }*/

            // get the first soil. For now we're assuming all soils have the same structure.
            Soil = Apsim.Find(Zones[0], typeof(Soil)) as Soil;

            ForestryViewer.SoilMidpoints = Soil.DepthMidPoints;
            // setup columns
            List <string> colNames = new List <string>();

            colNames.Add("Parameter");
            colNames.Add("0");
            colNames.Add("0.5h");
            colNames.Add("1h");
            colNames.Add("1.5h");
            colNames.Add("2h");
            colNames.Add("2.5h");
            colNames.Add("3h");
            colNames.Add("4h");
            colNames.Add("5h");
            colNames.Add("6h");

            if (ForestryModel.Table.Count == 0)
            {
                ForestryModel.Table = new List <List <String> >();
                ForestryModel.Table.Add(colNames);

                // setup rows
                List <string> rowNames = new List <string>();

                rowNames.Add("Shade (%)");
                rowNames.Add("Root Length Density (cm/cm3)");
                rowNames.Add("Depth (cm)");

                foreach (string s in Soil.Depth)
                {
                    rowNames.Add(s);
                }

                ForestryModel.Table.Add(rowNames);
                for (int i = 2; i < colNames.Count + 1; i++)
                {
                    ForestryModel.Table.Add(Enumerable.Range(1, rowNames.Count).Select(x => "0").ToList());
                }

                for (int i = 2; i < ForestryModel.Table.Count; i++) // set Depth and RLD rows to empty strings
                {
                    ForestryModel.Table[i][1] = string.Empty;
                    ForestryModel.Table[i][2] = string.Empty;
                }
            }
            else
            {
                // add Zones not in the table
                IEnumerable <string> except = colNames.Except(ForestryModel.Table[0]);
                foreach (string s in except)
                {
                    ForestryModel.Table.Add(Enumerable.Range(1, ForestryModel.Table[1].Count).Select(x => "0").ToList());
                }
                ForestryModel.Table[0].AddRange(except);
                for (int i = 2; i < ForestryModel.Table.Count; i++) // set Depth and RLD rows to empty strings
                {
                    ForestryModel.Table[i][2] = string.Empty;
                    // ForestryModel.Table[i][3] = string.Empty;
                }

                // remove Zones from table that don't exist in simulation
                except = ForestryModel.Table[0].Except(colNames);
                List <int> indexes = new List <int>();
                foreach (string s in except.ToArray())
                {
                    indexes.Add(ForestryModel.Table[0].FindIndex(x => s == x));
                }

                indexes.Sort();
                indexes.Reverse();

                foreach (int i in indexes)
                {
                    ForestryModel.Table[0].RemoveAt(i);
                    ForestryModel.Table.RemoveAt(i + 1);
                }
            }
            ForestryViewer.SetupGrid(ForestryModel.Table);
        }