This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Model/CalculatedChannelCreator.cs
generated_at: "2026-04-16T11:21:42.260506+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "d05bf6b72e9c97be"
---
# Documentation: CalculatedChannelCreator
## 1. Purpose
The `CalculatedChannelCreator` class is a static factory that creates derived data channels from existing test data channels. It supports multiple calculation types including aggregate operations (SUM, AVE, Resultant, HIC), binary operations (Integral, DoubleIntegral, Derivative, Sin, Cos), and specialized 3D IR-Tracc sensor calculations. The module handles sample rate alignment via super-sampling, creates persistent memory-mapped file storage for calculated data, and integrates the results back into the test data hierarchy.
## 2. Public Interface
### `CreateChannels`
```csharp
public static Test.Module.CalculatedChannel[] CreateChannels(
string testId,
string folder,
Calculation calculation,
List<Test.Module.Channel> inputChannels,
string channelName,
int startingNumber,
List<Test.Module.Channel> allChannels,
int clipLength,
out List<string> errorList,
int defaultEncoding)
```
**Behavior:** Main entry point for creating calculated channels. Routes to appropriate internal creation method based on `Calculation` type:
- `ThreeDIRTracc`, `ThreeDIRTraccLowerThorax`, `ThreeDIRTraccAbdomen``Create3DIRTraccChannels`
- `SUM`, `AVE`, `Resultant`, `HIC``CreateChannelsAggregateOperation`
- All others → `CreateChannelsBinaryOperation`
Returns `null` if channel name validation fails or calculation produces no results. Sets `AbsoluteDisplayOrder` on each returned channel starting from `startingNumber`.
### `ValidateChannelName`
```csharp
public static bool ValidateChannelName(
string channelName,
List<Test.Module.Channel> inputChannels,
List<Test.Module.Channel> allChannels,
out List<string> errorList)
```
**Behavior:** Validates that the channel name is non-empty and unique across both `inputChannels` and `allChannels`. Returns `true` if valid (empty error list). If `allChannels` is `null`, returns `true` immediately with no validation performed.
### `ThreeDIRTraccType` (nested enum)
```csharp
public enum ThreeDIRTraccType
{
Thorax,
Abdomen,
LowerThorax
}
```
**Behavior:** Specifies the anatomical mounting position for 3D IR-Tracc sensors, which affects calculation constants (`δ` and `D0`).
---
## 3. Invariants
1. **Channel Number Offset:** All calculated channels use `ChannelNumberCalculationChannelIndicator` (100000) as a base offset added to the provided starting number.
2. **3D IR-Tracc Input Count:** `Create3DIRTraccChannels` asserts that exactly 3 input channels are provided. Failure triggers `System.Diagnostics.Trace.Assert`.
3. **Aggregate Operation Input Count:** `CreateChannelsAggregateOperation` asserts at least 1 input channel is provided.
4. **Sample Rate Compatibility:** For aggregate and 3D IR-Tracc operations, the maximum sample rate must be an integer multiple of all input channel sample rates. If not, `NotSupportedException` is thrown.
5. **Binary Operations:** Only the first channel in `inputChannels` is used for binary operations (Integral, Derivative, Sin, Cos, etc.).
6. **HIC Unit Requirement:** HIC calculations require acceleration in g's. If input engineering units are not "g", data is converted from m/s² using factor `9.80665`.
7. **Super-Sampling Warning:** When input channels have different sample rates, a `PageErrorEvent` is published with `SuperSamplingWarning` resource string.
---
## 4. Dependencies
### This module depends on:
- `DTS.Common.Enums.Sensors` - `SensorConstants` for IR-Tracc physical constants
- `DTS.Common.Utilities.Logging` - `APILogger` for file operation logging
- `DTS.Common.Utils` - `FileUtils` for file deletion
- `DTS.Serialization` - `SliceRaw.File` format handling
- `DTS.Slice.Control` - Test/Event module channel types
- `DTS.Common` - `Constants.ADC_MIDPOINT`, `ZeroMethodType`
- `DTS.Common.Events` - `PageErrorEvent`, `PageErrorArg`
- `DTS.Common.Calculations` - `HeadInjuryCriterion` for HIC calculation
- `DTS.Common.Utilities.Math.Nhtsa` - `Integration`, `Differentiation` classes
- `Prism.Ioc` - `ContainerLocator` for service resolution
- `Prism.Events` - `IEventAggregator` for event publishing
### What depends on this module:
- **Inferred:** `AddCalculatedChannelViewModel` (referenced via `using static` for `ThreeDIRTraccType` context)
- **Inferred:** Any module calling `CreateChannels` to generate derived data channels
---
## 5. Gotchas
1. **Explicit GC.Collect():** `CreatePersistentInformationObject` calls `GC.Collect()` before attempting file deletion to release file handles. This is a heavy operation that may cause performance issues.
2. **Unused Variable:** In `PerformCalculationsAggregate`, the variable `timeAtIndex` is declared and assigned (`var timeAtIndex =`) but the value is never used—the assignment result is discarded.
3. **Debug File Replacement:** `PerformCalculation` (3D IR-Tracc) calls `DiskUtility.ReplaceDataIfNeeded` with hardcoded filenames (`"DISPLEU.txt"`, `"YPOTEU.txt"`, `"ZPOTEU.txt"`). This appears to be debug/test instrumentation left in production code.
4. **ScaleEuData Scaling Logic:** The scaling factor calculation handles bipolar signals by doubling the max value (`max *= 2`), but the scaleFactor calculation differs based on whether max exceeds `short.MaxValue`—one path divides, the other multiplies, which may produce unexpected scaling behavior.
5. **Null Return on Validation Failure:** `CreateChannels` returns `null` if `ValidateChannelName` fails, but the error list is populated via `out` parameter. Callers must check both the return value and error list.
6. **Binary Operations Ignore Additional Channels:** `CreateChannelsBinaryOperation` and `PerformCalculationBinary` only use `inputChannels[0]`. Additional channels in the list are silently ignored.
7. **HIC-Specific Handling:** HIC calculation is performed inside `CreateChannelsAggregateOperation` after channel creation, setting `T1`, `T2`, and `HIC` properties on the calculated channel. This is not visible from the public method signature.

View File

@@ -0,0 +1,41 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Properties/AssemblyInfo.cs
generated_at: "2026-04-16T11:21:22.849143+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "013fcfe349498337"
---
# Documentation: DTS.Viewer.AddCalculatedChannel Assembly Configuration
## 1. Purpose
This file provides assembly-level metadata and configuration for the `DTS.Viewer.AddCalculatedChannel` module. It exists to define the module's identity, version, and COM visibility settings within the larger DTS Viewer application. It serves as the build-time configuration for the compiled .NET assembly.
## 2. Public Interface
This file contains no public classes, methods, or functions. It applies the following assembly-level attributes:
* **`AssemblyTitle`**: Set to `"DTS.Viewer.AddCalculatedChannel"`.
* **`AssemblyProduct`**: Set to `"DTS.Viewer.AddCalculatedChannel"`.
* **`AssemblyCopyright`**: Set to `"Copyright © 2017"`.
* **`ComVisible`**: Set to `false`. Prevents types in this assembly from being visible to COM components.
* **`Guid`**: Set to `"6451f3ed-934e-47e3-a1ca-33c223a6507a"`. Identifies the type library ID if the project is exposed to COM.
* **`AssemblyVersion`**: Set to `"1.0.0.0"`.
* **`AssemblyFileVersion`**: Set to `"1.0.0.0"`.
## 3. Invariants
* **COM Visibility:** The attribute `ComVisible(false)` ensures that all types within this assembly are not exposed to COM by default.
* **Versioning:** The assembly and file versions are currently fixed at `1.0.0.0`.
* **Identity:** The assembly is uniquely identified by the GUID `6451f3ed-934e-47e3-a1ca-33c223a6507a`.
## 4. Dependencies
* **Internal Dependencies:**
* `System.Reflection`
* `System.Runtime.CompilerServices`
* `System.Runtime.InteropServices`
* **External Dependencies:** None identified from source alone (other than the standard .NET Framework).
## 5. Gotchas
* **Incomplete Metadata:** The `AssemblyDescription` and `AssemblyCompany` attributes are initialized as empty strings.
* **Hardcoded Version:** The version is hardcoded to `1.0.0.0`. The file contains a commented-out example for auto-incrementing syntax (`"1.0.*"`), but it is not active.
* **Stale Copyright:** The copyright string is hardcoded to 2017.

View File

@@ -0,0 +1,151 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Resources/TranslateExtension.cs
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Resources/StringResources.Designer.cs
generated_at: "2026-04-16T11:20:45.009025+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "5726c0d4d71935f1"
---
# Documentation: DTS.Viewer.AddCalculatedChannel.Resources
## 1. Purpose
This module provides localization infrastructure for the "Add Calculated Channel" feature within the DTS Viewer application. It consists of a WPF XAML markup extension (`TranslateExtension`) that enables declarative resource lookups in XAML bindings, and a strongly-typed resource accessor class (`StringResources`) that wraps a `.resx` file containing localized strings for UI elements, calculation types, error messages, and IR-TRACC measurement labels. The module supports the crash test data analysis domain, providing terminology for head injury criterion (HIC), 3D IR-TRACC calculations, and various mathematical operations.
---
## 2. Public Interface
### TranslateExtension (DTS.Viewer.AddCalculatedChannel)
A WPF markup extension for performing localized string lookups in XAML.
```csharp
[MarkupExtensionReturnType(typeof(string))]
public class TranslateExtension : MarkupExtension
```
**Constructor:**
- `TranslateExtension(string key)` — Initializes the extension with the resource key to look up. The key is stored in a private readonly field `_key`.
**Methods:**
- `public override object ProvideValue(IServiceProvider serviceProvider)` — Returns the localized string for the stored key. Returns `#stringnotfound#` if `_key` is null or empty. Returns `#stringnotfound# {key}` if the resource manager returns null for the given key.
**Constants:**
- `private const string NotFound = "#stringnotfound#"` — Fallback string used when a resource lookup fails.
---
### StringResources (DTS.Viewer.AddCalculatedChannel.Resources)
An auto-generated, strongly-typed resource accessor class. This class is `internal`.
```csharp
internal class StringResources
```
**Static Properties:**
| Property | Type | Description |
|----------|------|-------------|
| `ResourceManager` | `global::System.Resources.ResourceManager` | Lazily-initialized cached ResourceManager instance for the `DTS.Viewer.AddCalculatedChannel.Resources.StringResources` resource bundle. |
| `Culture` | `global::System.Globalization.CultureInfo` | Gets or sets the current thread's UI culture for resource lookups. |
**Resource String Properties (static, read-only):**
The following localized string properties are exposed. All return `string`:
- `AddCalculatedChannel` — "Add Calculated Channel"
- `CalculatedChannel_Average` — "Average"
- `CalculatedChannel_IRTRACC3D` — "3D IR-TRACC (upper thorax)"
- `CalculatedChannel_IRTRACC3D_Abdomen` — "3D IR-TRACC (abdomen)"
- `CalculatedChannel_IRTRACC3D_LowerThorax` — "3D IR-TRACC (lower thorax)"
- `CalculatedChannel_IRTRACC3D_Thorax` — "3D IR-TRACC (thorax)"
- `CalculatedChannel_IRTRACC3DAbdomen` — "3D IR-TRACC (abdomen)"
- `CalculatedChannel_IRTRACC3DLowerThorax` — "3D IR-TRACC (lower thorax)"
- `CalculatedChannel_Sum` — "Sum"
- `Calculation` — "Calculation"
- `CALCULATION_Cos` — "Cosine"
- `CALCULATION_Derivative` — "Derivative"
- `CALCULATION_DoubleIntegral` — "Double integral"
- `CALCULATION_Integral` — "Integral"
- `CALCULATION_Sin` — "Sine"
- `CALCULATION_ThreeDIRTracc` — "3D IR-TRACC (upper thorax)"
- `CALCULATION_ThreeDIRTraccAbdomen` — "3D IR-TRACC (abdomen)"
- `CALCULATION_ThreeDIRTraccLowerThorax` — "3D IR-TRACC (lower thorax)"
- `CalculationInputChannel` — "Calculation Input Channel"
- `Channel` — "Channel"
- `ChannelName` — "Channel Name"
- `ClipLengthMS` — "Clip length (ms)"
- `Description` — "Description"
- `HICAccelerationX` — "Acceleration X"
- `HICAccelerationY` — "Acceleration Y"
- `HICAccelerationZ` — "AccelerationZ"
- `HICRequires3Channels` — "Error: Head injury criterion requires 3 channels."
- `InputChannels` — "Input channels"
- `ISOCode` — "ISO Code"
- `NoChannelsIncluded` — "Error: No channels included."
- `ResultantUnitsDontMatch` — "Error: Units don't match for all input channels."
- `SampleRatesDontMatch` — "Error: Sample rates don't match for all input channels."
- `SuperSamplingWarning` — "Calculation contains multiple sample rates. Input will be resampled to the highest sample rate using linear interpolation."
- `ThreeD_IRTracc` — "IR-TRACC"
- `ThreeD_RotPot1` — "R. Pot Y"
- `ThreeD_RotPot2` — "R. Pot Z"
---
## 3. Invariants
1. **TranslateExtension always returns a non-null string.** The `ProvideValue` method guarantees a string return value—either the localized resource, `#stringnotfound#`, or `#stringnotfound# {key}`.
2. **Empty/null key handling differs from missing key handling.** When `_key` is null or empty, the return is exactly `#stringnotfound#`. When `_key` is valid but the resource is missing, the return is `#stringnotfound# {key}` (includes the key name).
3. **StringResources.ResourceManager is lazily initialized and thread-safe.** The property uses a null-check pattern with a temporary variable before assignment.
4. **StringResources is auto-generated.** The class bears `GeneratedCodeAttribute`, `DebuggerNonUserCodeAttribute`, and `CompilerGeneratedAttribute`. Manual modifications will be lost on regeneration.
5. **StringResources.Culture defaults to null.** If not explicitly set, resource lookups will use the current thread's UI culture.
6. **All resource string properties are internal.** They are only accessible within the `DTS.Viewer.AddCalculatedChannel.Resources` namespace or via friend assemblies.
---
## 4. Dependencies
### This module depends on:
- `System` — Core .NET types
- `System.Windows.Markup``MarkupExtension` base class and `MarkupExtensionReturnTypeAttribute`
- `System.Resources``ResourceManager` for resource lookups
- `System.Globalization``CultureInfo` for culture-specific lookups
- `System.CodeDom.Compiler``GeneratedCodeAttribute` (auto-generated code)
- `System.Diagnostics``DebuggerNonUserCodeAttribute`
- `System.Runtime.CompilerServices``CompilerGeneratedAttribute`
- `System.ComponentModel``EditorBrowsableAttribute`
### What depends on this module:
**Inferred from context:** The `TranslateExtension` class is designed for use in XAML files within the `DTS.Viewer.AddCalculatedChannel` namespace. The resource strings reference calculation types, IR-TRACC measurements, and HIC (Head Injury Criterion) parameters, suggesting this module supports a crash test data analysis UI.
**Note:** The actual XAML consumers and other code-behind files that reference `StringResources` are not present in the provided source files.
---
## 5. Gotchas
1. **Duplicate/overlapping resource keys exist.** There appear to be semantically duplicate keys with slightly different naming conventions:
- `CalculatedChannel_IRTRACC3D_Abdomen` and `CalculatedChannel_IRTRACC3DAbdomen` both return "3D IR-TRACC (abdomen)"
- `CalculatedChannel_IRTRACC3D_LowerThorax` and `CalculatedChannel_IRTRACC3DLowerThorax` both return "3D IR-TRACC (lower thorax)"
- `CalculatedChannel_IRTRACC3D` and `CALCULATION_ThreeDIRTracc` both return "3D IR-TRACC (upper thorax)"
This may indicate a naming convention shift or migration artifact. Developers should verify which key is intended for use in new code.
2. **Inconsistent naming conventions.** Some keys use underscores with prefixes (`CALCULATION_*`), others use different patterns (`CalculatedChannel_*`). The rationale for this is unclear from source alone.
3. **HICAccelerationZ lacks a space.** The value is "AccelerationZ" while X and Y variants are "Acceleration X" and "Acceleration Y". This may be a typo in the `.resx` file.
4. **TranslateExtension does not use the Culture property.** The extension calls `StringResources.ResourceManager.GetString(_key)` without passing a culture, meaning it uses the current thread's UI culture. If `StringResources.Culture` has been set to a different value, the extension will not respect it.
5. **IServiceProvider parameter is unused.** The `serviceProvider` parameter in `ProvideValue` is accepted but never used, which is typical for simple markup extensions but worth noting if advanced target-aware behavior is ever needed.

View File

@@ -0,0 +1,37 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/View/AddCalculatedChannelView.xaml.cs
generated_at: "2026-04-16T11:21:57.219744+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "13409539a2c3243c"
---
# Documentation: AddCalculatedChannelView.xaml.cs
## 1. Purpose
This file defines the code-behind class `AddCalculatedChannelView` for a WPF User Control. It serves as the "View" component in the "Add Calculated Channel" module, responsible for initializing the UI components defined in the associated XAML markup. It implements the `IAddCalculatedChannelView` interface, suggesting it is designed for decoupled instantiation, likely via a dependency injection container or a specific UI framework pattern.
## 2. Public Interface
* **`AddCalculatedChannelView` (Class)**
* **Signature:** `public partial class AddCalculatedChannelView : IAddCalculatedChannelView`
* **Description:** The primary class defined in this file. It is a `partial` class, meaning its definition is split between this C# file and the generated code from the XAML file (e.g., `AddCalculatedChannelView.g.cs`). It implements `IAddCalculatedChannelView` from the `DTS.Common.Interface` namespace.
* **`AddCalculatedChannelView()` (Constructor)**
* **Signature:** `public AddCalculatedChannelView()`
* **Description:** The default constructor. It calls `InitializeComponent()`, a standard WPF method that loads and initializes the XAML-defined user interface elements.
## 3. Invariants
* **Partial Definition:** The class is declared `partial`. The code assumes a corresponding XAML file exists (`AddCalculatedChannelView.xaml`) with a matching root element. Without this, the `InitializeComponent()` method would not be found, and compilation would fail.
* **Interface Contract:** The class guarantees it fulfills the contract defined by `IAddCalculatedChannelView`, though the specific members of that interface are not visible in this source file.
## 4. Dependencies
* **Internal Dependencies:**
* `DTS.Common.Interface`: The class implements `IAddCalculatedChannelView` from this namespace.
* **External/Implicit Dependencies:**
* **WPF (Windows Presentation Foundation):** Relies on `System.Windows.Controls.UserControl` (implied by the inheritance structure of a standard `.xaml.cs` file) and the `InitializeComponent()` method generated by the WPF build process.
## 5. Gotchas
* **Namespace Mismatch Suppression:** The file includes `// ReSharper disable CheckNamespace`. This indicates that the declared namespace `DTS.Viewer.AddCalculatedChannel` likely does not match the folder structure inferred by ReSharper (specifically, the file is located in a `View` subfolder, but the namespace does not end in `.View`). This discrepancy may cause navigation issues or confusion regarding project organization standards.
* **Missing Interface Implementation Details:** The source file shows the class implements `IAddCalculatedChannelView`, but no explicit implementation members (properties, methods) are visible. They are either implemented in the XAML (via code-behind bindings) or the interface is empty/marker interface. The exact requirements of the interface cannot be determined from this file alone.

View File

@@ -0,0 +1,178 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/ViewModel/AddCalculatedChannelViewModel.cs
generated_at: "2026-04-16T11:21:00.745415+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "5cfd5d272102b3bf"
---
# Documentation: AddCalculatedChannelViewModel
## 1. Purpose
This module provides a ViewModel for the "Add Calculated Channel" feature in the DTS Viewer application. It enables users to create derived data channels from existing test data by applying mathematical transformations (integrals, derivatives, trigonometric functions) or specialized biomechanical calculations (HIC, 3D IR-Tracc, Resultant). The ViewModel manages channel selection UI state, validates user inputs, orchestrates the calculated channel creation via `CalculatedChannelCreator`, and persists changes back to `.dts` test files.
---
## 2. Public Interface
### Public Properties
| Property | Type | Description |
|----------|------|-------------|
| `View` | `IBaseView` | The associated view instance. |
| `Parent` | `IBaseViewModel` | Reference to the parent ViewModel. |
| `ContextSearchRegion` | `object` | Placeholder for context search region. |
| `NotificationRequest` | `InteractionRequest<Notification>` | Raises notification dialogs. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Raises confirmation dialogs. |
| `HeaderInfo` | `string` | Returns `"AddCalculatedChannelRegion"`. |
| `IsBusy` | `bool` | **Throws `NotImplementedException`** on get/set. |
| `IsDirty` | `bool` | **Throws `NotImplementedException`** on get. |
| `IsAddCalculatedChannelIncluded` | `bool` | Feature inclusion flag. |
| `IncludeGroupNameInISOExport` | `bool` | Controls ISO export formatting. |
| `DefaultDTSEncoding` | `int` | Encoding code page for DTS file operations. |
| `ChannelName` | `string` | Name for the new calculated channel. |
| `ChannelDescription` | `string` | Auto-generated description based on selected calculation and channels. |
| `IsoCode` | `string` | ISO code for the channel (defaults to `"NONE"`). |
| `SingleChannelSelectorVisibility` | `bool` | Controls visibility for single-channel selection UI. |
| `HICChannelSelectorVisibility` | `bool` | Controls visibility for HIC channel selection UI. |
| `MultipleChannelSelectorVisibility` | `bool` | Controls visibility for multi-channel selection UI. |
| `ThreeDIRTRACCVisibility` | `bool` | Controls visibility for 3D IR-Tracc selection UI. |
| `CalculationList` | `CalculationHelper[]` | Lazy-initialized list of available calculations. |
| `SelectedCalculation` | `CalculationHelper` | Currently selected calculation type. |
| `ChannelList` | `ObservableCollection<ITestChannel>` | All available input channels. |
| `ChannelListObjects` | `ObservableCollection<ChannelHelper>` | Wrapped channel objects with `IsIncluded` selection state. |
| `AvailableHICChannels` | `ChannelHelper[]` | Channels with acceleration units valid for HIC calculation. |
| `HICAccelerationX/Y/Z` | `ChannelHelper` | Selected X/Y/Z acceleration channels for HIC. |
| `HICLength` | `int` | HIC calculation length (default: 16). |
| `SourceChannel` | `ITestChannel` | Selected source channel for single-channel calculations. |
| `IRTraccChannelList` | `ObservableCollection<ChannelHelper>` | Valid IR-Tracc channels. |
| `IRTraccChannel` | `ChannelHelper` | Selected IR-Tracc channel. |
| `Pot1ChannelList/Pot2ChannelList` | `ObservableCollection<ChannelHelper>` | Valid potentiometer channels. |
| `Pot1Channel/Pot2Channel` | `ChannelHelper` | Selected potentiometer channels. |
### Public Commands
| Command | Handler | Description |
|---------|---------|-------------|
| `AddCalculatedChannelCommand` | `AddCalculatedChannel(object obj)` | Validates inputs, creates calculated channel(s), and saves to `.dts` file. |
### Public Methods
| Method | Signature | Description |
|--------|-----------|-------------|
| `PublishChanges` | `void PublishChanges()` | **Not implemented** (contains commented-out `NotImplementedException`). |
| `Initialize` | `void Initialize()` | Calls `Initialize(null)`. |
| `Initialize` | `void Initialize(object parameter)` | Sets `Parent` from parameter and subscribes to events. |
| `Activated` | `void Activated()` | Resets UI state: sets default source channel, ISO code, calculation, and channel name. |
| `Cleanup` | `void Cleanup()` | Empty implementation. |
| `Validate` | `bool Validate(ref List<string> errors, ref List<string> warnings, bool displayWindow)` | Validates channel name and calculation-specific requirements. |
### Public Enums
#### `Calculation`
Defines available calculation types with `Description` attributes for display:
| Value | Description |
|-------|-------------|
| `Integral = 0` | "Integral" |
| `DoubleIntegral = 1` | "Double Integral" |
| `Derivative = 2` | "Derivative" |
| `Sin = 3` | "Sin" |
| `Cos = 4` | "Cos" |
| `ThreeDIRTracc = 5` | "3D IR-Tracc" |
| `SUM = 6` | "SUM" |
| `AVE = 7` | "Average" |
| `ThreeDIRTraccAbdomen = 8` | "3D IR-TRACC Abdomen" |
| `ThreeDIRTraccLowerThorax = 9` | "3D IR-TRACC Lower Thorax" |
| `Resultant = 10` | "Resultant" |
| `HIC = 11` | "HIC" |
### Public Nested Classes
#### `ChannelHelper : BasePropertyChanged`
Wraps `ITestChannel` for UI binding with `DisplayName` formatting based on `IsoViewModeStatic.ViewMode` and `IsIncluded` selection state.
#### `CalculationHelper`
Wraps a `Calculation` enum value with localized string display via `StringResources.ResourceManager.GetString("CALCULATION_" + MyCalculation)`.
---
## 3. Invariants
1. **Channel Name Validation**: `ValidateChannelName()` returns `true` only if `ChannelName` is not null or empty.
2. **HIC Calculation Requirements**: `ValidateHIC()` requires all three acceleration channels (`HICAccelerationX`, `HICAccelerationY`, `HICAccelerationZ`) to be non-null.
3. **Resultant Calculation Requirements**: `ValidateResultant()` requires:
- At least one channel with `IsIncluded == true`
- All included channels must have matching `SensitivityUnits`
- All included channels must have matching `SampleRateHz`
4. **Display Order**: New calculated channels are assigned `maxDisplayOrder + 1` from existing channels.
5. **Channel Uniqueness**: `ChannelList` excludes duplicate channels by `ChannelId` during population.
6. **IR-Tracc Channel Filtering**: Channels appear in `IRTraccChannelList` only if:
- `ChannelType` is `Test.Module.AnalogInputChannel`
- `LinearizationFormula` is valid per `LinearizationFormula.IsValid()`
- `ZeroMethod` equals `ZeroMethodType.None`
- `ZeroPoint != 0`
- `FactoryExcitationVoltage != 0`
7. **Potentiometer Channel Filtering**: Channels appear in `Pot1ChannelList`/`Pot2ChannelList` only if:
- `ChannelType` is `Test.Module.AnalogInputChannel`
- `Eu` is `"deg"` or `"deg-ang"` (case-insensitive, trimmed)
- `ZeroMethod` equals `ZeroMethodType.None`
- `FactoryExcitationVoltage != 0`
---
## 4. Dependencies
### This Module Depends On
- `DTS.Common` - Constants, utilities
- `DTS.Common.Base` - `BaseViewModel<T>`, `BasePropertyChanged`
- `DTS.Common.Classes.Viewer.Commands` - `RelayCommand`
- `DTS.Common.DAS.Concepts` - Data concepts
- `DTS.Common.Enums.Sensors` - `ZeroMethodType`
- `DTS.Common.Events` - Event types (`RaiseNotification`, `TestSummaryChangeNotification`, `PageErrorEvent`, `SetSaveButton`, `RefreshTestRequestEvent`)
- `DTS.Common.Interactivity` - `InteractionRequest<T>`, `Notification`, `Confirmation`
- `DTS.Common.Interface` - `IAddCalculatedChannelViewModel`, `IBaseView`, `IBaseViewModel`, `ITestChannel`
- `DTS.Common.Utilities.Logging` - `APILogger`
- `DTS.Common.Utils` - `Utils` class for channel info loading
- `DTS.Slice.Control` - Slice control functionality
- `DTS.Viewer.AddCalculatedChannel.Model` - Model types (inferred)
- `DTS.Serialization` - `Test`, `TestSetup`, `SliceRaw.File`
- `Prism.Events` - `IEventAggregator`
- `Prism.Regions` - `IRegionManager`
- `Unity` - `IUnityContainer`
### Events Subscribed
- `RaiseNotification``OnRaiseNotification`
- `TestSummaryChangeNotification``OnTestSummaryChanged`
### Events Published
- `RaiseNotification`
- `PageErrorEvent`
- `SetSaveButton`
- `RefreshTestRequestEvent`
---
## 5. Gotchas
1. **`IsBusy` and `IsDirty` Throw Exceptions**: Both properties throw `NotImplementedException`. Code paths that access these will fail at runtime.
2. **HIC Save Button Logic Appears Inverted**: In `UpdateSaveButtonVisibility()`, the HIC case sets `IsUsable = true` when acceleration channels are **null** and `IsUsable = false` when they are **not null**. This contradicts the validation logic in `ValidateHIC()` which requires non-null channels. This appears to be a bug.
3. **File Backup Behavior**: The `.dts` backup file (with `BACKUP_FILE_EXTENSION`) is created only if one doesn't already exist. The backup is deleted after successful save only if it was created during that save operation.
4. **Hardcoded Thread.Sleep**: A `Thread.Sleep(10)` exists after file writing in `AddCalculatedChannel()`. Purpose is unclear from source alone.
5. **Lazy Channel Loading**: In `OnTestSummaryChanged()`, if `ts.Channels.FirstOrDefault() == null`, channels are loaded on-demand via `Utils.SetChannelInfo()`. This side effect may not be obvious to callers.
6. **Duplicate Calculated Channel Handling**: `AddCalculatedChannelToTest()` silently overwrites existing calculated channels with matching `ChannelId` by removing the duplicate before adding the new one. A log message is generated but no user confirmation is requested.
7. **`PublishChanges()` Not Implemented**: The method body contains only a commented-out `NotImplementedException`. It is unclear if this is intentional or incomplete.