text: #include "AdditionDataModel.h"
  #include <QtCore/QJsonValue>
  #include <QtGui/QDoubleValidator>
  #include "DataFloat.h"
  #include "DataVector2.h"
  #include "DataVector3.h"
  #include "DataVector4.h"
  #include "DataInvalid.h"
  #include "ShaderScene.h"
  #include "OperationRules.h"
  
  namespace DataFlowProgramming
  {
      AdditionDataModel::AdditionDataModel()
      {
          m_inputDataTypes = 
          {
              {"any", "A"},
              {"any", "B"},
          };
  
          m_inputs.resize(m_inputDataTypes.size());
  
          m_outputs.resize(1);
          m_outputs[0] = std::make_shared<DataInvalid>(this);
          m_outputs[0]->setVariableName(getVariableName());
      }
  
      QJsonObject AdditionDataModel::save() const
      {
          QJsonObject modelJson = NodeDataModel::save();
          return modelJson;
      }
  
      void AdditionDataModel::restore(QJsonObject const &p)
      {
      }
  
      unsigned int AdditionDataModel::nPorts(PortType portType) const
      {
          unsigned int result = 1;
  
          switch (portType)
          {
              case PortType::In: result = m_inputs.size(); break;
              case PortType::Out:result = m_outputs.size(); break;
              default:                       break;
          }
  
          return result;
      }
  
      NodeDataType AdditionDataModel::dataType(PortType portType, PortIndex portIndex) const
      {
          if(portType==PortType::In)
          {
              return m_inputDataTypes[portIndex];
          }
          else if (portType == PortType::Out)
          {
              return m_outputs[portIndex]->type();
          }
          
          return NodeDataType {"invalid", "invalid"};
      }
  
      std::shared_ptr<NodeData> AdditionDataModel::outData(PortIndex portIndex)
      {
          return m_outputs[portIndex];
      }
  
      void AdditionDataModel::setInData(std::shared_ptr<NodeData> nodeData, PortIndex portIndex)
      {
          m_inputs[portIndex] = std::dynamic_pointer_cast<ShaderData>(nodeData);
          if (m_inputs[0] && m_inputs[1])
          {
              m_outputs[0] = OperationRules::instance().NewAdditionOutput( DataAny::getInternalData(m_inputs[0])->type().id, DataAny::getInternalData(m_inputs[1])->type().id, this);
              m_outputs[0]->setVariableName(getVariableName());
          }
          else
          {
  			m_outputs[0] = std::make_shared<DataInvalid>(this);
  			m_outputs[0]->setVariableName(getVariableName());
          }
  
          checkValidation();
  
  		Q_EMIT dataUpdated(0);
      }
  
      bool AdditionDataModel::generateCode(ShaderCompiler& compiler)
      {
          if (m_inputs[0] && m_inputs[1])
          {
              compiler.addCode(Echo::StringUtil::Format("\t%s %s = %s + %s;\n",
                  m_outputs[0]->type().id.c_str(),
                  m_outputs[0]->getVariableName().c_str(),
                  DataAny::getInternalData(m_inputs[0])->getVariableName().c_str(),
                  DataAny::getInternalData(m_inputs[1])->getVariableName().c_str()));
          }
  
          return true;
      }
  }
  