depth2baseline.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import 'dart:ui';
  2. import 'package:fis_measure/interfaces/date_types/point.dart';
  3. import 'package:fis_measure/interfaces/enums/items.dart';
  4. import 'package:fis_measure/interfaces/process/items/item.dart';
  5. import 'package:fis_measure/interfaces/process/items/item_metas.dart';
  6. import 'package:fis_measure/interfaces/process/items/types.dart';
  7. import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
  8. import 'package:fis_measure/process/calcuators/depth.dart';
  9. import 'package:fis_measure/process/calcuators/depth2baseline.dart';
  10. import 'package:fis_measure/process/items/item.dart';
  11. import 'package:fis_measure/process/items/item_feature.dart';
  12. import 'package:fis_measure/process/items/top_item.dart';
  13. import 'package:fis_measure/process/items/top_item_feature.dart';
  14. import 'package:fis_measure/process/primitives/location.dart';
  15. import 'package:fis_measure/process/primitives/ray.dart';
  16. class DepthToBaseLine extends TopMeasureItem<DepthToBaseLineFeature> {
  17. late final Ray baseline;
  18. late final Location depth;
  19. DepthToBaseLine(ItemMeta meta) : super(meta) {
  20. final metaBaseLine = meta.getChildByType(MeasureTypes.Ray)!;
  21. final metaDepth = meta.getChildByType(MeasureTypes.Distance)!;
  22. baseline = Ray.createRay(metaBaseLine, this);
  23. depth = _Depth.createDepth(metaDepth, this);
  24. childItems.add(baseline);
  25. childItems.add(depth);
  26. }
  27. @override
  28. bool onExecuteMouse(PointInfo args) {
  29. if (feature == null) {
  30. feature = DepthToBaseLineFeature(this);
  31. listenChildrenUpdate();
  32. }
  33. if (args.pointType == PointInfoType.mouseDown) {
  34. if (childrenAllDone) {
  35. workingChild.clear();
  36. }
  37. }
  38. feature?.hostVisualArea = args.hostVisualArea;
  39. final result = workingChild.execute(args);
  40. doCalculate();
  41. return result;
  42. }
  43. @override
  44. bool onExecuteTouch(PointInfo args) {
  45. return workingChild.execute(args);
  46. }
  47. static DepthToBaseLine createDepthToBaseLine(ItemMeta meta,
  48. [IMeasureItem? parent]) {
  49. if (meta.measureType != MeasureTypes.DepthToBaseLine) {
  50. throw ArgumentError();
  51. }
  52. var location = DepthToBaseLine(meta);
  53. location.calculator = DistanceToRayCal(location);
  54. return location;
  55. }
  56. }
  57. class DepthToBaseLineFeature extends TopMeasureItemFeature {
  58. DepthToBaseLineFeature(
  59. DepthToBaseLine refItem,
  60. ) : super(refItem);
  61. }
  62. class _Depth extends Location {
  63. _Depth(ItemMeta meta, DepthToBaseLine parent) : super(meta, parent);
  64. @override
  65. bool onExecuteMouse(PointInfo args) {
  66. if (state == ItemStates.finished || state == ItemStates.waiting) {
  67. if (args.pointType == PointInfoType.mouseMove) {
  68. if (feature == null && measuredFeatures.isEmpty) {
  69. _createFeature(args);
  70. return true;
  71. }
  72. } else if (args.pointType == PointInfoType.mouseDown) {
  73. _createFeature(args);
  74. return true;
  75. }
  76. return false;
  77. }
  78. if (state == ItemStates.running) {
  79. if (args.pointType == PointInfoType.mouseUp) return false;
  80. feature?.point = args;
  81. doCalculate();
  82. if (args.pointType == PointInfoType.mouseDown) {
  83. doFeatureFinish();
  84. }
  85. }
  86. return true;
  87. }
  88. void _createFeature(PointInfo args) {
  89. measuredFeatures.clear();
  90. feature ??= _DepthFeature(this, args);
  91. if (args.hostVisualArea != null) {
  92. feature!.hostVisualArea = args.hostVisualArea;
  93. }
  94. doCalculate();
  95. state = ItemStates.running;
  96. }
  97. static _Depth createDepth(ItemMeta meta, DepthToBaseLine parent) {
  98. final depth = _Depth(meta, parent);
  99. depth.calculator = TissueDepthCal(depth);
  100. return depth;
  101. }
  102. }
  103. class _DepthFeature extends LocationFeature {
  104. _DepthFeature(IMeasureItem refItem, DPoint point) : super(refItem, point);
  105. @override
  106. void paint(Canvas canvas, Size size) {
  107. drawId(canvas, size);
  108. final viewPoint = convert2ViewPoint(size, point).toOffset();
  109. drawVertex(canvas, viewPoint);
  110. }
  111. }