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 | 1319 | const std::vector<NAV::Node*>& NAV::NodeManager::m_Nodes() | |
56 | { | ||
57 | 1319 | return m_nodes; | |
58 | } | ||
59 | |||
60 | 340 | void NAV::NodeManager::AddNode(NAV::Node* node) | |
61 | { | ||
62 |
1/2✓ Branch 1 taken 340 times.
✗ Branch 2 not taken.
|
340 | if (!node->id) |
63 | { | ||
64 | 340 | node->id = GetNextNodeId(); | |
65 | } | ||
66 | 340 | m_nodes.push_back(node); | |
67 |
2/4✓ Branch 2 taken 340 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 340 times.
✗ Branch 7 not taken.
|
340 | LOG_DEBUG("Creating node: {}", node->nameId()); |
68 | |||
69 |
2/2✓ Branch 4 taken 204 times.
✓ Branch 5 taken 340 times.
|
544 | for (auto& pin : node->inputPins) |
70 | { | ||
71 | 204 | pin.parentNode = node; | |
72 | } | ||
73 |
2/2✓ Branch 4 taken 261 times.
✓ Branch 5 taken 340 times.
|
601 | for (auto& pin : node->outputPins) |
74 | { | ||
75 | 261 | pin.parentNode = node; | |
76 | } | ||
77 | |||
78 |
1/2✓ Branch 1 taken 340 times.
✗ Branch 2 not taken.
|
340 | m_NextId = std::max(m_NextId, size_t(node->id) + 1); |
79 |
2/2✓ Branch 4 taken 204 times.
✓ Branch 5 taken 340 times.
|
544 | for (const auto& pin : node->inputPins) |
80 | { | ||
81 |
1/2✓ Branch 1 taken 204 times.
✗ Branch 2 not taken.
|
204 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
82 | } | ||
83 |
2/2✓ Branch 4 taken 261 times.
✓ Branch 5 taken 340 times.
|
601 | for (const auto& pin : node->outputPins) |
84 | { | ||
85 |
1/2✓ Branch 1 taken 261 times.
✗ Branch 2 not taken.
|
261 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
86 | } | ||
87 | |||
88 | 340 | flow::ApplyChanges(); | |
89 | 340 | } | |
90 | |||
91 | 340 | void NAV::NodeManager::UpdateNode(Node* node) | |
92 | { | ||
93 | LOG_TRACE("called for node: {}", node->nameId()); | ||
94 |
2/2✓ Branch 4 taken 283 times.
✓ Branch 5 taken 340 times.
|
623 | for (auto& pin : node->inputPins) |
95 | { | ||
96 | 283 | pin.parentNode = node; | |
97 | } | ||
98 |
2/2✓ Branch 4 taken 282 times.
✓ Branch 5 taken 340 times.
|
622 | for (auto& pin : node->outputPins) |
99 | { | ||
100 | 282 | pin.parentNode = node; | |
101 | } | ||
102 | |||
103 |
2/2✓ Branch 4 taken 283 times.
✓ Branch 5 taken 340 times.
|
623 | for (const auto& pin : node->inputPins) |
104 | { | ||
105 |
1/2✓ Branch 1 taken 283 times.
✗ Branch 2 not taken.
|
283 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
106 | } | ||
107 |
2/2✓ Branch 4 taken 282 times.
✓ Branch 5 taken 340 times.
|
622 | for (const auto& pin : node->outputPins) |
108 | { | ||
109 |
1/2✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
|
282 | m_NextId = std::max(m_NextId, size_t(pin.id) + 1); |
110 | } | ||
111 | 340 | } | |
112 | |||
113 | 338 | 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 338 times.
✗ Branch 2 not taken.
|
1334 | auto it = std::ranges::find_if(m_nodes, [nodeId](const auto& node) { return node->id == nodeId; }); |
118 |
1/2✓ Branch 2 taken 338 times.
✗ Branch 3 not taken.
|
338 | if (it != m_nodes.end()) |
119 | { | ||
120 | 338 | Node* node = *it; | |
121 |
1/2✓ Branch 2 taken 338 times.
✗ Branch 3 not taken.
|
338 | m_nodes.erase(it); |
122 |
3/6✓ Branch 1 taken 338 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 338 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 338 times.
✗ Branch 9 not taken.
|
338 | LOG_DEBUG("Deleting node: {}", node->nameId()); |
123 | |||
124 |
3/4✓ Branch 1 taken 338 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 336 times.
✓ Branch 4 taken 2 times.
|
338 | if (node->isInitialized()) |
125 | { | ||
126 |
1/2✓ Branch 1 taken 336 times.
✗ Branch 2 not taken.
|
336 | node->doDeinitialize(true); |
127 | } | ||
128 |
2/2✓ Branch 5 taken 282 times.
✓ Branch 6 taken 338 times.
|
620 | for (auto& inputPin : node->inputPins) |
129 | { | ||
130 |
3/4✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 182 times.
✓ Branch 4 taken 100 times.
|
282 | if (inputPin.isPinLinked()) |
131 | { | ||
132 |
1/2✓ Branch 1 taken 182 times.
✗ Branch 2 not taken.
|
182 | inputPin.deleteLink(); |
133 | } | ||
134 | } | ||
135 |
2/2✓ Branch 5 taken 281 times.
✓ Branch 6 taken 338 times.
|
619 | for (auto& outputPin : node->outputPins) |
136 | { | ||
137 |
3/4✓ Branch 1 taken 281 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 67 times.
✓ Branch 4 taken 214 times.
|
281 | if (outputPin.isPinLinked()) |
138 | { | ||
139 |
1/2✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
|
67 | outputPin.deleteLinks(); |
140 | } | ||
141 | } | ||
142 | |||
143 |
1/2✓ Branch 0 taken 338 times.
✗ Branch 1 not taken.
|
338 | delete node; // NOLINT(cppcoreguidelines-owning-memory) |
144 | |||
145 |
1/2✓ Branch 1 taken 338 times.
✗ Branch 2 not taken.
|
338 | flow::ApplyChanges(); |
146 | |||
147 | 338 | return true; | |
148 | } | ||
149 | |||
150 | ✗ | return false; | |
151 | } | ||
152 | |||
153 | 223 | void NAV::NodeManager::DeleteAllNodes() | |
154 | { | ||
155 | LOG_TRACE("called"); | ||
156 | |||
157 | 223 | bool saveLastActionsValue = NAV::flow::saveLastActions; | |
158 | 223 | NAV::flow::saveLastActions = false; | |
159 | |||
160 |
2/2✓ Branch 1 taken 338 times.
✓ Branch 2 taken 223 times.
|
561 | while (!m_nodes.empty()) |
161 | { | ||
162 | 338 | NodeManager::DeleteNode(m_nodes.back()->id); | |
163 | } | ||
164 | |||
165 | 223 | m_NextId = 1; | |
166 | |||
167 | 223 | NAV::flow::saveLastActions = saveLastActionsValue; | |
168 | 223 | flow::ApplyChanges(); | |
169 | 223 | } | |
170 | |||
171 | 272 | void NAV::NodeManager::AddLink(ax::NodeEditor::LinkId linkId) | |
172 | { | ||
173 |
1/2✓ Branch 1 taken 272 times.
✗ Branch 2 not taken.
|
272 | m_NextId = std::max(m_NextId, size_t(linkId) + 1); |
174 | 272 | } | |
175 | |||
176 | 4652 | 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 4506 times.
✓ Branch 1 taken 146 times.
|
4652 | if (idx < 0) |
181 | { | ||
182 | 4506 | idx = static_cast<int>(node->inputPins.size()); | |
183 | } | ||
184 | 4652 | idx = std::min(idx, static_cast<int>(node->inputPins.size())); | |
185 | 4652 | auto iter = std::next(node->inputPins.begin(), idx); | |
186 | |||
187 |
2/4✓ Branch 1 taken 4652 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 4652 times.
✗ Branch 6 not taken.
|
4652 | node->inputPins.emplace(iter, GetNextPinId(), name, pinType, node); |
188 | |||
189 |
1/2✓ Branch 1 taken 4652 times.
✗ Branch 2 not taken.
|
4652 | node->inputPins.at(static_cast<size_t>(idx)).callback = callback; |
190 |
2/2✓ Branch 0 taken 371 times.
✓ Branch 1 taken 4281 times.
|
4652 | if (firable != nullptr) |
191 | { | ||
192 |
1/2✓ Branch 1 taken 371 times.
✗ Branch 2 not taken.
|
371 | node->inputPins.at(static_cast<size_t>(idx)).firable = firable; |
193 | } | ||
194 |
2/4✓ Branch 1 taken 4652 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4652 times.
✗ Branch 5 not taken.
|
4652 | node->inputPins.at(static_cast<size_t>(idx)).dataIdentifier = dataIdentifier; |
195 |
1/2✓ Branch 1 taken 4652 times.
✗ Branch 2 not taken.
|
4652 | node->inputPins.at(static_cast<size_t>(idx)).priority = priority; |
196 | |||
197 |
1/2✓ Branch 1 taken 4652 times.
✗ Branch 2 not taken.
|
4652 | flow::ApplyChanges(); |
198 | |||
199 |
1/2✓ Branch 1 taken 4652 times.
✗ Branch 2 not taken.
|
9304 | return &node->inputPins.at(static_cast<size_t>(idx)); |
200 | } | ||
201 | |||
202 | 6673 | 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 6650 times.
✓ Branch 1 taken 23 times.
|
6673 | if (idx < 0) |
206 | { | ||
207 | 6650 | idx = static_cast<int>(node->outputPins.size()); | |
208 | } | ||
209 | 6673 | idx = std::min(idx, static_cast<int>(node->outputPins.size())); | |
210 | 6673 | auto iter = std::next(node->outputPins.begin(), idx); | |
211 | |||
212 |
2/4✓ Branch 1 taken 6673 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6673 times.
✗ Branch 6 not taken.
|
6673 | node->outputPins.emplace(iter, GetNextPinId(), name, pinType, node); |
213 | |||
214 |
1/2✓ Branch 1 taken 6673 times.
✗ Branch 2 not taken.
|
6673 | node->outputPins.at(static_cast<size_t>(idx)).data = data; |
215 |
2/4✓ Branch 1 taken 6673 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6673 times.
✗ Branch 5 not taken.
|
6673 | node->outputPins.at(static_cast<size_t>(idx)).dataIdentifier = dataIdentifier; |
216 | |||
217 |
1/2✓ Branch 1 taken 6673 times.
✗ Branch 2 not taken.
|
6673 | flow::ApplyChanges(); |
218 | |||
219 |
1/2✓ Branch 1 taken 6673 times.
✗ Branch 2 not taken.
|
13346 | 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 | 1 | 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 1 times.
✗ Branch 2 not taken.
|
1 | pin.deleteLink(); |
239 | |||
240 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t pinIndex = pin.parentNode->inputPinIndexFromId(pin.id); |
241 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | LOG_DEBUG("Erasing pin at idx {}", pinIndex); |
242 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | pin.parentNode->inputPins.erase(pin.parentNode->inputPins.begin() + static_cast<int64_t>(pinIndex)); |
243 | |||
244 | 1 | return true; | |
245 | } | ||
246 | |||
247 | namespace NAV::NodeManager | ||
248 | { | ||
249 | namespace | ||
250 | { | ||
251 | |||
252 | 11666 | size_t GetNextId() | |
253 | { | ||
254 | 11666 | return m_NextId++; | |
255 | } | ||
256 | |||
257 | } // namespace | ||
258 | } // namespace NAV::NodeManager | ||
259 | |||
260 | 340 | ax::NodeEditor::NodeId NAV::NodeManager::GetNextNodeId() | |
261 | { | ||
262 |
1/2✓ Branch 2 taken 340 times.
✗ Branch 3 not taken.
|
340 | return { GetNextId() }; |
263 | } | ||
264 | |||
265 | 1 | ax::NodeEditor::LinkId NAV::NodeManager::GetNextLinkId() | |
266 | { | ||
267 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return { GetNextId() }; |
268 | } | ||
269 | |||
270 | 11325 | ax::NodeEditor::PinId NAV::NodeManager::GetNextPinId() | |
271 | { | ||
272 |
1/2✓ Branch 2 taken 11325 times.
✗ Branch 3 not taken.
|
11325 | return { GetNextId() }; |
273 | } | ||
274 | |||
275 | 221 | NAV::Node* NAV::NodeManager::FindNode(ax::NodeEditor::NodeId id) | |
276 | { | ||
277 |
1/2✓ Branch 5 taken 329 times.
✗ Branch 6 not taken.
|
329 | for (auto& node : m_nodes) |
278 | { | ||
279 |
3/4✓ Branch 1 taken 329 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 221 times.
✓ Branch 4 taken 108 times.
|
329 | if (node->id == id) |
280 | { | ||
281 | 221 | 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 | 111 | void NAV::NodeManager::EnableAllCallbacks() | |
321 | { | ||
322 | LOG_TRACE("called"); | ||
323 |
2/2✓ Branch 5 taken 338 times.
✓ Branch 6 taken 111 times.
|
449 | for (auto* node : m_nodes) |
324 | { | ||
325 |
7/10✓ Branch 0 taken 338 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 338 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 337 times.
✓ Branch 6 taken 1 times.
✓ Branch 8 taken 337 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 337 times.
✓ Branch 11 taken 1 times.
|
338 | if (node && !node->isDisabled() && node->kind != Node::Kind::GroupBox) |
326 | { | ||
327 | 337 | node->callbacksEnabled = true; | |
328 | } | ||
329 | } | ||
330 | 111 | } | |
331 | |||
332 | 222 | void NAV::NodeManager::DisableAllCallbacks() | |
333 | { | ||
334 | LOG_TRACE("called"); | ||
335 |
2/2✓ Branch 4 taken 676 times.
✓ Branch 5 taken 222 times.
|
898 | for (auto* node : m_nodes) |
336 | { | ||
337 | 676 | node->callbacksEnabled = false; | |
338 | } | ||
339 | 222 | } | |
340 | |||
341 | 111 | void NAV::NodeManager::ClearAllNodeQueues() | |
342 | { | ||
343 | LOG_TRACE("called"); | ||
344 |
2/2✓ Branch 5 taken 338 times.
✓ Branch 6 taken 111 times.
|
449 | for (auto* node : m_nodes) |
345 | { | ||
346 |
2/2✓ Branch 5 taken 282 times.
✓ Branch 6 taken 338 times.
|
620 | for (auto& inputPin : node->inputPins) |
347 | { | ||
348 | 282 | inputPin.queue.clear(); | |
349 | } | ||
350 | } | ||
351 | 111 | } | |
352 | |||
353 | 223 | bool NAV::NodeManager::InitializeAllNodes() | |
354 | { | ||
355 | LOG_TRACE("called"); | ||
356 | 223 | bool nodeCouldNotInitialize = false; | |
357 | |||
358 | 223 | InitializeAllNodesAsync(); | |
359 | |||
360 |
2/2✓ Branch 5 taken 678 times.
✓ Branch 6 taken 223 times.
|
901 | for (auto* node : m_nodes) |
361 | { | ||
362 |
10/14✓ Branch 0 taken 678 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 678 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 678 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 676 times.
✓ Branch 9 taken 2 times.
✓ Branch 11 taken 676 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 158 times.
✓ Branch 14 taken 518 times.
✓ Branch 15 taken 158 times.
✓ Branch 16 taken 520 times.
|
678 | if (node && node->kind != Node::Kind::GroupBox && !node->isDisabled() && !node->isInitialized()) |
363 | { | ||
364 |
3/4✓ Branch 1 taken 158 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 157 times.
|
158 | 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 | 223 | return !nodeCouldNotInitialize; | |
373 | } | ||
374 | |||
375 | 223 | void NAV::NodeManager::InitializeAllNodesAsync() | |
376 | { | ||
377 | LOG_TRACE("called"); | ||
378 | |||
379 |
2/2✓ Branch 5 taken 678 times.
✓ Branch 6 taken 223 times.
|
901 | for (auto* node : m_nodes) |
380 | { | ||
381 |
10/14✓ Branch 0 taken 678 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 678 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 678 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 676 times.
✓ Branch 9 taken 2 times.
✓ Branch 11 taken 676 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 339 times.
✓ Branch 14 taken 337 times.
✓ Branch 15 taken 339 times.
✓ Branch 16 taken 339 times.
|
678 | if (node && node->kind != Node::Kind::GroupBox && !node->isDisabled() && !node->isInitialized()) |
382 | { | ||
383 |
1/2✓ Branch 1 taken 339 times.
✗ Branch 2 not taken.
|
339 | node->doInitialize(); |
384 | } | ||
385 | } | ||
386 | 223 | } | |
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 | 143 | void NAV::NodeManager::RegisterWatcherCallbackToInputPin(ax::NodeEditor::PinId id, const InputPin::WatcherCallback& callback) | |
401 | { | ||
402 | 143 | watcherPinList.emplace_back(id, callback); | |
403 | 143 | } | |
404 | |||
405 | ✗ | void NAV::NodeManager::RegisterWatcherCallbackToLink(ax::NodeEditor::LinkId id, const InputPin::WatcherCallback& callback) | |
406 | { | ||
407 | ✗ | watcherLinkList.emplace_back(id, callback); | |
408 | ✗ | } | |
409 | |||
410 | 111 | void NAV::NodeManager::ApplyWatcherCallbacks() | |
411 | { | ||
412 |
1/2✗ Branch 7 not taken.
✓ Branch 8 taken 111 times.
|
111 | 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 143 times.
✓ Branch 8 taken 111 times.
|
254 | for (auto& [id, callback] : watcherPinList) |
429 | { | ||
430 |
2/2✓ Branch 5 taken 740 times.
✓ Branch 6 taken 143 times.
|
883 | for (auto& node : m_nodes) |
431 | { | ||
432 |
2/2✓ Branch 1 taken 725 times.
✓ Branch 2 taken 740 times.
|
1465 | for (size_t pinIdx = 0; pinIdx < node->inputPins.size(); pinIdx++) |
433 | { | ||
434 | 725 | auto& pin = node->inputPins[pinIdx]; | |
435 |
3/4✓ Branch 1 taken 725 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 143 times.
✓ Branch 4 taken 582 times.
|
725 | if (pin.id == id) |
436 | { | ||
437 |
3/6✓ Branch 1 taken 143 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 143 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 143 times.
✗ Branch 9 not taken.
|
143 | LOG_DEBUG("Adding watcher callback on node '{}' on pin with index {}", pin.parentNode->nameId(), pinIdx); |
438 |
1/2✓ Branch 1 taken 143 times.
✗ Branch 2 not taken.
|
143 | pin.watcherCallbacks.emplace_back(callback); |
439 | } | ||
440 | } | ||
441 | } | ||
442 | } | ||
443 | 111 | } | |
444 | |||
445 | 103 | void NAV::NodeManager::RegisterPreInitCallback(std::function<void()> callback) | |
446 | { | ||
447 | 103 | preInitCallback = std::move(callback); | |
448 | 103 | } | |
449 | |||
450 | 112 | void NAV::NodeManager::CallPreInitCallback() | |
451 | { | ||
452 |
2/2✓ Branch 1 taken 103 times.
✓ Branch 2 taken 9 times.
|
112 | if (preInitCallback) |
453 | { | ||
454 | 103 | preInitCallback(); | |
455 | } | ||
456 | 112 | } | |
457 | |||
458 | 38 | void NAV::NodeManager::RegisterCleanupCallback(std::function<void()> callback) | |
459 | { | ||
460 | 38 | cleanupCallback = std::move(callback); | |
461 | 38 | } | |
462 | 111 | void NAV::NodeManager::CallCleanupCallback() | |
463 | { | ||
464 |
2/2✓ Branch 1 taken 38 times.
✓ Branch 2 taken 73 times.
|
111 | if (cleanupCallback) |
465 | { | ||
466 | 38 | cleanupCallback(); | |
467 | } | ||
468 | 111 | } | |
469 | |||
470 | 112 | void NAV::NodeManager::ClearRegisteredCallbacks() | |
471 | { | ||
472 | 112 | watcherPinList.clear(); | |
473 | 112 | watcherLinkList.clear(); | |
474 | 112 | preInitCallback = nullptr; | |
475 | 112 | cleanupCallback = nullptr; | |
476 | 112 | } | |
477 | |||
478 | #endif | ||
479 |