/// <summary>
        /// Writes the readme to file.
        /// </summary>
        public void WriteOut(Assembly executingAssembly, ModelGroup test, string assetFolder)
        {
            string template;
            var    templatePath = $"AssetGenerator.ReadmeTemplates.{test.Id}.md";

            // Reads the template file.
            using (Stream stream = executingAssembly.GetManifestResourceStream(templatePath))
                using (var streamReader = new StreamReader(stream))
                {
                    template = streamReader.ReadToEnd();
                }

            // If there are required properties, build the header table and inserts it into the template.
            if (test.CommonProperties != null)
            {
                foreach (var line in readmePrereqs)
                {
                    if (line.Count > 0)
                    {
                        md.AppendLine($"| {string.Join(" | ", line)} |");
                    }
                }
                template = template.Replace("~~HeaderTable~~", md.ToString());
                md.Clear();
            }
            else
            {
                template = template.Replace("~~HeaderTable~~", "");
            }

            // Build the table for the test properties and inserts it into the template.
            foreach (var line in readme)
            {
                if (line.Count > 0)
                {
                    md.AppendLine($"| {string.Join(" | ", line)} |");
                }
            }
            template = template.Replace("~~Table~~", md.ToString());

            // Writes the logs out to file.
            string readmeFilePath = Path.Combine(assetFolder, "README.md");

            File.WriteAllText(readmeFilePath, template);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds the strings used to make the main table for each model group's readme.
        /// </summary>
        public void SetupTable(ModelGroup test, int modelIndex, Model model, string testType)
        {
            var modelGroupName = test.Id.ToString();
            var modelNumber    = modelIndex.ToString("D2");
            var modelName      = $"{modelGroupName}_{modelNumber}";
            var liveURL        = $"https://bghgary.github.io/glTF-Assets-Viewer/?type={testType}&folder={test.Id:D}&model={modelIndex}";

            // Creates a new row for a new model.
            var modelInfo = new List <string>
            {
                // Displays the number of the model and is a link to the model.
                $"[{modelNumber}]({modelName}.gltf)<br>[View]({liveURL})"
            };

            if (test.NoSampleImages == false)
            {
                // Also a sample image in the second cell.

                modelInfo.Add($"[<img src=\"Figures/Thumbnails/{modelName}.{(model.Animated ? "gif" : "png")}\" align=\"middle\">](Figures/SampleImages/{modelName}.{(model.Animated ? "gif" : "png")})");
            }
            readme.Add(modelInfo);

            // Checks the list of properties used in the model against the list of column names.
            // If there is no property that matches a column name, that cell is left blank. Otherwise the property value is added to that cell.
            // There is no handling for multiple properties with the same name on the same model.
            var logIndex = readme.Count - 1;

            foreach (var possibleAttribute in columnNames)
            {
                var attributeIndex = model.Properties.FindIndex(e => e.Name == possibleAttribute);
                if (attributeIndex == -1)
                {
                    readme[logIndex].Add(" ");
                }
                else
                {
                    readme[logIndex].Add(model.Properties[attributeIndex].ReadmeValue);
                }
            }
        }
        /// <summary>
        /// Creates the table of required properties, as well as the column names for the main table.
        /// </summary>
        public void SetupHeader(ModelGroup test)
        {
            // Setup the log file header.
            // List attributes that are set in every generated model (prerequisites).
            if (test.CommonProperties != null)
            {
                // First line of table must be blank.
                readmePrereqs.Add(new List <string>());

                // First cells are a static label.
                readmePrereqs.Add(new List <string>
                {
                    "Property",
                    "**Values**",
                });

                // Hyphens for row after header.
                readmePrereqs.Add(new List <string>
                {
                    ":---:",
                    ":---:",
                });

                foreach (var property in test.CommonProperties)
                {
                    readmePrereqs.Add(new List <string>
                    {
                        property.ReadmeColumnName,
                        property.ReadmeValue
                    });
                }
            }

            // Now start the table for generated models.
            // First line of table must be blank.
            readme.Add(new List <string>());

            // First cell is empty.
            var firstLine = new List <string>
            {
                " "
            };

            // Hyphens for rows after header.
            var secondLine = new List <string>
            {
                ":---:"
            };

            if (test.NoSampleImages == false)
            {
                // The second cell is a static header name.
                firstLine.Add("Sample Image");
                // Add another row for the header name.
                secondLine.Add(":---:");
            }

            readme.Add(firstLine);
            readme.Add(secondLine);

            // Generates the list of column names for use when setting up the table, and generates that part of the table as well.
            foreach (var property in test.Properties)
            {
                string attributeName = property.ReadmeColumnName;

                if (!columnNames.Contains(property.Name))
                {
                    readme[1].Add(attributeName);
                    readme[2].Add(":---:");
                    columnNames.Add(property.Name);
                }
            }
        }
Esempio n. 4
0
 public virtual List <List <Property> > ApplySpecialProperties(ModelGroup modelGroup, List <List <Property> > combos)
 {
     return(combos);
 }
Esempio n. 5
0
        public void SetupHeader(ModelGroup test)
        {
            // Setup the log file header
            if (test.requiredProperty != null)
            {
                // List attributes that are set in every generated model (prerequisites)
                readmePrereqs.Add(new List <string>()); // First line of table must be blank
                readmePrereqs.Add(new List <string>
                {
                    "Property", // First cells are a static label
                    "**Values**"
                });
                readmePrereqs.Add(new List <string>
                {
                    ":---:", // Hyphens for row after header
                    ":---:",
                });
                for (int i = 0; i < test.requiredProperty.Count; i++)
                {
                    string attributeName;
                    attributeName = test.requiredProperty[i].name.ToString();
                    attributeName = ReadmeStringHelper.GenerateNameWithSpaces(attributeName);
                    readmePrereqs.Add(new List <string>
                    {
                        attributeName,
                        ReadmeStringHelper.ConvertTestValueToString(test.requiredProperty[i])
                    });
                }
            }

            // Now start the table for generated models
            readme.Add(new List <string>()); // First line of table must be blank
            readme.Add(new List <string>
            {
                " ",
                "Reference Image"     // First cell is empty, the second is a static header name
            });
            readme.Add(new List <string>
            {
                ":---:",     // Hyphens for rows after header
                ":---:"
            });
            for (int i = 0; i < test.properties.Count; i++)
            {
                string attributeName;
                if (test.properties[i].prerequisite != Propertyname.Undefined && test.properties[i].propertyGroup == 0)
                {
                    attributeName = test.properties[i].prerequisite.ToString() + test.properties[i].name.ToString();
                }
                else
                {
                    attributeName = test.properties[i].name.ToString();
                }
                attributeName = ReadmeStringHelper.GenerateNameWithSpaces(attributeName);
                if (attributeName != lastName) // Skip duplicate names caused by non-binary attributes
                {
                    lastName = attributeName;
                    readme[1].Add(attributeName);
                    readme[2].Add(":---:");
                }
            }
        }
Esempio n. 6
0
        public void SetupTable(ModelGroup test, int comboIndex, List <List <Property> > combos)
        {
            string modelGroupName = test.modelGroupName.ToString();
            string modelNumber    = comboIndex.ToString("D2");
            string liveURL        = string.Format("https://bghgary.github.io/glTF-Asset-Generator/Preview/BabylonJS/?fileName={0}_{1}.gltf",
                                                  modelGroupName, modelNumber);

            readme.Add(new List <string> // New row for a new model
            {
                // Displays the number of the model and is a link to the model
                string.Format("[{1}]({0}_{1}.gltf)<br>[View]({2})", modelGroupName, modelNumber, liveURL),
                // Also a reference image in the second cell
                string.Format("[<img src=\"Thumbnails/{0}_{1}.png\" align=\"middle\">](ReferenceImages/{0}_{1}.png)",
                              modelGroupName, modelNumber)
            });
            int        logIndex      = readme.Count - 1;
            List <int> nonBinaryUsed = new List <int>();

            foreach (var possibleAttribute in test.properties)
            {
                var attributeIndex = combos[comboIndex].FindIndex(e =>
                                                                  e.name == possibleAttribute.name &&
                                                                  e.prerequisite == possibleAttribute.prerequisite);
                if (attributeIndex != -1)
                {
                    if (possibleAttribute.propertyGroup > 0)
                    {
                        var alreadyUsed = nonBinaryUsed.Exists(x => x == possibleAttribute.propertyGroup);
                        if (alreadyUsed)
                        {
                            // Overwrites the empty cell if a nonbinary of the same time had already been encountered and not used
                            readme[logIndex][readme[logIndex].Count - 1] = ReadmeStringHelper.ConvertTestValueToString(possibleAttribute);
                        }
                        else
                        {
                            // Creates a new cell, since this nonbinary type had not been encountered before
                            readme[logIndex].Add(ReadmeStringHelper.ConvertTestValueToString(possibleAttribute));
                            nonBinaryUsed.Add(possibleAttribute.propertyGroup);
                        }
                    }
                    else
                    {
                        readme[logIndex].Add(ReadmeStringHelper.ConvertTestValueToString(possibleAttribute));
                    }
                }
                else
                {
                    if (possibleAttribute.propertyGroup > 0)
                    {
                        var alreadyUsed = nonBinaryUsed.Exists(x => x == possibleAttribute.propertyGroup);
                        if (!alreadyUsed)
                        {
                            readme[logIndex].Add(" ");
                            nonBinaryUsed.Add(possibleAttribute.propertyGroup);
                        }
                    }
                    else
                    {
                        readme[logIndex].Add(" ");
                    }
                }
            }
        }
        public static List <List <Property> > AttributeCombos(ModelGroup test)
        {
            List <List <Property> > finalResult;
            List <List <Property> > removeTheseCombos = new List <List <Property> >();
            List <List <Property> > keepTheseCombos   = new List <List <Property> >();
            List <Property>         isPrerequisite    = new List <Property>();
            bool hasPrerequisiteAttribute;

            var combos = BasicSet <Property>(test.properties);

            // Include any special combos
            if (test.specialCombos.Any())
            {
                foreach (var x in test.specialCombos)
                {
                    var comboIndex = combos.FindIndex(e => e.Any() && e[0].name == x[0].name && e.Count() == 1);
                    combos.Insert(comboIndex + 1, x);
                }
            }

            // Remove the explicitly excluded combos
            if (test.removeCombos.Any())
            {
                foreach (var x in test.removeCombos)
                {
                    if (x.Count == 0)
                    {
                        combos.RemoveAll(e => e.Count == 0); // Removes the empty set
                    }
                    else
                    {
                        //combos.RemoveAll(e => e.Count == 1 && e[0].name == x[0].name);
                        combos.RemoveAll(e => FindCombo(e, x));
                    }
                }
            }

            if (test.noPrerequisite == false)
            {
                // Makes a list of names of possible prerequisites
                List <Propertyname> Prerequisites = new List <Propertyname>();
                foreach (var x in test.properties)
                {
                    if (x.prerequisite != Propertyname.Undefined)
                    {
                        if (Prerequisites.Any())
                        {
                            bool isNew = true;
                            foreach (var y in Prerequisites)
                            {
                                if (y == x.prerequisite)
                                {
                                    isNew = false;
                                    break;
                                }
                            }
                            if (isNew == true)
                            {
                                Prerequisites.Add(x.prerequisite);
                            }
                        }
                        else
                        {
                            Prerequisites.Add(x.prerequisite);
                        }
                    }
                }
                // Convert the name list into a list of the actual prerequisites
                foreach (var x in Prerequisites)
                {
                    foreach (var y in test.properties)
                    {
                        if (x == y.name)
                        {
                            isPrerequisite.Add(y);
                            break;
                        }
                    }
                }
                // Add combos where prerequisite property have all dependant property set
                foreach (var x in isPrerequisite)
                {
                    // Start a list with the prerequisite attribute
                    var addList = new List <Property>
                    {
                        x
                    };

                    // Populate that list will all of the required property
                    foreach (var y in test.properties)
                    {
                        if (y.prerequisite == x.name)
                        {
                            addList.Add(y);
                        }
                    }
                    // Then include the combo with the rest
                    var comboIndex = combos.FindIndex(e => e.Any() && e[0].name == addList[0].name && e.Count() == 1);
                    combos.Insert(comboIndex + 1, addList);
                }
            }

            // Handle non-binary property in the first combo
            if (test.onlyBinaryProperties == false)
            {
                List <Property> keep = new List <Property>();
                foreach (var x in combos[1])
                {
                    // Keep property if it is the first found or is binary
                    if (x.propertyGroup == 0 || (x.propertyGroup > 0 && !keep.Any()))
                    {
                        keep.Add(x);
                    }
                    else if (x.propertyGroup > 0)
                    {
                        bool alreadyKept = false;
                        foreach (var y in keep)
                        {
                            // Don't keep the nonbinary property if there is already one of that set on the list
                            if (y.propertyGroup == x.propertyGroup)
                            {
                                alreadyKept = true;
                                break;
                            }
                        }
                        if (alreadyKept == false) // Keep nonbinary property
                        {
                            keep.Add(x);
                        }
                    }
                }
                // Remove the extra nonbinary attributes
                combos[1] = keep;
            }

            // Removes sets that duplicate binary entries for a single property (e.g. alphaMode)
            // Removes sets where an attribute is missing a required property
            if (test.onlyBinaryProperties == false || test.noPrerequisite == false)
            {
                // Are there any prerequisite property?
                hasPrerequisiteAttribute = isPrerequisite.Any();

                // Makes a list of combos to remove
                int combosCount = combos.Count();
                for (int x = 2; x < combosCount; x++) // The first two combos are already taken care of
                {
                    bool                usedPrereq       = false;
                    List <int>          binarySets       = new List <int>();
                    List <Propertyname> usedPrerequisite = new List <Propertyname>();

                    // Makes a list of each prerequisite property in the current combo
                    if (hasPrerequisiteAttribute == true)
                    {
                        foreach (var prereq in isPrerequisite)
                        {
                            foreach (var attribute in combos[x])
                            {
                                if (attribute.name == prereq.name)
                                {
                                    usedPrerequisite.Add(prereq.name);
                                }
                            }
                        }
                        usedPrereq = usedPrerequisite.Any();
                    }

                    foreach (var attribute in combos[x])
                    {
                        // Remove combos that have multiple of the same binary combo
                        if (attribute.propertyGroup > 0)
                        {
                            if (binarySets.Contains(attribute.propertyGroup))
                            {
                                removeTheseCombos.Add(combos[x]);
                                break;
                            }
                            else
                            {
                                binarySets.Add(attribute.propertyGroup);
                            }
                        }
                        // Removes combos that have a property missing a prerequisite
                        if (usedPrereq == true && attribute.prerequisite != Propertyname.Undefined)
                        {
                            bool prereqNotFound = true;
                            foreach (var prereq in usedPrerequisite)
                            {
                                if (attribute.prerequisite == prereq)
                                {
                                    prereqNotFound = false;
                                    break;
                                }
                            }
                            if (prereqNotFound != false)
                            {
                                removeTheseCombos.Add(combos[x]);
                                break;
                            }
                        }
                        else if (usedPrereq == false && attribute.prerequisite != Propertyname.Undefined)
                        {
                            removeTheseCombos.Add(combos[x]);
                            break;
                        }
                    }
                }

                // Uses the list of bad combos to trim down the original set
                int numCombos            = combos.Count();
                int numRemoveTheseCombos = removeTheseCombos.Count();
                for (int x = 0; x < numCombos; x++)
                {
                    bool excludeCombo = false;
                    for (int y = 0; y < numRemoveTheseCombos; y++)
                    {
                        if (combos[x] == removeTheseCombos[y])
                        {
                            excludeCombo = true;
                            break;
                        }
                    }
                    if (excludeCombo == false)
                    {
                        keepTheseCombos.Add(combos[x]);
                    }
                }
                finalResult = keepTheseCombos;
            }
            else
            {
                // If there are only binary properties, we don't need to check for duplicates
                finalResult = combos;
            }

            // Runs any special property code that is specific to the model group
            finalResult = test.ApplySpecialProperties(test, finalResult);

            return(finalResult);
        }