| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// This file is part of INSTINCT, the INS Toolkit for Integrated | ||
| 2 | /// Navigation Concepts and Training by the Institute of Navigation of | ||
| 3 | /// the University of Stuttgart, Germany. | ||
| 4 | /// | ||
| 5 | /// This Source Code Form is subject to the terms of the Mozilla Public | ||
| 6 | /// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| 7 | /// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| 8 | |||
| 9 | #include "Temperature.hpp" | ||
| 10 | |||
| 11 | #include "internal/gui/widgets/EnumCombo.hpp" | ||
| 12 | #include "internal/gui/widgets/imgui_ex.hpp" | ||
| 13 | #include "internal/gui/NodeEditorApplication.hpp" | ||
| 14 | #include "util/Logger.hpp" | ||
| 15 | #include "util/Assert.h" | ||
| 16 | |||
| 17 | #include "Models/StandardAtmosphere.hpp" | ||
| 18 | |||
| 19 | namespace NAV | ||
| 20 | { | ||
| 21 | |||
| 22 | ✗ | bool ComboTemperatureModel(const char* label, TemperatureModel& temperatureModel) | |
| 23 | { | ||
| 24 | ✗ | bool changed = false; | |
| 25 | ✗ | changed |= gui::widgets::EnumCombo(label, temperatureModel._model); | |
| 26 | ✗ | if (temperatureModel._model == TemperatureModel::Model::Const) | |
| 27 | { | ||
| 28 | ✗ | ImGui::SameLine(); | |
| 29 | ✗ | ImGui::SetNextItemWidth(62.0F * gui::NodeEditorApplication::windowFontRatio()); | |
| 30 | ✗ | changed |= ImGui::InputDoubleL(fmt::format("##TemperatureModel constTemp {}", label).c_str(), &temperatureModel._constantTemperature, | |
| 31 | 0.0, std::numeric_limits<double>::max(), 0.0, 0.0, "%.1f K"); | ||
| 32 | ✗ | ImGui::SameLine(); | |
| 33 | ✗ | ImGui::Text("%.1f°C", temperatureModel._constantTemperature - 273.15); | |
| 34 | } | ||
| 35 | ✗ | return changed; | |
| 36 | } | ||
| 37 | |||
| 38 | 140360 | double TemperatureModel::calcAbsoluteTemperature(double altitudeMSL) const | |
| 39 | { | ||
| 40 |
2/5✓ Branch 0 taken 62229 times.
✓ Branch 1 taken 78135 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
140360 | switch (_model) |
| 41 | { | ||
| 42 | 62229 | case TemperatureModel::Model::Const: | |
| 43 | 62229 | return _constantTemperature; | |
| 44 | 78135 | case TemperatureModel::Model::ISA: | |
| 45 | 78135 | return calcAbsoluteTemperatureStAtm(altitudeMSL); | |
| 46 | ✗ | case TemperatureModel::Model::GPT2: | |
| 47 | case TemperatureModel::Model::GPT3: | ||
| 48 | ✗ | LOG_CRITICAL("GPT2/GPT3 Model needs to be called separately because of parameter lookup."); | |
| 49 | break; | ||
| 50 | ✗ | case TemperatureModel::Model::None: | |
| 51 | case TemperatureModel::Model::COUNT: | ||
| 52 | ✗ | break; | |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | return 0.0; | |
| 56 | } | ||
| 57 | |||
| 58 | ✗ | const char* to_string(const TemperatureModel& temperatureModel) | |
| 59 | { | ||
| 60 | ✗ | return to_string(temperatureModel._model); | |
| 61 | } | ||
| 62 | |||
| 63 | ✗ | const char* to_string(TemperatureModel::Model temperatureModel) | |
| 64 | { | ||
| 65 | ✗ | switch (temperatureModel) | |
| 66 | { | ||
| 67 | ✗ | case TemperatureModel::Model::None: | |
| 68 | ✗ | return "None"; | |
| 69 | ✗ | case TemperatureModel::Model::Const: | |
| 70 | ✗ | return "Const"; | |
| 71 | ✗ | case TemperatureModel::Model::ISA: | |
| 72 | ✗ | return "ISA"; | |
| 73 | ✗ | case TemperatureModel::Model::GPT2: | |
| 74 | ✗ | return "GPT2"; | |
| 75 | ✗ | case TemperatureModel::Model::GPT3: | |
| 76 | ✗ | return "GPT3"; | |
| 77 | ✗ | case TemperatureModel::Model::COUNT: | |
| 78 | ✗ | break; | |
| 79 | } | ||
| 80 | ✗ | return ""; | |
| 81 | } | ||
| 82 | |||
| 83 | ✗ | void to_json(json& j, const TemperatureModel& obj) | |
| 84 | { | ||
| 85 | ✗ | j = json{ | |
| 86 | ✗ | { "model", to_string(obj._model) }, | |
| 87 | ✗ | { "constantTemperature", obj._constantTemperature }, | |
| 88 | ✗ | }; | |
| 89 | ✗ | } | |
| 90 | |||
| 91 | 8 | void from_json(const json& j, TemperatureModel& obj) | |
| 92 | { | ||
| 93 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 | auto model = j.at("model").get<std::string>(); |
| 94 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
|
8 | if (model == "None") { obj._model = TemperatureModel::Model::None; } |
| 95 |
3/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
|
8 | else if (model == "Const") { obj._model = TemperatureModel::Model::Const; } |
| 96 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | else if (model == "ISA") { obj._model = TemperatureModel::Model::ISA; } |
| 97 | ✗ | else if (model == "GPT2") { obj._model = TemperatureModel::Model::GPT2; } | |
| 98 | ✗ | else if (model == "GPT3") { obj._model = TemperatureModel::Model::GPT3; } | |
| 99 | |||
| 100 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 | j.at("constantTemperature").get_to(obj._constantTemperature); |
| 101 | 8 | } | |
| 102 | |||
| 103 | } // namespace NAV | ||
| 104 |