| 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 "internal/NodeManager.hpp" | ||
| 10 | |||
| 11 | #include "internal/Node/Node.hpp" | ||
| 12 | #include "internal/Node/Pin.hpp" | ||
| 13 | |||
| 14 | #include "internal/FlowManager.hpp" | ||
| 15 | |||
| 16 | #include "util/Assert.h" | ||
| 17 | |||
| 18 | #include <algorithm> | ||
| 19 | #include <thread> | ||
| 20 | #include <deque> | ||
| 21 | |||
| 22 | #include "NodeRegistry.hpp" | ||
| 23 | |||
| 24 | namespace NAV::NodeManager | ||
| 25 | { | ||
| 26 | /* -------------------------------------------------------------------------------------------------------- */ | ||
| 27 | /* Private Members */ | ||
| 28 | /* -------------------------------------------------------------------------------------------------------- */ | ||
| 29 | |||
| 30 | namespace | ||
| 31 | { | ||
| 32 | std::vector<NAV::Node*> m_nodes; | ||
| 33 | size_t m_NextId = 1; | ||
| 34 | |||
| 35 | } // namespace | ||
| 36 | |||
| 37 | /* -------------------------------------------------------------------------------------------------------- */ | ||
| 38 | /* Public Members */ | ||
| 39 | /* -------------------------------------------------------------------------------------------------------- */ | ||
| 40 | |||
| 41 | #if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) | ||
| 42 | bool showFlowWhenInvokingCallbacks = true; | ||
| 43 | bool showFlowWhenNotifyingValueChange = true; | ||
| 44 | #else | ||
| 45 | bool showFlowWhenInvokingCallbacks = false; | ||
| 46 | bool showFlowWhenNotifyingValueChange = false; | ||
| 47 | #endif | ||
| 48 | |||
| 49 | } // namespace NAV::NodeManager | ||
| 50 | |||
| 51 | /* -------------------------------------------------------------------------------------------------------- */ | ||
| 52 | /* Function Definitions */ | ||
| 53 | /* -------------------------------------------------------------------------------------------------------- */ | ||
| 54 | |||
| 55 | 1371 | const std::vector<NAV::Node*>& NAV::NodeManager::m_Nodes() | |
| 56 | { | ||
| 57 | 1371 | return m_nodes; | |
| 58 | } | ||
| 59 | |||
| 60 | 357 | void NAV::NodeManager::AddNode(NAV::Node* node) | |
| 61 | { | ||
| 62 |
1/2✓ Branch 1 taken 357 times.
✗ Branch 2 not taken.
|
357 | if (!node->id) |
| 63 | { | ||
| 64 | 357 | node->id = GetNextNodeId(); | |
| 65 | } | ||
| 66 | 357 | m_nodes.push_back(node); | |
| 67 |
2/4✓ Branch 2 taken 357 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 357 times.
✗ Branch 7 not taken.
|
357 | LOG_DEBUG("Creating node: {}", node->nameId()); |
| 68 | |||
| 69 |
2/2✓ Branch 4 taken 216 times.
✓ Branch 5 taken 357 times.
|
573 | for (auto& pin : node->inputPins) |
| 70 | { | ||
| 71 | 216 | pin.parentNode = node; | |
| 72 | } | ||
| 73 |
2/2✓ Branch 4 taken 273 times.
✓ Branch 5 taken 357 times.
|
630 | for (auto& pin : node->outputPins) |
| 74 | { | ||
| 75 | 273 | pin.parentNode = node; | |
| 76 | } | ||
| 77 | |||
| 78 |
1/2✓ Branch 1 taken 357 times.
✗ Branch 2 not taken.
|
357 | m_NextId = std::max(m_NextId, size_t(node->id) + 1); |
| 79 |
2/2✓ Branch 4 taken 216 times.
✓ Branch 5 taken 357 times.
|
573 | for (const auto& pin : node->inputPins) |
| 80 | { | ||
| 81 |
1/2✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
|
216 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
| 82 | } | ||
| 83 |
2/2✓ Branch 4 taken 273 times.
✓ Branch 5 taken 357 times.
|
630 | for (const auto& pin : node->outputPins) |
| 84 | { | ||
| 85 |
1/2✓ Branch 1 taken 273 times.
✗ Branch 2 not taken.
|
273 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
| 86 | } | ||
| 87 | |||
| 88 | 357 | flow::ApplyChanges(); | |
| 89 | 357 | } | |
| 90 | |||
| 91 | 357 | void NAV::NodeManager::UpdateNode(Node* node) | |
| 92 | { | ||
| 93 | LOG_TRACE("called for node: {}", node->nameId()); | ||
| 94 |
2/2✓ Branch 4 taken 302 times.
✓ Branch 5 taken 357 times.
|
659 | for (auto& pin : node->inputPins) |
| 95 | { | ||
| 96 | 302 | pin.parentNode = node; | |
| 97 | } | ||
| 98 |
2/2✓ Branch 4 taken 294 times.
✓ Branch 5 taken 357 times.
|
651 | for (auto& pin : node->outputPins) |
| 99 | { | ||
| 100 | 294 | pin.parentNode = node; | |
| 101 | } | ||
| 102 | |||
| 103 |
2/2✓ Branch 4 taken 302 times.
✓ Branch 5 taken 357 times.
|
659 | for (const auto& pin : node->inputPins) |
| 104 | { | ||
| 105 |
1/2✓ Branch 1 taken 302 times.
✗ Branch 2 not taken.
|
302 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
| 106 | } | ||
| 107 |
2/2✓ Branch 4 taken 294 times.
✓ Branch 5 taken 357 times.
|
651 | for (const auto& pin : node->outputPins) |
| 108 | { | ||
| 109 |
1/2✓ Branch 1 taken 294 times.
✗ Branch 2 not taken.
|
294 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
| 110 | } | ||
| 111 | 357 | } | |
| 112 | |||
| 113 | 355 | bool NAV::NodeManager::DeleteNode(ax::NodeEditor::NodeId nodeId) | |
| 114 | { | ||
| 115 | LOG_TRACE("called for node with id {}", size_t(nodeId)); | ||
| 116 | |||
| 117 |
1/2✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
|
1474 | auto it = std::ranges::find_if(m_nodes, [nodeId](const auto& node) { return node->id == nodeId; }); |
| 118 |
1/2✓ Branch 2 taken 355 times.
✗ Branch 3 not taken.
|
355 | if (it != m_nodes.end()) |
| 119 | { | ||
| 120 | 355 | Node* node = *it; | |
| 121 |
1/2✓ Branch 2 taken 355 times.
✗ Branch 3 not taken.
|
355 | m_nodes.erase(it); |
| 122 |
3/6✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 355 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 355 times.
✗ Branch 9 not taken.
|
355 | LOG_DEBUG("Deleting node: {}", node->nameId()); |
| 123 | |||
| 124 |
3/4✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 347 times.
✓ Branch 4 taken 8 times.
|
355 | if (node->isInitialized()) |
| 125 | { | ||
| 126 |
1/2✓ Branch 1 taken 347 times.
✗ Branch 2 not taken.
|
347 | node->doDeinitialize(true); |
| 127 | } | ||
| 128 |
2/2✓ Branch 5 taken 301 times.
✓ Branch 6 taken 355 times.
|
656 | for (auto& inputPin : node->inputPins) |
| 129 | { | ||
| 130 |
3/4✓ Branch 1 taken 301 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 188 times.
✓ Branch 4 taken 113 times.
|
301 | if (inputPin.isPinLinked()) |
| 131 | { | ||
| 132 |
1/2✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
|
188 | inputPin.deleteLink(); |
| 133 | } | ||
| 134 | } | ||
| 135 |
2/2✓ Branch 5 taken 293 times.
✓ Branch 6 taken 355 times.
|
648 | for (auto& outputPin : node->outputPins) |
| 136 | { | ||
| 137 |
3/4✓ Branch 1 taken 293 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 218 times.
|
293 | if (outputPin.isPinLinked()) |
| 138 | { | ||
| 139 |
1/2✓ Branch 1 taken 75 times.
✗ Branch 2 not taken.
|
75 | outputPin.deleteLinks(); |
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 |
1/2✓ Branch 0 taken 355 times.
✗ Branch 1 not taken.
|
355 | delete node; // NOLINT(cppcoreguidelines-owning-memory) |
| 144 | |||
| 145 |
1/2✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
|
355 | flow::ApplyChanges(); |
| 146 | |||
| 147 | 355 | return true; | |
| 148 | } | ||
| 149 | |||
| 150 | ✗ | return false; | |
| 151 | } | ||
| 152 | |||
| 153 | 227 | void NAV::NodeManager::DeleteAllNodes() | |
| 154 | { | ||
| 155 | LOG_TRACE("called"); | ||
| 156 | |||
| 157 | 227 | bool saveLastActionsValue = NAV::flow::saveLastActions; | |
| 158 | 227 | NAV::flow::saveLastActions = false; | |
| 159 | |||
| 160 |
2/2✓ Branch 1 taken 355 times.
✓ Branch 2 taken 227 times.
|
582 | while (!m_nodes.empty()) |
| 161 | { | ||
| 162 | 355 | NodeManager::DeleteNode(m_nodes.back()->id); | |
| 163 | } | ||
| 164 | |||
| 165 | 227 | m_NextId = 1; | |
| 166 | |||
| 167 | 227 | NAV::flow::saveLastActions = saveLastActionsValue; | |
| 168 | 227 | flow::ApplyChanges(); | |
| 169 | 227 | } | |
| 170 | |||
| 171 | 293 | void NAV::NodeManager::AddLink(ax::NodeEditor::LinkId linkId) | |
| 172 | { | ||
| 173 |
1/2✓ Branch 1 taken 293 times.
✗ Branch 2 not taken.
|
293 | m_NextId = std::max(m_NextId, size_t(linkId) + 1); |
| 174 | 293 | } | |
| 175 | |||
| 176 | 5207 | NAV::InputPin* NAV::NodeManager::CreateInputPin(NAV::Node* node, const char* name, NAV::Pin::Type pinType, const std::vector<std::string>& dataIdentifier, | |
| 177 | InputPin::Callback callback, InputPin::FlowFirableCheckFunc firable, int priority, int idx) | ||
| 178 | { | ||
| 179 | LOG_TRACE("called for pin ({}) of type ({}) for node [{}]", name, std::string(pinType), node->nameId()); | ||
| 180 |
2/2✓ Branch 0 taken 5058 times.
✓ Branch 1 taken 149 times.
|
5207 | if (idx < 0) |
| 181 | { | ||
| 182 | 5058 | idx = static_cast<int>(node->inputPins.size()); | |
| 183 | } | ||
| 184 | 5207 | idx = std::min(idx, static_cast<int>(node->inputPins.size())); | |
| 185 | 5207 | auto iter = std::next(node->inputPins.begin(), idx); | |
| 186 | |||
| 187 |
2/4✓ Branch 1 taken 5207 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 5207 times.
✗ Branch 6 not taken.
|
5207 | node->inputPins.emplace(iter, GetNextPinId(), name, pinType, node); |
| 188 | |||
| 189 |
1/2✓ Branch 1 taken 5207 times.
✗ Branch 2 not taken.
|
5207 | node->inputPins.at(static_cast<size_t>(idx)).callback = callback; |
| 190 |
2/2✓ Branch 0 taken 377 times.
✓ Branch 1 taken 4830 times.
|
5207 | if (firable != nullptr) |
| 191 | { | ||
| 192 |
1/2✓ Branch 1 taken 377 times.
✗ Branch 2 not taken.
|
377 | node->inputPins.at(static_cast<size_t>(idx)).firable = firable; |
| 193 | } | ||
| 194 |
2/4✓ Branch 1 taken 5207 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5207 times.
✗ Branch 5 not taken.
|
5207 | node->inputPins.at(static_cast<size_t>(idx)).dataIdentifier = dataIdentifier; |
| 195 |
1/2✓ Branch 1 taken 5207 times.
✗ Branch 2 not taken.
|
5207 | node->inputPins.at(static_cast<size_t>(idx)).priority = priority; |
| 196 | |||
| 197 |
1/2✓ Branch 1 taken 5207 times.
✗ Branch 2 not taken.
|
5207 | flow::ApplyChanges(); |
| 198 | |||
| 199 |
1/2✓ Branch 1 taken 5207 times.
✗ Branch 2 not taken.
|
10414 | return &node->inputPins.at(static_cast<size_t>(idx)); |
| 200 | } | ||
| 201 | |||
| 202 | 6913 | NAV::OutputPin* NAV::NodeManager::CreateOutputPin(NAV::Node* node, const char* name, NAV::Pin::Type pinType, const std::vector<std::string>& dataIdentifier, OutputPin::PinData data, int idx) | |
| 203 | { | ||
| 204 | LOG_TRACE("called for pin ({}) of type ({}) for node [{}]", name, std::string(pinType), node->nameId()); | ||
| 205 |
2/2✓ Branch 0 taken 6890 times.
✓ Branch 1 taken 23 times.
|
6913 | if (idx < 0) |
| 206 | { | ||
| 207 | 6890 | idx = static_cast<int>(node->outputPins.size()); | |
| 208 | } | ||
| 209 | 6913 | idx = std::min(idx, static_cast<int>(node->outputPins.size())); | |
| 210 | 6913 | auto iter = std::next(node->outputPins.begin(), idx); | |
| 211 | |||
| 212 |
2/4✓ Branch 1 taken 6913 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6913 times.
✗ Branch 6 not taken.
|
6913 | node->outputPins.emplace(iter, GetNextPinId(), name, pinType, node); |
| 213 | |||
| 214 |
1/2✓ Branch 1 taken 6913 times.
✗ Branch 2 not taken.
|
6913 | node->outputPins.at(static_cast<size_t>(idx)).data = data; |
| 215 |
2/4✓ Branch 1 taken 6913 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6913 times.
✗ Branch 5 not taken.
|
6913 | node->outputPins.at(static_cast<size_t>(idx)).dataIdentifier = dataIdentifier; |
| 216 | |||
| 217 |
1/2✓ Branch 1 taken 6913 times.
✗ Branch 2 not taken.
|
6913 | flow::ApplyChanges(); |
| 218 | |||
| 219 |
1/2✓ Branch 1 taken 6913 times.
✗ Branch 2 not taken.
|
13826 | return &node->outputPins.at(static_cast<size_t>(idx)); |
| 220 | } | ||
| 221 | |||
| 222 | 7 | bool NAV::NodeManager::DeleteOutputPin(NAV::OutputPin& pin) | |
| 223 | { | ||
| 224 | LOG_TRACE("called for pin ({})", size_t(pin.id)); | ||
| 225 | |||
| 226 | 7 | pin.deleteLinks(); | |
| 227 | |||
| 228 | 7 | size_t pinIndex = pin.parentNode->outputPinIndexFromId(pin.id); | |
| 229 |
1/2✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | pin.parentNode->outputPins.erase(pin.parentNode->outputPins.begin() + static_cast<int64_t>(pinIndex)); |
| 230 | |||
| 231 | 7 | return true; | |
| 232 | } | ||
| 233 | |||
| 234 | 3 | bool NAV::NodeManager::DeleteInputPin(NAV::InputPin& pin) | |
| 235 | { | ||
| 236 | LOG_TRACE("called for pin ({})", size_t(pin.id)); | ||
| 237 | |||
| 238 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | pin.deleteLink(); |
| 239 | |||
| 240 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | size_t pinIndex = pin.parentNode->inputPinIndexFromId(pin.id); |
| 241 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
3 | LOG_DEBUG("Erasing pin at idx {}", pinIndex); |
| 242 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | pin.parentNode->inputPins.erase(pin.parentNode->inputPins.begin() + static_cast<int64_t>(pinIndex)); |
| 243 | |||
| 244 | 3 | return true; | |
| 245 | } | ||
| 246 | |||
| 247 | namespace NAV::NodeManager | ||
| 248 | { | ||
| 249 | namespace | ||
| 250 | { | ||
| 251 | |||
| 252 | 12480 | size_t GetNextId() | |
| 253 | { | ||
| 254 | 12480 | return m_NextId++; | |
| 255 | } | ||
| 256 | |||
| 257 | } // namespace | ||
| 258 | } // namespace NAV::NodeManager | ||
| 259 | |||
| 260 | 357 | ax::NodeEditor::NodeId NAV::NodeManager::GetNextNodeId() | |
| 261 | { | ||
| 262 |
1/2✓ Branch 2 taken 357 times.
✗ Branch 3 not taken.
|
357 | return { GetNextId() }; |
| 263 | } | ||
| 264 | |||
| 265 | 3 | ax::NodeEditor::LinkId NAV::NodeManager::GetNextLinkId() | |
| 266 | { | ||
| 267 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | return { GetNextId() }; |
| 268 | } | ||
| 269 | |||
| 270 | 12120 | ax::NodeEditor::PinId NAV::NodeManager::GetNextPinId() | |
| 271 | { | ||
| 272 |
1/2✓ Branch 2 taken 12120 times.
✗ Branch 3 not taken.
|
12120 | return { GetNextId() }; |
| 273 | } | ||
| 274 | |||
| 275 | 222 | NAV::Node* NAV::NodeManager::FindNode(ax::NodeEditor::NodeId id) | |
| 276 | { | ||
| 277 |
1/2✓ Branch 5 taken 330 times.
✗ Branch 6 not taken.
|
330 | for (auto& node : m_nodes) |
| 278 | { | ||
| 279 |
3/4✓ Branch 1 taken 330 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 222 times.
✓ Branch 4 taken 108 times.
|
330 | if (node->id == id) |
| 280 | { | ||
| 281 | 222 | return node; | |
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | ✗ | return nullptr; | |
| 286 | } | ||
| 287 | |||
| 288 | 39 | NAV::OutputPin* NAV::NodeManager::FindOutputPin(ax::NodeEditor::PinId id) | |
| 289 | { | ||
| 290 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
|
39 | if (!id) { return nullptr; } |
| 291 | |||
| 292 |
1/2✓ Branch 5 taken 42 times.
✗ Branch 6 not taken.
|
42 | for (auto& node : m_nodes) |
| 293 | { | ||
| 294 |
3/6✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
|
42 | if (!node || node->kind == Node::Kind::GroupBox) { continue; } |
| 295 |
2/2✓ Branch 5 taken 42 times.
✓ Branch 6 taken 3 times.
|
45 | for (auto& pin : node->outputPins) |
| 296 | { | ||
| 297 |
3/4✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 3 times.
|
42 | if (pin.id == id) { return &pin; } |
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 301 | ✗ | return nullptr; | |
| 302 | } | ||
| 303 | |||
| 304 | ✗ | NAV::InputPin* NAV::NodeManager::FindInputPin(ax::NodeEditor::PinId id) | |
| 305 | { | ||
| 306 | ✗ | if (!id) { return nullptr; } | |
| 307 | |||
| 308 | ✗ | for (auto& node : m_nodes) | |
| 309 | { | ||
| 310 | ✗ | if (!node || node->kind == Node::Kind::GroupBox) { continue; } | |
| 311 | ✗ | for (auto& pin : node->inputPins) | |
| 312 | { | ||
| 313 | ✗ | if (pin.id == id) { return &pin; } | |
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | ✗ | return nullptr; | |
| 318 | } | ||
| 319 | |||
| 320 | 113 | void NAV::NodeManager::EnableAllCallbacks() | |
| 321 | { | ||
| 322 | LOG_TRACE("called"); | ||
| 323 |
2/2✓ Branch 5 taken 355 times.
✓ Branch 6 taken 113 times.
|
468 | for (auto* node : m_nodes) |
| 324 | { | ||
| 325 |
8/10✓ Branch 0 taken 355 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 355 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 354 times.
✓ Branch 6 taken 1 times.
✓ Branch 8 taken 350 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 350 times.
✓ Branch 11 taken 5 times.
|
355 | if (node && !node->isDisabled() && node->kind != Node::Kind::GroupBox) |
| 326 | { | ||
| 327 | 350 | node->callbacksEnabled = true; | |
| 328 | } | ||
| 329 | } | ||
| 330 | 113 | } | |
| 331 | |||
| 332 | 226 | void NAV::NodeManager::DisableAllCallbacks() | |
| 333 | { | ||
| 334 | LOG_TRACE("called"); | ||
| 335 |
2/2✓ Branch 4 taken 710 times.
✓ Branch 5 taken 226 times.
|
936 | for (auto* node : m_nodes) |
| 336 | { | ||
| 337 | 710 | node->callbacksEnabled = false; | |
| 338 | } | ||
| 339 | 226 | } | |
| 340 | |||
| 341 | 113 | void NAV::NodeManager::ClearAllNodeQueues() | |
| 342 | { | ||
| 343 | LOG_TRACE("called"); | ||
| 344 |
2/2✓ Branch 5 taken 355 times.
✓ Branch 6 taken 113 times.
|
468 | for (auto* node : m_nodes) |
| 345 | { | ||
| 346 |
2/2✓ Branch 5 taken 301 times.
✓ Branch 6 taken 355 times.
|
656 | for (auto& inputPin : node->inputPins) |
| 347 | { | ||
| 348 | 301 | inputPin.queue.clear(); | |
| 349 | } | ||
| 350 | } | ||
| 351 | 113 | } | |
| 352 | |||
| 353 | 227 | bool NAV::NodeManager::InitializeAllNodes() | |
| 354 | { | ||
| 355 | LOG_TRACE("called"); | ||
| 356 | 227 | bool nodeCouldNotInitialize = false; | |
| 357 | |||
| 358 | 227 | InitializeAllNodesAsync(); | |
| 359 | |||
| 360 |
2/2✓ Branch 5 taken 712 times.
✓ Branch 6 taken 227 times.
|
939 | for (auto* node : m_nodes) |
| 361 | { | ||
| 362 |
11/14✓ Branch 0 taken 712 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 704 times.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 704 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 702 times.
✓ Branch 9 taken 2 times.
✓ Branch 11 taken 702 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 159 times.
✓ Branch 14 taken 543 times.
✓ Branch 15 taken 159 times.
✓ Branch 16 taken 553 times.
|
712 | if (node && node->kind != Node::Kind::GroupBox && !node->isDisabled() && !node->isInitialized()) |
| 363 | { | ||
| 364 |
3/4✓ Branch 1 taken 159 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 158 times.
|
159 | if (!node->doInitialize(true)) |
| 365 | { | ||
| 366 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
1 | LOG_ERROR("Node '{}' could not initialize.", node->nameId()); |
| 367 | 1 | nodeCouldNotInitialize = true; | |
| 368 | } | ||
| 369 | } | ||
| 370 | } | ||
| 371 | |||
| 372 | 227 | return !nodeCouldNotInitialize; | |
| 373 | } | ||
| 374 | |||
| 375 | 227 | void NAV::NodeManager::InitializeAllNodesAsync() | |
| 376 | { | ||
| 377 | LOG_TRACE("called"); | ||
| 378 | |||
| 379 |
2/2✓ Branch 5 taken 712 times.
✓ Branch 6 taken 227 times.
|
939 | for (auto* node : m_nodes) |
| 380 | { | ||
| 381 |
11/14✓ Branch 0 taken 712 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 704 times.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 704 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 702 times.
✓ Branch 9 taken 2 times.
✓ Branch 11 taken 702 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 352 times.
✓ Branch 14 taken 350 times.
✓ Branch 15 taken 352 times.
✓ Branch 16 taken 360 times.
|
712 | if (node && node->kind != Node::Kind::GroupBox && !node->isDisabled() && !node->isInitialized()) |
| 382 | { | ||
| 383 |
1/2✓ Branch 1 taken 352 times.
✗ Branch 2 not taken.
|
352 | node->doInitialize(); |
| 384 | } | ||
| 385 | } | ||
| 386 | 227 | } | |
| 387 | |||
| 388 | #ifdef TESTING | ||
| 389 | |||
| 390 | namespace | ||
| 391 | { | ||
| 392 | std::vector<std::pair<ax::NodeEditor::PinId, NAV::InputPin::WatcherCallback>> watcherPinList; | ||
| 393 | std::vector<std::pair<ax::NodeEditor::LinkId, NAV::InputPin::WatcherCallback>> watcherLinkList; | ||
| 394 | |||
| 395 | std::function<void()> preInitCallback = nullptr; | ||
| 396 | std::function<void()> cleanupCallback = nullptr; | ||
| 397 | |||
| 398 | } // namespace | ||
| 399 | |||
| 400 | 144 | void NAV::NodeManager::RegisterWatcherCallbackToInputPin(ax::NodeEditor::PinId id, const InputPin::WatcherCallback& callback) | |
| 401 | { | ||
| 402 | 144 | watcherPinList.emplace_back(id, callback); | |
| 403 | 144 | } | |
| 404 | |||
| 405 | ✗ | void NAV::NodeManager::RegisterWatcherCallbackToLink(ax::NodeEditor::LinkId id, const InputPin::WatcherCallback& callback) | |
| 406 | { | ||
| 407 | ✗ | watcherLinkList.emplace_back(id, callback); | |
| 408 | ✗ | } | |
| 409 | |||
| 410 | 113 | void NAV::NodeManager::ApplyWatcherCallbacks() | |
| 411 | { | ||
| 412 |
1/2✗ Branch 7 not taken.
✓ Branch 8 taken 113 times.
|
113 | for (auto& [linkId, callback] : watcherLinkList) |
| 413 | { | ||
| 414 | ✗ | for (auto& node : m_nodes) | |
| 415 | { | ||
| 416 | ✗ | for (size_t pinIdx = 0; pinIdx < node->inputPins.size(); pinIdx++) | |
| 417 | { | ||
| 418 | ✗ | auto& pin = node->inputPins[pinIdx]; | |
| 419 | ✗ | if (pin.isPinLinked() && pin.link.linkId == linkId) | |
| 420 | { | ||
| 421 | ✗ | LOG_DEBUG("Adding watcher callback on node '{}' on pin with index {}", pin.parentNode->nameId(), pinIdx); | |
| 422 | ✗ | pin.watcherCallbacks.emplace_back(callback); | |
| 423 | } | ||
| 424 | } | ||
| 425 | } | ||
| 426 | } | ||
| 427 | |||
| 428 |
2/2✓ Branch 7 taken 144 times.
✓ Branch 8 taken 113 times.
|
257 | for (auto& [id, callback] : watcherPinList) |
| 429 | { | ||
| 430 |
2/2✓ Branch 5 taken 742 times.
✓ Branch 6 taken 144 times.
|
886 | for (auto& node : m_nodes) |
| 431 | { | ||
| 432 |
2/2✓ Branch 1 taken 726 times.
✓ Branch 2 taken 742 times.
|
1468 | for (size_t pinIdx = 0; pinIdx < node->inputPins.size(); pinIdx++) |
| 433 | { | ||
| 434 | 726 | auto& pin = node->inputPins[pinIdx]; | |
| 435 |
3/4✓ Branch 1 taken 726 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
✓ Branch 4 taken 582 times.
|
726 | if (pin.id == id) |
| 436 | { | ||
| 437 |
3/6✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 144 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 144 times.
✗ Branch 9 not taken.
|
144 | LOG_DEBUG("Adding watcher callback on node '{}' on pin with index {}", pin.parentNode->nameId(), pinIdx); |
| 438 |
1/2✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
|
144 | pin.watcherCallbacks.emplace_back(callback); |
| 439 | } | ||
| 440 | } | ||
| 441 | } | ||
| 442 | } | ||
| 443 | 113 | } | |
| 444 | |||
| 445 | 104 | void NAV::NodeManager::RegisterPreInitCallback(std::function<void()> callback) | |
| 446 | { | ||
| 447 | 104 | preInitCallback = std::move(callback); | |
| 448 | 104 | } | |
| 449 | |||
| 450 | 114 | void NAV::NodeManager::CallPreInitCallback() | |
| 451 | { | ||
| 452 |
2/2✓ Branch 1 taken 104 times.
✓ Branch 2 taken 10 times.
|
114 | if (preInitCallback) |
| 453 | { | ||
| 454 | 104 | preInitCallback(); | |
| 455 | } | ||
| 456 | 114 | } | |
| 457 | |||
| 458 | 38 | void NAV::NodeManager::RegisterCleanupCallback(std::function<void()> callback) | |
| 459 | { | ||
| 460 | 38 | cleanupCallback = std::move(callback); | |
| 461 | 38 | } | |
| 462 | 113 | void NAV::NodeManager::CallCleanupCallback() | |
| 463 | { | ||
| 464 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 2 taken 75 times.
|
113 | if (cleanupCallback) |
| 465 | { | ||
| 466 | 38 | cleanupCallback(); | |
| 467 | } | ||
| 468 | 113 | } | |
| 469 | |||
| 470 | 114 | void NAV::NodeManager::ClearRegisteredCallbacks() | |
| 471 | { | ||
| 472 | 114 | watcherPinList.clear(); | |
| 473 | 114 | watcherLinkList.clear(); | |
| 474 | 114 | preInitCallback = nullptr; | |
| 475 | 114 | cleanupCallback = nullptr; | |
| 476 | 114 | } | |
| 477 | |||
| 478 | #endif | ||
| 479 |