Exemple #1
0
        /// <summary>Writes documentation for this function by adding to the list of documentation tags.</summary>
        /// <param name="tags">The list of tags to add to.</param>
        /// <param name="headingLevel">The level (e.g. H2) of the headings.</param>
        /// <param name="indent">The level of indentation 1, 2, 3 etc.</param>
        public virtual void Document(List <AutoDocumentation.ITag> tags, int headingLevel, int indent)
        {
            if (IncludeInDocumentation)
            {
                // add a heading.
                tags.Add(new AutoDocumentation.Heading(Name, headingLevel));

                // write description of this class.
                AutoDocumentation.DocumentModel(this, tags, headingLevel, indent, true);

                //foreach (IModel model in Children)
                //    model.Document(tags, headingLevel+1, indent);
            }
        }
Exemple #2
0
        /// <summary>Documents the specified model.</summary>
        /// <param name="modelNameToDocument">The model name to document.</param>
        /// <param name="tags">The auto doc tags.</param>
        /// <param name="headingLevel">The starting heading level.</param>
        public void DocumentModel(string modelNameToDocument, List <AutoDocumentation.ITag> tags, int headingLevel)
        {
            Simulation simulation = Apsim.Find(this, typeof(Simulation)) as Simulation;

            if (simulation != null)
            {
                // Find the model of the right name.
                IModel modelToDocument = Apsim.Find(simulation, modelNameToDocument);

                // If not found then find a model of the specified type.
                if (modelToDocument == null)
                {
                    modelToDocument = Apsim.Get(simulation, "[" + modelNameToDocument + "]") as IModel;
                }

                // If the simulation has the same name as the model we want to document, dig a bit deeper
                if (modelToDocument == simulation)
                {
                    modelToDocument = Apsim.ChildrenRecursivelyVisible(simulation).FirstOrDefault(m => m.Name.Equals(modelNameToDocument, StringComparison.OrdinalIgnoreCase));
                }

                // If still not found throw an error.
                if (modelToDocument != null)
                {
                    // Get the path of the model (relative to parentSimulation) to document so that
                    // when replacements happen below we will point to the replacement model not the
                    // one passed into this method.
                    string pathOfSimulation      = Apsim.FullPath(simulation) + ".";
                    string pathOfModelToDocument = Apsim.FullPath(modelToDocument).Replace(pathOfSimulation, "");

                    // Clone the simulation
                    Simulation clonedSimulation = Apsim.Clone(simulation) as Simulation;

                    // Make any substitutions.
                    MakeSubstitutions(clonedSimulation);

                    // Now use the path to get the model we want to document.
                    modelToDocument = Apsim.Get(clonedSimulation, pathOfModelToDocument) as IModel;

                    if (modelToDocument == null)
                    {
                        throw new Exception("Cannot find model to document: " + modelNameToDocument);
                    }

                    // resolve all links in cloned simulation.
                    Links.Resolve(clonedSimulation);

                    modelToDocument.IncludeInDocumentation = true;
                    foreach (IModel child in Apsim.ChildrenRecursively(modelToDocument))
                    {
                        child.IncludeInDocumentation = true;
                    }

                    // Document the model.
                    AutoDocumentation.DocumentModel(modelToDocument, tags, headingLevel, 0, documentAllChildren: true);

                    // Unresolve links.
                    Links.Unresolve(clonedSimulation);
                }
            }
        }
Exemple #3
0
        /// <summary>Writes documentation for this function by adding to the list of documentation tags.</summary>
        /// <param name="tags">The list of tags to add to.</param>
        /// <param name="headingLevel">The level (e.g. H2) of the headings.</param>
        /// <param name="indent">The level of indentation 1, 2, 3 etc.</param>
        public void Document(List <AutoDocumentation.ITag> tags, int headingLevel, int indent)
        {
            if (IncludeInDocumentation)
            {
                // add a heading.
                tags.Add(new AutoDocumentation.Heading(Name, headingLevel));

                if (ShowPageOfGraphs)
                {
                    foreach (Memo memo in FindAllChildren <Memo>())
                    {
                        memo.Document(tags, headingLevel, indent);
                    }

                    if (FindAllChildren <Experiment>().Any())
                    {
                        // Write Phase Table
                        tags.Add(new AutoDocumentation.Paragraph("**List of experiments.**", indent));
                        DataTable tableData = new DataTable();
                        tableData.Columns.Add("Experiment Name", typeof(string));
                        tableData.Columns.Add("Design (Number of Treatments)", typeof(string));

                        foreach (IModel child in FindAllChildren <Experiment>())
                        {
                            IModel Factors = child.FindChild <Factors>();
                            string Design  = "";
                            foreach (Factor factor in Factors.FindAllChildren <Factor>())
                            {
                                if (Design != "")
                                {
                                    Design += " x ";
                                }
                                Design += factor.Name;
                            }

                            var simulationNames = (child as Experiment).GenerateSimulationDescriptions().Select(s => s.Name);
                            Design += " (" + simulationNames.ToArray().Length + ")";

                            DataRow row = tableData.NewRow();
                            row[0] = child.Name;
                            row[1] = Design;
                            tableData.Rows.Add(row);
                        }
                        tags.Add(new AutoDocumentation.Table(tableData, indent));
                    }
                    int          pageNumber = 1;
                    int          i          = 0;
                    List <Graph> children   = FindAllChildren <Graph>().ToList();
                    while (i < children.Count)
                    {
                        GraphPage page = new GraphPage();
                        page.name = Name + pageNumber;
                        for (int j = i; j < i + 6 && j < children.Count; j++)
                        {
                            if (children[j].IncludeInDocumentation)
                            {
                                page.graphs.Add(children[j] as Graph);
                            }
                        }
                        if (page.graphs.Count > 0)
                        {
                            tags.Add(page);
                        }
                        i += 6;
                        pageNumber++;
                    }

                    // Document everything else other than graphs
                    foreach (IModel model in Children)
                    {
                        if (!(model is Graph) && !(model is Memo))
                        {
                            AutoDocumentation.DocumentModel(model, tags, headingLevel + 1, indent);
                        }
                    }
                }
                else
                {
                    foreach (IModel model in Children)
                    {
                        AutoDocumentation.DocumentModel(model, tags, headingLevel + 1, indent);
                    }
                }
            }
        }