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 |
|
|
/// @file DynamicInputPins.hpp |
10 |
|
|
/// @brief Inputs pins which can be added dynamically |
11 |
|
|
/// @author T. Topp (topp@ins.uni-stuttgart.de) |
12 |
|
|
/// @date 2023-12-21 |
13 |
|
|
|
14 |
|
|
#pragma once |
15 |
|
|
|
16 |
|
|
#include <vector> |
17 |
|
|
#include <string> |
18 |
|
|
#include <functional> |
19 |
|
|
|
20 |
|
|
#include "internal/Node/Node.hpp" |
21 |
|
|
#include "internal/Node/Pin.hpp" |
22 |
|
|
|
23 |
|
|
#include "util/Json.hpp" |
24 |
|
|
|
25 |
|
|
namespace NAV::gui::widgets |
26 |
|
|
{ |
27 |
|
|
/// @brief Inputs pins which can be added dynamically |
28 |
|
|
struct DynamicInputPins |
29 |
|
|
{ |
30 |
|
|
/// Information to create extra columns |
31 |
|
|
struct ExtraColumn |
32 |
|
|
{ |
33 |
|
|
/// Column header text |
34 |
|
|
std::string header; |
35 |
|
|
/// Function to create the column content. Argument is the pin index. Returns true if changes occurred. |
36 |
|
|
std::function<bool(size_t)> content; |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
/// @brief Constructor |
40 |
|
|
/// @param[in] firstDynamicPinIndex First pin index which is dynamic |
41 |
|
|
/// @param[in, out] node Pointer to the calling node (needs to be valid only during construction) |
42 |
|
|
/// @param[in] pinAddCallback Function to call to add a new pin |
43 |
|
|
/// @param[in] pinDeleteCallback Function to call to delete a pin |
44 |
|
|
/// @param[in] defaultInputPins Default value for the input pins |
45 |
|
|
DynamicInputPins(size_t firstDynamicPinIndex, |
46 |
|
|
Node* node, |
47 |
|
|
std::function<void(Node*)> pinAddCallback, |
48 |
|
|
std::function<void(Node*, size_t)> pinDeleteCallback, |
49 |
|
|
size_t defaultInputPins = 0); |
50 |
|
|
|
51 |
|
|
/// @brief Shows the GUI input to select the options |
52 |
|
|
/// @param[in] id Unique id for ImGui. |
53 |
|
|
/// @param[in, out] inputPins Input Pins of the node |
54 |
|
|
/// @param[in, out] node Pointer to the calling node |
55 |
|
|
/// @param[in] extraColumns Extra columns to display in the table |
56 |
|
|
/// @return True when changes occurred |
57 |
|
|
bool ShowGuiWidgets(size_t id, std::vector<InputPin>& inputPins, Node* node, const std::vector<ExtraColumn>& extraColumns = {}); |
58 |
|
|
|
59 |
|
|
/// @brief Get the number Of dynamic pins |
60 |
|
|
[[nodiscard]] size_t getNumberOfDynamicPins() const; |
61 |
|
|
|
62 |
|
|
/// @brief Adds a pin and call the pinAddCallback |
63 |
|
|
/// @param[in, out] node Pointer to the calling node |
64 |
|
|
void addPin(Node* node); |
65 |
|
|
|
66 |
|
|
/// @brief Set the First Dynamic Pin Idx |
67 |
|
|
/// @param[in] firstDynamicPinIndex First pin index which is dynamic |
68 |
|
17 |
void setFirstDynamicPinIdx(size_t firstDynamicPinIndex) { _firstDynamicPinIdx = firstDynamicPinIndex; } |
69 |
|
|
|
70 |
|
|
/// @brief Get the First Dynamic Pin Idx |
71 |
|
221 |
[[nodiscard]] size_t getFirstDynamicPinIdx() const { return _firstDynamicPinIdx; } |
72 |
|
|
|
73 |
|
|
private: |
74 |
|
|
/// @brief Index of the Pin currently being dragged |
75 |
|
|
int _dragAndDropPinIndex = -1; |
76 |
|
|
/// @brief First pin index which is dynamic |
77 |
|
|
size_t _firstDynamicPinIdx = 0; |
78 |
|
|
/// @brief Number of dynamic input pins |
79 |
|
|
size_t _nDynamicInputPins = 0; |
80 |
|
|
/// @brief Function to call to add a new pin |
81 |
|
|
std::function<void(Node*)> _pinAddCallback; |
82 |
|
|
/// @brief Function to call to delete a pin. Argument is the pin index. |
83 |
|
|
std::function<void(Node*, size_t)> _pinDeleteCallback; |
84 |
|
|
|
85 |
|
|
friend void to_json(json& j, const DynamicInputPins& obj); |
86 |
|
|
friend void from_json(const json& j, DynamicInputPins& obj, Node* node); |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
|
/// @brief Converts the provided object into json |
90 |
|
|
/// @param[out] j Json object which gets filled with the info |
91 |
|
|
/// @param[in] obj Object to convert into json |
92 |
|
|
void to_json(json& j, const DynamicInputPins& obj); |
93 |
|
|
/// @brief Converts the provided json object into a node object |
94 |
|
|
/// @param[in] j Json object with the needed values |
95 |
|
|
/// @param[out] obj Object to fill from the json |
96 |
|
|
/// @param[in, out] node Pointer to the node calling this |
97 |
|
|
void from_json(const json& j, DynamicInputPins& obj, Node* node); |
98 |
|
|
|
99 |
|
|
} // namespace NAV::gui::widgets |
100 |
|
|
|