FlowArithmeticCalculator 1.0.0
Flow Arithmetic Calculator
Loading...
Searching...
No Matches
business_logic::BlocksManager Class Reference

Manages the blocks in the GUI, both their rendering and interaction. More...

#include <BlocksManager.h>

+ Inheritance diagram for business_logic::BlocksManager:
+ Collaboration diagram for business_logic::BlocksManager:

Public Member Functions

 BlocksManager (business_logic::delegate::IWindowDelegate *windowDelegate)
 
 ~BlocksManager () noexcept override=default
 
 BlocksManager (const BlocksManager &)=delete
 
BlocksManageroperator= (const BlocksManager &)=delete
 
 BlocksManager (BlocksManager &&)=delete
 
BlocksManageroperator= (BlocksManager &&)=delete
 
void handleMouseDown ()
 Handles the mouse down event.
 
void handleMouseUp ()
 Handles the mouse up event.
 
void handleMouseMove (int x, int y)
 Handles the mouse move event.
 
void handleNumericKeyPress (int number)
 Handles the numeric key press event.
 
void handleEscapeKeyPress ()
 Handles the ESC key press event.
 
std::optional< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > getBlockAtMousePos ()
 Gets the block at the mouse position.
 
std::optional< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > getBlockAt (int x, int y)
 Gets the block at the given coordinates.
 
void onNewBlockChoice (const business_logic::elements::blocks::BlockType &blockType) override
 Called when a new block is chosen to be added to the canvas.
 
void setActiveChoicesInput (business_logic::input::InputChoiceInteraction< business_logic::elements::blocks::BlockType > &&inputChoiceInteraction)
 Sets the input callback; this will override rendering other entities.
 
bool hasActiveChoicesInput () const
 Checks if the input callback is active.
 
void clearActiveChoicesInput ()
 Clears the active input choices and the corresponding generated UI texts rows.
 
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)
 
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.
 
bool isInputConnected (const business_logic::elements::structures::BlocksConnectionSide &side) const override
 Checks if the input port is connected to anything.
 
void onBlockDeleted (const business_logic::elements::blocks::BaseBlock *block) override
 Called when a block is deleted.
 
void handleRightClickOnBlock (const std::shared_ptr< business_logic::elements::blocks::BaseBlock > &block)
 Handles right click event on a block.
 
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.
 
- Public Member Functions inherited from business_logic::delegate::INewBlockChoiceDelegate
virtual ~INewBlockChoiceDelegate ()=default
 
- Public Member Functions inherited from business_logic::delegate::IBlockLifecycleManagerDelegate
virtual ~IBlockLifecycleManagerDelegate ()=default
 
- Public Member Functions inherited from business_logic::calculations::delegate::IBlocksRegistryDelegate
 IBlocksRegistryDelegate ()=default
 
virtual ~IBlocksRegistryDelegate ()=default
 
 IBlocksRegistryDelegate (const IBlocksRegistryDelegate &)=delete
 
IBlocksRegistryDelegateoperator= (const IBlocksRegistryDelegate &)=delete
 
 IBlocksRegistryDelegate (IBlocksRegistryDelegate &&)=delete
 
IBlocksRegistryDelegateoperator= (IBlocksRegistryDelegate &&)=delete
 
- Public Member Functions inherited from business_logic::calculations::BlocksCalculator
 BlocksCalculator (business_logic::calculations::delegate::IBlocksRegistryDelegate *blocksRegistryDelegate)
 
virtual ~BlocksCalculator () noexcept=default
 
 BlocksCalculator (const BlocksCalculator &)=delete
 
BlocksCalculatoroperator= (const BlocksCalculator &)=delete
 
 BlocksCalculator (BlocksCalculator &&)=delete
 
BlocksCalculatoroperator= (BlocksCalculator &&)=delete
 
void calculateValuesFlow ()
 Calculates the values flowing through the graph.
 
- Public Member Functions inherited from business_logic::Loggable< BlocksCalculator >
 Loggable ()
 
- Public Member Functions inherited from business_logic::Loggable< BlocksManager >
 Loggable ()
 

Protected Attributes

std::vector< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > blocks
 
business_logic::elements::blocks::BaseBlockdraggedBlock
 
int mouseX
 
int mouseY
 
business_logic::geometry::Size2D dragOffset
 
std::chrono::steady_clock::time_point doubleClickCtLastMouseClickTime
 
business_logic::delegate::IWindowDelegatewindowDelegate
 
std::optional< business_logic::input::InputChoiceInteraction< business_logic::elements::blocks::BlockType > > inputChoiceInteraction
 
business_logic::input::ConnectPortsInteraction connectPortsInteraction
 
std::vector< components::UITextsRowinputChoicesUiTextsRows
 
std::unordered_map< business_logic::elements::structures::BlocksConnectionSide, std::unordered_set< business_logic::elements::structures::BlocksConnectionSide > > connectionsRegistry
 
std::optional< std::unordered_set< business_logic::elements::structures::BlocksConnectionSide > > maybeGraphCycle
 
- Protected Attributes inherited from business_logic::calculations::BlocksCalculator
std::unordered_set< business_logic::elements::structures::BlocksConnectionSidevisited
 The set of visited blocks to detect cycles.
 
std::unordered_set< business_logic::elements::structures::BlocksConnectionSiderecursionStack
 The stack of recursion to detect cycles.
 
std::unordered_set< business_logic::elements::blocks::BaseBlock * > calcVisited
 The set of visited blocks to note which blocks have been visited when calculating their values.
 
business_logic::calculations::delegate::IBlocksRegistryDelegateblocksRegistryDelegate
 The delegate that provides the connections registry.
 
- Protected Attributes inherited from business_logic::Loggable< BlocksCalculator >
std::shared_ptr< spdlog::logger > logger
 
- Protected Attributes inherited from business_logic::Loggable< BlocksManager >
std::shared_ptr< spdlog::logger > logger
 

Additional Inherited Members

- Protected Member Functions inherited from business_logic::calculations::BlocksCalculator
void calculateBlockValues (business_logic::elements::blocks::BaseBlock *block)
 Calculates the values of the dependencies of a block and then the block itself.
 
std::optional< std::unordered_set< business_logic::elements::structures::BlocksConnectionSide > > hasCycle (elements::structures::BlocksConnectionSide side)
 Checks if there is a cycle in the graph.
 

Detailed Description

Manages the blocks in the GUI, both their rendering and interaction.

Definition at line 34 of file BlocksManager.h.

Constructor & Destructor Documentation

◆ BlocksManager() [1/3]

business_logic::BlocksManager::BlocksManager ( business_logic::delegate::IWindowDelegate windowDelegate)
explicit

Definition at line 5 of file BlocksManager.cpp.

◆ ~BlocksManager()

business_logic::BlocksManager::~BlocksManager ( )
overridedefaultnoexcept

◆ BlocksManager() [2/3]

business_logic::BlocksManager::BlocksManager ( const BlocksManager )
delete

◆ BlocksManager() [3/3]

business_logic::BlocksManager::BlocksManager ( BlocksManager &&  )
delete

Member Function Documentation

◆ clearActiveChoicesInput()

void business_logic::BlocksManager::clearActiveChoicesInput ( )

Clears the active input choices and the corresponding generated UI texts rows.

Definition at line 261 of file BlocksManager.cpp.

References inputChoiceInteraction, inputChoicesUiTextsRows, and business_logic::Loggable< BlocksManager >::logger.

Referenced by handleEscapeKeyPress(), and handleNumericKeyPress().

+ Here is the caller graph for this function:

◆ getBlockAt()

std::optional< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > business_logic::BlocksManager::getBlockAt ( int  x,
int  y 
)

Gets the block at the given coordinates.

Parameters
xX coordinate of the mouse
yY coordinate of the mouse
Returns
The block at the given coordinates, or std::nullopt if no block is at the given coordinates

Definition at line 143 of file BlocksManager.cpp.

References blocks.

Referenced by getBlockAtMousePos().

+ Here is the caller graph for this function:

◆ getBlockAtMousePos()

std::optional< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > business_logic::BlocksManager::getBlockAtMousePos ( )

Gets the block at the mouse position.

Returns
The block at the mouse position, or std::nullopt if no block is at the mouse position

Definition at line 138 of file BlocksManager.cpp.

References getBlockAt(), mouseX, and mouseY.

Referenced by handleMouseDown(), and gui::elements::SkiaBlocksManagerRenderer::render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBlocks()

const std::vector< std::shared_ptr< business_logic::elements::blocks::BaseBlock > > & business_logic::BlocksManager::getBlocks ( ) const
overridevirtual

Gets the blocks.

Returns
The blocks

Implements business_logic::calculations::delegate::IBlocksRegistryDelegate.

Definition at line 372 of file BlocksManager.cpp.

References blocks.

◆ getConnectionsRegistry()

const std::unordered_map< elements::structures::BlocksConnectionSide, std::unordered_set< elements::structures::BlocksConnectionSide > > & business_logic::BlocksManager::getConnectionsRegistry ( ) const
overridevirtual

Gets the connections registry.

Returns
The connections registry

Implements business_logic::calculations::delegate::IBlocksRegistryDelegate.

Definition at line 378 of file BlocksManager.cpp.

References connectionsRegistry.

◆ handleEscapeKeyPress()

void business_logic::BlocksManager::handleEscapeKeyPress ( )

◆ handleMouseDown()

◆ handleMouseMove()

void business_logic::BlocksManager::handleMouseMove ( int  x,
int  y 
)

Handles the mouse move event.

Parameters
xX coordinate of the mouse
yY coordinate of the mouse

Definition at line 128 of file BlocksManager.cpp.

References draggedBlock, dragOffset, business_logic::geometry::Size2D::height, mouseX, mouseY, business_logic::elements::blocks::BaseBlock::onDragProgress(), and business_logic::geometry::Size2D::width.

+ Here is the call graph for this function:

◆ handleMouseUp()

void business_logic::BlocksManager::handleMouseUp ( )

◆ handleNumericKeyPress()

void business_logic::BlocksManager::handleNumericKeyPress ( int  number)

Handles the numeric key press event.

Parameters
numberThe number that was pressed

Definition at line 107 of file BlocksManager.cpp.

References clearActiveChoicesInput(), inputChoiceInteraction, business_logic::Loggable< BlocksManager >::logger, onNewBlockChoice(), business_logic::delegate::IWindowDelegate::showWarning(), and windowDelegate.

+ Here is the call graph for this function:

◆ handleRightClickOnBlock()

◆ hasActiveChoicesInput()

bool business_logic::BlocksManager::hasActiveChoicesInput ( ) const

Checks if the input callback is active.

Returns
True if the input callback is active, false otherwise

Definition at line 259 of file BlocksManager.cpp.

References inputChoiceInteraction.

Referenced by handleEscapeKeyPress(), and handleMouseDown().

+ Here is the caller graph for this function:

◆ hasConnectionBetween()

bool business_logic::BlocksManager::hasConnectionBetween ( const business_logic::elements::structures::BlocksConnectionSide source,
const business_logic::elements::structures::BlocksConnectionSide dest 
) const
overridevirtual

Checks if there is a connection between two entities.

Parameters
sourceThe source side of the connection
destThe destination side of the connection
Returns
True if there is a connection between the two entities, false otherwise

Implements business_logic::delegate::IBlockLifecycleManagerDelegate.

Definition at line 270 of file BlocksManager.cpp.

References business_logic::elements::structures::BlocksConnectionSide::block, connectionsRegistry, and business_logic::elements::structures::BlocksConnectionSide::port.

◆ isInputConnected()

bool business_logic::BlocksManager::isInputConnected ( const business_logic::elements::structures::BlocksConnectionSide side) const
overridevirtual

Checks if the input port is connected to anything.

Parameters
sideThe side to check
Returns
True if the input port is connected to anything, false otherwise

Implements business_logic::delegate::IBlockLifecycleManagerDelegate.

Definition at line 286 of file BlocksManager.cpp.

References connectionsRegistry.

◆ onBlockDeleted()

void business_logic::BlocksManager::onBlockDeleted ( const business_logic::elements::blocks::BaseBlock block)
overridevirtual

Called when a block is deleted.

Parameters
blockThe block that was deleted

Implements business_logic::delegate::IBlockLifecycleManagerDelegate.

Definition at line 299 of file BlocksManager.cpp.

References connectionsRegistry, and draggedBlock.

◆ onNewBlockChoice()

void business_logic::BlocksManager::onNewBlockChoice ( const business_logic::elements::blocks::BlockType blockType)
overridevirtual

◆ onPortsConnected()

void business_logic::BlocksManager::onPortsConnected ( const business_logic::elements::structures::BlocksConnectionSide source,
const business_logic::elements::structures::BlocksConnectionSide dest 
)
overridevirtual

Invoked when a connection is made between two ports + blocks (sides)

Parameters
sourceThe source side of the connection
destThe destination side of the connection

Implements business_logic::delegate::IBlockLifecycleManagerDelegate.

Definition at line 294 of file BlocksManager.cpp.

References connectionsRegistry.

◆ operator=() [1/2]

BlocksManager & business_logic::BlocksManager::operator= ( BlocksManager &&  )
delete

◆ operator=() [2/2]

BlocksManager & business_logic::BlocksManager::operator= ( const BlocksManager )
delete

◆ setActiveChoicesInput()

void business_logic::BlocksManager::setActiveChoicesInput ( business_logic::input::InputChoiceInteraction< business_logic::elements::blocks::BlockType > &&  inputChoiceInteraction)

Sets the input callback; this will override rendering other entities.

Parameters
inputChoiceInteractionThe input choice interaction

Definition at line 216 of file BlocksManager.cpp.

References business_logic::components::UIText::Choice, inputChoiceInteraction, inputChoicesUiTextsRows, business_logic::Loggable< BlocksManager >::logger, and business_logic::constants::MAX_INPUT_CHOICES_PER_ROW.

Member Data Documentation

◆ blocks

std::vector<std::shared_ptr<business_logic::elements::blocks::BaseBlock> > business_logic::BlocksManager::blocks
protected

◆ connectionsRegistry

◆ connectPortsInteraction

business_logic::input::ConnectPortsInteraction business_logic::BlocksManager::connectPortsInteraction
protected

◆ doubleClickCtLastMouseClickTime

std::chrono::steady_clock::time_point business_logic::BlocksManager::doubleClickCtLastMouseClickTime
protected

The time of the last mouse click, used for tracking double-clicks

Definition at line 205 of file BlocksManager.h.

Referenced by handleMouseDown().

◆ draggedBlock

business_logic::elements::blocks::BaseBlock* business_logic::BlocksManager::draggedBlock
protected

The block that is currently being dragged

Definition at line 185 of file BlocksManager.h.

Referenced by handleMouseDown(), handleMouseMove(), handleMouseUp(), and onBlockDeleted().

◆ dragOffset

business_logic::geometry::Size2D business_logic::BlocksManager::dragOffset
protected

The offset from the block's center when dragging started

Definition at line 200 of file BlocksManager.h.

Referenced by handleMouseDown(), and handleMouseMove().

◆ inputChoiceInteraction

std::optional<business_logic::input::InputChoiceInteraction< business_logic::elements::blocks::BlockType> > business_logic::BlocksManager::inputChoiceInteraction
protected

◆ inputChoicesUiTextsRows

std::vector<components::UITextsRow> business_logic::BlocksManager::inputChoicesUiTextsRows
protected

The UI texts for the choices; prepared inside setActiveChoicesInput(...) and used in render(...)

Definition at line 228 of file BlocksManager.h.

Referenced by clearActiveChoicesInput(), gui::elements::SkiaBlocksManagerRenderer::render(), and setActiveChoicesInput().

◆ maybeGraphCycle

std::optional< std::unordered_set<business_logic::elements::structures::BlocksConnectionSide> > business_logic::BlocksManager::maybeGraphCycle
protected

Stores the cycle path (if present)

Definition at line 243 of file BlocksManager.h.

Referenced by gui::elements::SkiaBlocksManagerRenderer::render().

◆ mouseX

◆ mouseY

◆ windowDelegate

business_logic::delegate::IWindowDelegate* business_logic::BlocksManager::windowDelegate
protected

The window delegate

Definition at line 210 of file BlocksManager.h.

Referenced by handleMouseDown(), handleNumericKeyPress(), handleRightClickOnBlock(), and onNewBlockChoice().


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