|
@ -10,7 +10,7 @@ import { |
|
|
} from '@ant-design/icons' |
|
|
} from '@ant-design/icons' |
|
|
import useRectangleStore from '../../stores/rectangleStore' |
|
|
import useRectangleStore from '../../stores/rectangleStore' |
|
|
import useDeviceStore from '../../stores/deviceStore' |
|
|
import useDeviceStore from '../../stores/deviceStore' |
|
|
import { useState } from 'react' |
|
|
import { useState, useMemo } from 'react' |
|
|
import { IPC_EVENT } from '../../common/ipcEvents' |
|
|
import { IPC_EVENT } from '../../common/ipcEvents' |
|
|
|
|
|
|
|
|
function MeasurementPointSetting() { |
|
|
function MeasurementPointSetting() { |
|
@ -25,10 +25,29 @@ function MeasurementPointSetting() { |
|
|
const [formData, setFormData] = useState({ |
|
|
const [formData, setFormData] = useState({ |
|
|
location: 1, // 测点位置 |
|
|
location: 1, // 测点位置 |
|
|
description: '', // 测点描述 |
|
|
description: '', // 测点描述 |
|
|
coefficient: 0, // 计算系数 |
|
|
|
|
|
baseTarget: 'n' // 基准标靶 |
|
|
baseTarget: 'n' // 基准标靶 |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// 系数计算相关状态 |
|
|
|
|
|
const [lensDistance, setLensDistance] = useState(50) // 镜头焦距 |
|
|
|
|
|
const [measureDistance, setMeasureDistance] = useState(10) // 测点距离 |
|
|
|
|
|
|
|
|
|
|
|
// 计算系数函数 |
|
|
|
|
|
const calculateCoefficient = (measureDist, lensDist) => { |
|
|
|
|
|
if (!lensDist || lensDist <= 0) return 0 |
|
|
|
|
|
return Number(((measureDist / lensDist) * 2.24).toFixed(6)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理镜头焦距变化 |
|
|
|
|
|
const handleLensDistanceChange = (value) => { |
|
|
|
|
|
setLensDistance(value) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理测点距离变化 |
|
|
|
|
|
const handleMeasureDistanceChange = (value) => { |
|
|
|
|
|
setMeasureDistance(value) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 测点列表状态 |
|
|
// 测点列表状态 |
|
|
const [sensorList, setSensorList] = useState([]) |
|
|
const [sensorList, setSensorList] = useState([]) |
|
|
|
|
|
|
|
@ -39,6 +58,11 @@ function MeasurementPointSetting() { |
|
|
const [loadingSensors, setLoadingSensors] = useState(false) |
|
|
const [loadingSensors, setLoadingSensors] = useState(false) |
|
|
const [settingSensors, setSettingSensors] = useState(false) |
|
|
const [settingSensors, setSettingSensors] = useState(false) |
|
|
|
|
|
|
|
|
|
|
|
// 使用useMemo计算系数,当镜头焦距或测点距离变化时自动重新计算 |
|
|
|
|
|
const calculatedCoefficient = useMemo(() => { |
|
|
|
|
|
return calculateCoefficient(measureDistance, lensDistance) |
|
|
|
|
|
}, [measureDistance, lensDistance]) |
|
|
|
|
|
|
|
|
// 根据选中的传感器更新矩形数据 |
|
|
// 根据选中的传感器更新矩形数据 |
|
|
const updateRectangleFromSensor = (sensorKey) => { |
|
|
const updateRectangleFromSensor = (sensorKey) => { |
|
|
if (!sensorKey) { |
|
|
if (!sensorKey) { |
|
@ -110,7 +134,7 @@ function MeasurementPointSetting() { |
|
|
children: [ |
|
|
children: [ |
|
|
{ key: `${newSensorKey}-1`, name: '测点位置', value: formData.location }, |
|
|
{ key: `${newSensorKey}-1`, name: '测点位置', value: formData.location }, |
|
|
{ key: `${newSensorKey}-2`, name: '测点描述', value: formData.description }, |
|
|
{ key: `${newSensorKey}-2`, name: '测点描述', value: formData.description }, |
|
|
{ key: `${newSensorKey}-3`, name: '计算系数', value: formData.coefficient }, |
|
|
{ key: `${newSensorKey}-3`, name: '计算系数', value: calculatedCoefficient }, |
|
|
{ |
|
|
{ |
|
|
key: `${newSensorKey}-4`, |
|
|
key: `${newSensorKey}-4`, |
|
|
name: '基准标靶', |
|
|
name: '基准标靶', |
|
@ -132,7 +156,6 @@ function MeasurementPointSetting() { |
|
|
setFormData((prev) => ({ |
|
|
setFormData((prev) => ({ |
|
|
location: prev.location + 1, // 自动递增位置 |
|
|
location: prev.location + 1, // 自动递增位置 |
|
|
description: '', |
|
|
description: '', |
|
|
coefficient: 0, |
|
|
|
|
|
baseTarget: 'n' |
|
|
baseTarget: 'n' |
|
|
})) |
|
|
})) |
|
|
} |
|
|
} |
|
@ -416,10 +439,10 @@ function MeasurementPointSetting() { |
|
|
<span className={styles.label}>计算系数:</span> |
|
|
<span className={styles.label}>计算系数:</span> |
|
|
<InputNumber |
|
|
<InputNumber |
|
|
className={styles.numberInput} |
|
|
className={styles.numberInput} |
|
|
value={formData.coefficient} |
|
|
value={calculatedCoefficient} |
|
|
onChange={(value) => handleFormChange('coefficient', value)} |
|
|
readOnly |
|
|
precision={4} |
|
|
precision={6} |
|
|
style={{ flex: 1 }} |
|
|
style={{ flex: 1, backgroundColor: '#f5f5f5' }} |
|
|
/> |
|
|
/> |
|
|
</Flex> |
|
|
</Flex> |
|
|
|
|
|
|
|
@ -486,15 +509,15 @@ function MeasurementPointSetting() { |
|
|
|
|
|
|
|
|
<Flex className={styles.formRow}> |
|
|
<Flex className={styles.formRow}> |
|
|
<span className={styles.label}>镜头焦距:</span> |
|
|
<span className={styles.label}>镜头焦距:</span> |
|
|
<Select |
|
|
<InputNumber |
|
|
className={styles.select} |
|
|
className={styles.numberInput} |
|
|
defaultValue="50" |
|
|
value={lensDistance} |
|
|
|
|
|
onChange={handleLensDistanceChange} |
|
|
|
|
|
min={0.001} |
|
|
|
|
|
precision={3} |
|
|
style={{ flex: 1 }} |
|
|
style={{ flex: 1 }} |
|
|
options={[ |
|
|
status={!lensDistance || lensDistance <= 0 ? 'error' : ''} |
|
|
{ value: '50', label: '50' }, |
|
|
placeholder="请输入大于0的数值" |
|
|
{ value: '125', label: '125' }, |
|
|
|
|
|
{ value: '200', label: '200' } |
|
|
|
|
|
]} |
|
|
|
|
|
/> |
|
|
/> |
|
|
</Flex> |
|
|
</Flex> |
|
|
|
|
|
|
|
@ -502,7 +525,8 @@ function MeasurementPointSetting() { |
|
|
<span className={styles.label}>测点距离:</span> |
|
|
<span className={styles.label}>测点距离:</span> |
|
|
<InputNumber |
|
|
<InputNumber |
|
|
className={styles.numberInput} |
|
|
className={styles.numberInput} |
|
|
defaultValue={10} |
|
|
value={measureDistance} |
|
|
|
|
|
onChange={handleMeasureDistanceChange} |
|
|
precision={4} |
|
|
precision={4} |
|
|
style={{ flex: 1 }} |
|
|
style={{ flex: 1 }} |
|
|
/> |
|
|
/> |
|
|