fix: normalize HiCAD engine responses
This commit is contained in:
parent
d93410b01b
commit
c028d2ad00
@ -84,10 +84,11 @@ function resolveBodyName(
|
||||
}
|
||||
|
||||
function modelingResponseData(response: unknown): ModelingResponse {
|
||||
if (!isModelingResponse(response)) {
|
||||
const normalized = Array.isArray(response) ? response[0] : response
|
||||
if (!isModelingResponse(normalized)) {
|
||||
throw new Error('HiCAD 引擎未返回有效结果')
|
||||
}
|
||||
return response.resp.data.modeling_response as ModelingResponse
|
||||
return normalized.resp.data.modeling_response as ModelingResponse
|
||||
}
|
||||
|
||||
function numberValue(data: unknown, key: string) {
|
||||
@ -160,12 +161,27 @@ export function HicadManufacturingPanel({
|
||||
}
|
||||
|
||||
const sendModelingCommand = async (cmd: ModelingCmd) => {
|
||||
const response = await kclManager.engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd,
|
||||
})
|
||||
return modelingResponseData(response)
|
||||
const maxAttempts = 15
|
||||
|
||||
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
||||
const response = await kclManager.engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd,
|
||||
})
|
||||
const normalized = Array.isArray(response) ? response[0] : response
|
||||
|
||||
if (isModelingResponse(normalized)) {
|
||||
return modelingResponseData(normalized)
|
||||
}
|
||||
if (response !== null && response !== undefined) {
|
||||
return modelingResponseData(response)
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 200))
|
||||
}
|
||||
|
||||
throw new Error('HiCAD 引擎连接尚未就绪,请稍后重新分析')
|
||||
}
|
||||
|
||||
const captureSnapshot = async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user