FlowArithmeticCalculator 1.0.0
Flow Arithmetic Calculator
Loading...
Searching...
No Matches
ConstantBlock.cpp
Go to the documentation of this file.
1#include "ConstantBlock.h"
2
4
6 int cx,
7 int cy,
11 : BaseBlock(cx,
12 cy,
13 CONSTANT_BLOCK_WIDTH,
14 CONSTANT_BLOCK_HEIGHT,
15 newBlockChoiceDelegate,
16 blockLifecycleManagerDelegate,
17 windowDelegate,
18 logger),
19 selfId(business_logic::stringifyAddressOf(this)) {}
20
21 void ConstantBlock::onDoubleClick(int x, int y) {
22 logger->info("Double clicked at ({}, {}), opening editor", x, y);
23
24 auto maybeNewValue = this->windowDelegate->promptFloatingPointInput(
25 "Edit Constant Value", "Value:", this->portValues[&outputPorts[0]]);
26
27 if (maybeNewValue) {
28 const auto& newValue = maybeNewValue.value();
29
30 logger->info("Constant block {} value changed from '{}' to '{}'",
31 selfId,
32 this->portValues[&outputPorts[0]].str(),
33 newValue.str());
34
35 // update the output port value
36 this->portValues[&outputPorts[0]] = newValue;
37 } else {
38 this->windowDelegate->showWarning("Invalid number",
39 "The entered value is not a valid number");
40 }
41 }
42
43 const std::vector<business_logic::elements::structures::Port> ConstantBlock::inputPorts = {};
44
45 const std::vector<business_logic::elements::structures::Port> ConstantBlock::outputPorts = {
47 };
48
49} // namespace business_logic::elements::blocks
Delegate that is notified when a new block is chosen to be added to the canvas.
virtual void showWarning(const std::string &title, const std::string &message)=0
Show a warning message.
virtual std::optional< FloatingPoint > promptFloatingPointInput(const std::string &title, const std::string &message, const std::optional< FloatingPoint > &defaultValue)=0
Prompt for a floating point input.
The base class for all blocks, containing common functionality and members.
Definition BaseBlock.h:36
std::shared_ptr< spdlog::logger > logger
Definition BaseBlock.h:285
business_logic::delegate::IWindowDelegate * windowDelegate
Definition BaseBlock.h:307
std::unordered_map< const structures::Port *, FloatingPoint > portValues
The registry of port values.
Definition BaseBlock.h:290
static const std::vector< business_logic::elements::structures::Port > inputPorts
ConstantBlock(int cx, int cy, business_logic::delegate::INewBlockChoiceDelegate *newBlockChoiceDelegate, business_logic::delegate::IBlockLifecycleManagerDelegate *blockLifecycleManagerDelegate, business_logic::delegate::IWindowDelegate *windowDelegate)
Constructor.
void onDoubleClick(int x, int y) override
Called when the element is double-clicked.
static const std::vector< business_logic::elements::structures::Port > outputPorts
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