| 1526 | } |
| 1527 | |
| 1528 | nlohmann::json MxNWindowInfoToWindowsListJson(const std::vector<mitk::MxNWindowInfo>& windows) |
| 1529 | { |
| 1530 | auto arr = nlohmann::json::array(); |
| 1531 | for (const auto& w : windows) |
| 1532 | { |
| 1533 | nlohmann::json wj; |
| 1534 | wj["id"] = w.id; |
| 1535 | // Optional display label: emit only when set, mirroring the layout |
| 1536 | // schema's `name` field semantics (see mxn-layout-v2.schema.json). |
| 1537 | if (w.displayName.has_value()) |
| 1538 | { |
| 1539 | wj["name"] = *w.displayName; |
| 1540 | } |
| 1541 | wj["kind"] = WindowKindToString(w.kind); |
| 1542 | // Under v2 the layout schema's view_direction enum is closed |
| 1543 | // {axial, sagittal, coronal, original} and required for every window |
| 1544 | // leaf, so every 2D MxN cell carries a value. The std::optional wrapper |
| 1545 | // exists purely for v3 forward-compat (3D cells with no plane). For 2D |
| 1546 | // cells we emit unconditionally; an unset optional under v2 indicates a |
| 1547 | // bridge-layer bug (loud failure beats silently dropping a required |
| 1548 | // field and producing a response that violates the OpenAPI schema). |
| 1549 | if (w.kind == WindowKind::TwoD) |
| 1550 | { |
| 1551 | if (!w.viewDirection.has_value()) |
| 1552 | { |
| 1553 | mitkThrow() << "MxN window list: 2D cell '" << w.id |
| 1554 | << "' has no view_direction set; expected an " |
| 1555 | "AnatomicalPlane value under v2."; |
| 1556 | } |
| 1557 | wj["view_direction"] = AnatomicalPlaneToV2String(*w.viewDirection); |
| 1558 | } |
| 1559 | else if (w.viewDirection.has_value()) |
| 1560 | { |
| 1561 | // v3 (3D cells): omit view_direction unless the descriptor still |
| 1562 | // carries one. |
| 1563 | wj["view_direction"] = AnatomicalPlaneToV2String(*w.viewDirection); |
| 1564 | } |
| 1565 | // links is always emitted; v2 has just one dimension (selection), v3 |
| 1566 | // will add more keys here additively without breaking v2 clients. |
| 1567 | wj["links"] = { { "selection", w.selectionGroup } }; |
| 1568 | arr.push_back(wj); |
| 1569 | } |
| 1570 | return arr; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | void RenderingController::HandleGET_mxnInfo(const httplib::Request& req, httplib::Response& res) const |
no test coverage detected