regionDraw.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /** 区域形状选项 */
  2. export interface RegionShape {
  3. key: string;
  4. label: string;
  5. }
  6. /** 左侧操作面板区域配置 */
  7. export interface RegionSection {
  8. key: string;
  9. title: string;
  10. /** 区域默认颜色 */
  11. color: string;
  12. /** 是否显示「修改」按钮 */
  13. showModify?: boolean;
  14. /** 是否显示 I/O 范围(闯入区域) */
  15. showIoRange?: boolean;
  16. /** 是否为测温区域(纠正系数 / 温度) */
  17. thermal?: boolean;
  18. shapes: RegionShape[];
  19. }
  20. /** 区域可编辑状态 */
  21. export interface RegionState {
  22. /** 编号(对应预置位编号) */
  23. no: number;
  24. /** 当前选择的区域形状,空串表示未选择 */
  25. shape: string;
  26. /** 区域颜色 */
  27. color: string;
  28. /** I/O 起始值 */
  29. ioStart: string;
  30. /** I/O 结束值 */
  31. ioEnd: string;
  32. /** 测温纠正系数 */
  33. k: number;
  34. /** 测温温度值 */
  35. temp: string;
  36. }
  37. /** 像素坐标点 */
  38. export interface PxPoint {
  39. x: number;
  40. y: number;
  41. }
  42. /** 绘制点(归一化 0-1 + 像素坐标) */
  43. export interface DrawPoint {
  44. x: number;
  45. y: number;
  46. px: number;
  47. py: number;
  48. }
  49. /** 矩形图形 */
  50. export interface RectData {
  51. no: number;
  52. region: string;
  53. type: 'rect';
  54. x: number;
  55. y: number;
  56. w: number;
  57. h: number;
  58. px: number;
  59. py: number;
  60. pw: number;
  61. ph: number;
  62. }
  63. /** 线图形 */
  64. export interface LineData {
  65. no: number;
  66. region: string;
  67. type: 'line';
  68. points: [DrawPoint, DrawPoint];
  69. }
  70. /** 多边形图形 */
  71. export interface PolyData {
  72. no: number;
  73. region: string;
  74. type: 'poly' | 'polyEdge';
  75. points: DrawPoint[];
  76. }
  77. /** 绘制图形 */
  78. export type DrawItem = RectData | LineData | PolyData;
  79. /** 可在画面上直接绘制的形状 */
  80. export const drawableShapes = ['rect', 'line', 'poly', 'polyEdge'];
  81. /** 是否为可绘制形状 */
  82. export function isDrawableShape(shape: string) {
  83. return drawableShapes.includes(shape);
  84. }
  85. /** 绘制提示文案 */
  86. export function shapeTip(shape: string) {
  87. if (shape === 'rect') return '矩形:在右侧画面拖拽绘制,松手自动保存坐标';
  88. if (shape === 'line') return '线:在右侧画面点击起点,拖到终点松手保存';
  89. if (shape === 'poly') return '多边形:在右侧画面单击添加顶点,双击结束保存';
  90. if (shape === 'polyEdge') return '多边形边界:在右侧画面单击添加顶点,双击结束保存';
  91. return '';
  92. }