0.5.1
Loading...
Searching...
No Matches
FlowManager.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 FlowManager.hpp
10/// @brief Save/Load the Nodes
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2020-12-16
13
14#pragma once
15
16#include <string>
17#include <filesystem>
20#include "NodeData/NodeData.hpp"
21
22#include <nlohmann/json.hpp>
23using json = nlohmann::json; ///< json namespace
24
25namespace NAV::flow
26{
27/// @brief List of all registered Nodes
28const std::vector<Node*>& m_Nodes();
29
30/// @brief Generates a new node id
31ax::NodeEditor::NodeId GetNextNodeId();
32
33/// @brief Generates a new link id
34ax::NodeEditor::LinkId GetNextLinkId();
35
36/// @brief Generates a new pin id
37ax::NodeEditor::PinId GetNextPinId();
38
39/// @brief Add the provided node object to the list of nodes
40/// @param[in] node Node object to add to the list
41void AddNode(Node* node);
42
43/// @brief Update the provided node object
44/// @param[in] node Node object to add to the list
45void UpdateNode(Node* node);
46
47/// @brief Delete the node provided by id
48/// @param[in] nodeId Unique Id of the Node to delete
49/// @return True if delete was successful, false if NodeId does not exist
50bool DeleteNode(ax::NodeEditor::NodeId nodeId);
51
52/// @brief Delete all nodes
53void DeleteAllNodes();
54
55/// @brief Adds the link
56/// @param[in] linkId Unique Id of the link
57void AddLink(ax::NodeEditor::LinkId linkId);
58
59/// @brief Finds the Node for the NodeId
60/// @param[in] id Unique Id of the Node to search for
61/// @return Pointer to the node or nullptr if the NodeId does not exist
62Node* FindNode(ax::NodeEditor::NodeId id);
63
64/// @brief Finds the Pin for the PinId
65/// @param[in] id Unique Id of the Pin to search for
66/// @return Pointer to the pin or nullptr if the PinId does not exist
67OutputPin* FindOutputPin(ax::NodeEditor::PinId id);
68
69/// @brief Finds the Pin for the PinId
70/// @param[in] id Unique Id of the Pin to search for
71/// @return Pointer to the pin or nullptr if the PinId does not exist
72InputPin* FindInputPin(ax::NodeEditor::PinId id);
73
74/// @brief Enables all Node callbacks
76
77/// @brief Disables all Node callbacks
79
80/// @brief Clears all nodes queues
82
83/// @brief Initializes all nodes.
84/// @return Returns false if one of the nodes could not initialize
86
87/// @brief Initializes all nodes in a separate thread
89
90/// @brief Saves the current flow into a file
91/// @param[out] globalAction If currentfilename is empty this will be returned as GlobalActions::SaveAs
92void SaveFlow(GlobalActions& globalAction);
93
94/// @brief Saves the current flow into the specified file
95/// @param[in] filepath Path where to save the flow
96void SaveFlowAs(const std::string& filepath);
97
98/// @brief Loads the flow from the specified file
99/// @param[in] filepath Path where to load the flow
100/// @return Whether the load was successfull
101bool LoadFlow(const std::string& filepath);
102
103/// @brief Loads the nodes and links from the specified json object
104/// @param[in] j Json object containing nodes and links to load
105/// @param[in] requestNewIds Set this true if the loaded nodes should receive new Ids (copy). False if the Ids should stay (cut/load)
106/// @return Whether the load was successfull
107bool LoadJson(const json& j, bool requestNewIds = false);
108
109/// @brief Checks if the currently open flow has unsaved changes
110/// @return True if there are changes
111bool HasUnsavedChanges();
112
113/// @brief Signals that there have been changes to the flow
114void ApplyChanges();
115
116/// @brief Discards the unsaved changes flag. Does not really discard the changes.
117void DiscardChanges();
118
119/// @brief Get the current filename of the open flow
120/// @return Current filename of the open flow
121std::string GetCurrentFilename();
122
123/// @brief Set the current filename of the open flow
124/// @param[in] newFilename New filename of the flow
125void SetCurrentFilename(const std::string& newFilename);
126
127/// @brief Get the program root path
128/// @return The path to the program root
129std::filesystem::path GetProgramRootPath();
130
131/// @brief Set the program root path
132/// @param[in] newRootPath The new program root path
133void SetProgramRootPath(const std::filesystem::path& newRootPath);
134
135/// @brief Get the path where logs and outputs are stored
136std::filesystem::path GetOutputPath();
137
138/// @brief Set the path where logs and outputs are stored
139void SetOutputPath();
140
141/// @brief Get the path where data files are searched
142std::filesystem::path GetInputPath();
143
144/// @brief Get the path where flow files are searched
145std::filesystem::path GetFlowPath();
146
147/// @brief Get the path where config files are searched
148std::filesystem::path GetConfigPath();
149
150#ifdef TESTING
151
152/// @brief Registers the callback function to the watcher list
153/// @param[in] id Output pin id to add the callback to
154/// @param[in] callback Callback function
155/// @attention ApplyWatcherCallbacks() needs to be called after loading the flow to apply the list to the pins.
156void RegisterWatcherCallbackToInputPin(ax::NodeEditor::PinId id, const InputPin::WatcherCallback& callback);
157
158/// @brief Registers the callback function to the watcher list
159/// @param[in] id Link id to add the callback to
160/// @param[in] callback Callback function
161/// @attention ApplyWatcherCallbacks() needs to be called after loading the flow to apply the list to the pins.
162void RegisterWatcherCallbackToLink(ax::NodeEditor::LinkId id, const InputPin::WatcherCallback& callback);
163
164/// @brief Applies the watcher lists to the node pins
165void ApplyWatcherCallbacks();
166
167/// @brief Registers a callback function which gets called before the nodes are initialized. Used to change node settings.
168/// @param[in] callback Callback function
169void RegisterPreInitCallback(std::function<void()> callback);
170
171/// @brief Calls the pre-init callback
172void CallPreInitCallback();
173
174/// @brief Registers a callback which gets called after flow execution before cleanup
175/// @param[in] callback Callback function
176void RegisterCleanupCallback(std::function<void()> callback);
177
178/// @brief Calls the cleanup callback
179void CallCleanupCallback();
180
181/// @brief Clears the watcher list
182void ClearRegisteredCallbacks();
183
184#endif
185
186} // namespace NAV::flow
nlohmann::json json
json namespace
Global Gui Actions.
GlobalActions
Possible Global Actions to perform in the GUI.
Abstract NodeData Class.
Node Class.
void UpdateNode(Node *node)
Update the provided node object.
InputPin * FindInputPin(ax::NodeEditor::PinId id)
Finds the Pin for the PinId.
ax::NodeEditor::LinkId GetNextLinkId()
Generates a new link id.
const std::vector< Node * > & m_Nodes()
List of all registered Nodes.
Node * FindNode(ax::NodeEditor::NodeId id)
Finds the Node for the NodeId.
void SetProgramRootPath(const std::filesystem::path &newRootPath)
Set the program root path.
bool LoadJson(const json &j, bool requestNewIds=false)
Loads the nodes and links from the specified json object.
void SetCurrentFilename(const std::string &newFilename)
Set the current filename of the open flow.
bool LoadFlow(const std::string &filepath)
Loads the flow from the specified file.
void DisableAllCallbacks()
Disables all Node callbacks.
std::filesystem::path GetConfigPath()
Get the path where config files are searched.
std::filesystem::path GetOutputPath()
Get the path where logs and outputs are stored.
void DeleteAllNodes()
Delete all nodes.
void SaveFlowAs(const std::string &filepath)
Saves the current flow into the specified file.
std::filesystem::path GetInputPath()
Get the path where data files are searched.
void DiscardChanges()
Discards the unsaved changes flag. Does not really discard the changes.
bool DeleteNode(ax::NodeEditor::NodeId nodeId)
Delete the node provided by id.
ax::NodeEditor::PinId GetNextPinId()
Generates a new pin id.
std::string GetCurrentFilename()
Get the current filename of the open flow.
void ApplyChanges()
Signals that there have been changes to the flow.
ax::NodeEditor::NodeId GetNextNodeId()
Generates a new node id.
void AddLink(ax::NodeEditor::LinkId linkId)
Adds the link.
std::filesystem::path GetFlowPath()
Get the path where flow files are searched.
void ClearAllNodeQueues()
Clears all nodes queues.
OutputPin * FindOutputPin(ax::NodeEditor::PinId id)
Finds the Pin for the PinId.
void EnableAllCallbacks()
Enables all Node callbacks.
std::filesystem::path GetProgramRootPath()
Get the program root path.
bool HasUnsavedChanges()
Checks if the currently open flow has unsaved changes.
void SaveFlow(GlobalActions &globalAction)
Saves the current flow into a file.
void SetOutputPath()
Set the path where logs and outputs are stored.
void AddNode(Node *node)
Add the provided node object to the list of nodes.
bool InitializeAllNodes()
Initializes all nodes.
void InitializeAllNodesAsync()
Initializes all nodes in a separate thread.