Files
DP44/docs/ai/Common/DTS.Common/Converters.md
2026-04-17 14:55:32 -04:00

15 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.Common/Converters/BooleanToBorderThicknessConverter.cs
Common/DTS.Common/Converters/BooleanToBorderBrushConverter.cs
Common/DTS.Common/Converters/BooleanToGreenBorderConverter.cs
Common/DTS.Common/Converters/YesNoRadioButtonsConventer.cs
Common/DTS.Common/Converters/BooleanOrMultiConverter.cs
Common/DTS.Common/Converters/DateTimeWithMillisecondsToStringConverter.cs
Common/DTS.Common/Converters/EnumVisibilityConverter.cs
Common/DTS.Common/Converters/InverseEnumVisibilityConverter.cs
Common/DTS.Common/Converters/ActiveContentConverter.cs
Common/DTS.Common/Converters/FaultedTextConverter.cs
Common/DTS.Common/Converters/TriggerTextConverter.cs
Common/DTS.Common/Converters/TriggerColorConverter.cs
Common/DTS.Common/Converters/FaultedColorConverter.cs
Common/DTS.Common/Converters/DateConverter.cs
Common/DTS.Common/Converters/NullableFloatConverter.cs
Common/DTS.Common/Converters/InverseEnumEnabledConverter.cs
Common/DTS.Common/Converters/IsLessThanConverter.cs
Common/DTS.Common/Converters/ListToStringConverter.cs
Common/DTS.Common/Converters/IsGreaterThanConverter.cs
Common/DTS.Common/Converters/NonZeroToColorConverter.cs
Common/DTS.Common/Converters/HeightConverter.cs
Common/DTS.Common/Converters/ErrorToBooleanConverter.cs
Common/DTS.Common/Converters/WidthConverter.cs
Common/DTS.Common/Converters/StringListToVisibilityConverter.cs
Common/DTS.Common/Converters/StatusToBorderThicknessConverter.cs
Common/DTS.Common/Converters/ArrayVisibilityConverter.cs
Common/DTS.Common/Converters/DSPStreamingFilterFrequencyConverter.cs
Common/DTS.Common/Converters/ErrorToColorConverter.cs
Common/DTS.Common/Converters/GreaterThanToBoolConverter.cs
Common/DTS.Common/Converters/BooleanToColorConverter.cs
Common/DTS.Common/Converters/BooleanToItalicFontStyleConverter.cs
Common/DTS.Common/Converters/IntervalToVisibilityConverter.cs
Common/DTS.Common/Converters/StatusToColorConverter.cs
Common/DTS.Common/Converters/DiagStatusShuntColorConverter.cs
Common/DTS.Common/Converters/DiagStatusOffsetColorConverter.cs
Common/DTS.Common/Converters/InverseBooleanToOpacityConverter.cs
Common/DTS.Common/Converters/ColorToSolidColorBrushConverter .cs
Common/DTS.Common/Converters/BooleanAndToVisibiltyMultiConverter.cs
Common/DTS.Common/Converters/BooleanOrToVisibilityMultiConverter.cs
Common/DTS.Common/Converters/DoubleFromThousandthUnitToBaseUnit.cs
Common/DTS.Common/Converters/BooleanToOpacityConverter.cs
Common/DTS.Common/Converters/DASStatusArmTextConverter.cs
Common/DTS.Common/Converters/RecordingModePreTriggerVisibilityConverter.cs
Common/DTS.Common/Converters/EnumBooleanConverter.cs
Common/DTS.Common/Converters/InitialOffsetToIEPESensorOffsetConverter.cs
Common/DTS.Common/Converters/DASStatusColorConverter.cs
Common/DTS.Common/Converters/DASStatusArmColorConverter .cs
Common/DTS.Common/Converters/PercentConverter.cs
Common/DTS.Common/Converters/NumericStringFormatConverter.cs
Common/DTS.Common/Converters/VisibilityToRowHeightConverter.cs
Common/DTS.Common/Converters/GroupImportErrorToStringConverter.cs
Common/DTS.Common/Converters/GroupNameToVisibilityConverter.cs
Common/DTS.Common/Converters/FilePathsToShortStringConverter.cs
Common/DTS.Common/Converters/InverseBooleanConverter.cs
Common/DTS.Common/Converters/EnumDescriptionTypeConverter.cs
2026-04-17T15:27:07.760999+00:00 zai-org/GLM-5-FP8 1 308c9c168d87b5fd

Documentation: DTS.Common.Converters

1. Purpose

This module provides a comprehensive library of WPF value converters (implementing IValueConverter and IMultiValueConverter) used to transform data models into UI representations within the DTS application. It bridges the gap between domain logic and presentation logic by handling conversions for data types such as Booleans, Enums, Collections, Dates, and domain-specific status objects into visual elements like Visibility, Brush (colors), Thickness, and formatted strings.

2. Public Interface

The module consists of the following classes, primarily located in the DTS.Common.Converters namespace.

Boolean Converters

  • BooleanToBorderThicknessConverter (IValueConverter)
    • Convert: Returns 1 if value is true, otherwise 2.
    • ConvertBack: Returns null.
  • BooleanToBorderBrushConverter (IValueConverter)
    • Convert: Returns BrushesAndColors.Brush_Warning if value is true and not null; otherwise Brushes.Transparent.
    • ConvertBack: Returns null.
  • BooleanToGreenBorderConverter (IValueConverter)
    • Convert: Returns BrushesAndColors.BrushApplicationStatusPowerGreen if value is true and not null; otherwise Brushes.Transparent.
    • ConvertBack: Returns null.
  • BooleanToColorConverter (IValueConverter)
    • Properties: Background (bool), Inverted (bool), AttentionBrush (bool), WarningBrush (bool).
    • Convert: Converts value (bool) to a Brush. Logic depends on configuration properties (e.g., returns Brush_NoError if true, Brush_Error/Brush_Attention/Brush_Warning if false).
    • ConvertBack: Returns null.
  • BooleanToItalicFontStyleConverter (IValueConverter)
    • Convert: Returns FontStyles.Italic if value is true; otherwise FontStyles.Normal.
    • ConvertBack: Returns null.
  • BooleanToOpacityConverter (IValueConverter)
    • Convert: Returns 0.5 if value is true; otherwise 1.
    • ConvertBack: Returns null.
  • InverseBooleanToOpacityConverter (IValueConverter)
    • Convert: Returns 1.0 if value is true; otherwise 0.5.
    • ConvertBack: Returns null.
  • InverseBooleanConverter (IValueConverter)
    • Convert: Returns the logical negation of value.
    • ConvertBack: Returns the logical negation of value.
  • BooleanOrMultiConverter (IMultiValueConverter)
    • Convert: Returns true if any value in the values array is true. Returns false if any element is not a bool.
    • ConvertBack: Throws NotImplementedException.

Visibility Converters

  • EnumVisibilityConverter (IValueConverter)
    • Convert: Returns Visibility.Visible if value.Equals(parameter); otherwise Visibility.Hidden.
    • ConvertBack: Returns parameter if value is Visibility.Visible; otherwise Binding.DoNothing.
  • InverseEnumVisibilityConverter (IValueConverter)
    • Convert: Returns Visibility.Hidden if value.Equals(parameter); otherwise Visibility.Visible.
    • ConvertBack: Returns parameter if value is Visibility.Hidden; otherwise Binding.DoNothing.
  • StringListToVisibilityConverter (IValueConverter)
    • Convert: Returns Visibility.Visible if the List<string> is not null and contains elements; otherwise Visibility.Collapsed.
    • ConvertBack: Throws NotImplementedException.
  • ArrayVisibilityConverter (IValueConverter)
    • Convert: Returns Visibility.Visible if value (IList or Array) has count/length > 0; otherwise Visibility.Collapsed or Hidden.
    • ConvertBack: Returns null.
  • BooleanAndToVisibilityMultiConverter (IMultiValueConverter)
    • Convert: Returns Visibility.Visible if all values are true. Supports parameter strings "FALSE" (inverts logic) and "HIDE" (uses Hidden instead of Collapsed).
    • ConvertBack: Throws NotImplementedException.
  • BooleanOrToVisibilityMultiConverter (IMultiValueConverter)
    • Convert: Returns Visibility.Visible if any value is true. Supports parameter strings "FALSE" and "HIDE".
    • ConvertBack: Throws NotImplementedException.
  • VisibilityToRowHeightConverter (IValueConverter, DependencyObject)
    • Convert: Returns 0 if value is Visibility.Collapsed; otherwise returns parameter. Supports InvertSource property.
    • ConvertBack: Returns null.
  • GroupNameToVisibilityConverter (IValueConverter)
    • Convert: Returns Visibility.Visible if value.ToString() starts with "Graph"; otherwise Visibility.Collapsed.
    • ConvertBack: Returns null.

Enum & Status Converters

  • EnumBooleanConverter (IValueConverter)
    • Convert: Returns value.Equals(parameter).
    • ConvertBack: Returns parameter if value is true; otherwise Binding.DoNothing.
  • InverseEnumEnabledConverter (IValueConverter)
    • Convert: Returns false if value.Equals(parameter); otherwise true.
    • ConvertBack: Returns parameter if value is false; otherwise Binding.DoNothing.
  • StatusToBorderThicknessConverter (IValueConverter)
    • Convert: Returns 2 if value (UIItemStatus) is Success, Failed, Error, or Warning; otherwise 1.
    • ConvertBack: Returns null.
  • StatusToColorConverter (IValueConverter)
    • Convert: Converts UIItemStatus to a specific Brush (e.g., Brush_ApplicationStatus_Complete for Success).
    • ConvertBack: Returns null.
  • DASStatusColorConverter, DASStatusArmColorConverter, DASStatusArmTextConverter
    • Convert DASStatuses enum to specific Brushes or Strings (e.g., "Armed", "NotArmed").
  • DiagStatusShuntColorConverter, DiagStatusOffsetColorConverter
    • Convert DiagStatuses to Brushes based on bitwise flag checks (& operator).

Numeric & Comparison Converters

  • IsLessThanConverter / IsGreaterThanConverter (IValueConverter)
    • Convert: Parses value and parameter as decimal. Returns result of comparison.
    • ConvertBack: Returns DependencyProperty.UnsetValue.
  • GreaterEqualThanToBoolConverter (IValueConverter)
    • Convert: Returns true if value >= parameter. Handles int, double, ushort.
    • ConvertBack: Returns false.
  • IntervalToVisibilityConverter (IValueConverter)
    • Convert: Returns Visibility.Visible if value >= parameter. Handles int, double, ushort.
    • ConvertBack: Returns false.
  • NonZeroToColorConverter (IValueConverter)
    • Convert: Returns Green if string is "0", Clear if "---", otherwise Red.
    • ConvertBack: Returns null.
  • DoubleFromThousandthUnitToBaseUnit (IValueConverter)
    • Convert: Divides value by 1000.0.
    • ConvertBack: Multiplies value by 1000.0.
  • PercentConverter (IValueConverter)
    • Convert: Formats decimal as "{0:F1}%".
    • ConvertBack: Throws NotImplementedException.

String & Text Converters

  • DateConverter (IValueConverter)
    • Convert: Returns DateTime if valid, otherwise Strings.Strings.Table_NA.
    • ConvertBack: Mirrors Convert.
  • DateTimeWithMillisecondsToStringConverter (IValueConverter)
    • Convert: Calls Utils.Utils.FormatTimeStamp.
    • ConvertBack: Returns null.
  • ListToStringConverter (IValueConverter)
    • Convert: Joins List<string> elements with ", ".
    • ConvertBack: Throws NotImplementedException.
  • FaultedTextConverter, TriggerTextConverter
    • Convert bool to specific localized strings (e.g., Strings.Strings.Faulted).
  • FilePathsToShortStringConverter (IValueConverter)
    • Convert: Returns filename for single path, or "MultipleFiles" string for array length > 1.
  • NumericStringFormatConverter (IMultiValueConverter)
    • Convert: Takes value and format string. Returns formatted string. Handles NaN.
  • EnumDescriptionTypeConverter (EnumConverter)
    • ConvertTo: Returns the DescriptionAttribute value of an Enum, looking up localization via Strings.Strings.ResourceManager.

Layout & Misc Converters

  • HeightConverter (MarkupExtension, IValueConverter)
    • Convert: Returns value - parameter.
    • ConvertBack: Returns null.
    • Usage: Can be instantiated directly in XAML due to MarkupExtension.
  • WidthConverter (MarkupExtension, IValueConverter)
    • Convert: Returns value * parameter.
    • ConvertBack: Throws NotImplementedException.
  • ActiveContentConverter (IValueConverter)
    • Convert/ConvertBack: Returns value if it is ContentControl, else Binding.DoNothing.
  • ColorToSolidColorBrushConverter (IValueConverter)
    • Convert: Returns new SolidColorBrush(color).
    • ConvertBack: Throws NotImplementedException.
  • NullableFloatConverter (IValueConverter)
    • Convert: Returns double or float value, or string.Empty.
    • ConvertBack: Returns float or string.Empty.

3. Invariants

  1. Input Type Requirements: Many converters perform direct casts (e.g., (bool)value in BooleanToBorderThicknessConverter) without null checks or type verification. The binding engine must supply the correct types, or a runtime exception will occur.
  2. One-Way Binding: The majority of converters return null, throw NotImplementedException, or return Binding.DoNothing in the ConvertBack method, indicating they are designed for OneWay binding mode.
  3. Parameter Usage: Several converters (e.g., EnumVisibilityConverter, IsLessThanConverter) rely heavily on the parameter argument passed from XAML. Omitting the parameter in the binding will result in incorrect logic or exceptions.
  4. Null Handling: Null handling is inconsistent across the module:
    • BooleanToBorderBrushConverter explicitly checks for null.
    • BooleanToBorderThicknessConverter does not check for null and will throw if value is null.
    • ArrayVisibilityConverter returns Hidden for null.
  5. Boolean Logic: BooleanOrMultiConverter returns false if any value in the input array is not of type bool. It does not ignore non-boolean values; it fails the operation.

4. Dependencies

Internal Dependencies (Inferred from imports):

  • DTS.Common.Base: Used for BrushesAndColors (static resource for specific brushes) and Strings.Strings (localized string lookup).
  • DTS.Common.Enums: Defines UIItemStatus, RecordingModes.
  • DTS.Common.Interface.Hardware: Defines DiagStatuses, DASStatuses.
  • DTS.Common.Classes.Groups: Defines GroupImportError.
  • Utils.Utils: Used for FormatTimeStamp in DateTimeWithMillisecondsToStringConverter.

External Dependencies:

  • System.Windows.Data (IValueConverter, IMultiValueConverter, Binding)
  • System.Windows.Media (Brush, Color, Brushes, SolidColorBrush)
  • System.Windows (Visibility, DependencyProperty, DependencyObject, ContentControl)
  • System.ComponentModel (EnumConverter, DescriptionAttribute)

5. Gotchas

  1. Filename/Classname Mismatch: The file GreaterThanToBoolConverter.cs contains the class GreaterEqualThanToBoolConverter. The logic performs a >= comparison, not just >.
  2. Copy-Paste Error in Documentation: The XML doc comment for `NullableFloat