diff --git a/src/Dataflow/Core/DataflowGraph.cpp b/src/Dataflow/Core/DataflowGraph.cpp index 6fec67ec402..928d3270032 100644 --- a/src/Dataflow/Core/DataflowGraph.cpp +++ b/src/Dataflow/Core/DataflowGraph.cpp @@ -4,10 +4,14 @@ #include #include +#include + namespace Ra { namespace Dataflow { namespace Core { +using namespace Ra::Core::Utils; + DataflowGraph::DataflowGraph( const std::string& name ) : DataflowGraph( name, getTypename() ) {} DataflowGraph::DataflowGraph( const std::string& instanceName, const std::string& typeName ) : @@ -31,19 +35,7 @@ void DataflowGraph::init() { void DataflowGraph::execute() { if ( !m_ready ) { -#ifdef GRAPH_CALL_TRACE - std::cout << std::endl - << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": not ready to execute, recompile the graph." << std::endl; -#endif - if ( !compile() ) { -#ifdef GRAPH_CALL_TRACE - std::cout << std::endl - << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": unable tocompile the graph." << std::endl; -#endif - return; - } + if ( !compile() ) { return; } } std::for_each( m_nodesByLevel.begin(), m_nodesByLevel.end(), []( const auto& level ) { std::for_each( level.begin(), level.end(), []( auto node ) { node->execute(); } ); @@ -122,16 +114,13 @@ void DataflowGraph::toJsonInternal( nlohmann::json& data ) const { } bool DataflowGraph::loadFromJson( const std::string& jsonFilePath ) { - m_loadStatus = true; std::ifstream file( jsonFilePath ); nlohmann::json j; file >> j; - fromJson( j ); - return m_loadStatus; + return fromJson( j ); } -void DataflowGraph::fromJsonInternal( const nlohmann::json& data ) { - +bool DataflowGraph::fromJsonInternal( const nlohmann::json& data ) { if ( data.contains( "graph" ) ) { // indicate that the graph must be recompiled after loading m_recompile = true; @@ -146,17 +135,13 @@ void DataflowGraph::fromJsonInternal( const nlohmann::json& data ) { auto factory = NodeFactoriesManager::getFactory( factoryName ); if ( factory ) { addFactory( factory ); } else { - std::cerr << "DataflowGraph::loadFromJson : Unable to find a factory with name " - << factoryName << std::endl; - m_loadStatus = false; - return; + LOG( logERROR ) + << "DataflowGraph::loadFromJson : Unable to find a factory with name " + << factoryName; + return false; } } } - if ( !m_factories ) { - std::cerr << "DataflowGraph::loadFromJson : no node factories available !"; - return; - } std::unordered_map nodeById; auto nodes = data["graph"]["nodes"]; @@ -167,8 +152,8 @@ void DataflowGraph::fromJsonInternal( const nlohmann::json& data ) { auto newNode = m_factories->createNode( name, n, this ); if ( newNode ) { nodeById.emplace( id, newNode ); } else { - std::cerr << "Unable to create the node " << name << std::endl; - m_loadStatus = false; + LOG( logERROR ) << "Unable to create the node " << name; + return false; } } @@ -187,19 +172,19 @@ void DataflowGraph::fromJsonInternal( const nlohmann::json& data ) { fromOutput = nodeFrom->getOutputs()[fromIndex]->getName(); } else { - m_loadStatus = false; - std::cerr << "Error when reading JSON file \"" - << "\": Output index " << fromIndex << " for node \"" - << nodeFrom->getInstanceName() << " (" << nodeFrom->getTypeName() - << ")\" must be between 0 and " << nodeFrom->getOutputs().size() - 1 - << ". Link not added." << std::endl; + LOG( logERROR ) << "Error when reading JSON file \"" + << "\": Output index " << fromIndex << " for node \"" + << nodeFrom->getInstanceName() << " (" + << nodeFrom->getTypeName() << ")\" must be between 0 and " + << nodeFrom->getOutputs().size() - 1 << ". Link not added."; + return false; } } else { - m_loadStatus = false; - std::cerr << "Error when reading JSON file \"" - << "\": Could not find a node associated with id " << l["out_id"] - << ". Link not added." << std::endl; + LOG( logERROR ) << "Error when reading JSON file \"" + << "\": Could not find a node associated with id " << l["out_id"] + << ". Link not added."; + return false; } if ( nodeById.find( l["in_id"] ) != nodeById.end() ) { @@ -210,42 +195,38 @@ void DataflowGraph::fromJsonInternal( const nlohmann::json& data ) { toInput = nodeTo->getInputs()[toIndex]->getName(); } else { - m_loadStatus = false; - std::cerr << "Error when reading JSON file \"" - << "\": Input index " << toIndex << " for node \"" - << nodeFrom->getInstanceName() << " (" << nodeFrom->getTypeName() - << ")\" must be between 0 and " << nodeTo->getInputs().size() - 1 - << ". Link not added." << std::endl; + LOG( logERROR ) << "Error when reading JSON file \"" + << "\": Input index " << toIndex << " for node \"" + << nodeFrom->getInstanceName() << " (" + << nodeFrom->getTypeName() << ")\" must be between 0 and " + << nodeTo->getInputs().size() - 1 << ". Link not added."; + return false; } } else { - m_loadStatus = false; - std::cerr << "Error when reading JSON file \"" - << "\": Could not find a node associated with id " << l["in_id"] - << ". Link not added." << std::endl; + LOG( logERROR ) << "Error when reading JSON file \"" + << "\": Could not find a node associated with id " << l["in_id"] + << ". Link not added."; + return false; } if ( nodeFrom && ( fromOutput != "" ) && nodeTo && ( toInput != "" ) ) { addLink( nodeFrom, fromOutput, nodeTo, toInput ); } else { - m_loadStatus = false; - std::cerr + LOG( logERROR ) << "Error when reading JSON file \"" << "\": Could not add a link (missing or wrong information, please refer to " - "the previous error messages). Link not added." - << std::endl; + "the previous error messages). Link not added."; + return false; } } } + return true; } bool DataflowGraph::addNode( Node* newNode ) { std::map m_mapInputs; -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName << "\": trying to add node \"" - << newNode->getInstanceName() << "\"..." << std::endl; -#endif // Check if the new node already exists (= same name and type) if ( findNode( newNode ) == -1 ) { if ( newNode->getInputs().empty() ) { @@ -263,45 +244,19 @@ bool DataflowGraph::addNode( Node* newNode ) { } } m_nodes.emplace_back( newNode ); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": success adding node \"" << newNode->getInstanceName() << "\"!" - << std::endl; -#endif m_ready = false; return true; } else { -#ifdef GRAPH_CALL_TRACE - std::cerr << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": could not add node \"" << newNode->getInstanceName() - << "\" (node already exists)." << std::endl; -#endif return false; } } bool DataflowGraph::removeNode( Node* node ) { -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": trying to remove node \"" << node->getInstanceName() << "\"..." << std::endl; -#endif // Check if the new node already exists (= same name) int index = -1; - if ( ( index = findNode( node ) ) == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": could not remove node \"" << node->getInstanceName() - << "\" (node does not exist)." << std::endl; -#endif - return false; - } + if ( ( index = findNode( node ) ) == -1 ) { return false; } else { -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": success removing node \"" << node->getInstanceName() << "\"!" - << std::endl; -#endif if ( node->getInputs().empty() ) { // Check if it is a source node for ( auto& port : node->getInterfaces() ) { // Erase input ports of the graph associated @@ -337,29 +292,15 @@ bool DataflowGraph::addLink( Node* nodeFrom, const std::string& nodeFromOutputName, Node* nodeTo, const std::string& nodeToInputName ) { -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": ADD LINK : try to connect output \"" + nodeFromOutputName + "\" of node \"" + - nodeFrom->getInstanceName() + "\" to input \"" + nodeToInputName + - "\" of node \"" + nodeTo->getInstanceName() + "\"." - << std::endl; -#endif // Check node "from" existence in the graph if ( findNode( nodeFrom ) == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : node \"from\" \"" + nodeFrom->getInstanceName() + - "\" does not exist." - << std::endl; -#endif + LOG( logERROR ) << "DataflowGraph::addLink Unable to find initial node."; return false; } // Check node "to" existence in the graph if ( findNode( nodeTo ) == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : node \"to\" \"" + nodeTo->getInstanceName() + "\" does not exist." - << std::endl; -#endif + LOG( logERROR ) << "DataflowGraph::addLink Unable to find destination node."; return false; } @@ -374,11 +315,9 @@ bool DataflowGraph::addLink( Node* nodeFrom, index++; } if ( foundFrom == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : output \"" + nodeFromOutputName + "\" for node \"from\" \"" + - nodeFrom->getInstanceName() + "\" does not exist." - << std::endl; -#endif + LOG( logERROR ) << "DataflowGraph::addLink Unable to find output port " + << nodeFromOutputName << " from initial node " + << nodeFrom->getInstanceName(); return false; } @@ -393,60 +332,24 @@ bool DataflowGraph::addLink( Node* nodeFrom, index++; } if ( foundTo == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : input \"" + nodeToInputName + "\" for target node \"" + - nodeTo->getInstanceName() + "\" does not exist." - << std::endl; -#endif + LOG( logERROR ) << "DataflowGraph::addLink Unable to find input port " << nodeFromOutputName + << " from destination node " << nodeTo->getInstanceName(); return false; } // Compare types // TODO fix the variable naming ... if ( nodeTo->getInputs()[foundTo]->getType() != nodeFrom->getOutputs()[foundFrom]->getType() ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : cannot connect output \"" + nodeFromOutputName + "\" for node \"" + - nodeTo->getInstanceName() + "\" and input \"" + nodeToInputName + - "\" for node \"" + nodeFrom->getInstanceName() + - "\" : type mismatch : \n\t" - "Type to : " - << nodeTo->getInputs()[foundTo]->getTypeName() - << "\n\t" - "Type from : " - << nodeFrom->getOutputs()[foundFrom]->getTypeName() << "\n\t" << std::endl; -#endif return false; } // Check if input is connected - if ( nodeTo->getInputs()[foundTo]->isLinked() ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : cannot connect output \"" + nodeFromOutputName + "\" for node \"" + - nodeTo->getInstanceName() + "\" and input \"" + nodeToInputName + - "\" for node \"" + nodeFrom->getInstanceName() + - "\" : input already connected." - << std::endl; -#endif - return false; - } + if ( nodeTo->getInputs()[foundTo]->isLinked() ) { return false; } // Try to connect ports if ( !nodeTo->getInputs()[foundTo]->connect( nodeFrom->getOutputs()[foundFrom].get() ) ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "ADD LINK : cannot connect output \"" + nodeFromOutputName + "\" for node \"" + - nodeTo->getInstanceName() + "\" and input \"" + nodeToInputName + - "\" for node \"" + nodeFrom->getInstanceName() + "\"." - << std::endl; -#endif return false; } -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": ADD LINK : success connecting output \"" + nodeFromOutputName + - "\" of node \"" + nodeFrom->getInstanceName() + "\" to input \"" + - nodeToInputName + "\" of node \"" + nodeTo->getInstanceName() + "\"." - << std::endl; -#endif // The state of the graph changes, set it to not ready m_ready = false; return true; @@ -454,13 +357,7 @@ bool DataflowGraph::addLink( Node* nodeFrom, bool DataflowGraph::removeLink( Node* node, const std::string& nodeInputName ) { // Check node's existence in the graph - if ( findNode( node ) == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "REMOVE LINK : node \"" + node->getInstanceName() + "\" does not exist." - << std::endl; -#endif - return false; - } + if ( findNode( node ) == -1 ) { return false; } // Check if node's input exists int found = -1; @@ -472,22 +369,9 @@ bool DataflowGraph::removeLink( Node* node, const std::string& nodeInputName ) { } index++; } - if ( found == -1 ) { -#ifdef GRAPH_CALL_TRACE - std::cerr << "REMOVE LINK : input \"" + nodeInputName + "\" for target node \"" + - node->getInstanceName() + "\" does not exist." - << std::endl; -#endif - return false; - } + if ( found == -1 ) { return false; } node->getInputs()[found]->disconnect(); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": REMOVE LINK : success disconnecting input \"" + nodeInputName + - "\" of node \"" + node->getInstanceName() + "\"." - << std::endl; -#endif return true; } @@ -500,11 +384,6 @@ int DataflowGraph::findNode( const Node* node ) { } bool DataflowGraph::compile() { -#ifdef GRAPH_CALL_TRACE - std::cout << std::endl - << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName << "\": begin compilation." - << std::endl; -#endif // Find useful nodes (directly or indirectly connected to a Sink) std::unordered_map>> infoNodes; for ( auto const& n : m_nodes ) { @@ -522,11 +401,6 @@ bool DataflowGraph::compile() { } } } -#ifdef GRAPH_CALL_TRACE - std::cout << std::endl - << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName << "\": useful nodes found." - << std::endl; -#endif // Compute the level (rank of execution) of useful nodes int maxLevel = 0; for ( auto& infNode : infoNodes ) { @@ -544,11 +418,6 @@ bool DataflowGraph::compile() { } } } -#ifdef GRAPH_CALL_TRACE - std::cout << std::endl - << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName << "\": nodes level computed." - << std::endl; -#endif m_nodesByLevel.clear(); m_nodesByLevel.resize( infoNodes.size() != 0 ? maxLevel + 1 : 0 ); for ( auto& infNode : infoNodes ) { @@ -564,22 +433,11 @@ bool DataflowGraph::compile() { for ( size_t k = 0; k < lvl[j]->getInputs().size(); k++ ) { if ( lvl[j]->getInputs()[k]->isLinkMandatory() && !lvl[j]->getInputs()[k]->isLinked() ) { -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName - << "\": compilation failed, node " << lvl[j]->getInstanceName() - << " has mandatory port " << lvl[j]->getInputs()[k]->getName() - << " not linked." << std::endl; -#endif return m_ready = false; } } } } -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[32m\e[1mDataflowGraph\e[0m \"" << m_instanceName << "\": end compilation." - << std::endl - << std::endl; -#endif m_recompile = false; m_ready = true; init(); @@ -697,11 +555,6 @@ std::shared_ptr DataflowGraph::getDataSetter( std::string portName ) { p->connect( in ); return p; } -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[36m\e[1mDataflowGraph::graphGetInput \e[0m \"" - << "Error, can't generate the interface node for graph input " << portName - << std::endl; -#endif return nullptr; } @@ -721,11 +574,6 @@ PortBase* DataflowGraph::getDataGetter( std::string portName ) { for ( auto& portOut : m_outputs ) { if ( portOut->getName() == portName ) { return portOut.get(); } } -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[36m\e[1mDataflowGraph::graphGetOutput \e[0m \"" - << "Error, can't generate the interface node for graph output " << portName - << std::endl; -#endif return nullptr; } @@ -742,8 +590,8 @@ Node* DataflowGraph::getNode( const std::string& instanceNameNode ) { for ( const auto& node : m_nodes ) { if ( node->getInstanceName() == instanceNameNode ) { return node.get(); } } - std::cerr << getTypename() + ": The node with the instance name " + instanceNameNode + - " has not been found"; + LOG( logERROR ) << "DataflowGraph::getNode : The node with the instance name " + << instanceNameNode << " has not been found"; return nullptr; } diff --git a/src/Dataflow/Core/DataflowGraph.hpp b/src/Dataflow/Core/DataflowGraph.hpp index bf5f624fcdc..8c545ff63d0 100644 --- a/src/Dataflow/Core/DataflowGraph.hpp +++ b/src/Dataflow/Core/DataflowGraph.hpp @@ -150,7 +150,7 @@ class RA_DATAFLOW_API DataflowGraph : public Node */ DataflowGraph( const std::string& instanceName, const std::string& typeName ); - void fromJsonInternal( const nlohmann::json& ) override; + bool fromJsonInternal( const nlohmann::json& data ) override; void toJsonInternal( nlohmann::json& ) const override; private: @@ -193,9 +193,6 @@ class RA_DATAFLOW_API DataflowGraph : public Node /// \param out The port to add. bool addGetter( PortBase* out ); - /// Loding status. Set tu true when starting loading, set to false if some nodes can't be laoded - bool m_loadStatus { true }; - public: static const std::string& getTypename(); }; diff --git a/src/Dataflow/Core/Node.cpp b/src/Dataflow/Core/Node.cpp index 62d4665abbb..2905fc1ed76 100644 --- a/src/Dataflow/Core/Node.cpp +++ b/src/Dataflow/Core/Node.cpp @@ -28,23 +28,7 @@ void Node::generateUuid() { } /// Gets the UUID of the node as a string std::string Node::getUuid() const { - if ( m_uuid.is_nil() ) { - // generates the uuid (need to remove const attribute) ... - const_cast( this )->generateUuid(); - } - std::string struuid = "{" + uuids::to_string( m_uuid ) + "}"; - return struuid; -} - -bool Node::setUuid( const std::string& uid ) { - if ( m_uuid.is_nil() ) { - auto id = uuids::uuid::from_string( uid ); - if ( id ) { - m_uuid = id.value(); - return true; - } - } - return false; + return std::string { "{" } + uuids::to_string( m_uuid ) + "}"; } Node::Node( const std::string& instanceName, const std::string& typeName ) : @@ -52,25 +36,33 @@ Node::Node( const std::string& instanceName, const std::string& typeName ) : generateUuid(); } -void Node::fromJson( const nlohmann::json& data ) { +bool Node::fromJson( const nlohmann::json& data ) { + if ( data.contains( "model" ) ) { + if ( data["model"].contains( "instance" ) ) { m_instanceName = data["model"]["instance"]; } + } + else { + LOG( logERROR ) << "Missing required model when loading a Dataflow::Node"; + return false; + } // get the common content of the Node from the json data if ( data.contains( "id" ) ) { std::string struuid = data["id"]; m_uuid = uuids::uuid::from_string( struuid ).value(); } else { - generateUuid(); - } - if ( data.contains( "model" ) ) { - if ( data["model"].contains( "instance" ) ) { m_instanceName = data["model"]["instance"]; } - // get the specific concrete node informations - const auto& datamodel = data["model"]; - fromJsonInternal( datamodel ); + LOG( logERROR ) << "Missing required uuid when loading node " << m_instanceName; + return false; } + + // get the specific concrete node information + const auto& datamodel = data["model"]; + auto loaded = fromJsonInternal( datamodel ); + // get the supplemental informations related to application/gui/... for ( auto& [key, value] : data.items() ) { if ( key != "id" && key != "model" ) { m_extraJsonData.emplace( key, value ); } } + return loaded; } void Node::toJson( nlohmann::json& data ) const { diff --git a/src/Dataflow/Core/Node.hpp b/src/Dataflow/Core/Node.hpp index 64411338611..36e1073b00c 100644 --- a/src/Dataflow/Core/Node.hpp +++ b/src/Dataflow/Core/Node.hpp @@ -106,10 +106,6 @@ class RA_DATAFLOW_API Node /// \brief Gets the UUID of the node as a string std::string getUuid() const; - /// \brief Sets the UUID of the node from a valid uuid string - /// \return true if the uuid is set, false if the node already have a valid uid or the string is - /// invalid - bool setUuid( const std::string& uid ); /// @} /// \name Serialization of a node @@ -122,7 +118,7 @@ class RA_DATAFLOW_API Node /// \brief unserialized the content of the node. /// Fill the node from its json representation - void fromJson( const nlohmann::json& data ); + bool fromJson( const nlohmann::json& data ); /// \brief Add a metadata to the node to store application specific information. /// used, e.g. by the node editor gui to save node position in the graphical canvas. @@ -148,7 +144,7 @@ class RA_DATAFLOW_API Node /// Must be implemented by inheriting classes. /// Be careful with template specialization and function member overriding when implementing /// this method. - virtual void fromJsonInternal( const nlohmann::json& ) = 0; + virtual bool fromJsonInternal( const nlohmann::json& ) = 0; /// internal json representation of the Node. /// Must be implemented by inheriting classes. diff --git a/src/Dataflow/Core/Node.inl b/src/Dataflow/Core/Node.inl index b4da91f6298..87a8cd5dd31 100644 --- a/src/Dataflow/Core/Node.inl +++ b/src/Dataflow/Core/Node.inl @@ -8,18 +8,10 @@ namespace Dataflow { namespace Core { inline void Node::init() { -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[34m\e[1m" << getTypeName() << "\e[0m \"" << m_instanceName - << "\": initialization." << std::endl; -#endif m_initialized = true; } inline void Node::destroy() { -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[34m\e[1m" << getTypeName() << "\e[0m \"" << m_instanceName << "\": destroy." - << std::endl; -#endif m_interface.clear(); m_inputs.clear(); m_outputs.clear(); diff --git a/src/Dataflow/Core/NodeFactory.cpp b/src/Dataflow/Core/NodeFactory.cpp index 5be1f667b26..f8c3cc6444f 100644 --- a/src/Dataflow/Core/NodeFactory.cpp +++ b/src/Dataflow/Core/NodeFactory.cpp @@ -27,15 +27,6 @@ Node* NodeFactory::createNode( std::string& nodeType, if ( owningGraph != nullptr ) { owningGraph->addNode( node ); } return node; } -#if 0 - else { - std::cerr << "NodeFactory: no defined node for type " << nodeType << "." << std::endl; - std::cerr << "Available nodes are : " << std::endl; - for ( const auto& e : m_nodesCreators ) { - std::cerr << "\t" << e.first << std::endl; - } - } -#endif return nullptr; } @@ -47,11 +38,10 @@ bool NodeFactory::registerNodeCreator( std::string nodeType, m_nodesCreators[nodeType] = { std::move( nodeCreator ), nodeCategory }; return true; } - else { - std::cerr << "NodeFactory: trying to add an already existing node creator for type " - << nodeType << "." << std::endl; - return false; - } + LOG( Ra::Core::Utils::logWARNING ) + << "NodeFactory: trying to add an already existing node creator for type " << nodeType + << "."; + return false; } size_t NodeFactory::nextNodeId() { @@ -70,11 +60,8 @@ Node* NodeFactorySet::createNode( std::string& nodeType, auto node = it.second->createNode( nodeType, data, owningGraph ); if ( node ) { return node; } } - std::cerr << "NodeFactorySet: unable to find constructor for " << nodeType - << " in any of the following factories :" << std::endl; - for ( const auto& it : m_factories ) { - std::cerr << "\t" << it.first << std::endl; - } + LOG( Ra::Core::Utils::logERROR ) << "NodeFactorySet: unable to find constructor for " + << nodeType << " in any managed factory."; return nullptr; } diff --git a/src/Dataflow/Core/Nodes/Functionals/BinaryOpNode.hpp b/src/Dataflow/Core/Nodes/Functionals/BinaryOpNode.hpp index 4d15563d8a1..373e06c9421 100644 --- a/src/Dataflow/Core/Nodes/Functionals/BinaryOpNode.hpp +++ b/src/Dataflow/Core/Nodes/Functionals/BinaryOpNode.hpp @@ -216,9 +216,10 @@ class BinaryOpNode : public Node << "Unable to save data when serializing a " << getTypeName() << "."; } - void fromJsonInternal( const nlohmann::json& ) override { + bool fromJsonInternal( const nlohmann::json& ) override { LOG( Ra::Core::Utils::logDEBUG ) << "Unable to read data when un-serializing a " << getTypeName() << "."; + return true; } private: diff --git a/src/Dataflow/Core/Nodes/Functionals/FilterNode.hpp b/src/Dataflow/Core/Nodes/Functionals/FilterNode.hpp index c4233b3dc26..89cece758fd 100644 --- a/src/Dataflow/Core/Nodes/Functionals/FilterNode.hpp +++ b/src/Dataflow/Core/Nodes/Functionals/FilterNode.hpp @@ -59,7 +59,7 @@ class FilterNode : public Node UnaryPredicate predicate ); void toJsonInternal( nlohmann::json& data ) const override; - void fromJsonInternal( const nlohmann::json& data ) override; + bool fromJsonInternal( const nlohmann::json& ) override; private: UnaryPredicate m_predicate; diff --git a/src/Dataflow/Core/Nodes/Functionals/FilterNode.inl b/src/Dataflow/Core/Nodes/Functionals/FilterNode.inl index 8524d2eff85..3799b5150ff 100644 --- a/src/Dataflow/Core/Nodes/Functionals/FilterNode.inl +++ b/src/Dataflow/Core/Nodes/Functionals/FilterNode.inl @@ -37,11 +37,6 @@ void FilterNode::execute() { // m_elements.reserve( inData.size() ); // --> this is not a requirement of // SequenceContainer std::copy_if( inData.begin(), inData.end(), std::back_inserter( m_elements ), f ); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[36m\e[1mFilterNode \e[0m \"" << m_instanceName << "\": execute, from " - << input->getData().size() << " to " << m_elements.size() << " " - << typeid( T ).name() << "." << std::endl; -#endif } } @@ -73,9 +68,10 @@ void FilterNode::toJsonInternal( nlohmann::json& data ) const { } template -void FilterNode::fromJsonInternal( const nlohmann::json& ) { +bool FilterNode::fromJsonInternal( const nlohmann::json& ) { LOG( Ra::Core::Utils::logWARNING ) // TODO make this logDEBUG << "Unable to read data when un-serializing a " << getTypeName() << "."; + return true; } } // namespace Functionals diff --git a/src/Dataflow/Core/Nodes/Functionals/ReduceNode.hpp b/src/Dataflow/Core/Nodes/Functionals/ReduceNode.hpp index 1a8d61be862..d881133dacd 100644 --- a/src/Dataflow/Core/Nodes/Functionals/ReduceNode.hpp +++ b/src/Dataflow/Core/Nodes/Functionals/ReduceNode.hpp @@ -65,7 +65,7 @@ class ReduceNode : public Node v_t initialValue ); void toJsonInternal( nlohmann::json& data ) const override; - void fromJsonInternal( const nlohmann::json& data ) override; + bool fromJsonInternal( const nlohmann::json& ) override; private: ReduceOperator m_operator; diff --git a/src/Dataflow/Core/Nodes/Functionals/ReduceNode.inl b/src/Dataflow/Core/Nodes/Functionals/ReduceNode.inl index 2f60ad24f3b..e37e15aa51b 100644 --- a/src/Dataflow/Core/Nodes/Functionals/ReduceNode.inl +++ b/src/Dataflow/Core/Nodes/Functionals/ReduceNode.inl @@ -41,10 +41,6 @@ void ReduceNode::execute() { if ( m_portIn->isLinked() ) { const auto& inData = m_portIn->getData(); m_result = std::accumulate( inData.begin(), inData.end(), iv, f ); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[36m\e[1mMReduceNode \e[0m \"" << m_instanceName << "\": execute, from " - << input->getData().size() << " " << getTypename() << "." << std::endl; -#endif } } @@ -78,9 +74,10 @@ void ReduceNode::toJsonInternal( nlohmann::json& data ) const { } template -void ReduceNode::fromJsonInternal( const nlohmann::json& ) { +bool ReduceNode::fromJsonInternal( const nlohmann::json& ) { LOG( Ra::Core::Utils::logWARNING ) // TODO make this logDEBUG << "Unable to read data when un-serializing a " << getTypeName() << "."; + return true; } } // namespace Functionals diff --git a/src/Dataflow/Core/Nodes/Functionals/TransformNode.hpp b/src/Dataflow/Core/Nodes/Functionals/TransformNode.hpp index f8926bd071e..094ed2bbf06 100644 --- a/src/Dataflow/Core/Nodes/Functionals/TransformNode.hpp +++ b/src/Dataflow/Core/Nodes/Functionals/TransformNode.hpp @@ -56,7 +56,7 @@ class TransformNode : public Node TransformOperator op ); void toJsonInternal( nlohmann::json& data ) const override; - void fromJsonInternal( const nlohmann::json& data ) override; + bool fromJsonInternal( const nlohmann::json& ) override; private: TransformOperator m_operator; diff --git a/src/Dataflow/Core/Nodes/Functionals/TransformNode.inl b/src/Dataflow/Core/Nodes/Functionals/TransformNode.inl index 4e81f27b2e6..2a75f07b843 100644 --- a/src/Dataflow/Core/Nodes/Functionals/TransformNode.inl +++ b/src/Dataflow/Core/Nodes/Functionals/TransformNode.inl @@ -35,11 +35,6 @@ void TransformNode::execute() { // m_elements.reserve( inData.size() ); // --> this is not a requirement of // SequenceContainer std::transform( inData.begin(), inData.end(), std::back_inserter( m_elements ), f ); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[36m\e[1mMapNode \e[0m \"" << m_instanceName << "\": execute, from " - << input->getData().size() << " to " << m_elements.size() << " " - << typeid( T ).name() << "." << std::endl; -#endif } } @@ -70,9 +65,10 @@ void TransformNode::toJsonInternal( nlohmann::json& data ) const { } template -void TransformNode::fromJsonInternal( const nlohmann::json& ) { +bool TransformNode::fromJsonInternal( const nlohmann::json& ) { LOG( Ra::Core::Utils::logWARNING ) // TODO make this logDEBUG << "Unable to read data when un-serializing a " << getTypeName() << "."; + return true; } } // namespace Functionals diff --git a/src/Dataflow/Core/Nodes/Private/SourcesNodeFactory.cpp b/src/Dataflow/Core/Nodes/Private/SourcesNodeFactory.cpp index a0b904d0568..ab9e2d50611 100644 --- a/src/Dataflow/Core/Nodes/Private/SourcesNodeFactory.cpp +++ b/src/Dataflow/Core/Nodes/Private/SourcesNodeFactory.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace Ra { diff --git a/src/Dataflow/Core/Nodes/Sinks/SinkNode.hpp b/src/Dataflow/Core/Nodes/Sinks/SinkNode.hpp index f472e2b72ed..2d70bc2013e 100644 --- a/src/Dataflow/Core/Nodes/Sinks/SinkNode.hpp +++ b/src/Dataflow/Core/Nodes/Sinks/SinkNode.hpp @@ -34,9 +34,11 @@ class SinkNode : public Node protected: void toJsonInternal( nlohmann::json& data ) const override; - void fromJsonInternal( const nlohmann::json& data ) override; + bool fromJsonInternal( const nlohmann::json& data ) override; private: + /// \todo : allow user to specify where to store the data ? (i.e. make this a shared_ptr ?). + // If yes, add a method setDataStorage(std::shared_ptr v) T m_data; /// @{ diff --git a/src/Dataflow/Core/Nodes/Sinks/SinkNode.inl b/src/Dataflow/Core/Nodes/Sinks/SinkNode.inl index aeffc73b69e..51a765264af 100644 --- a/src/Dataflow/Core/Nodes/Sinks/SinkNode.inl +++ b/src/Dataflow/Core/Nodes/Sinks/SinkNode.inl @@ -27,10 +27,6 @@ void SinkNode::init() { template void SinkNode::execute() { m_data = m_portIn->getData(); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[33m\e[1m" << getTypename() << "\e[0m \"" << getInstanceName() << "\": execute." - << std::endl; -#endif } template @@ -51,10 +47,12 @@ const std::string& SinkNode::getTypename() { } template -void SinkNode::toJsonInternal( nlohmann::json& /*data*/ ) const {} +void SinkNode::toJsonInternal( nlohmann::json& ) const {} template -void SinkNode::fromJsonInternal( const nlohmann::json& /*data*/ ) {} +bool SinkNode::fromJsonInternal( const nlohmann::json& ) { + return true; +} } // namespace Sinks } // namespace Core diff --git a/src/Dataflow/Core/Nodes/Sources/CoreDataSources.hpp b/src/Dataflow/Core/Nodes/Sources/CoreDataSources.hpp index 73564e49971..4e345b83d83 100644 --- a/src/Dataflow/Core/Nodes/Sources/CoreDataSources.hpp +++ b/src/Dataflow/Core/Nodes/Sources/CoreDataSources.hpp @@ -67,11 +67,12 @@ DECLARE_COREDATA_SOURCES( Vector4ui, Vector4ui ); } \ \ template <> \ - inline void SingleDataSourceNode::fromJsonInternal( const nlohmann::json& data ) { \ + inline bool SingleDataSourceNode::fromJsonInternal( const nlohmann::json& data ) { \ if ( data.contains( #NAME ) ) { \ TYPE v = data[#NAME]; \ setData( v ); \ } \ + return true; \ } SPECIALIZE_EDITABLE_SOURCE( bool, boolean ); @@ -95,7 +96,7 @@ SingleDataSourceNode::toJsonInternal( nlohmann::json& da } template <> -inline void +inline bool SingleDataSourceNode::fromJsonInternal( const nlohmann::json& data ) { if ( data.contains( "color" ) ) { std::array c = data["color"]; @@ -103,6 +104,7 @@ SingleDataSourceNode::fromJsonInternal( const nlohmann:: Ra::Core::Utils::Color::sRGBToLinearRGB( Ra::Core::Utils::Color( c[0], c[1], c[2] ) ); setData( v ); } + return true; } #undef SPECIALIZE_EDITABLE_SOURCE diff --git a/src/Dataflow/Core/Nodes/Sources/FunctionSource.hpp b/src/Dataflow/Core/Nodes/Sources/FunctionSource.hpp index f23169787e5..c7cfc9b63ba 100644 --- a/src/Dataflow/Core/Nodes/Sources/FunctionSource.hpp +++ b/src/Dataflow/Core/Nodes/Sources/FunctionSource.hpp @@ -41,8 +41,8 @@ class FunctionSourceNode : public Node protected: FunctionSourceNode( const std::string& instanceName, const std::string& typeName ); - void fromJsonInternal( const nlohmann::json& ) override; - void toJsonInternal( nlohmann::json& ) const override; + bool fromJsonInternal( const nlohmann::json& ) override; + void toJsonInternal( nlohmann::json& data ) const override; /// @{ /// The data provided by the node diff --git a/src/Dataflow/Core/Nodes/Sources/FunctionSource.inl b/src/Dataflow/Core/Nodes/Sources/FunctionSource.inl index 558fde3313e..05791dfd494 100644 --- a/src/Dataflow/Core/Nodes/Sources/FunctionSource.inl +++ b/src/Dataflow/Core/Nodes/Sources/FunctionSource.inl @@ -22,10 +22,6 @@ void FunctionSourceNode::execute() { m_data = &m_localData; } m_portOut->setData( m_data ); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[34m\e[1mFunctionSourceNode\e[0m \"" << m_instanceName << "\": execute." - << std::endl; -#endif } template @@ -58,9 +54,10 @@ void FunctionSourceNode::toJsonInternal( nlohmann::json& data ) cons } template -void FunctionSourceNode::fromJsonInternal( const nlohmann::json& ) { +bool FunctionSourceNode::fromJsonInternal( const nlohmann::json& ) { LOG( Ra::Core::Utils::logDEBUG ) << "Unable to read data when un-serializing a " << getTypeName() << "."; + return true; } } // namespace Sources diff --git a/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.hpp b/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.hpp index 15bf9afca59..2356e82258d 100644 --- a/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.hpp +++ b/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.hpp @@ -59,8 +59,8 @@ class SingleDataSourceNode : public Node void removeEditable( const std::string& name = "Data" ); protected: - void fromJsonInternal( const nlohmann::json& ) override; - void toJsonInternal( nlohmann::json& ) const override; + bool fromJsonInternal( const nlohmann::json& ) override; + void toJsonInternal( nlohmann::json& data ) const override; /// @{ /// The data provided by the node diff --git a/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.inl b/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.inl index 5e956e0c556..e97a97945ee 100644 --- a/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.inl +++ b/src/Dataflow/Core/Nodes/Sources/SingleDataSourceNode.inl @@ -27,29 +27,17 @@ void SingleDataSourceNode::execute() { m_data = &m_localData; } m_portOut->setData( m_data ); -#ifdef GRAPH_CALL_TRACE - std::cout << "\e[34m\e[1mSingleDataSourceNode\e[0m \"" << m_instanceName << "\": execute." - << std::endl; -#endif } template void SingleDataSourceNode::setData( T* data ) { /// \warning this will copy data into local storage m_localData = *data; -#if 0 - m_data = &m_localData; - m_portOut->setData( m_data ); -#endif } template void SingleDataSourceNode::setData( T& data ) { m_localData = data; -#if 0 - m_data = &m_localData; - m_portOut->setData( m_data ); -#endif } template @@ -84,9 +72,10 @@ void SingleDataSourceNode::toJsonInternal( nlohmann::json& data ) const { } template -void SingleDataSourceNode::fromJsonInternal( const nlohmann::json& ) { +bool SingleDataSourceNode::fromJsonInternal( const nlohmann::json& ) { LOG( Ra::Core::Utils::logDEBUG ) << "Unable to read data when un-serializing a " << getTypeName() << "."; + return true; } } // namespace Sources diff --git a/src/Dataflow/Core/Port.inl b/src/Dataflow/Core/Port.inl index 2e1fe3f4254..4460cbd5650 100644 --- a/src/Dataflow/Core/Port.inl +++ b/src/Dataflow/Core/Port.inl @@ -97,16 +97,6 @@ void PortBase::setData( T* data ) { return; } } -#ifdef GRAPH_CALL_TRACE - if ( is_input() ) { - std::cout << "\e[41m\e[1mError, can't set data on the input port " << this->getName() - << "\e[0m" << std::endl; - } - else { - std::cout << "\e[41m\e[1mError, can't set data on the port of incompatible data type." - << this->getName() << "\e[0m" << std::endl; - } -#endif } template @@ -115,17 +105,6 @@ void PortBase::getData( T& t ) { auto thisOut = dynamic_cast*>( this ); if ( thisOut ) { t = thisOut->getData(); } } -#ifdef GRAPH_CALL_TRACE - if ( is_input() ) { - std::cout << "\e[41m\e[1mError, can't get data on the input port " << this->getName() - << "\e[0m" << std::endl; - } - else { - std::cout << "\e[41m\e[1mError, can't get data on the port of incompatible data type " - << this->getName() << " (" << this->getTypeName() << " vs " - << RadiumAddons::Core::Utils::demang() << ")\e[0m" << std::endl; - } -#endif } template @@ -134,7 +113,8 @@ T& PortBase::getData() { auto thisOut = dynamic_cast*>( this ); if ( thisOut ) { return thisOut->getData(); } } - std::cerr << "Could not call T& PortBase::getData() on an input port !!!\n"; + LOG( Ra::Core::Utils::logERROR ) + << "Could not call T& PortBase::getData() on an input port !!!\n"; std::abort(); }