1#ifndef BUSINESS_LOGIC_ELEMENTS_BLOCKS_BASE_BLOCK_H
2#define BUSINESS_LOGIC_ELEMENTS_BLOCKS_BASE_BLOCK_H
4#include <magic_enum/magic_enum.hpp>
6#include <unordered_map>
22 class IBlockLifecycleManagerDelegate;
60 std::shared_ptr<spdlog::logger>
logger);
290 std::unordered_map<const structures::Port*, FloatingPoint>
portValues;
344 return std::hash<int>()(p.
cx) ^ (std::hash<int>()(p.
cy) << 1U);
Delegate that manages the lifecycles of blocks.
Delegate that is notified when a new block is chosen to be added to the canvas.
The delegate for the window.
The base class for all blocks, containing common functionality and members.
virtual void calculateOutputValues()=0
Calculates the output port values based on input port values.
business_logic::delegate::IBlockLifecycleManagerDelegate * blockLifecycleManagerDelegate
std::optional< const structures::Port * > checkPort(const structures::Port *port, const geometry::Point2D &point) const
Checks if a point is inside the hitbox of a port.
std::shared_ptr< spdlog::logger > logger
std::unordered_map< const structures::Port *, geometry::Point2D > portCoordinates
Caches the (center) coordinates of the ports of the block; must be updated after rendering.
virtual bool isHovered(int x, int y) const
Checks if the block is hovered over by the mouse.
business_logic::delegate::INewBlockChoiceDelegate * newBlockChoiceDelegate
void onDragStart() override
Called when dragging starts.
void cacheCornerCoordinates()
Caches the bottom right corner of the block, so that it is not recalculated every time isHovered() is...
business_logic::delegate::IWindowDelegate * windowDelegate
int getBottomY() const
Gets the bottom y coordinate of the block.
int getRightX() const
Gets the right x coordinate of the block.
BaseBlock & operator=(BaseBlock &&)=delete
const FloatingPoint & getPortValue(const structures::Port *port) const
Gets the value of the port.
int getCx() const
Gets the center y coordinate of the block.
std::unordered_map< const structures::Port *, geometry::Point2D > & getPortCoordinates()
Gets the cache of (center) coordinates of the ports of the block; updated after rendering.
int getCy() const
Gets the center y coordinate of the block.
int getHeight() const
Gets the height of the block.
virtual const std::vector< structures::Port > & getOutputPorts() const =0
Gets the output ports of the block.
int getLeftX() const
Gets the left x coordinate of the block.
void onDragEnd() override
Called when dragging ends.
~BaseBlock() noexcept override
BaseBlock(BaseBlock &&)=delete
BaseBlock & operator=(const BaseBlock &)=delete
static const FloatingPoint NaN
std::optional< const structures::Port * > getPortAtCoordinates(const geometry::Point2D &point) const
Gets the port at given coordinates.
virtual const std::vector< structures::Port > & getInputPorts() const =0
Gets the input ports of the block.
std::unordered_map< const structures::Port *, FloatingPoint > portValues
The registry of port values.
int getWidth() const
Gets the width of the block.
void updateWidthHeight(int newWidth, int newHeight)
Updates the width and height of the block.
void onDragProgress(int x, int y) override
Called during dragging.
virtual std::string getSelfId() const =0
virtual BlockType getBlockType() const =0
Gets the type of the block.
int getTopY() const
Gets the top y coordinate of the block.
virtual std::optional< std::string > getValueToRenderAboveBlock(bool isHovered)
Wrapper that gets the value of the output port above the block; if more or less than 1 output port is...
BaseBlock(const BaseBlock &)=delete
void setPortValue(const business_logic::elements::structures::Port *port, const FloatingPoint &value)
Sets the value of the port.
Interface for elements that can be dragged.
Delegates exposed by the business_logic module, used for integrating with a GUI / renderer implementa...
The base classes and structs for elements.
BlockType
The available block types.
The elements (i.e., renderable entities constituting for the calculator) module.
The business logic module.
Represents a port on a block.
A basic struct representing a 2D point.
std::size_t operator()(const business_logic::elements::blocks::BaseBlock &p) const
boost::multiprecision::cpp_dec_float_50 FloatingPoint