<commit_before>#include <nanogui/layout.h>
#include "common.hpp"
#include "directpopup.hpp"
#include "clickablelabel.hpp"
#include "glshadersource.hpp"
#include "glshaderobject.hpp"
#include "graphnodelink.hpp"
#include "connector.hpp"
#include "graphnode.hpp"
#include "genericgraphnode.hpp"
#include "outputgraphnode.hpp"
#include "sink.hpp"
#include "qce.hpp"
#include "graph.hpp"


NAMESPACE_BEGIN(QCE);

Graph::Graph(Widget *parent, Qce *qce, const std::string &title) :
    Window(parent, title),
    mQce(qce),
    mPopup(nullptr),
    mActiveConnector(nullptr),
    mActiveNode(nullptr)
{
    mPopup = new DirectPopup(this, this);
    mPopup->setId("addPopup");
    mPopup->setSize(Eigen::Vector2i(10, 10));
    mPopup->setLayout(new nanogui::GroupLayout());
    mPopup->setVisible(false);

    mOutputNode = new OutputGraphNode(this, this, "Output");
}

void Graph::addNodeType(GLShaderSource *shaderSource)
{
    spdlog::get("qde")->debug(
        "Adding nodeType for selection: {}",
        shaderSource->name()
    );
    nanogui::ref<ClickableLabel> addNodeButton = new ClickableLabel(
        mPopup,
        fmt::format("Add {} node", shaderSource->name())
    );
    addNodeButton->setCallback([this, shaderSource](const Eigen::Vector2i &p) {
        addNodeButtonEvent(p, shaderSource);
    });
}

void Graph::calculateOutput()
{
    std::string nodeOuptut = mOutputNode->calculateOutput();
   
    if (!nodeOuptut.empty()) {
        std::string output = fmt::format(
            "result = {}", mOutputNode->calculateOutput()
        );
        spdlog::get("qde")->debug("Graph {}: Calculated and set output {}", id(), output);
        mQce->setShaderOutput(output);
    }
}

void Graph::nodeSelectedEvent(GraphNode *node)
{
    spdlog::get("qde")->debug("Graph: Node '{}' was selected", node->id());
    
    if (mActiveNode != nullptr) {
        mActiveNode->shaderObject()->hideForm();
    }
    
    auto shaderObject = node->shaderObject();
    if (shaderObject != nullptr) {
        if (shaderObject->hasProperties()) {
            spdlog::get("qde")->debug("Graph: Rendering properties of node '{}'", node->id());
            shaderObject->showForm();
            mActiveNode = node;
        }
    }
}

void Graph::nodeConnectedEvent(Connector *source, Connector *target)
{
    spdlog::get("qde")->debug("Graph: Source {} was connected to target {}", source->id(), target->id());
    
    auto shaderParameter = target->shaderParameter();
    if (shaderParameter != nullptr) {
        target->shaderParameter()->setInput(source->parent()->shaderObject());
    }
    mQce->addShaderToOutput(source->parent()->shaderObject());
}

bool Graph::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool down, int modifiers)<commit_msg>Add sanity check when trying to add shader to output<commit_after>#include <nanogui/layout.h>
#include "common.hpp"
#include "directpopup.hpp"
#include "clickablelabel.hpp"
#include "glshadersource.hpp"
#include "glshaderobject.hpp"
#include "graphnodelink.hpp"
#include "connector.hpp"
#include "graphnode.hpp"
#include "genericgraphnode.hpp"
#include "outputgraphnode.hpp"
#include "sink.hpp"
#include "qce.hpp"
#include "graph.hpp"


NAMESPACE_BEGIN(QCE);

Graph::Graph(Widget *parent, Qce *qce, const std::string &title) :
    Window(parent, title),
    mQce(qce),
    mPopup(nullptr),
    mActiveConnector(nullptr),
    mActiveNode(nullptr)
{
    mPopup = new DirectPopup(this, this);
    mPopup->setId("addPopup");
    mPopup->setSize(Eigen::Vector2i(10, 10));
    mPopup->setLayout(new nanogui::GroupLayout());
    mPopup->setVisible(false);

    mOutputNode = new OutputGraphNode(this, this, "Output");
}

void Graph::addNodeType(GLShaderSource *shaderSource)
{
    spdlog::get("qde")->debug(
        "Adding nodeType for selection: {}",
        shaderSource->name()
    );
    nanogui::ref<ClickableLabel> addNodeButton = new ClickableLabel(
        mPopup,
        fmt::format("Add {} node", shaderSource->name())
    );
    addNodeButton->setCallback([this, shaderSource](const Eigen::Vector2i &p) {
        addNodeButtonEvent(p, shaderSource);
    });
}

void Graph::calculateOutput()
{
    std::string nodeOuptut = mOutputNode->calculateOutput();
   
    if (!nodeOuptut.empty()) {
        std::string output = fmt::format(
            "result = {}", mOutputNode->calculateOutput()
        );
        spdlog::get("qde")->debug("Graph {}: Calculated and set output {}", id(), output);
        mQce->setShaderOutput(output);
    }
}

void Graph::nodeSelectedEvent(GraphNode *node)
{
    spdlog::get("qde")->debug("Graph: Node '{}' was selected", node->id());
    
    if (mActiveNode != nullptr) {
        mActiveNode->shaderObject()->hideForm();
    }
    
    auto shaderObject = node->shaderObject();
    if (shaderObject != nullptr) {
        if (shaderObject->hasProperties()) {
            spdlog::get("qde")->debug("Graph: Rendering properties of node '{}'", node->id());
            shaderObject->showForm();
            mActiveNode = node;
        }
    }
}

void Graph::nodeConnectedEvent(Connector *source, Connector *target)
{
    spdlog::get("qde")->debug("Graph: Source {} was connected to target {}", source->id(), target->id());
    
    auto shaderParameter = target->shaderParameter();
    
    // Set input to source shader object only if we actually have a shader set
    if (shaderParameter != nullptr) {
        target->shaderParameter()->setInput(source->parent()->shaderObject());
    }
    
    // Add shader source only if we actually have a shader set
    if (source->parent()->shaderObject() != nullptr) {
        mQce->addShaderToOutput(source->parent()->shaderObject());
    }
}

bool Graph::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool down, int modifiers)
{'fraction_non_alphanumeric': 0.1611785095320624, 'fraction_numerical': 0.0024263431542461003, 'mean_word_length': 3.8292887029288702, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '599945', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1844, 'n_words': 356}