FlowArithmeticCalculator 1.0.0
Flow Arithmetic Calculator
Loading...
Searching...
No Matches
MonitorBlock.cpp
Go to the documentation of this file.
1#include "MonitorBlock.h"
2
4
6 int cx,
7 int cy,
11 : BaseBlock(cx,
12 cy,
13 MONITOR_BLOCK_WIDTH,
14 MONITOR_BLOCK_HEIGHT,
15 newBlockChoiceDelegate,
16 blockLifecycleManagerDelegate,
17 windowDelegate,
18 logger),
19 selfId(business_logic::stringifyAddressOf(this)) {}
20
21 std::optional<std::string> MonitorBlock::getValueToRenderAboveBlock(bool isHovered) {
24 .block = this, .port = theInputPort};
25
26 // draw the input port value above the block (if the input is connected)
27 if (this->blockLifecycleManagerDelegate->isInputConnected(theInputSide)) {
28 auto blockValue = this->getPortValue(theInputPort);
29
30 std::ostringstream oss;
31 // display either up to business_logic::constants::DEFAULT_VALUE_DISPLAY_PRECISION
32 // significant digits or up to the max floating point structure capability (if hovered),
33 // in scientific notation
34 oss << std::scientific
35 << std::setprecision(
36 isHovered ? std::numeric_limits<FloatingPoint>::digits10
38 << blockValue;
39
40 return oss.str();
41 }
42
43 return std::nullopt;
44 }
45
46 const std::vector<business_logic::elements::structures::Port> MonitorBlock::inputPorts = {
48 };
49
50 const std::vector<business_logic::elements::structures::Port> MonitorBlock::outputPorts = {};
51
52} // namespace business_logic::elements::blocks
virtual bool isInputConnected(const business_logic::elements::structures::BlocksConnectionSide &side) const =0
Checks if the input port is connected to anything.
Delegate that is notified when a new block is chosen to be added to the canvas.
The base class for all blocks, containing common functionality and members.
Definition BaseBlock.h:36
business_logic::delegate::IBlockLifecycleManagerDelegate * blockLifecycleManagerDelegate
Definition BaseBlock.h:301
virtual bool isHovered(int x, int y) const
Checks if the block is hovered over by the mouse.
Definition BaseBlock.h:85
const FloatingPoint & getPortValue(const structures::Port *port) const
Gets the value of the port.
static const std::vector< business_logic::elements::structures::Port > inputPorts
MonitorBlock(int cx, int cy, business_logic::delegate::INewBlockChoiceDelegate *newBlockChoiceDelegate, business_logic::delegate::IBlockLifecycleManagerDelegate *blockLifecycleManagerDelegate, business_logic::delegate::IWindowDelegate *windowDelegate)
Constructor.
static const std::vector< business_logic::elements::structures::Port > outputPorts
std::optional< std::string > getValueToRenderAboveBlock(bool isHovered) override
Wrapper that gets the value of the output port above the block; if the input port is not connected,...
constexpr int DEFAULT_VALUE_DISPLAY_PRECISION
Definition constants.h:39
The base classes and structs for elements.
The business logic module.
std::string stringifyAddressOf(const T *value)
Convert a pointer to a string in format "0x..." containing its hexadecimal address.
Definition misc.h:16
business_logic::elements::blocks::BaseBlock * block
The block.
Represents a port on a block.
Definition Port.h:11