diff --git a/CMakeLists.txt b/CMakeLists.txt index e1d4f7f..368a4f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,36 +25,57 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/external) # compile the program add_executable(Atlas_Install source/main.cpp - source/Atlas/nodes/decimal/data.cpp - include/Atlas/nodes/decimal/data.h - source/Atlas/nodes/decimal/model/constant.cpp - include/Atlas/nodes/decimal/model/constant.h + include/Atlas/nodes/node/register.h + source/Atlas/nodes/node/register.cpp - include/Atlas/nodes/common/model/reduce.h - source/Atlas/nodes/common/model/reduce.cpp + include/Atlas/nodes/node/base/model/reduce.h + source/Atlas/nodes/node/base/model/reduce.cpp + include/Atlas/nodes/node/base/data.h + source/Atlas/nodes/node/base/data.cpp - include/Atlas/nodes/decimal/model/addition.h - source/Atlas/nodes/decimal/model/addition.cpp - include/Atlas/nodes/decimal/model/subtraction.h - source/Atlas/nodes/decimal/model/subtraction.cpp - include/Atlas/nodes/decimal/model/multiplication.h - source/Atlas/nodes/decimal/model/multiplication.cpp - include/Atlas/nodes/decimal/model/division.h - source/Atlas/nodes/decimal/model/division.cpp - include/Atlas/nodes/variant/data.h - source/Atlas/nodes/variant/data.cpp - include/Atlas/nodes/common/data.h - source/Atlas/nodes/common/data.cpp - include/Atlas/nodes/variant/model/display.h - source/Atlas/nodes/variant/model/display.cpp - include/Atlas/nodes/variant/model/to_variant.h - include/Atlas/nodes/variant/model/from_variant.h - source/Atlas/nodes/variant/model/to_variant.cpp - source/Atlas/nodes/variant/model/from_variant.cpp - source/Atlas/nodes/decimal/model/to_variant.cpp - include/Atlas/nodes/decimal/model/to_variant.h + source/Atlas/nodes/node/decimal/data.cpp + include/Atlas/nodes/node/decimal/data.h + source/Atlas/nodes/node/decimal/model/constant.cpp + include/Atlas/nodes/node/decimal/model/constant.h + include/Atlas/nodes/node/decimal/model/addition.h + source/Atlas/nodes/node/decimal/model/addition.cpp + include/Atlas/nodes/node/decimal/model/subtraction.h + source/Atlas/nodes/node/decimal/model/subtraction.cpp + include/Atlas/nodes/node/decimal/model/multiplication.h + source/Atlas/nodes/node/decimal/model/multiplication.cpp + include/Atlas/nodes/node/decimal/model/division.h + source/Atlas/nodes/node/decimal/model/division.cpp + source/Atlas/nodes/node/decimal/model/to_variant.cpp + include/Atlas/nodes/node/decimal/model/to_variant.h + include/Atlas/nodes/node/decimal/model/absolute.h + source/Atlas/nodes/node/decimal/model/absolute.cpp + include/Atlas/nodes/node/decimal/register.h + source/Atlas/nodes/node/decimal/register.cpp + + include/Atlas/nodes/node/variant/data.h + source/Atlas/nodes/node/variant/data.cpp + include/Atlas/nodes/node/variant/model/display.h + source/Atlas/nodes/node/variant/model/display.cpp + include/Atlas/nodes/node/variant/model/to_variant.h + include/Atlas/nodes/node/variant/model/from_variant.h + source/Atlas/nodes/node/variant/model/to_variant.cpp + source/Atlas/nodes/node/variant/model/from_variant.cpp + source/Atlas/nodes/node/variant/model/to_variant.cpp + include/Atlas/nodes/node/variant/model/to_variant.h + include/Atlas/nodes/node/variant/model/from_variant.h + source/Atlas/nodes/node/variant/model/from_variant.cpp + source/Atlas/nodes/node/variant/model/from_variant.cpp + source/Atlas/nodes/node/variant/register.cpp + include/Atlas/nodes/node/variant/register.h + source/Atlas/nodes/node/string/register.cpp + source/Atlas/nodes/node/string/data.cpp + include/Atlas/nodes/node/string/model/constant.h + source/Atlas/nodes/node/string/model/constant.cpp + include/utils/string.h + source/utils/string.cpp ) + target_link_libraries(Atlas_Install # Qt Qt::Core diff --git a/external/wiimms-szs-tools b/external/wiimms-szs-tools index 336da83..a051a6c 160000 --- a/external/wiimms-szs-tools +++ b/external/wiimms-szs-tools @@ -1 +1 @@ -Subproject commit 336da838ce43edae40dd708dd465f1f43a2c312d +Subproject commit a051a6cc397d47a4dee0bac4c67ac31b6e4ab34c diff --git a/include/Atlas/nodes/README.md b/include/Atlas/nodes/README.md new file mode 100644 index 0000000..d1cee76 --- /dev/null +++ b/include/Atlas/nodes/README.md @@ -0,0 +1,19 @@ +# Node System Module + +The node system module is an interface allowing you to manipulate nodes on a canvas +to assemble a logic that can allow you to describe how to patch a file, a text, +an image, etc. + +## Node sub-module + +The directory `node` contains a directory for every type of nodes, plus a `base` +directory for special functions and class used by the other type of nodes. + +These type of nodes are: +- `decimal`: a node that can be used to manipulate decimal values (`double` in C++). +- `variant`: a node that can be used to contains any type of value. Useful to + use a function that can use any type of value (example : a print-like function). + +All the directories contains some special files : +- `register` file to register all the nodes in the registry. +- `data` file containing the implementation of the type itself. diff --git a/include/Atlas/nodes/decimal/model/to_variant.h b/include/Atlas/nodes/decimal/model/to_variant.h deleted file mode 100644 index 541f2e1..0000000 --- a/include/Atlas/nodes/decimal/model/to_variant.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - - -#include -#include - - -using namespace Atlas::Nodes; - - -namespace Atlas::Nodes::Decimal::Model { - - - class ToVariant : public Variant::Model::ToVariant { - Q_OBJECT - - public: - [[nodiscard]] QString name() const override; - - [[nodiscard]] QString caption() const override; - }; - - -} diff --git a/include/Atlas/nodes/common/data.h b/include/Atlas/nodes/node/base/data.h similarity index 64% rename from include/Atlas/nodes/common/data.h rename to include/Atlas/nodes/node/base/data.h index 6a0f1b8..babe5e5 100644 --- a/include/Atlas/nodes/common/data.h +++ b/include/Atlas/nodes/node/base/data.h @@ -1,14 +1,14 @@ #pragma once -#include +#include "QtNodes/NodeData" -namespace Atlas::Nodes::Common { +namespace Atlas::Nodes::Base { /** - * @brief the decimal data type - * @details this class is used to store decimal data (double internally) + * @brief an abstract data type + * @details this class is used to store data */ class Data : public QtNodes::NodeData { public: diff --git a/include/Atlas/nodes/common/model/reduce.h b/include/Atlas/nodes/node/base/model/reduce.h similarity index 99% rename from include/Atlas/nodes/common/model/reduce.h rename to include/Atlas/nodes/node/base/model/reduce.h index 1121692..941bea5 100644 --- a/include/Atlas/nodes/common/model/reduce.h +++ b/include/Atlas/nodes/node/base/model/reduce.h @@ -4,7 +4,7 @@ #include "QtNodes/NodeDelegateModel" -namespace Atlas::Nodes::Common::Model { +namespace Atlas::Nodes::Base::Model { template diff --git a/include/Atlas/nodes/decimal/data.h b/include/Atlas/nodes/node/decimal/data.h similarity index 93% rename from include/Atlas/nodes/decimal/data.h rename to include/Atlas/nodes/node/decimal/data.h index e47684a..fd2ad42 100644 --- a/include/Atlas/nodes/decimal/data.h +++ b/include/Atlas/nodes/node/decimal/data.h @@ -1,7 +1,7 @@ #pragma once #include "QtNodes/NodeData" -#include "Atlas/nodes/common/data.h" +#include "Atlas/nodes/node/base/data.h" using namespace Atlas::Nodes; @@ -13,7 +13,7 @@ namespace Atlas::Nodes::Decimal { * @brief the decimal data type * @details this class is used to store decimal data (double internally) */ - class Data : public Common::Data { + class Data : public Base::Data { protected: double _value; //< the value of the data diff --git a/include/Atlas/nodes/node/decimal/model/absolute.h b/include/Atlas/nodes/node/decimal/model/absolute.h new file mode 100644 index 0000000..02f7efa --- /dev/null +++ b/include/Atlas/nodes/node/decimal/model/absolute.h @@ -0,0 +1,37 @@ +#pragma once + + +#include "QtNodes/NodeDelegateModel" +#include "Atlas/nodes/node/decimal/data.h" + + +using namespace Atlas::Nodes; + + +namespace Atlas::Nodes::Decimal::Model { + + + class Absolute : public QtNodes::NodeDelegateModel { + Q_OBJECT + + private: + std::shared_ptr _output; ///< the output + + public: + [[nodiscard]] QString name() const override; + + [[nodiscard]] QString caption() const override; + + [[nodiscard]] unsigned int nPorts(QtNodes::PortType portType) const override; + + [[nodiscard]] QtNodes::NodeDataType dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const override; + + void setInData(std::shared_ptr nodeData, QtNodes::PortIndex portIndex) override; + + std::shared_ptr outData(QtNodes::PortIndex port) override; + + QWidget *embeddedWidget() override; + }; + + +} \ No newline at end of file diff --git a/include/Atlas/nodes/decimal/model/addition.h b/include/Atlas/nodes/node/decimal/model/addition.h similarity index 75% rename from include/Atlas/nodes/decimal/model/addition.h rename to include/Atlas/nodes/node/decimal/model/addition.h index 1505d72..f9419ad 100644 --- a/include/Atlas/nodes/decimal/model/addition.h +++ b/include/Atlas/nodes/node/decimal/model/addition.h @@ -1,8 +1,8 @@ #pragma once -#include "Atlas/nodes/decimal/data.h" -#include "Atlas/nodes/common/model/reduce.h" +#include "Atlas/nodes/node/decimal/data.h" +#include "Atlas/nodes/node/base/model/reduce.h" using namespace Atlas::Nodes; @@ -11,7 +11,7 @@ using namespace Atlas::Nodes; namespace Atlas::Nodes::Decimal::Model { - class Addition : public Common::Model::Reduce { + class Addition : public Base::Model::Reduce { Q_OBJECT private: diff --git a/include/Atlas/nodes/decimal/model/constant.h b/include/Atlas/nodes/node/decimal/model/constant.h similarity index 98% rename from include/Atlas/nodes/decimal/model/constant.h rename to include/Atlas/nodes/node/decimal/model/constant.h index 2df8a59..3392f9c 100644 --- a/include/Atlas/nodes/decimal/model/constant.h +++ b/include/Atlas/nodes/node/decimal/model/constant.h @@ -3,7 +3,7 @@ #include "QtNodes/NodeDelegateModel" #include -#include "Atlas/nodes/decimal/data.h" +#include "Atlas/nodes/node/decimal/data.h" using namespace Atlas::Nodes; diff --git a/include/Atlas/nodes/decimal/model/division.h b/include/Atlas/nodes/node/decimal/model/division.h similarity index 75% rename from include/Atlas/nodes/decimal/model/division.h rename to include/Atlas/nodes/node/decimal/model/division.h index fc3eb55..06bbff1 100644 --- a/include/Atlas/nodes/decimal/model/division.h +++ b/include/Atlas/nodes/node/decimal/model/division.h @@ -1,8 +1,8 @@ #pragma once -#include "Atlas/nodes/decimal/data.h" -#include "Atlas/nodes/common/model/reduce.h" +#include "Atlas/nodes/node/decimal/data.h" +#include "Atlas/nodes/node/base/model/reduce.h" using namespace Atlas::Nodes; @@ -11,7 +11,7 @@ using namespace Atlas::Nodes; namespace Atlas::Nodes::Decimal::Model { - class Division : public Common::Model::Reduce { + class Division : public Base::Model::Reduce { Q_OBJECT private: diff --git a/include/Atlas/nodes/decimal/model/multiplication.h b/include/Atlas/nodes/node/decimal/model/multiplication.h similarity index 75% rename from include/Atlas/nodes/decimal/model/multiplication.h rename to include/Atlas/nodes/node/decimal/model/multiplication.h index f27a624..db62e62 100644 --- a/include/Atlas/nodes/decimal/model/multiplication.h +++ b/include/Atlas/nodes/node/decimal/model/multiplication.h @@ -1,8 +1,8 @@ #pragma once -#include "Atlas/nodes/decimal/data.h" -#include "Atlas/nodes/common/model/reduce.h" +#include "Atlas/nodes/node/decimal/data.h" +#include "Atlas/nodes/node/base/model/reduce.h" using namespace Atlas::Nodes; @@ -11,7 +11,7 @@ using namespace Atlas::Nodes; namespace Atlas::Nodes::Decimal::Model { - class Multiplication : public Common::Model::Reduce { + class Multiplication : public Base::Model::Reduce { Q_OBJECT private: diff --git a/include/Atlas/nodes/decimal/model/subtraction.h b/include/Atlas/nodes/node/decimal/model/subtraction.h similarity index 75% rename from include/Atlas/nodes/decimal/model/subtraction.h rename to include/Atlas/nodes/node/decimal/model/subtraction.h index 28f0549..544f798 100644 --- a/include/Atlas/nodes/decimal/model/subtraction.h +++ b/include/Atlas/nodes/node/decimal/model/subtraction.h @@ -1,8 +1,8 @@ #pragma once -#include "Atlas/nodes/decimal/data.h" -#include "Atlas/nodes/common/model/reduce.h" +#include "Atlas/nodes/node/decimal/data.h" +#include "Atlas/nodes/node/base/model/reduce.h" using namespace Atlas::Nodes; @@ -11,7 +11,7 @@ using namespace Atlas::Nodes; namespace Atlas::Nodes::Decimal::Model { - class Subtraction : public Common::Model::Reduce { + class Subtraction : public Base::Model::Reduce { Q_OBJECT private: diff --git a/include/Atlas/nodes/node/decimal/model/to_variant.h b/include/Atlas/nodes/node/decimal/model/to_variant.h new file mode 100644 index 0000000..f1e08ff --- /dev/null +++ b/include/Atlas/nodes/node/decimal/model/to_variant.h @@ -0,0 +1,21 @@ +#pragma once + + +#include "Atlas/nodes/node/variant/model/to_variant.h" +#include "Atlas/nodes/node/decimal/data.h" + + +using namespace Atlas::Nodes; + + +namespace Atlas::Nodes::Decimal::Model { + + + class ToVariant : public Variant::Model::ToVariant { + public: + ToVariant() = default; + ~ToVariant() override = default; + }; + + +} \ No newline at end of file diff --git a/include/Atlas/nodes/node/decimal/register.h b/include/Atlas/nodes/node/decimal/register.h new file mode 100644 index 0000000..fa75a2a --- /dev/null +++ b/include/Atlas/nodes/node/decimal/register.h @@ -0,0 +1,12 @@ +#pragma once + + +#include +#include "QtNodes/NodeDelegateModelRegistry" + + +namespace Atlas::Nodes::Decimal { + /// @brief registers all the decimal models + /// @param registry the registry to register the models to + void register_all(const std::shared_ptr& registry); +} diff --git a/include/Atlas/nodes/node/register.h b/include/Atlas/nodes/node/register.h new file mode 100644 index 0000000..52c67f1 --- /dev/null +++ b/include/Atlas/nodes/node/register.h @@ -0,0 +1,12 @@ +#pragma once + + +#include +#include "QtNodes/NodeDelegateModelRegistry" + + +namespace Atlas::Nodes { + /// @brief registers all the models + /// @param registry the registry to register the models to + void register_all(const std::shared_ptr& registry); +} diff --git a/include/Atlas/nodes/node/string/data.h b/include/Atlas/nodes/node/string/data.h new file mode 100644 index 0000000..f249632 --- /dev/null +++ b/include/Atlas/nodes/node/string/data.h @@ -0,0 +1,49 @@ +#pragma once + +#include "QtNodes/NodeData" +#include "Atlas/nodes/node/base/data.h" + + +using namespace Atlas::Nodes; + + +namespace Atlas::Nodes::String { + + /** + * @brief the string data type + * @details this class is used to store string data (std::string internally) + */ + class Data : public Base::Data { + protected: + std::string _value; //< the value of the data + + public: + /** + * @brief Default constructor + * @details Use the default value + */ + Data(); + /** + * @brief Constructor + * @param value The value to use + */ + explicit Data(std::string value); + + /** + * @brief Returns the value of the data + * @return the value of the data + */ + [[nodiscard]] std::string value() const; + + /// @copydoc QtNodes::NodeData::type + [[nodiscard]] QtNodes::NodeDataType type() const override; + + /** + * @brief Returns the representation of the data + * @return The representation of the data + */ + [[nodiscard]] QString text() const override; + }; + + +} diff --git a/include/Atlas/nodes/node/string/model/constant.h b/include/Atlas/nodes/node/string/model/constant.h new file mode 100644 index 0000000..32eb740 --- /dev/null +++ b/include/Atlas/nodes/node/string/model/constant.h @@ -0,0 +1,78 @@ +#pragma once + + +#include "QtNodes/NodeDelegateModel" +#include +#include "Atlas/nodes/node/string/data.h" + + +using namespace Atlas::Nodes; + + +namespace Atlas::Nodes::String::Model { + + + class Constant : public QtNodes::NodeDelegateModel { + Q_OBJECT + + public: + Constant(); + ~Constant() override; + + /** + * @brief the name of the node + * @return the name of the node + */ + [[nodiscard]] QString name() const override; + /** + * @brief the caption of the node + * @return the caption of the node + */ + [[nodiscard]] QString caption() const override; + + /** + * @brief the number of ports the node has + * @param portType the type of the port (input or output) + * @return the number of ports the node has + */ + [[nodiscard]] unsigned int nPorts(QtNodes::PortType portType) const override; + /** + * @brief the data type of the port + * @param portType the type of the port (input or output) + * @param portType the index of the port + * @return the data type of the port + */ + [[nodiscard]] QtNodes::NodeDataType dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const override; + /** + * @brief the output data of a port + * @param port the index of the port + * @return the output data of a port + */ + std::shared_ptr outData(QtNodes::PortIndex port) override; + + /** + * @brief set the input data of a port + * @param data the input data + * @param portIndex the index of the port + */ + void setInData(std::shared_ptr data, QtNodes::PortIndex portIndex) override; + + /** + * @brief refresh the node + * @note this is called when the text in the line edit is changed + */ + void refresh(); + + /** + * @brief get the embedded widget + * @return the embedded widget + */ + QWidget *embeddedWidget() override; + + protected: + QLineEdit *_lineEdit; + std::string _value = ""; + }; + + +} \ No newline at end of file diff --git a/include/Atlas/nodes/node/string/model/to_variant.h b/include/Atlas/nodes/node/string/model/to_variant.h new file mode 100644 index 0000000..b03055e --- /dev/null +++ b/include/Atlas/nodes/node/string/model/to_variant.h @@ -0,0 +1,21 @@ +#pragma once + + +#include "Atlas/nodes/node/variant/model/to_variant.h" +#include "Atlas/nodes/node/string/data.h" + + +using namespace Atlas::Nodes; + + +namespace Atlas::Nodes::String::Model { + + + class ToVariant : public Variant::Model::ToVariant { + public: + ToVariant() = default; + ~ToVariant() override = default; + }; + + +} \ No newline at end of file diff --git a/include/Atlas/nodes/node/string/register.h b/include/Atlas/nodes/node/string/register.h new file mode 100644 index 0000000..58c1d03 --- /dev/null +++ b/include/Atlas/nodes/node/string/register.h @@ -0,0 +1,12 @@ +#pragma once + + +#include +#include "QtNodes/NodeDelegateModelRegistry" + + +namespace Atlas::Nodes::String { + /// @brief registers all the decimal models + /// @param registry the registry to register the models to + void register_all(const std::shared_ptr& registry); +} diff --git a/include/Atlas/nodes/variant/data.h b/include/Atlas/nodes/node/variant/data.h similarity index 65% rename from include/Atlas/nodes/variant/data.h rename to include/Atlas/nodes/node/variant/data.h index cf26444..e375769 100644 --- a/include/Atlas/nodes/variant/data.h +++ b/include/Atlas/nodes/node/variant/data.h @@ -1,8 +1,8 @@ #pragma once -#include -#include "Atlas/nodes/common/data.h" +#include "QtNodes/NodeData" +#include "Atlas/nodes/node/base/data.h" using namespace Atlas::Nodes; @@ -15,19 +15,19 @@ namespace Atlas::Nodes::Variant { * @brief the decimal data type * @details this class is used to store decimal data (double internally) */ - class Data : public Common::Data { + class Data : public Base::Data { protected: - std::shared_ptr _data; //< a reference to a data object + std::shared_ptr _data; //< a reference to a data object public: Data(); - explicit Data(const std::shared_ptr& data); + explicit Data(const std::shared_ptr& data); /** * @brief Returns the value of the data * @return the value of the data */ - [[nodiscard]] std::shared_ptr value() const; + [[nodiscard]] std::shared_ptr value() const; /// @copydoc QtNodes::NodeData::type [[nodiscard]] QtNodes::NodeDataType type() const override; diff --git a/include/Atlas/nodes/variant/model/display.h b/include/Atlas/nodes/node/variant/model/display.h similarity index 97% rename from include/Atlas/nodes/variant/model/display.h rename to include/Atlas/nodes/node/variant/model/display.h index 5b8a909..c0d481c 100644 --- a/include/Atlas/nodes/variant/model/display.h +++ b/include/Atlas/nodes/node/variant/model/display.h @@ -1,7 +1,7 @@ #pragma once -#include "Atlas/nodes/variant/data.h" +#include "Atlas/nodes/node/variant/data.h" #include "QtNodes/NodeDelegateModel" #include diff --git a/include/Atlas/nodes/node/variant/model/from_variant.h b/include/Atlas/nodes/node/variant/model/from_variant.h new file mode 100644 index 0000000..2cd54a0 --- /dev/null +++ b/include/Atlas/nodes/node/variant/model/from_variant.h @@ -0,0 +1,46 @@ +#pragma once + +#include + +#include "QtNodes/NodeDelegateModel" +#include "Atlas/nodes/node/variant/data.h" + + +using namespace Atlas::Nodes; + + +namespace Atlas::Nodes::Variant::Model { + + + class FromVariant : public QtNodes::NodeDelegateModel { + private: + std::shared_ptr _input; ///< the input + + public: + FromVariant() = default; + ~FromVariant() override = default; + + /// @copydoc QtNodes::NodeDelegateModel::caption + [[nodiscard]] QString caption() const override; + + /// @copydoc QtNodes::NodeDelegateModel::name + [[nodiscard]] QString name() const override; + + /// @copydoc QtNodes::NodeDelegateModel::nPorts + [[nodiscard]] unsigned int nPorts(QtNodes::PortType portType) const override; + + /// @copydoc QtNodes::NodeDelegateModel::dataType + [[nodiscard]] QtNodes::NodeDataType dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const override; + + /// @copydoc QtNodes::NodeDelegateModel::setInData + void setInData(std::shared_ptr data, QtNodes::PortIndex portIndex) override; + + /// @copydoc QtNodes::NodeDelegateModel::outData + std::shared_ptr outData(QtNodes::PortIndex portIndex) override; + + /// @copydoc QtNodes::NodeDelegateModel::embeddedWidget + QWidget* embeddedWidget() override; + }; + + +} diff --git a/include/Atlas/nodes/variant/model/to_variant.h b/include/Atlas/nodes/node/variant/model/to_variant.h similarity index 54% rename from include/Atlas/nodes/variant/model/to_variant.h rename to include/Atlas/nodes/node/variant/model/to_variant.h index d9d48c2..f04b3b0 100644 --- a/include/Atlas/nodes/variant/model/to_variant.h +++ b/include/Atlas/nodes/node/variant/model/to_variant.h @@ -2,7 +2,7 @@ #include "QtNodes/NodeDelegateModel" -#include +#include "Atlas/nodes/node/variant/data.h" using namespace Atlas::Nodes; @@ -11,33 +11,47 @@ using namespace Atlas::Nodes; namespace Atlas::Nodes::Variant::Model { - template + template class ToVariant : public QtNodes::NodeDelegateModel { private: - std::shared_ptr _input; ///< the input std::shared_ptr _output; ///< the output public: ToVariant() = default; ~ToVariant() override = default; + /// @copydoc QtNodes::NodeDelegateModel::name + QString name() const override { + return NodeInputType().type().name + QStringLiteral("::To Variant"); + } + + /// @copydoc QtNodes::NodeDelegateModel::caption + QString caption() const override { + return NodeInputType().type().name + QStringLiteral(" to Variant"); + } + /// @copydoc QtNodes::NodeDelegateModel::nPorts [[nodiscard]] unsigned int nPorts(QtNodes::PortType portType) const override { - // a "to_variant" function only has one input and one output - return 1; + // a "to_variant" function only has one input if the output is set and one output + return portType == QtNodes::PortType::In ? 1 : 1; } /// @copydoc QtNodes::NodeDelegateModel::dataType [[nodiscard]] QtNodes::NodeDataType dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const override { - return portType == QtNodes::PortType::In ? DataInputType().type() : Variant::Data().type(); + return portType == QtNodes::PortType::In ? NodeInputType().type() : Variant::Data().type(); } /// @copydoc QtNodes::NodeDelegateModel::setInData void setInData(std::shared_ptr data, QtNodes::PortIndex portIndex) override { - // convert the data to the correct type - std::shared_ptr casted_data = std::dynamic_pointer_cast(data); - // update the input - this->_output = std::make_shared(casted_data); + if (data == nullptr) { + // clear the output + this->_output = nullptr; + } else { + // convert the data to the common type + std::shared_ptr casted_data = std::dynamic_pointer_cast(data); + // update the output + this->_output = std::make_shared(casted_data); + } // update the next nodes Q_EMIT dataUpdated(0); } @@ -45,7 +59,7 @@ namespace Atlas::Nodes::Variant::Model { /// @copydoc QtNodes::NodeDelegateModel::outData std::shared_ptr outData(QtNodes::PortIndex portIndex) override { // return the last computed output - return this->_output; + return static_cast &>(this->_output); } /// @copydoc QtNodes::NodeDelegateModel::embeddedWidget @@ -56,4 +70,4 @@ namespace Atlas::Nodes::Variant::Model { }; -} \ No newline at end of file +} diff --git a/include/Atlas/nodes/node/variant/register.h b/include/Atlas/nodes/node/variant/register.h new file mode 100644 index 0000000..0f6bbdc --- /dev/null +++ b/include/Atlas/nodes/node/variant/register.h @@ -0,0 +1,12 @@ +#pragma once + + +#include +#include "QtNodes/NodeDelegateModelRegistry" + + +namespace Atlas::Nodes::Variant { + /// @brief registers all the variant models + /// @param registry the registry to register the models to + void register_all(const std::shared_ptr& registry); +} diff --git a/include/Atlas/nodes/variant/model/from_variant.h b/include/Atlas/nodes/variant/model/from_variant.h deleted file mode 100644 index 6f70f09..0000000 --- a/include/Atlas/nodes/variant/model/from_variant.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/include/utils/string.h b/include/utils/string.h new file mode 100644 index 0000000..8c3e627 --- /dev/null +++ b/include/utils/string.h @@ -0,0 +1,13 @@ +#pragma once + + +#include + + +namespace Utils::String { + /// @brief escapes a string + /// @details this function escapes a string so that it look like its c++ representation + /// @param str the string to escape + /// @return the escaped string + std::string escape(const std::string& string); +} diff --git a/source/Atlas/nodes/common/data.cpp b/source/Atlas/nodes/common/data.cpp deleted file mode 100644 index 4666f72..0000000 --- a/source/Atlas/nodes/common/data.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/source/Atlas/nodes/common/model/reduce.cpp b/source/Atlas/nodes/common/model/reduce.cpp deleted file mode 100644 index 8d8050c..0000000 --- a/source/Atlas/nodes/common/model/reduce.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/source/Atlas/nodes/decimal/model/to_variant.cpp b/source/Atlas/nodes/decimal/model/to_variant.cpp deleted file mode 100644 index b0fe2ef..0000000 --- a/source/Atlas/nodes/decimal/model/to_variant.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - - -using namespace Atlas::Nodes::Decimal::Model; - - -[[nodiscard]] QString ToVariant::name() const { - return QStringLiteral("Decimal to Variant"); -} -[[nodiscard]] QString ToVariant::caption() const { - return QStringLiteral("Decimal to Variant"); -} diff --git a/source/Atlas/nodes/node/base/data.cpp b/source/Atlas/nodes/node/base/data.cpp new file mode 100644 index 0000000..0ea5024 --- /dev/null +++ b/source/Atlas/nodes/node/base/data.cpp @@ -0,0 +1 @@ +#include "Atlas/nodes/node/base/data.h" diff --git a/source/Atlas/nodes/node/base/model/reduce.cpp b/source/Atlas/nodes/node/base/model/reduce.cpp new file mode 100644 index 0000000..1067db3 --- /dev/null +++ b/source/Atlas/nodes/node/base/model/reduce.cpp @@ -0,0 +1 @@ +#include "Atlas/nodes/node/base/model/reduce.h" diff --git a/source/Atlas/nodes/decimal/data.cpp b/source/Atlas/nodes/node/decimal/data.cpp similarity index 89% rename from source/Atlas/nodes/decimal/data.cpp rename to source/Atlas/nodes/node/decimal/data.cpp index ce2ebc9..4f89b4e 100644 --- a/source/Atlas/nodes/decimal/data.cpp +++ b/source/Atlas/nodes/node/decimal/data.cpp @@ -1,4 +1,4 @@ -#include "Atlas/nodes/decimal/data.h" +#include "Atlas/nodes/node/decimal/data.h" using namespace Atlas::Nodes::Decimal; diff --git a/source/Atlas/nodes/node/decimal/model/absolute.cpp b/source/Atlas/nodes/node/decimal/model/absolute.cpp new file mode 100644 index 0000000..c16bb08 --- /dev/null +++ b/source/Atlas/nodes/node/decimal/model/absolute.cpp @@ -0,0 +1,41 @@ +#include + + +using namespace Atlas::Nodes::Decimal::Model; + + +QString Absolute::name() const { + return QStringLiteral("Absolute"); +} + +QString Absolute::caption() const { + return QStringLiteral("Absolute"); +} + +unsigned int Absolute::nPorts(QtNodes::PortType portType) const { + return 1; +} + +QtNodes::NodeDataType Absolute::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const { + return Decimal::Data().type(); +} + +void Absolute::setInData(std::shared_ptr nodeData, const QtNodes::PortIndex portIndex) { + if (nodeData == nullptr) { + this->_output = nullptr; + } else { + std::shared_ptr casted_data = std::dynamic_pointer_cast(nodeData); + double value = std::abs(casted_data->value()); + this->_output = std::make_shared(value); + } + + Q_EMIT dataUpdated(0); +} + +std::shared_ptr Absolute::outData(const QtNodes::PortIndex port) { + return this->_output; +} + +QWidget *Absolute::embeddedWidget() { + return nullptr; +} diff --git a/source/Atlas/nodes/decimal/model/addition.cpp b/source/Atlas/nodes/node/decimal/model/addition.cpp similarity index 90% rename from source/Atlas/nodes/decimal/model/addition.cpp rename to source/Atlas/nodes/node/decimal/model/addition.cpp index 9ee7b86..bdd644b 100644 --- a/source/Atlas/nodes/decimal/model/addition.cpp +++ b/source/Atlas/nodes/node/decimal/model/addition.cpp @@ -1,4 +1,4 @@ -#include "Atlas/nodes/decimal/model/addition.h" +#include "Atlas/nodes/node/decimal/model/addition.h" using namespace Atlas::Nodes::Decimal::Model; diff --git a/source/Atlas/nodes/decimal/model/constant.cpp b/source/Atlas/nodes/node/decimal/model/constant.cpp similarity index 96% rename from source/Atlas/nodes/decimal/model/constant.cpp rename to source/Atlas/nodes/node/decimal/model/constant.cpp index 5082e0c..2c99283 100644 --- a/source/Atlas/nodes/decimal/model/constant.cpp +++ b/source/Atlas/nodes/node/decimal/model/constant.cpp @@ -1,7 +1,7 @@ #include #include -#include "Atlas/nodes/decimal/model/constant.h" +#include "Atlas/nodes/node/decimal/model/constant.h" using namespace Atlas::Nodes::Decimal::Model; diff --git a/source/Atlas/nodes/decimal/model/division.cpp b/source/Atlas/nodes/node/decimal/model/division.cpp similarity index 90% rename from source/Atlas/nodes/decimal/model/division.cpp rename to source/Atlas/nodes/node/decimal/model/division.cpp index 6343eac..d4b7146 100644 --- a/source/Atlas/nodes/decimal/model/division.cpp +++ b/source/Atlas/nodes/node/decimal/model/division.cpp @@ -1,4 +1,4 @@ -#include "Atlas/nodes/decimal/model/division.h" +#include "Atlas/nodes/node/decimal/model/division.h" using namespace Atlas::Nodes::Decimal::Model; diff --git a/source/Atlas/nodes/decimal/model/multiplication.cpp b/source/Atlas/nodes/node/decimal/model/multiplication.cpp similarity index 90% rename from source/Atlas/nodes/decimal/model/multiplication.cpp rename to source/Atlas/nodes/node/decimal/model/multiplication.cpp index 9f0ed97..98d5184 100644 --- a/source/Atlas/nodes/decimal/model/multiplication.cpp +++ b/source/Atlas/nodes/node/decimal/model/multiplication.cpp @@ -1,4 +1,4 @@ -#include "Atlas/nodes/decimal/model/multiplication.h" +#include "Atlas/nodes/node/decimal/model/multiplication.h" using namespace Atlas::Nodes::Decimal::Model; diff --git a/source/Atlas/nodes/decimal/model/subtraction.cpp b/source/Atlas/nodes/node/decimal/model/subtraction.cpp similarity index 90% rename from source/Atlas/nodes/decimal/model/subtraction.cpp rename to source/Atlas/nodes/node/decimal/model/subtraction.cpp index c3cd8b8..647a8b6 100644 --- a/source/Atlas/nodes/decimal/model/subtraction.cpp +++ b/source/Atlas/nodes/node/decimal/model/subtraction.cpp @@ -1,4 +1,4 @@ -#include "Atlas/nodes/decimal/model/subtraction.h" +#include "Atlas/nodes/node/decimal/model/subtraction.h" using namespace Atlas::Nodes::Decimal::Model; diff --git a/source/Atlas/nodes/node/decimal/model/to_variant.cpp b/source/Atlas/nodes/node/decimal/model/to_variant.cpp new file mode 100644 index 0000000..22412d2 --- /dev/null +++ b/source/Atlas/nodes/node/decimal/model/to_variant.cpp @@ -0,0 +1 @@ +#include "Atlas/nodes/node/variant/model/to_variant.h" diff --git a/source/Atlas/nodes/node/decimal/register.cpp b/source/Atlas/nodes/node/decimal/register.cpp new file mode 100644 index 0000000..9f535d0 --- /dev/null +++ b/source/Atlas/nodes/node/decimal/register.cpp @@ -0,0 +1,27 @@ +#include + + +#include "Atlas/nodes/node/decimal/model/constant.h" +#include "Atlas/nodes/node/decimal/model/to_variant.h" +#include "Atlas/nodes/node/decimal/model/addition.h" +#include "Atlas/nodes/node/decimal/model/subtraction.h" +#include "Atlas/nodes/node/decimal/model/multiplication.h" +#include "Atlas/nodes/node/decimal/model/division.h" +#include "Atlas/nodes/node/decimal/model/absolute.h" +#include "Atlas/nodes/node/decimal/data.h" + + +using namespace Atlas::Nodes::Decimal; + + +void Atlas::Nodes::Decimal::register_all(const std::shared_ptr& registry) { + QString category = Data().type().name; + + registry->registerModel(category); + registry->registerModel(category); + registry->registerModel(category); + registry->registerModel(category); + registry->registerModel(category); + registry->registerModel(category); + registry->registerModel(category); +} \ No newline at end of file diff --git a/source/Atlas/nodes/node/register.cpp b/source/Atlas/nodes/node/register.cpp new file mode 100644 index 0000000..6715635 --- /dev/null +++ b/source/Atlas/nodes/node/register.cpp @@ -0,0 +1,15 @@ +#include "Atlas/nodes/node/register.h" + +#include "Atlas/nodes/node/decimal/register.h" +#include "Atlas/nodes/node/string/register.h" +#include "Atlas/nodes/node/variant/register.h" + + +using namespace Atlas; + + +void Atlas::Nodes::register_all(const std::shared_ptr& registry) { + Nodes::Decimal::register_all(registry); + Nodes::String::register_all(registry); + Nodes::Variant::register_all(registry); +} \ No newline at end of file diff --git a/source/Atlas/nodes/node/string/data.cpp b/source/Atlas/nodes/node/string/data.cpp new file mode 100644 index 0000000..c3a3951 --- /dev/null +++ b/source/Atlas/nodes/node/string/data.cpp @@ -0,0 +1,22 @@ +#include "Atlas/nodes/node/string/data.h" +#include "utils/string.h" + + +using namespace Atlas::Nodes::String; + + + +Data::Data() : _value("") {} +Data::Data(std::string value) : _value(value) {} + +[[nodiscard]] std::string Data::value() const { + return this->_value; +} + +[[nodiscard]] QtNodes::NodeDataType Data::type() const { + return QtNodes::NodeDataType("string", "String"); +} + +QString Data::text() const { + return QString::fromStdString(Utils::String::escape(this->_value)); +} diff --git a/source/Atlas/nodes/node/string/model/constant.cpp b/source/Atlas/nodes/node/string/model/constant.cpp new file mode 100644 index 0000000..d01a116 --- /dev/null +++ b/source/Atlas/nodes/node/string/model/constant.cpp @@ -0,0 +1,54 @@ +#include +#include + +#include "Atlas/nodes/node/string/model/constant.h" + + +using namespace Atlas::Nodes::String; + + +Model::Constant::Constant() { + // initialise the line edit + this->_lineEdit = new QLineEdit(); + QObject::connect(this->_lineEdit, &QLineEdit::textChanged, this, &Constant::refresh); +} + + +Model::Constant::~Constant() { + // delete the line edit + delete this->_lineEdit; +} + + +QString Model::Constant::name() const { + return Data().type().name + QStringLiteral("::Constant"); +} + +QString Model::Constant::caption() const { + return QStringLiteral("Constant"); +} + +unsigned int Model::Constant::nPorts(QtNodes::PortType port_type) const { + return port_type == QtNodes::PortType::In ? 0 : 1; +} + +[[nodiscard]] QtNodes::NodeDataType Model::Constant::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const { + return String::Data().type(); +} + +std::shared_ptr Model::Constant::outData(QtNodes::PortIndex port) { + return std::make_shared(this->_value); +} + +void Model::Constant::setInData(std::shared_ptr data, QtNodes::PortIndex portIndex) { + Q_ASSERT(false && "No input, shouldn't be called"); +} + +void Model::Constant::refresh() { + this->_value = this->_lineEdit->text().toStdString(); // TODO: use the NodeData type for string directory on this->_output + Q_EMIT dataUpdated(0); +} + +QWidget* Model::Constant::embeddedWidget() { + return this->_lineEdit; +} diff --git a/source/Atlas/nodes/node/string/model/to_variant.cpp b/source/Atlas/nodes/node/string/model/to_variant.cpp new file mode 100644 index 0000000..22412d2 --- /dev/null +++ b/source/Atlas/nodes/node/string/model/to_variant.cpp @@ -0,0 +1 @@ +#include "Atlas/nodes/node/variant/model/to_variant.h" diff --git a/source/Atlas/nodes/node/string/register.cpp b/source/Atlas/nodes/node/string/register.cpp new file mode 100644 index 0000000..ca21829 --- /dev/null +++ b/source/Atlas/nodes/node/string/register.cpp @@ -0,0 +1,17 @@ +#include + + +#include "Atlas/nodes/node/string/data.h" +#include "Atlas/nodes/node/string/model/constant.h" +#include "Atlas/nodes/node/string/model/to_variant.h" + + +using namespace Atlas::Nodes::String; + + +void Atlas::Nodes::String::register_all(const std::shared_ptr& registry) { + QString category = Data().type().name; + + registry->registerModel(category); + registry->registerModel(category); +} diff --git a/source/Atlas/nodes/variant/data.cpp b/source/Atlas/nodes/node/variant/data.cpp similarity index 50% rename from source/Atlas/nodes/variant/data.cpp rename to source/Atlas/nodes/node/variant/data.cpp index 82742b3..643c947 100644 --- a/source/Atlas/nodes/variant/data.cpp +++ b/source/Atlas/nodes/node/variant/data.cpp @@ -1,15 +1,15 @@ -#include -#include +#include "Atlas/nodes/node/variant/data.h" +#include "Atlas/nodes/node/decimal/data.h" using namespace Atlas::Nodes::Variant; using namespace Atlas::Nodes; -Data::Data() : _data(std::make_shared(0.0)) {} // TODO: make this a null data type -Data::Data(const std::shared_ptr& data) : _data(data) {} +Data::Data() : _data(std::make_shared(0.0)) {} +Data::Data(const std::shared_ptr& data) : _data(data) {} -[[nodiscard]] std::shared_ptr Data::value() const { +[[nodiscard]] std::shared_ptr Data::value() const { return this->_data; } diff --git a/source/Atlas/nodes/variant/model/display.cpp b/source/Atlas/nodes/node/variant/model/display.cpp similarity index 95% rename from source/Atlas/nodes/variant/model/display.cpp rename to source/Atlas/nodes/node/variant/model/display.cpp index 6941ae2..a66e437 100644 --- a/source/Atlas/nodes/variant/model/display.cpp +++ b/source/Atlas/nodes/node/variant/model/display.cpp @@ -1,4 +1,4 @@ -#include "Atlas/nodes/variant/model/display.h" +#include "Atlas/nodes/node/variant/model/display.h" using namespace Atlas::Nodes; diff --git a/source/Atlas/nodes/node/variant/model/from_variant.cpp b/source/Atlas/nodes/node/variant/model/from_variant.cpp new file mode 100644 index 0000000..1f547de --- /dev/null +++ b/source/Atlas/nodes/node/variant/model/from_variant.cpp @@ -0,0 +1,40 @@ +#include "Atlas/nodes/node/variant/model/from_variant.h" + + +using namespace Atlas::Nodes::Variant::Model; + + +[[nodiscard]] QString FromVariant::name() const { + QString output_name = this->_input == nullptr ? QStringLiteral("...") : this->_input->value()->type().name; + return QStringLiteral("Variant to ") + output_name; +} +[[nodiscard]] QString FromVariant::caption() const { + QString output_name = this->_input == nullptr ? QStringLiteral("???") : this->_input->value()->type().name; + return QStringLiteral("Variant to ") + output_name; +} + +[[nodiscard]] unsigned int FromVariant::nPorts(QtNodes::PortType portType) const { + // a "from_variant" function only has one input and one output only if the input is set + return portType == QtNodes::PortType::In ? 1 : (this->_input == nullptr ? 0 : 1); +} + +[[nodiscard]] QtNodes::NodeDataType FromVariant::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const { +return portType == QtNodes::PortType::In ? Variant::Data().type() : this->_input->value()->type(); +} + +void FromVariant::setInData(std::shared_ptr data, QtNodes::PortIndex portIndex) { + // update the input + this->_input = data == nullptr ? nullptr : std::dynamic_pointer_cast(data); + // update the next nodes + if (this->_input != nullptr) Q_EMIT dataUpdated(0); +} + +std::shared_ptr FromVariant::outData(QtNodes::PortIndex portIndex) { + // return the last computed output + return this->_input->value(); +} + +QWidget* FromVariant::embeddedWidget() { + // reduced node doesn't have any embedded widget + return nullptr; +} diff --git a/source/Atlas/nodes/node/variant/model/to_variant.cpp b/source/Atlas/nodes/node/variant/model/to_variant.cpp new file mode 100644 index 0000000..22412d2 --- /dev/null +++ b/source/Atlas/nodes/node/variant/model/to_variant.cpp @@ -0,0 +1 @@ +#include "Atlas/nodes/node/variant/model/to_variant.h" diff --git a/source/Atlas/nodes/node/variant/register.cpp b/source/Atlas/nodes/node/variant/register.cpp new file mode 100644 index 0000000..f134b7a --- /dev/null +++ b/source/Atlas/nodes/node/variant/register.cpp @@ -0,0 +1,17 @@ +#include + + +#include "Atlas/nodes/node/variant/model/from_variant.h" +#include "Atlas/nodes/node/variant/model/display.h" +#include "Atlas/nodes/node/variant/data.h" + + +using namespace Atlas::Nodes::Variant; + + +void Atlas::Nodes::Variant::register_all(const std::shared_ptr& registry) { + QString category = Data().type().name; + + registry->registerModel(category); + registry->registerModel(category); +} \ No newline at end of file diff --git a/source/Atlas/nodes/variant/model/from_variant.cpp b/source/Atlas/nodes/variant/model/from_variant.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Atlas/nodes/variant/model/to_variant.cpp b/source/Atlas/nodes/variant/model/to_variant.cpp deleted file mode 100644 index 842e148..0000000 --- a/source/Atlas/nodes/variant/model/to_variant.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/source/main.cpp b/source/main.cpp index 277a21e..5fefb9f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,14 +8,7 @@ #include "QtNodes/DataFlowGraphicsScene" #include "QtNodes/DataFlowGraphModel" -#include "Atlas/nodes/decimal/data.h" -#include "Atlas/nodes/decimal/model/constant.h" -#include "Atlas/nodes/decimal/model/addition.h" -#include "Atlas/nodes/decimal/model/subtraction.h" -#include "Atlas/nodes/decimal/model/multiplication.h" -#include "Atlas/nodes/decimal/model/division.h" -#include "Atlas/nodes/variant/model/display.h" -#include "Atlas/nodes/decimal/model/to_variant.h" +#include "Atlas/nodes/node/register.h" using namespace Atlas; @@ -24,15 +17,13 @@ using namespace Atlas; int main(int argc, char *argv[]) { QApplication a(argc, argv); - // initialise the registry + // set up the registry std::shared_ptr registry = std::make_shared(); - registry->registerModel(QStringLiteral("Decimal")); - registry->registerModel(QStringLiteral("Decimal")); - registry->registerModel(QStringLiteral("Decimal")); - registry->registerModel(QStringLiteral("Decimal")); - registry->registerModel(QStringLiteral("Decimal")); - registry->registerModel(QStringLiteral("Decimal")); - registry->registerModel(QStringLiteral("Variant")); + // register all the models + Nodes::register_all(registry); + + // set up the graph + QtNodes::DataFlowGraphModel dataFlowGraphModel(registry); // TEST QWidget mainWidget; @@ -44,8 +35,6 @@ int main(int argc, char *argv[]) { auto *layout = new QVBoxLayout(&mainWidget); - QtNodes::DataFlowGraphModel dataFlowGraphModel(registry); - layout->addWidget(menuBar); auto scene = new QtNodes::DataFlowGraphicsScene(dataFlowGraphModel, &mainWidget); diff --git a/source/utils/string.cpp b/source/utils/string.cpp new file mode 100644 index 0000000..fd39916 --- /dev/null +++ b/source/utils/string.cpp @@ -0,0 +1,8 @@ +#include + +#include + + +std::string Utils::String::escape(const std::string& string) { + return "\"" + std::regex_replace(string, std::regex("\""), "\\\"") + "\""; +}