FlowArithmeticCalculator 1.0.0
Flow Arithmetic Calculator
Loading...
Searching...
No Matches
business_logic::elements::blocks::SubtractBlock Class Referencefinal

A block that subtracts the second input value from the first input value. More...

#include <SubtractBlock.h>

+ Inheritance diagram for business_logic::elements::blocks::SubtractBlock:
+ Collaboration diagram for business_logic::elements::blocks::SubtractBlock:

Public Member Functions

 SubtractBlock (int cx, int cy, business_logic::delegate::INewBlockChoiceDelegate *newBlockChoiceDelegate, business_logic::delegate::IBlockLifecycleManagerDelegate *blockLifecycleManagerDelegate, business_logic::delegate::IWindowDelegate *windowDelegate)
 
std::string getSelfId () const override
 
void calculateOutputValues () override
 Calculates the output port values based on input port values.
 
- Public Member Functions inherited from business_logic::Loggable< SubtractBlock >
 Loggable ()
 
- Public Member Functions inherited from 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.
 
void updateWidthHeight (int newWidth, int newHeight)
 Updates the width and height of the block.
 
 ~BaseBlock () noexcept override
 
 BaseBlock (const BaseBlock &)=delete
 
BaseBlockoperator= (const BaseBlock &)=delete
 
 BaseBlock (BaseBlock &&)=delete
 
BaseBlockoperator= (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::Point2DgetPortCoordinates (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.
 
const FloatingPointgetPortValue (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.
 
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

const std::vector< business_logic::elements::structures::Port > & getInputPorts () const override
 Gets the input ports of the block.
 
const std::vector< business_logic::elements::structures::Port > & getOutputPorts () const override
 Gets the output ports of the block.
 
business_logic::elements::blocks::BlockType getBlockType () const override
 Gets the type of the block.
 
- Protected Member Functions inherited from business_logic::elements::blocks::BaseBlock
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

std::string selfId
 
- Protected Attributes inherited from business_logic::Loggable< SubtractBlock >
std::shared_ptr< spdlog::logger > logger
 
- Protected Attributes inherited from business_logic::elements::blocks::BaseBlock
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 *, FloatingPointportValues
 The registry of port values.
 
business_logic::delegate::INewBlockChoiceDelegatenewBlockChoiceDelegate
 
business_logic::delegate::IBlockLifecycleManagerDelegateblockLifecycleManagerDelegate
 
business_logic::delegate::IWindowDelegatewindowDelegate
 
std::unordered_map< const structures::Port *, geometry::Point2DportCoordinates
 Caches the (center) coordinates of the ports of the block; must be updated after rendering.
 

Static Protected Attributes

static constexpr int SUBTRACT_BLOCK_WIDTH = 120
 
static constexpr int SUBTRACT_BLOCK_HEIGHT = 120
 
static const std::vector< business_logic::elements::structures::PortinputPorts
 
static const std::vector< business_logic::elements::structures::PortoutputPorts
 
- Static Protected Attributes inherited from business_logic::elements::blocks::BaseBlock
static const FloatingPoint NaN = std::numeric_limits<FloatingPoint>::quiet_NaN()
 

Detailed Description

A block that subtracts the second input value from the first input value.

Definition at line 13 of file SubtractBlock.h.

Constructor & Destructor Documentation

◆ SubtractBlock()

business_logic::elements::blocks::SubtractBlock::SubtractBlock ( int  cx,
int  cy,
business_logic::delegate::INewBlockChoiceDelegate newBlockChoiceDelegate,
business_logic::delegate::IBlockLifecycleManagerDelegate blockLifecycleManagerDelegate,
business_logic::delegate::IWindowDelegate windowDelegate 
)

Definition at line 5 of file SubtractBlock.cpp.

Member Function Documentation

◆ calculateOutputValues()

void business_logic::elements::blocks::SubtractBlock::calculateOutputValues ( )
overridevirtual

Calculates the output port values based on input port values.

Exceptions
std::runtime_errorif input values are missing

Implements business_logic::elements::blocks::BaseBlock.

Definition at line 21 of file SubtractBlock.cpp.

References business_logic::elements::blocks::BaseBlock::getPortValue(), inputPorts, outputPorts, and business_logic::elements::blocks::BaseBlock::portValues.

+ Here is the call graph for this function:

◆ getBlockType()

business_logic::elements::blocks::BlockType business_logic::elements::blocks::SubtractBlock::getBlockType ( ) const
inlineoverrideprotectedvirtual

Gets the type of the block.

Returns
The type of the block

Implements business_logic::elements::blocks::BaseBlock.

Definition at line 45 of file SubtractBlock.h.

References business_logic::elements::blocks::Subtract.

◆ getInputPorts()

const std::vector< business_logic::elements::structures::Port > & business_logic::elements::blocks::SubtractBlock::getInputPorts ( ) const
inlineoverrideprotectedvirtual

Gets the input ports of the block.

Returns
Vector of input ports

Implements business_logic::elements::blocks::BaseBlock.

Definition at line 35 of file SubtractBlock.h.

References inputPorts.

◆ getOutputPorts()

const std::vector< business_logic::elements::structures::Port > & business_logic::elements::blocks::SubtractBlock::getOutputPorts ( ) const
inlineoverrideprotectedvirtual

Gets the output ports of the block.

Returns
Vector of output ports

Implements business_logic::elements::blocks::BaseBlock.

Definition at line 40 of file SubtractBlock.h.

References outputPorts.

◆ getSelfId()

std::string business_logic::elements::blocks::SubtractBlock::getSelfId ( ) const
inlineoverridevirtual

The unique identifier of the block (its address in memory), used for logging purposes; should return the same value as business_logic::stringifyAddressOf(this)

Implements business_logic::elements::blocks::BaseBlock.

Definition at line 23 of file SubtractBlock.h.

References selfId.

Member Data Documentation

◆ inputPorts

const std::vector< business_logic::elements::structures::Port > business_logic::elements::blocks::SubtractBlock::inputPorts
staticprotected

◆ outputPorts

const std::vector< business_logic::elements::structures::Port > business_logic::elements::blocks::SubtractBlock::outputPorts
staticprotected
Initial value:

Definition at line 50 of file SubtractBlock.h.

Referenced by calculateOutputValues(), and getOutputPorts().

◆ selfId

std::string business_logic::elements::blocks::SubtractBlock::selfId
protected

Definition at line 30 of file SubtractBlock.h.

Referenced by getSelfId().

◆ SUBTRACT_BLOCK_HEIGHT

constexpr int business_logic::elements::blocks::SubtractBlock::SUBTRACT_BLOCK_HEIGHT = 120
staticconstexprprotected

Definition at line 33 of file SubtractBlock.h.

◆ SUBTRACT_BLOCK_WIDTH

constexpr int business_logic::elements::blocks::SubtractBlock::SUBTRACT_BLOCK_WIDTH = 120
staticconstexprprotected

Definition at line 32 of file SubtractBlock.h.


The documentation for this class was generated from the following files: