|
FlowArithmeticCalculator 1.0.0
Flow Arithmetic Calculator
|
The base class for all blocks, containing common functionality and members. More...
#include <BaseBlock.h>
Inheritance diagram for business_logic::elements::blocks::BaseBlock:
Collaboration diagram for business_logic::elements::blocks::BaseBlock:Public Member Functions | |
| BaseBlock (int cx, int cy, int blockWidth, int blockHeight, business_logic::delegate::INewBlockChoiceDelegate *newBlockChoiceDelegate, business_logic::delegate::IBlockLifecycleManagerDelegate *blockLifecycleManagerDelegate, business_logic::delegate::IWindowDelegate *windowDelegate, std::shared_ptr< spdlog::logger > logger) | |
| Constructor. | |
| void | updateWidthHeight (int newWidth, int newHeight) |
| Updates the width and height of the block. | |
| ~BaseBlock () noexcept override | |
| BaseBlock (const BaseBlock &)=delete | |
| BaseBlock & | operator= (const BaseBlock &)=delete |
| BaseBlock (BaseBlock &&)=delete | |
| BaseBlock & | operator= (BaseBlock &&)=delete |
| virtual bool | isHovered (int x, int y) const |
| Checks if the block is hovered over by the mouse. | |
| 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 present, it will not be rendered. | |
| void | onDragStart () override |
| Called when dragging starts. | |
| void | onDragProgress (int x, int y) override |
| Called during dragging. | |
| void | onDragEnd () override |
| Called when dragging ends. | |
| const business_logic::geometry::Point2D & | getPortCoordinates (const structures::Port *port) const |
| Gets the coordinates of a port. | |
| std::optional< const structures::Port * > | getPortAtCoordinates (const geometry::Point2D &point) const |
| Gets the port at given coordinates. | |
| virtual std::string | getSelfId () const =0 |
| virtual BlockType | getBlockType () const =0 |
| Gets the type of the block. | |
| const FloatingPoint & | getPortValue (const structures::Port *port) const |
| Gets the value of the port. | |
| void | setPortValue (const business_logic::elements::structures::Port *port, const FloatingPoint &value) |
| Sets the value of the port. | |
| virtual void | calculateOutputValues ()=0 |
| Calculates the output port values based on input port values. | |
| virtual const std::vector< structures::Port > & | getInputPorts () const =0 |
| Gets the input ports of the block. | |
| virtual const std::vector< structures::Port > & | getOutputPorts () const =0 |
| Gets the output ports of the block. | |
| int | getCx () const |
| Gets the center y coordinate of the block. | |
| int | getCy () const |
| Gets the center y coordinate of the block. | |
| int | getLeftX () const |
| Gets the left x coordinate of the block. | |
| int | getRightX () const |
| Gets the right x coordinate of the block. | |
| int | getTopY () const |
| Gets the top y coordinate of the block. | |
| int | getBottomY () const |
| Gets the bottom y coordinate of the block. | |
| int | getWidth () const |
| Gets the width of the block. | |
| int | getHeight () const |
| Gets the height 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. | |
Public Member Functions inherited from business_logic::elements::interactions::IDraggable | |
| virtual | ~IDraggable ()=default |
Protected Member Functions | |
| void | cacheCornerCoordinates () |
Caches the bottom right corner of the block, so that it is not recalculated every time isHovered() is called. | |
| 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. | |
Protected Attributes | |
| int | cx |
| int | cy |
| int | width |
| int | height |
| int | leftX |
| int | rightX |
| int | topY |
| int | bottomY |
| float | centerY |
| std::shared_ptr< spdlog::logger > | logger |
| std::unordered_map< const structures::Port *, FloatingPoint > | portValues |
| The registry of port values. | |
| business_logic::delegate::INewBlockChoiceDelegate * | newBlockChoiceDelegate |
| business_logic::delegate::IBlockLifecycleManagerDelegate * | blockLifecycleManagerDelegate |
| business_logic::delegate::IWindowDelegate * | windowDelegate |
| std::unordered_map< const structures::Port *, geometry::Point2D > | portCoordinates |
| Caches the (center) coordinates of the ports of the block; must be updated after rendering. | |
Static Protected Attributes | |
| static const FloatingPoint | NaN = std::numeric_limits<FloatingPoint>::quiet_NaN() |
Friends | |
| struct | std::hash< BaseBlock > |
The base class for all blocks, containing common functionality and members.
Any block subclassing this class can be dragged around to change its position
Definition at line 36 of file BaseBlock.h.
| business_logic::elements::blocks::BaseBlock::BaseBlock | ( | int | cx, |
| int | cy, | ||
| int | blockWidth, | ||
| int | blockHeight, | ||
| business_logic::delegate::INewBlockChoiceDelegate * | newBlockChoiceDelegate, | ||
| business_logic::delegate::IBlockLifecycleManagerDelegate * | blockLifecycleManagerDelegate, | ||
| business_logic::delegate::IWindowDelegate * | windowDelegate, | ||
| std::shared_ptr< spdlog::logger > | logger | ||
| ) |
Constructor.
| cx | The center x coordinate where to place the center of the block |
| cy | The center y coordinate where to place the center of the block |
| blockWidth | The width of the block |
| blockHeight | The height of the block |
| newBlockChoiceDelegate | The delegate that is notified when a new block is chosen to be added to the canvas |
| blockLifecycleManagerDelegate | The delegate that manages the lifecycles of blocks |
| windowDelegate | The delegate of the window |
| logger | The logger for the block |
Definition at line 10 of file BaseBlock.cpp.
References cacheCornerCoordinates().
Here is the call graph for this function:
|
overridenoexcept |
Definition at line 35 of file BaseBlock.cpp.
References blockLifecycleManagerDelegate, and business_logic::delegate::IBlockLifecycleManagerDelegate::onBlockDeleted().
Here is the call graph for this function:
|
delete |
|
delete |
|
protected |
Caches the bottom right corner of the block, so that it is not recalculated every time isHovered() is called.
Definition at line 58 of file BaseBlock.cpp.
References bottomY, centerY, cx, cy, business_logic::delegate::IWindowDelegate::getWindowSize(), height, leftX, rightX, topY, width, and windowDelegate.
Referenced by BaseBlock(), onDragProgress(), and updateWidthHeight().
Here is the call graph for this function:
Here is the caller graph for this function:
|
pure virtual |
Calculates the output port values based on input port values.
| std::runtime_error | if input values are missing |
Implemented in business_logic::elements::blocks::AddBlock, business_logic::elements::blocks::ConstantBlock, business_logic::elements::blocks::DivideBlock, business_logic::elements::blocks::InvertBlock, business_logic::elements::blocks::MonitorBlock, business_logic::elements::blocks::MultiplyBlock, business_logic::elements::blocks::PowerBlock, and business_logic::elements::blocks::SubtractBlock.
Referenced by business_logic::calculations::BlocksCalculator::calculateBlockValues().
Here is the caller graph for this function:
|
protected |
Checks if a point is inside the hitbox of a port.
| port | The port that hitbox of is to be checked |
| point | The point to check whether it is inside the hitbox of the port |
std::nullopt otherwise Definition at line 113 of file BaseBlock.cpp.
References getPortCoordinates(), business_logic::geometry::isCircleHovered(), business_logic::constants::TOTAL_PORT_HITBOX_RADIUS, business_logic::geometry::Point2D::x, and business_logic::geometry::Point2D::y.
Referenced by getPortAtCoordinates().
Here is the call graph for this function:
Here is the caller graph for this function:
|
pure virtual |
Gets the type of the block.
Implemented in business_logic::elements::blocks::AddBlock, business_logic::elements::blocks::ConstantBlock, business_logic::elements::blocks::DivideBlock, business_logic::elements::blocks::InvertBlock, business_logic::elements::blocks::MonitorBlock, business_logic::elements::blocks::MultiplyBlock, business_logic::elements::blocks::PowerBlock, and business_logic::elements::blocks::SubtractBlock.
Referenced by gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:
|
inline |
Gets the bottom y coordinate of the block.
Definition at line 212 of file BaseBlock.h.
References bottomY.
Referenced by gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:
|
inline |
Gets the center y coordinate of the block.
Definition at line 182 of file BaseBlock.h.
References cx.
|
inline |
Gets the center y coordinate of the block.
Definition at line 188 of file BaseBlock.h.
References cy.
Referenced by gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:
|
inline |
Gets the height of the block.
Definition at line 224 of file BaseBlock.h.
References height.
|
pure virtual |
Gets the input ports of the block.
Implemented in business_logic::elements::blocks::AddBlock, business_logic::elements::blocks::ConstantBlock, business_logic::elements::blocks::DivideBlock, business_logic::elements::blocks::InvertBlock, business_logic::elements::blocks::MonitorBlock, business_logic::elements::blocks::MultiplyBlock, business_logic::elements::blocks::PowerBlock, and business_logic::elements::blocks::SubtractBlock.
Referenced by getPortAtCoordinates(), and gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:
|
inline |
Gets the left x coordinate of the block.
Definition at line 194 of file BaseBlock.h.
References leftX.
Referenced by gui::elements::SkiaBaseBlockRenderer::render(), and gui::elements::SkiaBaseBlockRenderer::renderValueAboveBlock().
Here is the caller graph for this function:
|
pure virtual |
Gets the output ports of the block.
Implemented in business_logic::elements::blocks::AddBlock, business_logic::elements::blocks::ConstantBlock, business_logic::elements::blocks::DivideBlock, business_logic::elements::blocks::InvertBlock, business_logic::elements::blocks::MonitorBlock, business_logic::elements::blocks::MultiplyBlock, business_logic::elements::blocks::PowerBlock, and business_logic::elements::blocks::SubtractBlock.
Referenced by getPortAtCoordinates(), getValueToRenderAboveBlock(), and gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:| std::optional< const business_logic::elements::structures::Port * > business_logic::elements::blocks::BaseBlock::getPortAtCoordinates | ( | const geometry::Point2D & | point | ) | const |
Gets the port at given coordinates.
| point | The coordinates to check |
std::nullopt otherwise Definition at line 130 of file BaseBlock.cpp.
References checkPort(), getInputPorts(), and getOutputPorts().
Referenced by business_logic::BlocksManager::handleRightClickOnBlock().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Gets the cache of (center) coordinates of the ports of the block; updated after rendering.
Definition at line 232 of file BaseBlock.h.
References portCoordinates.
Referenced by checkPort().
Here is the caller graph for this function:| const business_logic::geometry::Point2D & business_logic::elements::blocks::BaseBlock::getPortCoordinates | ( | const structures::Port * | port | ) | const |
Gets the coordinates of a port.
| port | The port to get the coordinates of |
Definition at line 100 of file BaseBlock.cpp.
References portCoordinates, and business_logic::geometry::Point2D::x.
Referenced by gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:| const FloatingPoint & business_logic::elements::blocks::BaseBlock::getPortValue | ( | const structures::Port * | port | ) | const |
Gets the value of the port.
| port | The port to get the value of |
Definition at line 149 of file BaseBlock.cpp.
References NaN, and portValues.
Referenced by business_logic::elements::blocks::AddBlock::calculateOutputValues(), business_logic::elements::blocks::DivideBlock::calculateOutputValues(), business_logic::elements::blocks::InvertBlock::calculateOutputValues(), business_logic::elements::blocks::MultiplyBlock::calculateOutputValues(), business_logic::elements::blocks::PowerBlock::calculateOutputValues(), business_logic::elements::blocks::SubtractBlock::calculateOutputValues(), getValueToRenderAboveBlock(), and business_logic::elements::blocks::MonitorBlock::getValueToRenderAboveBlock().
Here is the caller graph for this function:
|
inline |
Gets the right x coordinate of the block.
Definition at line 200 of file BaseBlock.h.
References rightX.
Referenced by gui::elements::SkiaBaseBlockRenderer::render().
Here is the caller graph for this function:
|
pure virtual |
The unique identifier of the block (its address in memory), used for logging purposes; should return the same value as business_logic::stringifyAddressOf(this)
Implemented in business_logic::elements::blocks::AddBlock, business_logic::elements::blocks::ConstantBlock, business_logic::elements::blocks::DivideBlock, business_logic::elements::blocks::InvertBlock, business_logic::elements::blocks::MonitorBlock, business_logic::elements::blocks::MultiplyBlock, business_logic::elements::blocks::PowerBlock, and business_logic::elements::blocks::SubtractBlock.
Referenced by business_logic::BlocksManager::handleMouseUp(), onDragEnd(), onDragProgress(), and onDragStart().
Here is the caller graph for this function:
|
inline |
Gets the top y coordinate of the block.
Definition at line 206 of file BaseBlock.h.
References topY.
Referenced by gui::elements::SkiaBaseBlockRenderer::render(), and gui::elements::SkiaBaseBlockRenderer::renderValueAboveBlock().
Here is the caller graph for this function:
|
virtual |
Wrapper that gets the value of the output port above the block; if more or less than 1 output port is present, it will not be rendered.
| isHovered | True if the block is hovered over, false otherwise |
std::nullopt if the value should not be rendered Reimplemented in business_logic::elements::blocks::MonitorBlock.
Definition at line 81 of file BaseBlock.cpp.
References business_logic::constants::DEFAULT_VALUE_DISPLAY_PRECISION, getOutputPorts(), and getPortValue().
Referenced by gui::elements::SkiaBaseBlockRenderer::render().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Gets the width of the block.
Definition at line 218 of file BaseBlock.h.
References width.
Referenced by gui::elements::SkiaBaseBlockRenderer::render(), and gui::elements::SkiaBaseBlockRenderer::renderValueAboveBlock().
Here is the caller graph for this function:
|
inlinevirtual |
Checks if the block is hovered over by the mouse.
| x | The x coordinate of the mouse |
| y | The y coordinate of the mouse |
Definition at line 85 of file BaseBlock.h.
References bottomY, leftX, and topY.
Referenced by business_logic::elements::blocks::MonitorBlock::getValueToRenderAboveBlock().
Here is the caller graph for this function:
|
overridevirtual |
Called when dragging ends.
Implements business_logic::elements::interactions::IDraggable.
Definition at line 56 of file BaseBlock.cpp.
References getSelfId(), and logger.
Referenced by business_logic::BlocksManager::handleMouseUp().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Called during dragging.
| x | Current X coordinate |
| y | Current Y coordinate |
Implements business_logic::elements::interactions::IDraggable.
Definition at line 45 of file BaseBlock.cpp.
References cacheCornerCoordinates(), cx, cy, getSelfId(), and logger.
Referenced by business_logic::BlocksManager::handleMouseMove().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Called when dragging starts.
Implements business_logic::elements::interactions::IDraggable.
Definition at line 54 of file BaseBlock.cpp.
References getSelfId(), and logger.
Referenced by business_logic::BlocksManager::handleMouseDown().
Here is the call graph for this function:
Here is the caller graph for this function:| void business_logic::elements::blocks::BaseBlock::setPortValue | ( | const business_logic::elements::structures::Port * | port, |
| const FloatingPoint & | value | ||
| ) |
Sets the value of the port.
| port | The port to set the value of |
| value | The value to set the port to |
Definition at line 160 of file BaseBlock.cpp.
References portValues.
Referenced by business_logic::calculations::BlocksCalculator::calculateBlockValues().
Here is the caller graph for this function:| void business_logic::elements::blocks::BaseBlock::updateWidthHeight | ( | int | newWidth, |
| int | newHeight | ||
| ) |
Updates the width and height of the block.
| newWidth | The new width of the block |
| newHeight | The new height of the block |
Definition at line 38 of file BaseBlock.cpp.
References cacheCornerCoordinates(), height, and width.
Here is the call graph for this function:
|
friend |
Definition at line 161 of file BaseBlock.h.
|
protected |
The delegate that manages the lifecycles of blocks
Definition at line 301 of file BaseBlock.h.
Referenced by business_logic::elements::blocks::MonitorBlock::getValueToRenderAboveBlock(), and ~BaseBlock().
|
protected |
The bottom edge y of the block; cached and used for the needs of isHovered()
Definition at line 275 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getBottomY(), and isHovered().
|
protected |
The center y coordinate of the block; cached and used elsewhere
Definition at line 280 of file BaseBlock.h.
Referenced by cacheCornerCoordinates().
|
protected |
The center x coordinate of the block
Definition at line 240 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getCx(), onDragProgress(), and std::hash< business_logic::elements::blocks::BaseBlock >::operator()().
|
protected |
The center y coordinate of the block
Definition at line 245 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getCy(), onDragProgress(), and std::hash< business_logic::elements::blocks::BaseBlock >::operator()().
|
protected |
The height of the block
Definition at line 255 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getHeight(), and updateWidthHeight().
|
protected |
The left edge x coordinate of the block; cached and used elsewhere
Definition at line 260 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getLeftX(), and isHovered().
|
protected |
The logger for the block
Definition at line 285 of file BaseBlock.h.
Referenced by business_logic::elements::blocks::ConstantBlock::onDoubleClick(), onDragEnd(), onDragProgress(), and onDragStart().
|
staticprotected |
The NaN value - for convenience of usage in blocks implementations
Definition at line 312 of file BaseBlock.h.
Referenced by getPortValue().
|
protected |
The delegate that is notified when a new block is chosen to be added to the canvas
Definition at line 295 of file BaseBlock.h.
|
protected |
Caches the (center) coordinates of the ports of the block; must be updated after rendering.
Definition at line 318 of file BaseBlock.h.
Referenced by getPortCoordinates(), and getPortCoordinates().
|
protected |
The registry of port values.
Definition at line 290 of file BaseBlock.h.
Referenced by business_logic::elements::blocks::AddBlock::calculateOutputValues(), business_logic::elements::blocks::DivideBlock::calculateOutputValues(), business_logic::elements::blocks::InvertBlock::calculateOutputValues(), business_logic::elements::blocks::MultiplyBlock::calculateOutputValues(), business_logic::elements::blocks::PowerBlock::calculateOutputValues(), business_logic::elements::blocks::SubtractBlock::calculateOutputValues(), getPortValue(), business_logic::elements::blocks::ConstantBlock::onDoubleClick(), and setPortValue().
|
protected |
The right edge x of the block; cached and used for the needs of isHovered()
Definition at line 265 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), and getRightX().
|
protected |
The top edge y coordinate of the block; cached and used elsewhere
Definition at line 270 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getTopY(), and isHovered().
|
protected |
The width of the block
Definition at line 250 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), getWidth(), and updateWidthHeight().
|
protected |
The delegate of the window
Definition at line 307 of file BaseBlock.h.
Referenced by cacheCornerCoordinates(), and business_logic::elements::blocks::ConstantBlock::onDoubleClick().