section.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import 'unit.dart';
  2. class LayoutSections {
  3. static const general = "Vinno_View_AreaLayouts";
  4. static const zoom = "Vinno_Zoom_AreaLayouts";
  5. static const v3d = "Vinno_S3D_AreaLayouts";
  6. static const strainRate = "Vinno_StrainRate_AreaLayouts";
  7. }
  8. class LayoutSection {
  9. String _name = '';
  10. List<LayoutUnit>? _layouts;
  11. /// 名称
  12. String get name => _name;
  13. /// 各模式布局单元
  14. List<LayoutUnit> get layouts => _layouts ?? const [];
  15. LayoutSection();
  16. factory LayoutSection.fromJson(Map<String, dynamic> map) {
  17. final instance = LayoutSection();
  18. instance._name = map['Name']!;
  19. instance._loadLayoutUnits(map['Layouts']);
  20. return instance;
  21. }
  22. void _loadLayoutUnits(dynamic data) {
  23. final List<LayoutUnit> arr = [];
  24. if (data != null && data is List) {
  25. final List<dynamic> jArr = data;
  26. for (final item in jArr) {
  27. arr.add(LayoutUnit.fromJson(item));
  28. }
  29. }
  30. if (arr.isEmpty) {
  31. throw ArgumentError(
  32. "Layout configuration error: Layout element not found.");
  33. }
  34. _layouts = arr;
  35. }
  36. }