0.4.1
Loading...
Searching...
No Matches
DynamicInputPins.hpp
Go to the documentation of this file.
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
21#include "internal/Node/Pin.hpp"
22
23#include "util/Json.hpp"
24
25namespace NAV::gui::widgets
26{
27/// @brief Inputs pins which can be added dynamically
29{
30 /// Information to create extra columns
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 void setFirstDynamicPinIdx(size_t firstDynamicPinIndex) { _firstDynamicPinIdx = firstDynamicPinIndex; }
69
70 /// @brief Get the First Dynamic Pin Idx
71 [[nodiscard]] size_t getFirstDynamicPinIdx() const { return _firstDynamicPinIdx; }
72
73 private:
74 /// @brief Index of the Pin currently being dragged
76 /// @brief First pin index which is dynamic
78 /// @brief Number of dynamic input pins
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
92void 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
97void from_json(const json& j, DynamicInputPins& obj, Node* node);
98
99} // namespace NAV::gui::widgets
nlohmann::json json
json namespace
Defines how to save certain datatypes to json.
Node Class.
Pin class.
Abstract parent class for all nodes.
Definition Node.hpp:92
void from_json(const json &j, DynamicInputPins &obj, Node *node)
Converts the provided json object into a node object.
void to_json(json &j, const DynamicInputPins &obj)
Converts the provided object into json.
std::function< bool(size_t)> content
Function to create the column content. Argument is the pin index. Returns true if changes occurred.
Inputs pins which can be added dynamically.
std::function< void(Node *, size_t)> _pinDeleteCallback
Function to call to delete a pin. Argument is the pin index.
void setFirstDynamicPinIdx(size_t firstDynamicPinIndex)
Set the First Dynamic Pin Idx.
size_t getNumberOfDynamicPins() const
Get the number Of dynamic pins.
size_t getFirstDynamicPinIdx() const
Get the First Dynamic Pin Idx.
size_t _firstDynamicPinIdx
First pin index which is dynamic.
size_t _nDynamicInputPins
Number of dynamic input pins.
friend void from_json(const json &j, DynamicInputPins &obj, Node *node)
Converts the provided json object into a node object.
bool ShowGuiWidgets(size_t id, std::vector< InputPin > &inputPins, Node *node, const std::vector< ExtraColumn > &extraColumns={})
Shows the GUI input to select the options.
std::function< void(Node *)> _pinAddCallback
Function to call to add a new pin.
friend void to_json(json &j, const DynamicInputPins &obj)
Converts the provided object into json.
DynamicInputPins(size_t firstDynamicPinIndex, Node *node, std::function< void(Node *)> pinAddCallback, std::function< void(Node *, size_t)> pinDeleteCallback, size_t defaultInputPins=0)
Constructor.
int _dragAndDropPinIndex
Index of the Pin currently being dragged.
void addPin(Node *node)
Adds a pin and call the pinAddCallback.