FlowArithmeticCalculator 1.0.0
Flow Arithmetic Calculator
Loading...
Searching...
No Matches
BlocksManager.h
Go to the documentation of this file.
1#ifndef BUSINESS_LOGIC_LOGIC_BLOCKS_MANAGER_H
2#define BUSINESS_LOGIC_LOGIC_BLOCKS_MANAGER_H
3
4#include <algorithm>
5#include <chrono>
6#include <magic_enum/magic_enum.hpp>
7#include <memory>
8#include <optional>
9#include <unordered_set>
10#include <vector>
11
14#include "components/UIText.h"
16#include "constants.h"
24#include "geometry/Size2D.h"
27#include "logging/Loggable.h"
28
29namespace business_logic {
38 public business_logic::Loggable<BlocksManager> {
39 public:
41
42 ~BlocksManager() noexcept override = default;
43
44 // disable copy semantics
45 BlocksManager(const BlocksManager&) = delete;
46 BlocksManager& operator=(const BlocksManager&) = delete;
47
48 // disable move semantics
50 BlocksManager& operator=(BlocksManager&&) = delete;
51
55 void handleMouseDown();
56
60 void handleMouseUp();
61
67 void handleMouseMove(int x, int y);
68
73 void handleNumericKeyPress(int number);
74
79
85 std::optional<std::shared_ptr<business_logic::elements::blocks::BaseBlock>>
87
95 std::optional<std::shared_ptr<business_logic::elements::blocks::BaseBlock>> getBlockAt(
96 int x, int y);
97
102 void onNewBlockChoice(
103 const business_logic::elements::blocks::BlockType& blockType) override;
104
110 business_logic::input::InputChoiceInteraction<
111 business_logic::elements::blocks::BlockType>&& inputChoiceInteraction);
112
117 bool hasActiveChoicesInput() const;
118
123
127 void onPortsConnected(
128 const business_logic::elements::structures::BlocksConnectionSide& source,
129 const business_logic::elements::structures::BlocksConnectionSide& dest) override;
130
135 const business_logic::elements::structures::BlocksConnectionSide& source,
136 const business_logic::elements::structures::BlocksConnectionSide& dest) const override;
137
141 bool isInputConnected(
142 const business_logic::elements::structures::BlocksConnectionSide& side) const override;
143
147 void onBlockDeleted(const business_logic::elements::blocks::BaseBlock* block) override;
148
154 const std::shared_ptr<business_logic::elements::blocks::BaseBlock>& block);
155
159 const std::vector<std::shared_ptr<business_logic::elements::blocks::BaseBlock>>& getBlocks()
160 const override;
161
166 const std::unordered_map<
167 business_logic::elements::structures::BlocksConnectionSide,
168 std::unordered_set<business_logic::elements::structures::BlocksConnectionSide>>&
169 getConnectionsRegistry() const override;
170
171 protected:
172 // since Loggable is a template base class, the compiler does not see Logger::logger in the
173 // current scope; so as not to use this->logger explicitly each time, the below brings it to
174 // the current scope explicitly
176
180 std::vector<std::shared_ptr<business_logic::elements::blocks::BaseBlock>> blocks;
181
185 business_logic::elements::blocks::BaseBlock* draggedBlock;
186
191
196
200 business_logic::geometry::Size2D dragOffset;
201
205 std::chrono::steady_clock::time_point doubleClickCtLastMouseClickTime;
206
210 business_logic::delegate::IWindowDelegate* windowDelegate;
211
215 std::optional<business_logic::input::InputChoiceInteraction<
216 business_logic::elements::blocks::BlockType>>
218
222 business_logic::input::ConnectPortsInteraction connectPortsInteraction;
223
229
233 std::unordered_map<
234 business_logic::elements::structures::BlocksConnectionSide,
235 std::unordered_set<business_logic::elements::structures::BlocksConnectionSide>>
237
241 std::optional<
242 std::unordered_set<business_logic::elements::structures::BlocksConnectionSide>>
244 };
245
246} // namespace business_logic
247
248#endif // BUSINESS_LOGIC_LOGIC_BLOCKS_MANAGER_H
Manages the blocks in the GUI, both their rendering and interaction.
bool hasActiveChoicesInput() const
Checks if the input callback is active.
std::unordered_map< business_logic::elements::structures::BlocksConnectionSide, std::unordered_set< business_logic::elements::structures::BlocksConnectionSide > > connectionsRegistry
~BlocksManager() noexcept override=default
void handleMouseUp()
Handles the mouse up event.
bool hasConnectionBetween(const business_logic::elements::structures::BlocksConnectionSide &source, const business_logic::elements::structures::BlocksConnectionSide &dest) const override
Checks if there is a connection between two entities.
void clearActiveChoicesInput()
Clears the active input choices and the corresponding generated UI texts rows.
void handleNumericKeyPress(int number)
Handles the numeric key press event.
void setActiveChoicesInput(business_logic::input::InputChoiceInteraction< business_logic::elements::blocks::BlockType > &&inputChoiceInteraction)
Sets the input callback; this will override rendering other entities.
void onNewBlockChoice(const business_logic::elements::blocks::BlockType &blockType) override
Called when a new block is chosen to be added to the canvas.
business_logic::geometry::Size2D dragOffset
std::optional< std::unordered_set< business_logic::elements::structures::BlocksConnectionSide > > maybeGraphCycle
std::chrono::steady_clock::time_point doubleClickCtLastMouseClickTime
void onPortsConnected(const business_logic::elements::structures::BlocksConnectionSide &source, const business_logic::elements::structures::BlocksConnectionSide &dest) override
Invoked when a connection is made between two ports + blocks (sides)
std::optional< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > getBlockAtMousePos()
Gets the block at the mouse position.
void handleRightClickOnBlock(const std::shared_ptr< business_logic::elements::blocks::BaseBlock > &block)
Handles right click event on a block.
business_logic::delegate::IWindowDelegate * windowDelegate
void handleEscapeKeyPress()
Handles the ESC key press event.
const std::vector< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > & getBlocks() const override
Gets the blocks.
const std::unordered_map< business_logic::elements::structures::BlocksConnectionSide, std::unordered_set< business_logic::elements::structures::BlocksConnectionSide > > & getConnectionsRegistry() const override
Gets the connections registry.
business_logic::input::ConnectPortsInteraction connectPortsInteraction
bool isInputConnected(const business_logic::elements::structures::BlocksConnectionSide &side) const override
Checks if the input port is connected to anything.
void handleMouseDown()
Handles the mouse down event.
std::optional< business_logic::input::InputChoiceInteraction< business_logic::elements::blocks::BlockType > > inputChoiceInteraction
void handleMouseMove(int x, int y)
Handles the mouse move event.
business_logic::elements::blocks::BaseBlock * draggedBlock
void onBlockDeleted(const business_logic::elements::blocks::BaseBlock *block) override
Called when a block is deleted.
std::vector< components::UITextsRow > inputChoicesUiTextsRows
std::vector< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > blocks
std::optional< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > getBlockAt(int x, int y)
Gets the block at the given coordinates.
Class that provides a logger for the given class; automatically deduces the logger.
Definition Loggable.h:37
std::shared_ptr< spdlog::logger > logger
Definition Loggable.h:75
The blocks calculator logic, computes the flowing values.
The delegate for the blocks registry, allowing to get connections and blocks.
Delegate that is notified when a new block is chosen to be added to the canvas.
UI primitives and components to be rendered as part of the UI.
Definition UIText.cpp:3
The business logic module.
STL namespace.