private static NgParameterRange DetectPattern(NgParameterRange parameter, NgBlock dbgBlock) { if (parameter.Kind != NgParameterKind.FixedEnumeration) { return(parameter); } // Parse the numbers inside the strings. var unmappedEnums = new List <Parsed>(); foreach (var entry in parameter.FixedEnumeration) { unmappedEnums.Add(new Parsed { Original = entry.Value, Substrings = SplitIntoNumbers(entry.Value.Name) }); } unmappedEnums.Sort(); var outputChoice = new List <NgParameterRange>(); while (DetectLinearity(outputChoice, unmappedEnums, dbgBlock)) { } return(new NgParameterRange(outputChoice)); }
private static void AddFixed(List <NgParameterRange> choice, IEnumerable <TriggerParameterUshort> enumsToAdd) { if (!enumsToAdd.Any()) { return; } for (int i = 0; i < choice.Count; ++i) { if (choice[i].Kind == NgParameterKind.FixedEnumeration) { choice[i] = new NgParameterRange(choice[i].FixedEnumeration.Values.Concat(enumsToAdd).ToDictionary(e => e.Key)); return; } } choice.Add(new NgParameterRange(enumsToAdd.ToDictionary(e => e.Key))); }
private static XObject[] WriteNgParameterRange(NgParameterRange parameter) { XElement parameterElement = new XElement(parameter.Kind.ToString()); switch (parameter.Kind) { case NgParameterKind.FixedEnumeration: foreach (TriggerParameterUshort value in parameter.FixedEnumeration.Values) { parameterElement.Add(new XElement("Enum", new XAttribute("K", value.Key), new XAttribute("V", value.Name))); } break; case NgParameterKind.LinearModel: foreach (NgLinearParameter linearParameter in parameter.LinearModel.Value.Parameters) { if (linearParameter.FixedStr != null) { parameterElement.Add(new XElement("Fixed", linearParameter.FixedStr)); } else { parameterElement.Add(new XElement("Linear", new XAttribute("Add", linearParameter.Add), new XAttribute("Factor", linearParameter.Factor))); } } parameterElement.Add(new XAttribute("Start", parameter.LinearModel.Value.Start)); parameterElement.Add(new XAttribute("End", parameter.LinearModel.Value.EndInclusive)); break; case NgParameterKind.Choice: foreach (NgParameterRange choice in parameter.Choices) { parameterElement.Add(WriteNgParameterRange(choice)); } break; } return(new XObject[] { parameterElement }); }