|
|
|
|
@ -574,16 +574,7 @@ void nmCalculationAutoFitLM::stopFitting()
|
|
|
|
|
emit logMessageGenerated(tr("Gracefully stopping LM automatic fitting..."));
|
|
|
|
|
m_shouldStop = true;
|
|
|
|
|
|
|
|
|
|
// 给当前评价一个短暂的自然退出时间。若仍在运行,
|
|
|
|
|
// runSolverDll() 会在下一个等待周期检查 m_shouldStop 并结束任务。
|
|
|
|
|
int waitCount = 0;
|
|
|
|
|
|
|
|
|
|
while(m_evaluationInProgress > 0 && waitCount < 30) {
|
|
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 50);
|
|
|
|
|
msleep(50);
|
|
|
|
|
waitCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 此槽由求解等待循环派发,必须立即返回,外层循环才能转发取消请求。
|
|
|
|
|
if(m_evaluationInProgress > 0) {
|
|
|
|
|
emit logMessageGenerated(tr("Waiting for current solver evaluation to stop..."));
|
|
|
|
|
}
|
|
|
|
|
@ -3919,7 +3910,7 @@ QVector<QVector<double>> nmCalculationAutoFitLM::runSolverDll()
|
|
|
|
|
// 异步执行 DLL 任务。循环等待期间持续 processEvents,保证界面不会完全卡死。
|
|
|
|
|
dllTask->start();
|
|
|
|
|
|
|
|
|
|
// 等待完成。最大等待 1 小时,适配大模型慢算;用户停止时会 terminate。
|
|
|
|
|
// 等待完成。最大等待 1 小时;用户停止使用任务已有的协作取消接口。
|
|
|
|
|
const int maxWait = 3600000; // 1h超时
|
|
|
|
|
const int checkInterval = 50;
|
|
|
|
|
QTime waitTimer;
|
|
|
|
|
@ -3933,12 +3924,12 @@ QVector<QVector<double>> nmCalculationAutoFitLM::runSolverDll()
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, checkInterval);
|
|
|
|
|
// 等待期间也派发鼠标、键盘事件,让停止按钮能及时登记请求。
|
|
|
|
|
QApplication::processEvents(QEventLoop::AllEvents, checkInterval);
|
|
|
|
|
|
|
|
|
|
if(m_shouldStop) {
|
|
|
|
|
DEBUG_OUT("DLL solver task terminated by user");
|
|
|
|
|
dllTask->terminate();
|
|
|
|
|
break;
|
|
|
|
|
// DLL 没有中断接口,返回后丢弃结果,避免强制终止破坏其内部锁。
|
|
|
|
|
dllTask->requestCancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -3957,6 +3948,13 @@ QVector<QVector<double>> nmCalculationAutoFitLM::runSolverDll()
|
|
|
|
|
|
|
|
|
|
// 线程结束后检查真实执行结果,防止失败时复用上一粒子的旧曲线。
|
|
|
|
|
dllTask->wait();
|
|
|
|
|
if(m_shouldStop) {
|
|
|
|
|
DEBUG_OUT("DLL solver evaluation cancelled by user");
|
|
|
|
|
delete dllTask;
|
|
|
|
|
dllTask = nullptr;
|
|
|
|
|
--m_evaluationInProgress;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if(!dllTask->wasSuccessful()) {
|
|
|
|
|
DEBUG_OUT("DLL solver task reported failure");
|
|
|
|
|
delete dllTask;
|
|
|
|
|
|