| 408 | } |
| 409 | |
| 410 | void RenderingController::HandleGET_selectedTime(const httplib::Request& req, httplib::Response& res) const |
| 411 | { |
| 412 | TimeStepType timestep = 0; |
| 413 | double timepointMs = 0.0; |
| 414 | double minTimepointMs = 0.0; |
| 415 | double maxTimepointMs = 0.0; |
| 416 | TimeStepType steps = 0; |
| 417 | |
| 418 | bool tncNull = false; |
| 419 | try |
| 420 | { |
| 421 | this->Dispatch([×tep, &timepointMs, &minTimepointMs, &maxTimepointMs, &steps, &tncNull]() |
| 422 | { |
| 423 | auto* const tnc = RenderingManager::GetInstance()->GetTimeNavigationController(); |
| 424 | if (tnc == nullptr) |
| 425 | { |
| 426 | tncNull = true; |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | timestep = tnc->GetSelectedTimeStep(); |
| 431 | timepointMs = tnc->GetSelectedTimePoint(); |
| 432 | |
| 433 | const auto tg = tnc->GetInputWorldTimeGeometry(); |
| 434 | if (nullptr != tg) |
| 435 | { |
| 436 | steps = tg->CountTimeSteps(); |
| 437 | minTimepointMs = tg->GetMinimumTimePoint(); |
| 438 | maxTimepointMs = tg->GetMaximumTimePoint(); |
| 439 | } |
| 440 | else |
| 441 | { |
| 442 | const auto* stepper = tnc->GetStepper(); |
| 443 | if (stepper != nullptr) |
| 444 | { |
| 445 | steps = stepper->GetSteps(); |
| 446 | } |
| 447 | } |
| 448 | }); |
| 449 | } |
| 450 | catch (const std::exception& e) |
| 451 | { |
| 452 | const auto error = ErrorResponse::InternalError( |
| 453 | std::string("Failed to read time navigation state: ") + e.what(), req.path); |
| 454 | this->SendErrorResponse(res, 500, error); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | if (tncNull) |
| 459 | { |
| 460 | const auto error = ErrorResponse::TimeNavigationNotAvailable(req.path); |
| 461 | this->SendErrorResponse(res, 503, error); |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | nlohmann::json response; |
| 466 | response["timepoint_ms"] = timepointMs; |
| 467 | response["timestep"] = timestep; |