MCPcopy Create free account
hub / github.com/MITK/MITK / HandlePUT_selectedPosition

Method HandlePUT_selectedPosition

Modules/RESTAPI/src/mitkRenderingController.cpp:356–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356void RenderingController::HandlePUT_selectedPosition(const httplib::Request& req, httplib::Response& res) const
357{
358 if (req.body.empty())
359 {
360 const auto error = ErrorResponse::InvalidRequest("Request body is required.", req.path);
361 this->SendErrorResponse(res, 400, error);
362 return;
363 }
364
365 nlohmann::json body;
366 try
367 {
368 body = nlohmann::json::parse(req.body);
369 }
370 catch (const nlohmann::json::exception&)
371 {
372 const auto error = ErrorResponse::InvalidRequest("Invalid JSON body.", req.path);
373 this->SendErrorResponse(res, 400, error);
374 return;
375 }
376
377 Point3D newPos;
378 if (const auto err = ParsePositionFromBody(body, newPos))
379 {
380 const auto error = ErrorResponse::InvalidRequest(*err, req.path);
381 this->SendErrorResponse(res, 400, error);
382 return;
383 }
384
385 if (m_RenderWindowBridge == nullptr || !m_RenderWindowBridge->HasPositionSetter())
386 {
387 const auto error = ErrorResponse::RenderWindowNotAvailable(req.path);
388 this->SendErrorResponse(res, 503, error);
389 return;
390 }
391
392 try
393 {
394 m_RenderWindowBridge->SetSelectedPosition(newPos);
395 res.status = 204;
396 }
397 catch (const RenderWindowBridgeNoEditorException& e)
398 {
399 const auto error = ErrorResponse::EditorNotActive(e.what(), req.path);
400 this->SendErrorResponse(res, 503, error);
401 }
402 catch (const std::exception& e)
403 {
404 const auto error = ErrorResponse::InternalError(
405 std::string("Failed to set crosshair position: ") + e.what(), req.path);
406 this->SendErrorResponse(res, 500, error);
407 }
408}
409
410void RenderingController::HandleGET_selectedTime(const httplib::Request& req, httplib::Response& res) const
411{

Calls 6

SendErrorResponseMethod · 0.95
ParsePositionFromBodyFunction · 0.85
HasPositionSetterMethod · 0.80
whatMethod · 0.80
emptyMethod · 0.45
SetSelectedPositionMethod · 0.45