* \brief Extract the integer `layer` property value from a node JSON object * for pre-Add ordering. * * Accepts both the simple primitive form (`"layer": 2`) and the tagged * object form (`"layer": {"type": "IntProperty", "value": 2}`) via the * standard property converter. Returns 0 if no usable layer value is * present or if the property is of a non-integer type. */
| 403 | * present or if the property is of a non-integer type. |
| 404 | */ |
| 405 | int ExtractLayer(const json &nodeJson) |
| 406 | { |
| 407 | const auto propsIt = nodeJson.find(FIELD_PROPERTIES); |
| 408 | if (propsIt == nodeJson.end() || !propsIt->is_object()) |
| 409 | return 0; |
| 410 | auto layerIt = propsIt->find(PROPERTY_LAYER); |
| 411 | if (layerIt == propsIt->end() || layerIt->is_null()) |
| 412 | return 0; |
| 413 | try |
| 414 | { |
| 415 | mitk::BaseProperty::Pointer prop = mitk::ConvertPropertyFromSelfContainedJson(*layerIt); |
| 416 | if (auto *intProp = dynamic_cast<mitk::IntProperty *>(prop.GetPointer())) |
| 417 | return intProp->GetValue(); |
| 418 | } |
| 419 | catch (const mitk::Exception &) |
| 420 | { |
| 421 | // Ignore — sort falls back to layer 0 for this node. |
| 422 | } |
| 423 | catch (const std::exception &) |
| 424 | { |
| 425 | // ConvertPropertyFromSelfContainedJson can also propagate non-mitk |
| 426 | // exceptions (e.g. nlohmann::json::out_of_range on a malformed tagged |
| 427 | // value). Treat the same as a missing/unusable layer: fall back to 0. |
| 428 | } |
| 429 | return 0; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | mitk::SceneJsonReader::SceneJsonReader() = default; |
no test coverage detected