private void UpdateFormatting() { bool updateVariables = false; foreach (var entry in _overlayEntries) { if (entry.FormatChanged) { updateVariables = true; // group name format var basicGroupFormat = entry.GroupSeparators == 0 ? "{0}" : Enumerable.Repeat("\n", entry.GroupSeparators).Aggregate((i, j) => i + j) + "{0}"; var groupNameFormatStringBuilder = new StringBuilder(); groupNameFormatStringBuilder.Append("<S="); groupNameFormatStringBuilder.Append(entry.GroupFontSize.ToString()); AppendColorFormat(groupNameFormatStringBuilder, entry.GroupColor); groupNameFormatStringBuilder.Append(basicGroupFormat); groupNameFormatStringBuilder.Append(" <C><S>"); entry.GroupNameFormat = groupNameFormatStringBuilder.ToString(); if (entry.ValueUnitFormat != null && entry.ValueAlignmentAndDigits != null) { var valueFormatStringBuilder = new StringBuilder(); valueFormatStringBuilder.Append("<S="); valueFormatStringBuilder.Append(entry.ValueFontSize.ToString()); AppendColorFormat(valueFormatStringBuilder, entry.Color); valueFormatStringBuilder.Append(entry.ValueAlignmentAndDigits); valueFormatStringBuilder.Append("<C><S>"); valueFormatStringBuilder.Append("<S="); valueFormatStringBuilder.Append((entry.ValueFontSize / 2).ToString()); AppendColorFormat(valueFormatStringBuilder, entry.Color); valueFormatStringBuilder.Append(entry.ValueUnitFormat); valueFormatStringBuilder.Append("<C><S>"); entry.ValueFormat = valueFormatStringBuilder.ToString(); } else { var valueFormatStringBuilder = new StringBuilder(); valueFormatStringBuilder.Append("<S="); valueFormatStringBuilder.Append(entry.ValueFontSize.ToString()); AppendColorFormat(valueFormatStringBuilder, entry.Color); valueFormatStringBuilder.Append("{0}<C><S>"); entry.ValueFormat = valueFormatStringBuilder.ToString(); } // reset format changed and last limit state entry.FormatChanged = false; entry.LastLimitState = LimitState.Undefined; } // check value limits if (entry.ShowOnOverlay) { if (!(entry.LowerLimitValue == string.Empty && entry.UpperLimitValue == string.Empty)) { var currentColor = string.Empty; bool upperLimit = false; bool lowerLimit = false; LimitState limitState = LimitState.Undefined; if (entry.Value == null) { continue; } if (entry.UpperLimitValue != string.Empty) { if (!double.TryParse(entry.Value.ToString(), out double currentConvertedValue)) { continue; } if (!double.TryParse(entry.UpperLimitValue, NumberStyles.Float, CultureInfo.InvariantCulture, out double convertedUpperValue)) { continue; } if (currentConvertedValue >= convertedUpperValue) { currentColor = entry.UpperLimitColor; upperLimit = true; limitState = LimitState.Upper; } } if (entry.LowerLimitValue != string.Empty) { if (!upperLimit) { if (!double.TryParse(entry.Value.ToString(), out double currentConvertedValue)) { continue; } if (!double.TryParse(entry.LowerLimitValue, NumberStyles.Float, CultureInfo.InvariantCulture, out double convertedLowerValue)) { continue; } if (currentConvertedValue <= convertedLowerValue) { currentColor = entry.LowerLimitColor; lowerLimit = true; limitState = LimitState.Lower; } } } if (!upperLimit && !lowerLimit) { currentColor = entry.Color; limitState = LimitState.None; } if (limitState != entry.LastLimitState) { if (entry.ValueUnitFormat != null && entry.ValueAlignmentAndDigits != null) { updateVariables = true; var valueFormatStringBuilder = new StringBuilder(); valueFormatStringBuilder.Append("<S="); valueFormatStringBuilder.Append(entry.ValueFontSize.ToString()); AppendColorFormat(valueFormatStringBuilder, currentColor); valueFormatStringBuilder.Append(entry.ValueAlignmentAndDigits); valueFormatStringBuilder.Append("<C><S>"); valueFormatStringBuilder.Append("<S="); valueFormatStringBuilder.Append((entry.ValueFontSize / 2).ToString()); AppendColorFormat(valueFormatStringBuilder, currentColor); valueFormatStringBuilder.Append(entry.ValueUnitFormat); valueFormatStringBuilder.Append("<C><S>"); entry.ValueFormat = valueFormatStringBuilder.ToString(); } else { updateVariables = true; var valueFormatStringBuilder = new StringBuilder(); valueFormatStringBuilder.Append("<S="); valueFormatStringBuilder.Append(entry.ValueFontSize.ToString()); AppendColorFormat(valueFormatStringBuilder, currentColor); valueFormatStringBuilder.Append("{0}<C><S>"); entry.ValueFormat = valueFormatStringBuilder.ToString(); } entry.LastLimitState = limitState; } } } } if (updateVariables) { var colorVariablesStringBuilder = new StringBuilder(); _colorIndexDictionary.ForEach(pair => colorVariablesStringBuilder.Append($"<C{pair.Value}={pair.Key}>")); _rTSSService.SetFormatVariables(colorVariablesStringBuilder.ToString()); } }