Browse Source

adjust layout config

melon.yin 2 years ago
parent
commit
d5a5f326d6

+ 365 - 0
assets/layout.json

@@ -0,0 +1,365 @@
+{
+  "LayoutSections": {
+    "LayoutSection": [
+      {
+        "Name": "Vinno_View_AreaLayouts",
+        "Layout": [
+          {
+            "Mode": "pColorBar",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "100",
+                "Top": "2",
+                "Right": "100",
+                "Bottom": "2"
+              }
+            }
+          },
+          {
+            "Mode": "pSweiReliableColorBar",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "3",
+                "Top": "2",
+                "Right": "6",
+                "Bottom": "8"
+              }
+            }
+          },
+          {
+            "Mode": "B",
+            "ViewPorts": {
+              "ViewPort": [
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "100",
+                  "Bottom": "100",
+                  "Format": "Normal"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "50",
+                  "Bottom": "100",
+                  "Format": "SideBySideHalfHalf"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "34",
+                  "Bottom": "100",
+                  "Format": "SideBySide14BOther"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "0",
+                  "Bottom": "0",
+                  "Format": "FullOther"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "100",
+                  "Bottom": "100",
+                  "Format": "FullTissue"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "100",
+                  "Bottom": "34",
+                  "Format": "UpDown13B"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "100",
+                  "Bottom": "49",
+                  "Format": "UpDownHalfHalf"
+                },
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "100",
+                  "Bottom": "67",
+                  "Format": "UpDown23B"
+                }
+              ]
+            }
+          },
+          {
+            "Mode": "TM",
+            "ViewPorts": {
+              "ViewPort": [
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "0",
+                  "Bottom": "0",
+                  "Format": "FullTissue"
+                },
+                {
+                  "Left": "52",
+                  "Top": "1",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "SideBySideHalfHalf"
+                },
+                {
+                  "Left": "36",
+                  "Top": "1",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "SideBySide14BOther"
+                },
+                {
+                  "Left": "3",
+                  "Top": "1",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "FullOther"
+                },
+                {
+                  "Left": "3",
+                  "Top": "36",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDown13B"
+                },
+                {
+                  "Left": "3",
+                  "Top": "51",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDownHalfHalf"
+                },
+                {
+                  "Left": "3",
+                  "Top": "69",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDown23B"
+                }
+              ]
+            }
+          },
+          {
+            "Mode": "Doppler",
+            "ViewPorts": {
+              "ViewPort": [
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "0",
+                  "Bottom": "0",
+                  "Format": "FullTissue"
+                },
+                {
+                  "Left": "52",
+                  "Top": "21",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "SideBySideHalfHalf"
+                },
+                {
+                  "Left": "36",
+                  "Top": "21",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "SideBySide14BOther"
+                },
+                {
+                  "Left": "3",
+                  "Top": "21",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "FullOther"
+                },
+                {
+                  "Left": "3",
+                  "Top": "36",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDown13B"
+                },
+                {
+                  "Left": "3",
+                  "Top": "51",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDownHalfHalf"
+                },
+                {
+                  "Left": "3",
+                  "Top": "69",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDown23B"
+                }
+              ]
+            }
+          },
+          {
+            "Mode": "Trace",
+            "ViewPorts": {
+              "ViewPort": [
+                {
+                  "Left": "0",
+                  "Top": "0",
+                  "Right": "0",
+                  "Bottom": "0",
+                  "Format": "FullTissue"
+                },
+                {
+                  "Left": "3",
+                  "Top": "1",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "Normal"
+                },
+                {
+                  "Left": "52",
+                  "Top": "1",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "SideBySideHalfHalf"
+                },
+                {
+                  "Left": "36",
+                  "Top": "1",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "SideBySide14BOther"
+                },
+                {
+                  "Left": "3",
+                  "Top": "1",
+                  "Right": "93",
+                  "Bottom": "94",
+                  "Format": "FullOther"
+                },
+                {
+                  "Left": "3",
+                  "Top": "1",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDown13B"
+                },
+                {
+                  "Left": "3",
+                  "Top": "1",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDownHalfHalf"
+                },
+                {
+                  "Left": "3",
+                  "Top": "1",
+                  "Right": "90",
+                  "Bottom": "94",
+                  "Format": "UpDown23B"
+                }
+              ]
+            }
+          }
+        ]
+      },
+      {
+        "Name": "Vinno_S3D_AreaLayouts",
+        "Layout": [
+          {
+            "Mode": "B",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "0",
+                "Top": "0",
+                "Right": "0",
+                "Bottom": "0"
+              }
+            }
+          },
+          {
+            "Mode": "4D",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "0",
+                "Top": "0",
+                "Right": "100",
+                "Bottom": "100"
+              }
+            }
+          }
+        ]
+      },
+      {
+        "Name": "Vinno_Zoom_AreaLayouts",
+        "Layout": [
+          {
+            "Mode": "TM",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "0",
+                "Top": "0",
+                "Right": "0",
+                "Bottom": "0"
+              }
+            }
+          },
+          {
+            "Mode": "Doppler",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "0",
+                "Top": "0",
+                "Right": "0",
+                "Bottom": "0"
+              }
+            }
+          },
+          {
+            "Mode": "Trace",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "0",
+                "Top": "0",
+                "Right": "0",
+                "Bottom": "0"
+              }
+            }
+          }
+        ]
+      },
+      {
+        "Name": "Vinno_StrainRate_AreaLayouts",
+        "Layout": [
+          {
+            "Mode": "B",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "0",
+                "Top": "0",
+                "Right": "50",
+                "Bottom": "100",
+                "Format": "SideBySideHalfHalf"
+              }
+            }
+          },
+          {
+            "Mode": "TM",
+            "ViewPorts": {
+              "ViewPort": {
+                "Left": "52",
+                "Top": "6",
+                "Right": "93",
+                "Bottom": "96",
+                "Format": "SideBySideHalfHalf"
+              }
+            }
+          }
+        ]
+      }
+    ]
+  }
+}

+ 10 - 8
lib/interfaces/enums/display_mode.dart

@@ -1,25 +1,27 @@
 /// C# enum begin at -1,so if u would like to match value, must calcluate -1
 /// C# enum begin at -1,so if u would like to match value, must calcluate -1
+// ignore_for_file: constant_identifier_names
+
 enum DisplayModeEnum {
 enum DisplayModeEnum {
   /// Normal B mode
   /// Normal B mode
-  normal,
+  Normal,
 
 
   /// Up/Down, B holds 1/3, Other hodes 2/3
   /// Up/Down, B holds 1/3, Other hodes 2/3
-  upDown13B,
+  UpDown13B,
 
 
   /// Up/Down, half, half
   /// Up/Down, half, half
-  upDownHalfHalf,
+  UpDownHalfHalf,
 
 
   /// Up/Down, B holds2/3, Other hodes1/3
   /// Up/Down, B holds2/3, Other hodes1/3
-  upDown23B,
+  UpDown23B,
 
 
   /// Left/Right, half, half
   /// Left/Right, half, half
-  sideBySideHalfHalf,
+  SideBySideHalfHalf,
 
 
   /// Left/Right, B holds2/3, Other hodes1/3
   /// Left/Right, B holds2/3, Other hodes1/3
-  sideBySide14BOther,
+  SideBySide14BOther,
 
 
   /// All Image area are Other image instead of B image
   /// All Image area are Other image instead of B image
-  fullOther,
+  FullOther,
 
 
-  fullTissue,
+  FullTissue,
 }
 }

+ 32 - 36
lib/interfaces/process/layout/configuration.dart

@@ -41,59 +41,34 @@ class LayoutConfiguration {
     VisualAreaTypeEnum areaType,
     VisualAreaTypeEnum areaType,
     DisplayModeEnum displayFormat,
     DisplayModeEnum displayFormat,
   ) {
   ) {
-    String mode;
-    switch (areaType) {
-      case VisualAreaTypeEnum.tissue:
-      case VisualAreaTypeEnum.flow:
-        mode = ModeNames.B;
-        break;
-      case VisualAreaTypeEnum.timeMotion:
-      case VisualAreaTypeEnum.tissueTimeMotion:
-        mode = ModeNames.TM;
-        break;
-      case VisualAreaTypeEnum.doppler:
-        mode = ModeNames.Doppler;
-        break;
-      case VisualAreaTypeEnum.trace:
-        mode = ModeNames.Trace;
-        break;
-      case VisualAreaTypeEnum.colorbar:
-        mode = ModeNames.P_ColorBar;
-        break;
-      case VisualAreaTypeEnum.tissue3D:
-        mode = ModeNames.FourD;
-        break;
-      case VisualAreaTypeEnum.sweiReliableColorBar:
-        mode = ModeNames.P_SweiReliableColorBar;
-        break;
-    }
-
+    final mode = _findVisualAreaMode(areaType);
     final viewPort = _matchViewPort(section, mode, displayFormat);
     final viewPort = _matchViewPort(section, mode, displayFormat);
     final rect = DRect(
     final rect = DRect(
-        viewPort.left / 100,
-        viewPort.top / 100,
-        (viewPort.right - viewPort.left) / 100,
-        (viewPort.bottom - viewPort.top) / 100);
+      viewPort.left / 100,
+      viewPort.top / 100,
+      (viewPort.right - viewPort.left) / 100,
+      (viewPort.bottom - viewPort.top) / 100,
+    );
     return rect;
     return rect;
   }
   }
 
 
   LayoutViewPort _matchViewPort(
   LayoutViewPort _matchViewPort(
-    String name,
-    String layoutKey,
+    String section,
+    String mode,
     DisplayModeEnum displayFormat,
     DisplayModeEnum displayFormat,
   ) {
   ) {
     bool found = false;
     bool found = false;
     LayoutViewPort viewPort = LayoutViewPort();
     LayoutViewPort viewPort = LayoutViewPort();
     List<LayoutSection> sections = [];
     List<LayoutSection> sections = [];
 
 
-    final sectionIdx = _layoutSections.indexWhere((x) => x.key == name);
+    final sectionIdx = _layoutSections.indexWhere((x) => x.name == section);
     if (sectionIdx > -1) {
     if (sectionIdx > -1) {
       sections.add(_layoutSections[sectionIdx]);
       sections.add(_layoutSections[sectionIdx]);
     }
     }
     sections.add(_layoutSections[0]);
     sections.add(_layoutSections[0]);
 
 
     for (final candidate in sections) {
     for (final candidate in sections) {
-      final layoutIdx = candidate.layouts.indexWhere((x) => x.key == layoutKey);
+      final layoutIdx = candidate.layouts.indexWhere((x) => x.mode == mode);
       if (layoutIdx > -1) {
       if (layoutIdx > -1) {
         final layout = candidate.layouts[layoutIdx];
         final layout = candidate.layouts[layoutIdx];
         int i = -1;
         int i = -1;
@@ -114,9 +89,30 @@ class LayoutConfiguration {
 
 
     if (!found) {
     if (!found) {
       logger.w(
       logger.w(
-          "MatchViewPort failed, ViewPort:$viewPort is used. layout section:$name, layout key:$layoutKey, display format:${displayFormat.name}.");
+          "MatchViewPort failed, ViewPort:$viewPort is used. layout section:$section, mode:$mode, display format:${displayFormat.name}.");
     }
     }
 
 
     return viewPort;
     return viewPort;
   }
   }
+
+  String _findVisualAreaMode(VisualAreaTypeEnum areaType) {
+    switch (areaType) {
+      case VisualAreaTypeEnum.tissue:
+      case VisualAreaTypeEnum.flow:
+        return ModeNames.B;
+      case VisualAreaTypeEnum.timeMotion:
+      case VisualAreaTypeEnum.tissueTimeMotion:
+        return ModeNames.TM;
+      case VisualAreaTypeEnum.doppler:
+        return ModeNames.Doppler;
+      case VisualAreaTypeEnum.trace:
+        return ModeNames.Trace;
+      case VisualAreaTypeEnum.colorbar:
+        return ModeNames.P_ColorBar;
+      case VisualAreaTypeEnum.tissue3D:
+        return ModeNames.FourD;
+      case VisualAreaTypeEnum.sweiReliableColorBar:
+        return ModeNames.P_SweiReliableColorBar;
+    }
+  }
 }
 }

+ 3 - 3
lib/interfaces/process/layout/section.dart

@@ -1,17 +1,17 @@
 import 'unit.dart';
 import 'unit.dart';
 
 
 class LayoutSection {
 class LayoutSection {
-  String _key = '';
+  String _name = '';
   List<LayoutUnit>? _layouts;
   List<LayoutUnit>? _layouts;
 
 
-  String get key => _key;
+  String get name => _name;
   List<LayoutUnit> get layouts => _layouts ?? const [];
   List<LayoutUnit> get layouts => _layouts ?? const [];
 
 
   LayoutSection();
   LayoutSection();
 
 
   factory LayoutSection.fromJson(Map<String, dynamic> map) {
   factory LayoutSection.fromJson(Map<String, dynamic> map) {
     final instance = LayoutSection();
     final instance = LayoutSection();
-    instance._key = map['n'] ?? '';
+    instance._name = map['Name']!;
     instance._loadLayoutUnits(map['Layouts']);
     instance._loadLayoutUnits(map['Layouts']);
     return instance;
     return instance;
   }
   }

+ 3 - 3
lib/interfaces/process/layout/unit.dart

@@ -1,17 +1,17 @@
 import 'view_port.dart';
 import 'view_port.dart';
 
 
 class LayoutUnit {
 class LayoutUnit {
-  String _key = '';
+  String _mode = '';
   List<LayoutViewPort>? _viewPorts;
   List<LayoutViewPort>? _viewPorts;
 
 
-  String get key => _key;
+  String get mode => _mode;
   List<LayoutViewPort> get viewPorts => _viewPorts ?? const [];
   List<LayoutViewPort> get viewPorts => _viewPorts ?? const [];
 
 
   LayoutUnit();
   LayoutUnit();
 
 
   factory LayoutUnit.fromJson(Map<String, dynamic> map) {
   factory LayoutUnit.fromJson(Map<String, dynamic> map) {
     final instance = LayoutUnit();
     final instance = LayoutUnit();
-    instance._key = map['k'] ?? '';
+    instance._mode = map['Mode']!;
     instance._loadViewPorts(map['ViewPorts']);
     instance._loadViewPorts(map['ViewPorts']);
     return instance;
     return instance;
   }
   }

+ 27 - 6
lib/interfaces/process/layout/view_port.dart

@@ -5,18 +5,39 @@ class LayoutViewPort {
   double right = 0;
   double right = 0;
   double top = 0;
   double top = 0;
   double bottom = 0;
   double bottom = 0;
-  DisplayModeEnum displayFormat = DisplayModeEnum.normal;
+  DisplayModeEnum displayFormat = DisplayModeEnum.Normal;
 
 
   LayoutViewPort();
   LayoutViewPort();
 
 
   factory LayoutViewPort.fromJson(Map<String, dynamic> map) {
   factory LayoutViewPort.fromJson(Map<String, dynamic> map) {
     final instance = LayoutViewPort();
     final instance = LayoutViewPort();
-    instance.bottom = map['b'] ?? double.nan;
-    instance.top = map['t'] ?? 0;
-    instance.left = map['l'] ?? 0;
-    instance.right = map['r'] ?? 0;
-    instance.displayFormat = DisplayModeEnum.values[map['format'] ?? 0];
+    instance.bottom = _convertItemValue(map['Bottom']);
+    instance.top = _convertItemValue(map['Top']);
+    instance.left = _convertItemValue(map['Left']);
+    instance.right = _convertItemValue(map['Right']);
+    instance.displayFormat = _convertFormat(map['Format']);
 
 
     return instance;
     return instance;
   }
   }
+
+  static double _convertItemValue(dynamic val) {
+    if (val == null) return 0.0;
+    if (val is String) {
+      return double.tryParse(val) ?? 0.0;
+    } else if (val is num) {
+      return val.toDouble();
+    }
+    return 0.0;
+  }
+
+  static DisplayModeEnum _convertFormat(dynamic val) {
+    if (val == null || val is! String) return DisplayModeEnum.Normal;
+
+    for (var item in DisplayModeEnum.values) {
+      if (val == item.name) {
+        return item;
+      }
+    }
+    return DisplayModeEnum.Normal;
+  }
 }
 }